java: Move contents of IdentityTest into TestStruct
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@928153 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/build.xml b/lib/java/build.xml
index 2a5c000..442caed 100644
--- a/lib/java/build.xml
+++ b/lib/java/build.xml
@@ -191,8 +191,6 @@
</target>
<target name="deprecated-test" description="Run the non-JUnit test suite" depends="compile-test">
- <java classname="org.apache.thrift.test.IdentityTest"
- classpathref="test.classpath" failonerror="true" />
<java classname="org.apache.thrift.test.EqualityTest"
classpathref="test.classpath" failonerror="true" />
<java classname="org.apache.thrift.test.ToStringTest"
diff --git a/lib/java/test/org/apache/thrift/TestStruct.java b/lib/java/test/org/apache/thrift/TestStruct.java
new file mode 100644
index 0000000..9ee305f
--- /dev/null
+++ b/lib/java/test/org/apache/thrift/TestStruct.java
@@ -0,0 +1,85 @@
+package org.apache.thrift;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.thrift.protocol.TBinaryProtocol;
+
+import thrift.test.HolyMoley;
+import thrift.test.JavaTestHelper;
+import thrift.test.Nesting;
+import thrift.test.OneOfEach;
+
+public class TestStruct extends TestCase {
+
+ public static Object deepCopyViaSerialization(Object oldObj) throws Exception {
+ ObjectOutputStream oos = null;
+ ObjectInputStream ois = null;
+ try {
+ ByteArrayOutputStream bos =
+ new ByteArrayOutputStream();
+ oos = new ObjectOutputStream(bos);
+ oos.writeObject(oldObj);
+ oos.flush();
+ ByteArrayInputStream bis =
+ new ByteArrayInputStream(bos.toByteArray());
+ ois = new ObjectInputStream(bis);
+ return ois.readObject();
+ } finally {
+ oos.close();
+ ois.close();
+ }
+ }
+
+ public void testIdentity() throws Exception {
+ TSerializer binarySerializer = new TSerializer(new TBinaryProtocol.Factory());
+ TDeserializer binaryDeserializer = new TDeserializer(new TBinaryProtocol.Factory());
+
+ OneOfEach ooe = Fixtures.oneOfEach;
+
+ Nesting n = new Nesting();
+ n.my_ooe = (OneOfEach)deepCopyViaSerialization(ooe);
+ n.my_ooe.integer16 = 16;
+ n.my_ooe.integer32 = 32;
+ n.my_ooe.integer64 = 64;
+ n.my_ooe.double_precision = (Math.sqrt(5)+1)/2;
+ n.my_ooe.some_characters = ":R (me going \"rrrr\")";
+ n.my_ooe.zomg_unicode = "\u04c0\u216e\u039d\u0020\u041d\u03bf\u217f"+
+ "\u043e\u0261\u0433\u0430\u03c1\u210e\u0020"+
+ "\u0391\u0074\u0074\u03b1\u217d\u03ba\u01c3"+
+ "\u203c";
+ n.my_bonk = Fixtures.nesting.my_bonk;
+
+ HolyMoley hm = Fixtures.holyMoley;
+
+ OneOfEach ooe2 = new OneOfEach();
+ binaryDeserializer.deserialize(
+ ooe2,
+ binarySerializer.serialize(ooe));
+
+ assertEquals(ooe, ooe2);
+ assertEquals(ooe.hashCode(), ooe2.hashCode());
+
+
+ Nesting n2 = new Nesting();
+ binaryDeserializer.deserialize(
+ n2,
+ binarySerializer.serialize(n));
+
+ assertEquals(n, n2);
+ assertEquals(n.hashCode(), n2.hashCode());
+
+ HolyMoley hm2 = new HolyMoley();
+ binaryDeserializer.deserialize(
+ hm2,
+ binarySerializer.serialize(hm));
+
+ assertEquals(hm, hm2);
+ assertEquals(hm.hashCode(), hm2.hashCode());
+ }
+}
diff --git a/lib/java/test/org/apache/thrift/test/IdentityTest.java b/lib/java/test/org/apache/thrift/test/IdentityTest.java
deleted file mode 100644
index d163ec8..0000000
--- a/lib/java/test/org/apache/thrift/test/IdentityTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.thrift.test;
-
-// Generated code
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-
-import org.apache.thrift.Fixtures;
-import org.apache.thrift.TDeserializer;
-import org.apache.thrift.TSerializer;
-import org.apache.thrift.protocol.TBinaryProtocol;
-
-import thrift.test.Bonk;
-import thrift.test.HolyMoley;
-import thrift.test.Nesting;
-import thrift.test.OneOfEach;
-
-/**
- *
- */
-public class IdentityTest {
- public static Object deepCopy(Object oldObj) throws Exception {
- ObjectOutputStream oos = null;
- ObjectInputStream ois = null;
- try {
- ByteArrayOutputStream bos =
- new ByteArrayOutputStream();
- oos = new ObjectOutputStream(bos);
- oos.writeObject(oldObj);
- oos.flush();
- ByteArrayInputStream bis =
- new ByteArrayInputStream(bos.toByteArray());
- ois = new ObjectInputStream(bis);
- return ois.readObject();
- } finally {
- oos.close();
- ois.close();
- }
- }
-
- public static void main(String[] args) throws Exception {
- TSerializer binarySerializer = new TSerializer(new TBinaryProtocol.Factory());
- TDeserializer binaryDeserializer = new TDeserializer(new TBinaryProtocol.Factory());
-
- OneOfEach ooe = Fixtures.oneOfEach;
-
- Nesting n = new Nesting();
- n.my_ooe = (OneOfEach)deepCopy(ooe);
- n.my_ooe.integer16 = 16;
- n.my_ooe.integer32 = 32;
- n.my_ooe.integer64 = 64;
- n.my_ooe.double_precision = (Math.sqrt(5)+1)/2;
- n.my_ooe.some_characters = ":R (me going \"rrrr\")";
- n.my_ooe.zomg_unicode = "\u04c0\u216e\u039d\u0020\u041d\u03bf\u217f"+
- "\u043e\u0261\u0433\u0430\u03c1\u210e\u0020"+
- "\u0391\u0074\u0074\u03b1\u217d\u03ba\u01c3"+
- "\u203c";
- n.my_bonk = Fixtures.nesting.my_bonk;
-
- HolyMoley hm = Fixtures.holyMoley;
-
- OneOfEach ooe2 = new OneOfEach();
- binaryDeserializer.deserialize(
- ooe2,
- binarySerializer.serialize(ooe));
-
- if (!ooe.equals(ooe2)) {
- throw new RuntimeException("Failure: ooe (equals)");
- }
- if (ooe.hashCode() != ooe2.hashCode()) {
- throw new RuntimeException("Failure: ooe (hash)");
- }
-
-
- Nesting n2 = new Nesting();
- binaryDeserializer.deserialize(
- n2,
- binarySerializer.serialize(n));
-
- if (!n.equals(n2)) {
- throw new RuntimeException("Failure: n (equals)");
- }
- if (n.hashCode() != n2.hashCode()) {
- throw new RuntimeException("Failure: n (hash)");
- }
-
- HolyMoley hm2 = new HolyMoley();
- binaryDeserializer.deserialize(
- hm2,
- binarySerializer.serialize(hm));
-
- if (!hm.equals(hm2)) {
- throw new RuntimeException("Failure: hm (equals)");
- }
- if (hm.hashCode() != hm2.hashCode()) {
- throw new RuntimeException("Failure: hm (hash)");
- }
-
- }
-}