Fix test errors

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/40bf4ce3
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/tree/40bf4ce3
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/diff/40bf4ce3

Branch: refs/heads/jms-dev-1.1.0
Commit: 40bf4ce3c6672082805c3a132d367c8a13d6d021
Parents: 464cbc1
Author: zhangke <zhangke_beij...@qq.com>
Authored: Mon Feb 27 22:07:18 2017 +0800
Committer: zhangke <zhangke_beij...@qq.com>
Committed: Mon Feb 27 22:07:18 2017 +0800

----------------------------------------------------------------------
 .../org/apache/rocketmq/jms/RocketMQQueue.java  |   4 +
 .../rocketmq/jms/msg/JMSBytesMessage.java       |   4 +-
 .../jms/msg/convert/JMS2RMQMessageConvert.java  |   1 +
 .../rocketmq/jms/msg/JMSBytesMessageTest.java   | 107 +++++++++++++++++++
 .../rocketmq/jms/msg/JMSObjectMessageTest.java  |  73 +++++++++++++
 .../rocketmq/jms/msg/JMSTextMessageTest.java    |  41 +++++++
 .../jms/msg/RocketMQBytesMessageTest.java       | 107 -------------------
 .../jms/msg/RocketMQObjectMessageTest.java      |  73 -------------
 .../jms/msg/RocketMQTextMessageTest.java        |  41 -------
 9 files changed, 227 insertions(+), 224 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/40bf4ce3/core/src/main/java/org/apache/rocketmq/jms/RocketMQQueue.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/rocketmq/jms/RocketMQQueue.java 
