Add all Serialize subclass tests

Project: 
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/commit/1a425dbf
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/tree/1a425dbf
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/diff/1a425dbf

Branch: refs/heads/jms-dev-1.1.0
Commit: 1a425dbf66fb79893be17540264b66b96d8b9d62
Parents: daa5626
Author: zhangke <zhangke_beij...@qq.com>
Authored: Tue Feb 28 19:00:46 2017 +0800
Committer: zhangke <zhangke_beij...@qq.com>
Committed: Tue Feb 28 19:00:46 2017 +0800

----------------------------------------------------------------------
 .../jms/msg/serialize/ObjectSerialize.java      |  5 +-
 .../jms/msg/serialize/MapSerializeTest.java     | 42 +++++++++++++
 .../jms/msg/serialize/ObjectSerializeTest.java  | 63 ++++++++++++++++++++
 .../jms/msg/serialize/StringSerializeTest.java  | 36 +++++++++++
 4 files changed, 144 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/1a425dbf/core/src/main/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerialize.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerialize.java 
b/core/src/main/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerialize.java
index 34e9c22..efa270c 100644
--- 
a/core/src/main/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerialize.java
+++ 
b/core/src/main/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerialize.java
@@ -24,6 +24,7 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import javax.jms.JMSException;
+import org.apache.commons.lang.exception.ExceptionUtils;
 
 public class ObjectSerialize implements Serialize<Object> {
 
@@ -46,7 +47,7 @@ public class ObjectSerialize implements Serialize<Object> {
             return baos.toByteArray();
         }
         catch (IOException e) {
-            throw new JMSException(e.getMessage());
+            throw new JMSException(ExceptionUtils.getStackTrace(e));
         }
     }
 
@@ -56,7 +57,7 @@ public class ObjectSerialize implements Serialize<Object> {
             ObjectInputStream ois = new ObjectInputStream(bais);
             ois.close();
             bais.close();
-            return (Serializable) ois.readObject();
+            return (Serializable)ois.readObject();
         }
         catch (IOException e) {
             throw new JMSException(e.getMessage());

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/1a425dbf/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/MapSerializeTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/MapSerializeTest.java
 
b/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/MapSerializeTest.java
new file mode 100644
index 0000000..5204fb3
--- /dev/null
+++ 
b/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/MapSerializeTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.rocketmq.jms.msg.serialize;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class MapSerializeTest {
+
+    @Test
+    public void serializeAndDeserialize() throws Exception {
+        Map map = new HashMap();
+        map.put("name", "John");
+        map.put("age", 20);
+
+        byte[] bytes = MapSerialize.instance().serialize(map);
+        Map newMap = MapSerialize.instance().deserialize(bytes);
+
+        assertThat(map.size(), is(newMap.size()));
+        assertThat(newMap.get("name").toString(), is("John"));
+        assertThat(newMap.get("age").toString(), is("20"));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/1a425dbf/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerializeTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerializeTest.java
 
b/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerializeTest.java
new file mode 100644
index 0000000..1661b08
--- /dev/null
+++ 
b/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerializeTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.rocketmq.jms.msg.serialize;
+
+import java.io.Serializable;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class ObjectSerializeTest {
+
+    @Test
+    public void serializeAndDeserialize() throws Exception {
+        Person person = new Person();
+        person.setName("John");
+        person.setAge(30);
+
+        byte[] bytes = ObjectSerialize.instance().serialize(person);
+        Person newPerson = 
(Person)ObjectSerialize.instance().deserialize(bytes);
+
+        assertThat(newPerson.getName(), is(person.getName()));
+        assertThat(newPerson.getAge(), is(person.getAge()));
+    }
+
+    private static class Person implements Serializable {
+        private static final long serialVersionUID = -4981805070659153282L;
+
+        private String name;
+        private int age;
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public int getAge() {
+            return age;
+        }
+
+        public void setAge(int age) {
+            this.age = age;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/1a425dbf/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/StringSerializeTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/StringSerializeTest.java
 
b/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/StringSerializeTest.java
new file mode 100644
index 0000000..4e6a54a
--- /dev/null
+++ 
b/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/StringSerializeTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.rocketmq.jms.msg.serialize;
+
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class StringSerializeTest {
+
+    @Test
+    public void serializeAndDeserialize() throws Exception {
+        String text = "MyText";
+
+        byte[] bytes = StringSerialize.instance().serialize(text);
+        String newText = StringSerialize.instance().deserialize(bytes);
+
+        assertThat(text, is(newText));
+    }
+}
\ No newline at end of file

Reply via email to