b/core/src/main/java/org/apache/rocketmq/jms/RocketMQQueue.java
index 8570040..bec021e 100644
--- a/core/src/main/java/org/apache/rocketmq/jms/RocketMQQueue.java
+++ b/core/src/main/java/org/apache/rocketmq/jms/RocketMQQueue.java
@@ -32,4 +32,8 @@ public class RocketMQQueue implements Queue {
     public String getQueueName() throws JMSException {
         return this.name;
     }
+
+    @Override public String toString() {
+        return this.name;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/40bf4ce3/core/src/main/java/org/apache/rocketmq/jms/msg/JMSBytesMessage.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/rocketmq/jms/msg/JMSBytesMessage.java 
b/core/src/main/java/org/apache/rocketmq/jms/msg/JMSBytesMessage.java
index 1e40b40..169088c 100644
--- a/core/src/main/java/org/apache/rocketmq/jms/msg/JMSBytesMessage.java
+++ b/core/src/main/java/org/apache/rocketmq/jms/msg/JMSBytesMessage.java
@@ -91,9 +91,7 @@ public class JMSBytesMessage extends AbstractJMSMessage 
implements javax.jms.Byt
     }
 
     @Override public byte[] getBody() throws JMSException {
-        byte[] result = Arrays.copyOf(bytesIn, bytesIn.length);
-        this.reset();
-        return result;
+        return getBody(byte[].class);
     }
 
     @Override public boolean isBodyAssignableTo(Class c) throws JMSException {

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/40bf4ce3/core/src/main/java/org/apache/rocketmq/jms/msg/convert/JMS2RMQMessageConvert.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/rocketmq/jms/msg/convert/JMS2RMQMessageConvert.java
 
b/core/src/main/java/org/apache/rocketmq/jms/msg/convert/JMS2RMQMessageConvert.java
index cf7d975..2dd4977 100644
--- 
a/core/src/main/java/org/apache/rocketmq/jms/msg/convert/JMS2RMQMessageConvert.java
+++ 
b/core/src/main/java/org/apache/rocketmq/jms/msg/convert/JMS2RMQMessageConvert.java
@@ -42,6 +42,7 @@ public class JMS2RMQMessageConvert {
     }
 
     private static void handleHeader(AbstractJMSMessage jmsMsg, MessageExt 
rmqMsg) {
+        rmqMsg.setTopic(jmsMsg.getJMSDestination().toString());
         rmqMsg.putUserProperty(JMSMessageID.name(), jmsMsg.getJMSMessageID());
         rmqMsg.setBornTimestamp(jmsMsg.getJMSTimestamp());
         rmqMsg.putUserProperty(JMSExpiration.name(), 
String.valueOf(jmsMsg.getJMSExpiration()));

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/40bf4ce3/core/src/test/java/org/apache/rocketmq/jms/msg/JMSBytesMessageTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSBytesMessageTest.java 
b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSBytesMessageTest.java
new file mode 100644
index 0000000..a56602c
--- /dev/null
+++ b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSBytesMessageTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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;
+
+import javax.jms.MessageNotReadableException;
+import javax.jms.MessageNotWriteableException;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class JMSBytesMessageTest {
+
+    private byte[] receiveData = "receive data test".getBytes();
+    private byte[] sendData = "send data test".getBytes();
+
+    @Test
+    public void testGetData() throws Exception {
+        JMSBytesMessage readMessage = new JMSBytesMessage(receiveData);
+        assertThat(new String(receiveData), is(new 
String(readMessage.getBody())));
+
+        JMSBytesMessage sendMessage = new JMSBytesMessage();
+        sendMessage.writeBytes(sendData, 0, sendData.length);
+        assertThat(new String(sendData), is(new 
String(sendMessage.getBody())));
+    }
+
+    @Test
+    public void testGetBodyLength() throws Exception {
+        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
+        assertThat(msg.getBodyLength(), is(new Long(receiveData.length)));
+    }
+
+    @Test
+    public void testReadBytes1() throws Exception {
+        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
+        byte[] receiveValue = new byte[receiveData.length];
+        msg.readBytes(receiveValue);
+        assertThat(new String(receiveValue), is(new String(receiveData)));
+
+    }
+
+    @Test
+    public void testReadBytes2() throws Exception {
+        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
+
+        byte[] receiveValue1 = new byte[2];
+        msg.readBytes(receiveValue1);
+        assertThat(new String(receiveData).substring(0, 2), is(new 
String(receiveValue1)));
+
+        byte[] receiveValue2 = new byte[2];
+        msg.readBytes(receiveValue2);
+        assertThat(new String(receiveData).substring(2, 4), is(new 
String(receiveValue2)));
+
+    }
+
+    @Test
+    public void testWriteBytes() throws Exception {
+        JMSBytesMessage msg = new JMSBytesMessage();
+        msg.writeBytes(sendData);
+        assertThat(new String(msg.getBody()), is(new String(sendData)));
+    }
+
+    @Test(expected = MessageNotReadableException.class)
+    public void testNotReadableException() throws Exception {
+        JMSBytesMessage msg = new JMSBytesMessage();
+        msg.writeBoolean(true);
+        msg.readBoolean();
+    }
+
+    @Test(expected = MessageNotWriteableException.class)
+    public void testNotWritableException() throws Exception {
+        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
+        msg.writeBoolean(true);
+    }
+
+    @Test
+    public void testClearBody() throws Exception {
+        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
+        msg.clearBody();
+        msg.writeBoolean(true);
+    }
+
+    @Test
+    public void testReset() throws Exception {
+        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
+        byte[] b = new byte[2];
+        msg.readBytes(b);
+        msg.reset();
+        msg.readBytes(b);
+        assertThat(new String(receiveData).substring(0, 2), is(new String(b)));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/40bf4ce3/core/src/test/java/org/apache/rocketmq/jms/msg/JMSObjectMessageTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSObjectMessageTest.java 
b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSObjectMessageTest.java
new file mode 100644
index 0000000..63c03ae
--- /dev/null
+++ b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSObjectMessageTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class JMSObjectMessageTest {
+
+    @Test
+    public void testGetObject() throws Exception {
+        final User user = new User("jack", 20);
+        JMSObjectMessage msg = new JMSObjectMessage(user);
+        assertThat((User)msg.getObject(), is(user));
+    }
+
+    @Test
+    public void testGetBody() throws Exception {
+        final User user = new User("jack", 20);
+        JMSObjectMessage msg = new JMSObjectMessage(user);
+        assertThat((User)msg.getBody(Object.class), is((User)msg.getObject()));
+    }
+
+    private class User implements Serializable {
+        private String name;
+        private int age;
+
+        private User(String name, int age) {
+            this.name = name;
+            this.age = age;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            return EqualsBuilder.reflectionEquals(this, obj);
+        }
+
+        public int getAge() {
+            return age;
+        }
+
+        public void setAge(int age) {
+            this.age = age;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/40bf4ce3/core/src/test/java/org/apache/rocketmq/jms/msg/JMSTextMessageTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSTextMessageTest.java 
b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSTextMessageTest.java
new file mode 100644
index 0000000..d9c0cac
--- /dev/null
+++ b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSTextMessageTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class JMSTextMessageTest {
+    private String text = "jmsRocketMQTextMessage test";
+
+    @Test
+    public void testGetBody() throws Exception {
+        JMSTextMessage msg = new JMSTextMessage(text);
+        assertThat(msg.getBody(String.class), is(text));
+    }
+
+    @Test
+    public void testSetText() throws Exception {
+        JMSTextMessage msg = new JMSTextMessage();
+        msg.setText(text);
+        assertThat(msg.getText(), is(text));
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/40bf4ce3/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQBytesMessageTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQBytesMessageTest.java 
b/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQBytesMessageTest.java
deleted file mode 100644
index 723ca1a..0000000
--- 
a/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQBytesMessageTest.java
+++ /dev/null
@@ -1,107 +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.rocketmq.jms.msg;
-
-import javax.jms.MessageNotReadableException;
-import javax.jms.MessageNotWriteableException;
-import org.junit.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-
-public class RocketMQBytesMessageTest {
-
-    private byte[] receiveData = "receive data test".getBytes();
-    private byte[] sendData = "send data test".getBytes();
-
-    @Test
-    public void testGetData() throws Exception {
-        JMSBytesMessage readMessage = new JMSBytesMessage(receiveData);
-        assertThat(new String(receiveData), is(new 
String(readMessage.getBody())));
-
-        JMSBytesMessage sendMessage = new JMSBytesMessage();
-        sendMessage.writeBytes(sendData, 0, sendData.length);
-        assertThat(new String(sendData), is(new 
String(sendMessage.getBody())));
-    }
-
-    @Test
-    public void testGetBodyLength() throws Exception {
-        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
-        assertThat(msg.getBodyLength(), is(new Long(receiveData.length)));
-    }
-
-    @Test
-    public void testReadBytes1() throws Exception {
-        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
-        byte[] receiveValue = new byte[receiveData.length];
-        msg.readBytes(receiveValue);
-        assertThat(new String(receiveValue), is(new String(receiveData)));
-
-    }
-
-    @Test
-    public void testReadBytes2() throws Exception {
-        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
-
-        byte[] receiveValue1 = new byte[2];
-        msg.readBytes(receiveValue1);
-        assertThat(new String(receiveData).substring(0, 2), is(new 
String(receiveValue1)));
-
-        byte[] receiveValue2 = new byte[2];
-        msg.readBytes(receiveValue2);
-        assertThat(new String(receiveData).substring(2, 4), is(new 
String(receiveValue2)));
-
-    }
-
-    @Test
-    public void testWriteBytes() throws Exception {
-        JMSBytesMessage msg = new JMSBytesMessage();
-        msg.writeBytes(sendData);
-        assertThat(new String(msg.getBody()), is(new String(sendData)));
-    }
-
-    @Test(expected = MessageNotReadableException.class)
-    public void testNotReadableException() throws Exception {
-        JMSBytesMessage msg = new JMSBytesMessage();
-        msg.writeBoolean(true);
-        msg.readBoolean();
-    }
-
-    @Test(expected = MessageNotWriteableException.class)
-    public void testNotWritableException() throws Exception {
-        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
-        msg.writeBoolean(true);
-    }
-
-    @Test
-    public void testClearBody() throws Exception {
-        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
-        msg.clearBody();
-        msg.writeBoolean(true);
-    }
-
-    @Test
-    public void testReset() throws Exception {
-        JMSBytesMessage msg = new JMSBytesMessage(receiveData);
-        byte[] b = new byte[2];
-        msg.readBytes(b);
-        msg.reset();
-        msg.readBytes(b);
-        assertThat(new String(receiveData).substring(0, 2), is(new String(b)));
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/40bf4ce3/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQObjectMessageTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQObjectMessageTest.java 
b/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQObjectMessageTest.java
deleted file mode 100644
index b68bd8d..0000000
--- 
a/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQObjectMessageTest.java
+++ /dev/null
@@ -1,73 +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.rocketmq.jms.msg;
-
-import java.io.Serializable;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.junit.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-
-public class RocketMQObjectMessageTest {
-
-    @Test
-    public void testGetObject() throws Exception {
-        final User user = new User("jack", 20);
-        JMSObjectMessage msg = new JMSObjectMessage(user);
-        assertThat((User)msg.getObject(), is(user));
-    }
-
-    @Test
-    public void testGetBody() throws Exception {
-        final User user = new User("jack", 20);
-        JMSObjectMessage msg = new JMSObjectMessage(user);
-        assertThat((User)msg.getBody(Object.class), is((User)msg.getObject()));
-    }
-
-    private class User implements Serializable {
-        private String name;
-        private int age;
-
-        private User(String name, int age) {
-            this.name = name;
-            this.age = age;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            return EqualsBuilder.reflectionEquals(this, obj);
-        }
-
-        public int getAge() {
-            return age;
-        }
-
-        public void setAge(int age) {
-            this.age = age;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public void setName(String name) {
-            this.name = name;
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/40bf4ce3/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQTextMessageTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQTextMessageTest.java 
b/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQTextMessageTest.java
deleted file mode 100644
index 3fd861b..0000000
--- 
a/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQTextMessageTest.java
+++ /dev/null
@@ -1,41 +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.rocketmq.jms.msg;
-
-import org.junit.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-
-public class RocketMQTextMessageTest {
-    private String text = "jmsRocketMQTextMessage test";
-
-    @Test
-    public void testGetBody() throws Exception {
-        JMSTextMessage msg = new JMSTextMessage(text);
-        assertThat(msg.getBody(String.class), is(text));
-    }
-
-    @Test
-    public void testSetText() throws Exception {
-        JMSTextMessage msg = new JMSTextMessage();
-        msg.setText(text);
-        assertThat(msg.getText(), is(text));
-    }
-
-}
\ No newline at end of file

Reply via email to