You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2014/07/24 16:23:22 UTC
[33/51] [partial] https://issues.apache.org/jira/browse/OPENWIRE-1
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java
new file mode 100644
index 0000000..e69eaf8
--- /dev/null
+++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java
@@ -0,0 +1,135 @@
+/**
+ * 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.activemq.openwire.commands;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.Topic;
+
+import org.apache.activemq.openwire.commands.OpenWireDestination;
+import org.apache.activemq.openwire.commands.OpenWireQueue;
+import org.apache.activemq.openwire.commands.OpenWireTempQueue;
+import org.apache.activemq.openwire.commands.OpenWireTempTopic;
+import org.apache.activemq.openwire.commands.OpenWireTopic;
+import org.junit.Test;
+
+/**
+ * Test various usages of the OpenWireDestination and its subclasses.
+ */
+public class OpenWireDestinationTest {
+
+ @Test
+ public void testSorting() throws Exception {
+ SortedSet<OpenWireDestination> set = new TreeSet<OpenWireDestination>();
+ OpenWireDestination[] destinations = {new OpenWireQueue("A"), new OpenWireQueue("B"),
+ new OpenWireTopic("A"), new OpenWireTopic("B")};
+ List<OpenWireDestination> expected = Arrays.asList(destinations);
+ set.addAll(expected);
+ List<OpenWireDestination> actual = new ArrayList<OpenWireDestination>(set);
+ assertEquals("Sorted order", expected, actual);
+ }
+
+ class CombyDest implements Queue, Topic, TemporaryQueue, TemporaryTopic {
+
+ private final String qName;
+ private final String topicName;
+
+ public CombyDest(String qName, String topicName) {
+ this.qName = qName;
+ this.topicName = topicName;
+ }
+
+ @Override
+ public void delete() throws JMSException {}
+
+ @Override
+ public String getTopicName() throws JMSException {
+ return topicName;
+ }
+
+ @Override
+ public String getQueueName() throws JMSException {
+ return qName;
+ }
+ }
+
+ @Test
+ public void testTransformPollymorphic() throws Exception {
+ OpenWireQueue queue = new OpenWireQueue("TEST");
+ assertEquals(OpenWireDestination.transform(queue), queue);
+ assertTrue("is a q", OpenWireDestination.transform(new CombyDest(null, "Topic")) instanceof OpenWireTopic);
+ assertTrue("is a q", OpenWireDestination.transform(new CombyDest("Q", null)) instanceof OpenWireQueue);
+ try {
+ OpenWireDestination.transform(new CombyDest(null, null));
+ fail("expect ex as cannot disambiguate");
+ } catch (JMSException expected) {
+ }
+ try {
+ OpenWireDestination.transform(new CombyDest("Q", "T"));
+ fail("expect ex as cannot disambiguate");
+ } catch (JMSException expected) {
+ }
+ }
+
+ @Test
+ public void testEmptyQueueName() {
+ try {
+ new OpenWireQueue("");
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ @Test
+ public void testEmptyTopicName() {
+ try {
+ new OpenWireTopic("");
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ @Test
+ public void testDestinationOptions() throws Exception {
+ doTestDestinationOptions(new OpenWireQueue("TEST?k1=v1&k2=v2"));
+ doTestDestinationOptions(new OpenWireTopic("TEST?k1=v1&k2=v2"));
+ doTestDestinationOptions(new OpenWireTempQueue("TEST:1?k1=v1&k2=v2"));
+ doTestDestinationOptions(new OpenWireTempTopic("TEST:1?k1=v1&k2=v2"));
+ }
+
+ private void doTestDestinationOptions(OpenWireDestination destination) throws IOException {
+ Map<String, String> options = destination.getOptions();
+ assertNotNull(options);
+ assertEquals("v1", options.get("k1"));
+ assertEquals("v2", options.get("k2"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java
new file mode 100644
index 0000000..0a7e66a
--- /dev/null
+++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java
@@ -0,0 +1,211 @@
+/**
+ * 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.activemq.openwire.commands;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.jms.JMSException;
+import javax.jms.MessageFormatException;
+
+import org.apache.activemq.openwire.commands.OpenWireMapMessage;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OpenWireMapMessageTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(OpenWireMapMessageTest.class);
+
+ @Rule
+ public TestName name = new TestName();
+
+ @Test
+ public void testBytesConversion() throws JMSException, IOException {
+ OpenWireMapMessage msg = new OpenWireMapMessage();
+ msg.setObject("boolean", true);
+ msg.setObject("byte", (byte) 1);
+ msg.setObject("bytes", new byte[1]);
+ msg.setObject("char", 'a');
+ msg.setObject("double", 1.5);
+ msg.setObject("float", 1.5f);
+ msg.setObject("int", 1);
+ msg.setObject("long", 1L);
+ msg.setObject("object", "stringObj");
+ msg.setObject("short", (short) 1);
+ msg.setObject("string", "string");
+
+ // Test with a 1Meg String
+ StringBuffer bigSB = new StringBuffer(1024 * 1024);
+ for (int i = 0; i < 1024 * 1024; i++) {
+ bigSB.append('a' + i % 26);
+ }
+ String bigString = bigSB.toString();
+
+ msg.setObject("bigString", bigString);
+
+ msg = (OpenWireMapMessage) msg.copy();
+
+ assertEquals(msg.getObject("boolean"), true);
+ assertEquals(msg.getObject("byte"), (byte) 1);
+ assertEquals(((byte[]) msg.getObject("bytes")).length, 1);
+ assertEquals(msg.getObject("char"), 'a');
+ assertEquals((Double) msg.getObject("double"), 1.5, 0);
+ assertEquals((Float) msg.getObject("float"), 1.5f, 0);
+ assertEquals(msg.getObject("int"), 1);
+ assertEquals(msg.getObject("long"), 1L);
+ assertEquals(msg.getObject("object"), "stringObj");
+ assertEquals(msg.getObject("short"), (short) 1);
+ assertEquals(msg.getObject("string"), "string");
+ assertEquals(msg.getObject("bigString"), bigString);
+ }
+
+ @Test
+ public void testGetObject() throws JMSException {
+ OpenWireMapMessage msg = new OpenWireMapMessage();
+ Boolean booleanValue = Boolean.TRUE;
+ Byte byteValue = Byte.valueOf("1");
+ byte[] bytesValue = new byte[3];
+ Character charValue = new Character('a');
+ Double doubleValue = Double.valueOf("1.5");
+ Float floatValue = Float.valueOf("1.5");
+ Integer intValue = Integer.valueOf("1");
+ Long longValue = Long.valueOf("1");
+ Short shortValue = Short.valueOf("1");
+ String stringValue = "string";
+
+ try {
+ msg.setObject("boolean", booleanValue);
+ msg.setObject("byte", byteValue);
+ msg.setObject("bytes", bytesValue);
+ msg.setObject("char", charValue);
+ msg.setObject("double", doubleValue);
+ msg.setObject("float", floatValue);
+ msg.setObject("int", intValue);
+ msg.setObject("long", longValue);
+ msg.setObject("short", shortValue);
+ msg.setObject("string", stringValue);
+ } catch (MessageFormatException mfe) {
+ LOG.warn("Caught: " + mfe);
+ mfe.printStackTrace();
+ fail("object formats should be correct");
+ }
+
+ msg = (OpenWireMapMessage) msg.copy();
+
+ assertTrue(msg.getObject("boolean") instanceof Boolean);
+ assertEquals(msg.getObject("boolean"), booleanValue);
+ assertTrue(msg.getObject("byte") instanceof Byte);
+ assertEquals(msg.getObject("byte"), byteValue);
+ assertTrue(msg.getObject("bytes") instanceof byte[]);
+ assertEquals(((byte[]) msg.getObject("bytes")).length, bytesValue.length);
+ assertEquals(((byte[])msg.getObject("bytes")).length, bytesValue.length);
+ assertTrue(msg.getObject("char") instanceof Character);
+ assertEquals(msg.getObject("char"), charValue);
+ assertTrue(msg.getObject("double") instanceof Double);
+ assertEquals(msg.getObject("double"), doubleValue);
+ assertTrue(msg.getObject("float") instanceof Float);
+ assertEquals(msg.getObject("float"), floatValue);
+ assertTrue(msg.getObject("int") instanceof Integer);
+ assertEquals(msg.getObject("int"), intValue);
+ assertTrue(msg.getObject("long") instanceof Long);
+ assertEquals(msg.getObject("long"), longValue);
+ assertTrue(msg.getObject("short") instanceof Short);
+ assertEquals(msg.getObject("short"), shortValue);
+ assertTrue(msg.getObject("string") instanceof String);
+ assertEquals(msg.getObject("string"), stringValue);
+
+ msg.clearBody();
+ try {
+ msg.setObject("object", new Object());
+ fail("should have thrown exception");
+ } catch (MessageFormatException e) {
+ }
+ }
+
+ @Test
+ public void testGetMapNames() throws JMSException {
+ OpenWireMapMessage msg = new OpenWireMapMessage();
+ msg.setObject("boolean", true);
+ msg.setObject("byte", (byte) 1);
+ msg.setObject("bytes1", new byte[1]);
+ msg.setObject("char", 'a');
+ msg.setObject("double", 1.5);
+ msg.setObject("float", 1.5f);
+ msg.setObject("int", 1);
+ msg.setObject("long", 1);
+ msg.setObject("object", "stringObj");
+ msg.setObject("short", (short) 1);
+ msg.setObject("string", "string");
+
+ msg = (OpenWireMapMessage) msg.copy();
+
+ Enumeration<String> mapNamesEnum = msg.getMapNames();
+ List<String> mapNamesList = Collections.list(mapNamesEnum);
+
+ assertEquals(mapNamesList.size(), 11);
+ assertTrue(mapNamesList.contains("boolean"));
+ assertTrue(mapNamesList.contains("byte"));
+ assertTrue(mapNamesList.contains("bytes1"));
+ assertTrue(mapNamesList.contains("char"));
+ assertTrue(mapNamesList.contains("double"));
+ assertTrue(mapNamesList.contains("float"));
+ assertTrue(mapNamesList.contains("int"));
+ assertTrue(mapNamesList.contains("long"));
+ assertTrue(mapNamesList.contains("object"));
+ assertTrue(mapNamesList.contains("short"));
+ assertTrue(mapNamesList.contains("string"));
+ }
+
+ @Test
+ public void testItemExists() throws JMSException {
+ OpenWireMapMessage mapMessage = new OpenWireMapMessage();
+
+ mapMessage.setObject("exists", "test");
+
+ mapMessage = (OpenWireMapMessage) mapMessage.copy();
+
+ assertTrue(mapMessage.itemExists("exists"));
+ assertFalse(mapMessage.itemExists("doesntExist"));
+ }
+
+ @Test
+ public void testClearBody() throws JMSException {
+ OpenWireMapMessage mapMessage = new OpenWireMapMessage();
+ mapMessage.setObject("String", "String");
+ mapMessage.clearBody();
+
+ mapMessage.setContent(mapMessage.getContent());
+ assertNull(mapMessage.getObject("String"));
+ mapMessage.clearBody();
+ mapMessage.setObject("String", "String");
+
+ mapMessage = (OpenWireMapMessage) mapMessage.copy();
+
+ mapMessage.getObject("String");
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java
new file mode 100644
index 0000000..b6263c7
--- /dev/null
+++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java
@@ -0,0 +1,461 @@
+/**
+ * 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.activemq.openwire.commands;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+
+import org.apache.activemq.openwire.codec.OpenWireFormat;
+import org.apache.activemq.openwire.commands.CommandTypes;
+import org.apache.activemq.openwire.commands.OpenWireBytesMessage;
+import org.apache.activemq.openwire.commands.OpenWireDestination;
+import org.apache.activemq.openwire.commands.OpenWireMessage;
+import org.apache.activemq.openwire.commands.OpenWireObjectMessage;
+import org.apache.activemq.openwire.commands.OpenWireTempTopic;
+import org.apache.activemq.openwire.commands.OpenWireTopic;
+import org.fusesource.hawtbuf.Buffer;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OpenWireMessageTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(OpenWireMessageTest.class);
+
+ protected boolean readOnlyMessage;
+
+ private String jmsMessageID;
+ private String jmsCorrelationID;
+ private OpenWireDestination jmsDestination;
+ private OpenWireDestination jmsReplyTo;
+ private int jmsDeliveryMode;
+ private boolean jmsRedelivered;
+ private String jmsType;
+ private long jmsExpiration;
+ private int jmsPriority;
+ private long jmsTimestamp;
+ private long[] consumerIDs;
+
+ @Before
+ public void setUp() throws Exception {
+ this.jmsMessageID = "ID:TEST-ID:0:0:0:1";
+ this.jmsCorrelationID = "testcorrelationid";
+ this.jmsDestination = new OpenWireTopic("test.topic");
+ this.jmsReplyTo = new OpenWireTempTopic("test.replyto.topic:001");
+ this.jmsDeliveryMode = Message.DEFAULT_DELIVERY_MODE;
+ this.jmsRedelivered = true;
+ this.jmsType = "test type";
+ this.jmsExpiration = 100000;
+ this.jmsPriority = 5;
+ this.jmsTimestamp = System.currentTimeMillis();
+ this.readOnlyMessage = false;
+ this.consumerIDs = new long[3];
+ for (int i = 0; i < this.consumerIDs.length; i++) {
+ this.consumerIDs[i] = i;
+ }
+ }
+
+ @Test
+ public void testGetDataStructureType() {
+ OpenWireMessage msg = new OpenWireMessage();
+ assertEquals(msg.getDataStructureType(), CommandTypes.OPENWIRE_MESSAGE);
+ }
+
+// @Test
+// public void testHashCode() throws Exception {
+// OpenWireMessage msg = new OpenWireMessage();
+// msg.setMessageId(this.jmsMessageID);
+// assertTrue(msg.getMessageId().hashCode() == jmsMessageID.hashCode());
+// }
+
+ @Test
+ public void testSetToForeignJMSID() throws Exception {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setMessageId("ID:EMS-SERVER.8B443C380083:429");
+ }
+
+ @Test
+ public void testEqualsObject() throws Exception {
+ OpenWireMessage msg1 = new OpenWireMessage();
+ OpenWireMessage msg2 = new OpenWireMessage();
+ msg1.setMessageId(this.jmsMessageID);
+ assertTrue(!msg1.equals(msg2));
+ msg2.setMessageId(this.jmsMessageID);
+ assertTrue(msg1.equals(msg2));
+ }
+
+ @Test
+ public void testShallowCopy() throws Exception {
+ OpenWireMessage msg1 = new OpenWireMessage();
+ msg1.setMessageId(jmsMessageID);
+ OpenWireMessage msg2 = msg1.copy();
+ assertTrue(msg1 != msg2 && msg1.equals(msg2));
+ }
+
+// @Test
+// public void testCopy() throws Exception {
+// this.jmsMessageID = "testid";
+// this.jmsCorrelationID = "testcorrelationid";
+// this.jmsDestination = new OpenWireTopic("test.topic");
+// this.jmsReplyTo = new OpenWireTempTopic("test.replyto.topic:001");
+// this.jmsDeliveryMode = Message.DEFAULT_DELIVERY_MODE;
+// this.jmsRedelivered = true;
+// this.jmsType = "test type";
+// this.jmsExpiration = 100000;
+// this.jmsPriority = 5;
+// this.jmsTimestamp = System.currentTimeMillis();
+// this.readOnlyMessage = false;
+//
+// OpenWireMessage msg1 = new OpenWireMessage();
+// msg1.setMessageId(this.jmsMessageID);
+// msg1.setCorrelationId(this.jmsCorrelationID);
+// msg1.setDestination(this.jmsDestination);
+// msg1.setReplyTo(this.jmsReplyTo);
+// msg1.setPersistent(this.jmsDeliveryMode == DeliveryMode.PERSISTENT);
+// msg1.setRedelivered(this.jmsRedelivered);
+// msg1.setType(this.jmsType);
+// msg1.setExpiration(this.jmsExpiration);
+// msg1.setPriority((byte) this.jmsPriority);
+// msg1.setTimestamp(this.jmsTimestamp);
+// msg1.setReadOnlyProperties(true);
+// OpenWireMessage msg2 = new OpenWireMessage();
+// msg1.copy(msg2);
+// assertEquals(msg1.getMessageId(), msg2.getMessageId());
+// assertTrue(msg1.getCorrelationId().equals(msg2.getCorrelationId()));
+// assertTrue(msg1.getDestination().equals(msg2.getDestination()));
+// assertTrue(msg1.getReplyTo().equals(msg2.getReplyTo()));
+// assertTrue(msg1.isPersistent() == msg2.isPersistent());
+// assertTrue(msg1.isRedelivered() == msg2.isRedelivered());
+// assertTrue(msg1.getType().equals(msg2.getType()));
+// assertTrue(msg1.getExpiration() == msg2.getExpiration());
+// assertTrue(msg1.getPriority() == msg2.getPriority());
+// assertTrue(msg1.getTimestamp() == msg2.getTimestamp());
+//
+// LOG.info("Message is: " + msg1);
+// }
+
+ @Test
+ public void testGetAndSetMessageId() throws Exception {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setMessageId(this.jmsMessageID);
+ assertEquals(msg.getMessageId().toString(), this.jmsMessageID);
+ }
+
+ @Test
+ public void testGetAndSetTimestamp() {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setTimestamp(this.jmsTimestamp);
+ assertTrue(msg.getTimestamp() == this.jmsTimestamp);
+ }
+
+ @Test
+ public void testGetCorrelationIDAsBytes() throws Exception {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setCorrelationId(this.jmsCorrelationID);
+ byte[] testbytes = msg.getCorrelationIdAsBytes();
+ String str2 = new String(testbytes);
+ assertTrue(this.jmsCorrelationID.equals(str2));
+ }
+
+ @Test
+ public void testSetCorrelationIDAsBytes() throws Exception {
+ OpenWireMessage msg = new OpenWireMessage();
+ byte[] testbytes = this.jmsCorrelationID.getBytes();
+ msg.setCorrelationIdAsBytes(testbytes);
+ testbytes = msg.getCorrelationIdAsBytes();
+ String str2 = new String(testbytes);
+ assertTrue(this.jmsCorrelationID.equals(str2));
+ }
+
+ @Test
+ public void testGetAndSetCorrelationID() {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setCorrelationId(this.jmsCorrelationID);
+ assertTrue(msg.getCorrelationId().equals(this.jmsCorrelationID));
+ }
+
+ @Test
+ public void testGetAndSetJMSReplyTo() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setReplyTo(this.jmsReplyTo);
+ assertTrue(msg.getReplyTo().equals(this.jmsReplyTo));
+ }
+
+ @Test
+ public void testGetAndSetJMSDestination() throws Exception {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setDestination(this.jmsDestination);
+ assertTrue(msg.getDestination().equals(this.jmsDestination));
+ }
+
+ @Test
+ public void testGetAndSetPersistentFlag() {
+ OpenWireMessage msg = new OpenWireMessage();
+ boolean persistent = this.jmsDeliveryMode == DeliveryMode.PERSISTENT;
+ msg.setPersistent(persistent);
+ assertTrue(msg.isPersistent() == persistent);
+ }
+
+ @Test
+ public void testGetAndSetRedelivered() {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setRedelivered(this.jmsRedelivered);
+ assertTrue(msg.isRedelivered() == this.jmsRedelivered);
+ }
+
+ @Test
+ public void testGetAndSetType() {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setType(this.jmsType);
+ assertTrue(msg.getType().equals(this.jmsType));
+ }
+
+ @Test
+ public void testGetAndSetExpiration() {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setExpiration(this.jmsExpiration);
+ assertTrue(msg.getExpiration() == this.jmsExpiration);
+ }
+
+ @Test
+ public void testGetAndSetPriority() {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setPriority((byte) this.jmsPriority);
+ assertTrue(msg.getPriority() == this.jmsPriority);
+
+ msg.setPriority((byte) -90);
+ assertEquals(0, msg.getPriority());
+
+ msg.setPriority((byte) 90);
+ assertEquals(9, msg.getPriority());
+ }
+
+ @Test
+ public void testClearProperties() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setProperty("test", "test");
+ msg.setContent(new Buffer(new byte[1], 0, 0));
+ msg.setMessageId(this.jmsMessageID);
+ msg.clearProperties();
+ assertNull(msg.getProperty("test"));
+ assertNotNull(msg.getMessageId());
+ assertNotNull(msg.getContent());
+ }
+
+ @Test
+ public void testPropertyExists() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setProperty("test", "test");
+ assertTrue(msg.propertyExists("test"));
+
+ msg.setProperty("JMSXDeliveryCount", 1);
+ assertTrue(msg.propertyExists("JMSXDeliveryCount"));
+ }
+
+ @Test
+ public void testGetBooleanProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "booleanProperty";
+ msg.setProperty(name, true);
+ assertTrue((Boolean) msg.getProperty(name));
+ }
+
+ @Test
+ public void testGetByteProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "byteProperty";
+ msg.setProperty(name, (byte) 1);
+ assertTrue((Byte) msg.getProperty(name) == 1);
+ }
+
+ @Test
+ public void testGetShortProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "shortProperty";
+ msg.setProperty(name, (short) 1);
+ assertTrue((Short) msg.getProperty(name) == 1);
+ }
+
+ @Test
+ public void testGetIntProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "intProperty";
+ msg.setProperty(name, 1);
+ assertTrue((Integer) msg.getProperty(name) == 1);
+ }
+
+ @Test
+ public void testGetLongProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "longProperty";
+ msg.setProperty(name, 1L);
+ assertTrue((Long) msg.getProperty(name) == 1L);
+ }
+
+ @Test
+ public void testGetFloatProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "floatProperty";
+ msg.setProperty(name, 1.3f);
+ assertTrue((Float) msg.getProperty(name) == 1.3f);
+ }
+
+ @Test
+ public void testGetDoubleProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "doubleProperty";
+ msg.setProperty(name, 1.3d);
+ assertTrue((Double) msg.getProperty(name) == 1.3);
+ }
+
+ @Test
+ public void testGetStringProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "stringProperty";
+ msg.setProperty(name, name);
+ assertTrue(msg.getProperty(name).equals(name));
+ }
+
+ @Test
+ public void testgetProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "floatProperty";
+ msg.setProperty(name, 1.3f);
+ assertTrue(msg.getProperty(name) instanceof Float);
+ assertTrue(((Float) msg.getProperty(name)).floatValue() == 1.3f);
+ }
+
+ @Test
+ public void testPropertiesInt() throws Exception {
+ OpenWireObjectMessage message = new OpenWireObjectMessage();
+ message.setProperty("TestProp", 333);
+ fakeUnmarshal(message);
+ roundTripProperties(message);
+ }
+
+ @Test
+ public void testPropertiesString() throws Exception {
+ OpenWireObjectMessage message = new OpenWireObjectMessage();
+ message.setProperty("TestProp", "Value");
+ fakeUnmarshal(message);
+ roundTripProperties(message);
+ }
+
+ @Test
+ public void testPropertiesObject() throws Exception {
+ OpenWireObjectMessage message = new OpenWireObjectMessage();
+ message.setProperty("TestProp", "Value");
+ fakeUnmarshal(message);
+ roundTripProperties(message);
+ }
+
+ @Test
+ public void testPropertiesObjectNoMarshalling() throws Exception {
+ OpenWireObjectMessage message = new OpenWireObjectMessage();
+ message.setProperty("TestProp", "Value");
+ roundTripProperties(message);
+ }
+
+ private void roundTripProperties(OpenWireObjectMessage message) throws IOException, JMSException {
+ OpenWireObjectMessage copy = new OpenWireObjectMessage();
+ for (Map.Entry<String, Object> prop : message.getProperties().entrySet()) {
+ LOG.debug("{} -> {}", prop.getKey(), prop.getValue().getClass());
+ copy.setProperty(prop.getKey(), prop.getValue());
+ }
+ }
+
+ private void fakeUnmarshal(OpenWireObjectMessage message) throws Exception {
+ OpenWireFormat format = new OpenWireFormat(OpenWireFormat.DEFAULT_WIRE_VERSION);
+ message.beforeMarshall(format);
+ message.afterMarshall(format);
+
+ Buffer seq = message.getMarshalledProperties();
+ message.clearProperties();
+ message.setMarshalledProperties(seq);
+ }
+
+ @Test
+ public void testSetNullProperty() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ String name = "cheese";
+ msg.setProperty(name, "Cheddar");
+ assertEquals("Cheddar", msg.getProperty(name));
+
+ msg.setProperty(name, null);
+ assertEquals(null, msg.getProperty(name));
+ }
+
+ @Test
+ public void testSetNullPropertyName() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+
+ try {
+ msg.setProperty(null, "Cheese");
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ LOG.info("Worked, caught: " + e);
+ }
+ }
+
+ @Test
+ public void testSetEmptyPropertyName() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+
+ try {
+ msg.setProperty("", "Cheese");
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ LOG.info("Worked, caught: " + e);
+ }
+ }
+
+ @Test
+ public void testGetAndSetDeliveryCount() throws JMSException {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setRedeliveryCounter(1);
+ int count = msg.getRedeliveryCounter();
+ assertTrue("expected delivery count = 1 - got: " + count, count == 1);
+ }
+
+ @Test
+ public void testClearBody() throws JMSException {
+ OpenWireBytesMessage message = new OpenWireBytesMessage();
+ message.clearBody();
+ assertNull(message.getContent());
+ }
+
+ @Test
+ public void testIsExpired() {
+ OpenWireMessage msg = new OpenWireMessage();
+ msg.setExpiration(System.currentTimeMillis() - 1);
+ assertTrue(msg.isExpired());
+ msg.setExpiration(System.currentTimeMillis() + 10000);
+ assertFalse(msg.isExpired());
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java
new file mode 100644
index 0000000..5363df8
--- /dev/null
+++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.activemq.openwire.commands;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+
+import javax.jms.JMSException;
+import javax.jms.MessageNotWriteableException;
+
+import org.apache.activemq.openwire.commands.OpenWireObjectMessage;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class OpenWireObjectMessageTest {
+
+ @Test
+ public void testBytes() throws JMSException, IOException {
+ OpenWireObjectMessage msg = new OpenWireObjectMessage();
+ String str = "testText";
+ msg.setObject(str);
+
+ msg = (OpenWireObjectMessage) msg.copy();
+ assertEquals(msg.getObject(), str);
+ }
+
+ @Test
+ public void testSetObject() throws JMSException {
+ OpenWireObjectMessage msg = new OpenWireObjectMessage();
+ String str = "testText";
+ msg.setObject(str);
+ assertTrue(msg.getObject() == str);
+ }
+
+ @Test
+ public void testClearBody() throws JMSException {
+ OpenWireObjectMessage objectMessage = new OpenWireObjectMessage();
+ try {
+ objectMessage.setObject("String");
+ objectMessage.clearBody();
+ assertNull(objectMessage.getObject());
+ objectMessage.setObject("String");
+ objectMessage.getObject();
+ } catch (MessageNotWriteableException mnwe) {
+ fail("should be writeable");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireStreamMessageTest.java
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireStreamMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireStreamMessageTest.java
new file mode 100644
index 0000000..cd3c299
--- /dev/null
+++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireStreamMessageTest.java
@@ -0,0 +1,116 @@
+/**
+ * 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.activemq.openwire.commands;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.activemq.openwire.commands.CommandTypes;
+import org.apache.activemq.openwire.commands.OpenWireStreamMessage;
+import org.fusesource.hawtbuf.Buffer;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class OpenWireStreamMessageTest {
+
+ private final List<Object> elements = new ArrayList<Object>();
+
+ @Before
+ public void setUp() throws Exception {
+
+ elements.add(Boolean.TRUE);
+ elements.add(Byte.valueOf(Byte.MAX_VALUE));
+ elements.add(Character.valueOf('a'));
+ elements.add(Short.valueOf(Short.MAX_VALUE));
+ elements.add(Integer.valueOf(Integer.MAX_VALUE));
+ elements.add(Long.valueOf(Long.MAX_VALUE));
+ elements.add(Float.valueOf(Float.MAX_VALUE));
+ elements.add(Double.valueOf(Double.MAX_VALUE));
+ elements.add("Test-String");
+ elements.add(new byte[] { 1, 2, 3, 4, 5, 6 });
+ }
+
+ @Test
+ public void testGetDataStructureType() {
+ OpenWireStreamMessage msg = new OpenWireStreamMessage();
+ assertEquals(msg.getDataStructureType(), CommandTypes.OPENWIRE_STREAM_MESSAGE);
+ }
+
+ @Test
+ public void testWriteListToStream() throws Exception {
+ OpenWireStreamMessage message = new OpenWireStreamMessage();
+
+ message.writeListToStream(Collections.emptyList());
+ assertNull(message.getContent());
+ message.writeListToStream(elements);
+ assertNotNull(message.getContent());
+ }
+
+ @Test
+ public void testWriteListToStreamCompressed() throws Exception {
+ OpenWireStreamMessage message = new OpenWireStreamMessage();
+ message.setUseCompression(true);
+
+ // Add something that should compress well.
+ elements.add("Repeating String" + "Repeating String" + "Repeating String" + "Repeating String" +
+ "Repeating String" + "Repeating String" + "Repeating String" + "Repeating String" +
+ "Repeating String" + "Repeating String" + "Repeating String" + "Repeating String");
+
+ message.writeListToStream(Collections.emptyList());
+ assertNull(message.getContent());
+ message.writeListToStream(elements);
+ assertNotNull(message.getContent());
+
+ Buffer rawContent = message.getContent();
+ Buffer processedContent = message.getPayload();
+
+ assertTrue(rawContent.length() < processedContent.length());
+ }
+
+ @Test
+ public void testReadStreamToList() throws Exception {
+ OpenWireStreamMessage message = new OpenWireStreamMessage();
+
+ message.writeListToStream(elements);
+ assertNotNull(message.getContent());
+
+ List<Object> results = message.readStreamToList();
+ assertEquals(elements.size(), results.size());
+
+ for (int i = 0; i < results.size(); ++i) {
+
+ Object element = elements.get(i);
+ Object result = results.get(i);
+
+ if (result instanceof byte[]) {
+ assertTrue(Arrays.equals((byte[]) result, (byte[]) element));
+ } else {
+ assertEquals(element, result);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java
new file mode 100644
index 0000000..c92f92c
--- /dev/null
+++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java
@@ -0,0 +1,131 @@
+/**
+ * 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.activemq.openwire.commands;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import javax.jms.JMSException;
+import javax.jms.MessageNotReadableException;
+import javax.jms.MessageNotWriteableException;
+
+import org.apache.activemq.openwire.commands.CommandTypes;
+import org.apache.activemq.openwire.commands.Message;
+import org.apache.activemq.openwire.commands.OpenWireTextMessage;
+import org.apache.activemq.util.MarshallingSupport;
+import org.fusesource.hawtbuf.Buffer;
+import org.fusesource.hawtbuf.ByteArrayOutputStream;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class OpenWireTextMessageTest {
+
+ @Test
+ public void testGetDataStructureType() {
+ OpenWireTextMessage msg = new OpenWireTextMessage();
+ assertEquals(msg.getDataStructureType(), CommandTypes.OPENWIRE_TEXT_MESSAGE);
+ }
+
+ @Test
+ public void testShallowCopy() throws JMSException {
+ OpenWireTextMessage msg = new OpenWireTextMessage();
+ String string = "str";
+ msg.setText(string);
+ Message copy = msg.copy();
+ assertTrue(msg.getText() == ((OpenWireTextMessage) copy).getText());
+ }
+
+ @Test
+ public void testSetText() {
+ OpenWireTextMessage msg = new OpenWireTextMessage();
+ String str = "testText";
+ try {
+ msg.setText(str);
+ assertEquals(msg.getText(), str);
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testGetBytes() throws JMSException, IOException {
+ OpenWireTextMessage msg = new OpenWireTextMessage();
+ String str = "testText";
+ msg.setText(str);
+ msg.beforeMarshall(null);
+
+ Buffer bytes = msg.getContent();
+ msg = new OpenWireTextMessage();
+ msg.setContent(bytes);
+
+ assertEquals(msg.getText(), str);
+ }
+
+ @Test
+ public void testClearBody() throws JMSException, IOException {
+ OpenWireTextMessage textMessage = new OpenWireTextMessage();
+ textMessage.setText("string");
+ textMessage.clearBody();
+ assertNull(textMessage.getText());
+ try {
+ textMessage.setText("String");
+ textMessage.getText();
+ } catch (MessageNotWriteableException mnwe) {
+ fail("should be writeable");
+ } catch (MessageNotReadableException mnre) {
+ fail("should be readable");
+ }
+ }
+
+ @Test
+ public void testShortText() throws Exception {
+ String shortText = "Content";
+ OpenWireTextMessage shortMessage = new OpenWireTextMessage();
+ setContent(shortMessage, shortText);
+ assertTrue(shortMessage.toString().contains("text = " + shortText));
+ assertTrue(shortMessage.getText().equals(shortText));
+
+ String longText = "Very very very very veeeeeeery loooooooooooooooooooooooooooooooooong text";
+ String longExpectedText = "Very very very very veeeeeeery looooooooooooo...ooooong text";
+ OpenWireTextMessage longMessage = new OpenWireTextMessage();
+ setContent(longMessage, longText);
+ assertTrue(longMessage.toString().contains("text = " + longExpectedText));
+ assertTrue(longMessage.getText().equals(longText));
+ }
+
+ @Test
+ public void testNullText() throws Exception {
+ OpenWireTextMessage nullMessage = new OpenWireTextMessage();
+ setContent(nullMessage, null);
+ assertTrue(nullMessage.toString().contains("text = null"));
+ }
+
+ void setContent(Message message, String text) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dataOut = new DataOutputStream(baos);
+ MarshallingSupport.writeUTF8(dataOut, text);
+ dataOut.close();
+ message.setContent(baos.toBuffer());
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/java/org/apache/activemq/openwire/ide/OpenWireCodecGenerator.java
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/ide/OpenWireCodecGenerator.java b/openwire-core/src/test/java/org/apache/activemq/openwire/ide/OpenWireCodecGenerator.java
new file mode 100644
index 0000000..e066fe7
--- /dev/null
+++ b/openwire-core/src/test/java/org/apache/activemq/openwire/ide/OpenWireCodecGenerator.java
@@ -0,0 +1,121 @@
+/**
+ * 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.activemq.openwire.ide;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.activemq.openwire.generator.GeneratorTask;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility class for running the OpenWire source generator from within an
+ * IDE or as part of a test.
+ */
+public class OpenWireCodecGenerator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(OpenWireCodecGenerator.class);
+
+ private final GeneratorTask generator = new GeneratorTask();
+
+ private int baseVersion = 10;
+ private int maxVersion = 10;
+
+ private File sourceDir;
+ private File targetDir;
+
+ /**
+ * @param args
+ * @throws IOException
+ */
+ public static void main(String[] args) throws IOException {
+
+ OpenWireCodecGenerator runner = new OpenWireCodecGenerator();
+
+ runner.setBaseVersion(10);
+ runner.setMaxVersion(10);
+
+ File sourceDir = new File("./src/main/java/io/neutronjms/openwire/commands").getCanonicalFile();
+ File targetDir = new File("./target/generated-sources/openwire").getCanonicalFile();
+
+ if (!sourceDir.exists()) {
+ throw new IOException("Source dir does not exist. " + sourceDir);
+ }
+
+ if (!targetDir.exists()) {
+ targetDir.createNewFile();
+ if (!targetDir.exists()) {
+ throw new IOException("Source dir does not exist. " + targetDir);
+ }
+ }
+
+ runner.setSourceDir(sourceDir);
+ runner.setTargetDir(targetDir);
+
+ runner.generate();
+ }
+
+ /**
+ * Runs the OpenWire generator using the configured generation values.
+ */
+ public void generate() {
+ generator.setFromVersion(getBaseVersion());
+ generator.setToVersion(getMaxVersion());
+ generator.setSourceDir(getSourceDir());
+ generator.setTargetDir(getTargetDir());
+
+ try {
+ generator.execute();
+ } catch (RuntimeException e) {
+ LOG.warn("Caught exception while executing generator: ", e);
+ throw e;
+ }
+ }
+
+ public int getBaseVersion() {
+ return baseVersion;
+ }
+
+ public void setBaseVersion(int version) {
+ this.baseVersion = version;
+ }
+
+ public int getMaxVersion() {
+ return maxVersion;
+ }
+
+ public void setMaxVersion(int version) {
+ this.maxVersion = version;
+ }
+
+ public File getSourceDir() {
+ return sourceDir;
+ }
+
+ public void setSourceDir(File sourceDir) {
+ this.sourceDir = sourceDir;
+ }
+
+ public File getTargetDir() {
+ return targetDir;
+ }
+
+ public void setTargetDir(File targetDir) {
+ this.targetDir = targetDir;
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/java/org/apache/activemq/openwire/utils/CronParserTest.java
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/utils/CronParserTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/utils/CronParserTest.java
new file mode 100644
index 0000000..907b524
--- /dev/null
+++ b/openwire-core/src/test/java/org/apache/activemq/openwire/utils/CronParserTest.java
@@ -0,0 +1,363 @@
+/**
+ * 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.activemq.openwire.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.Calendar;
+import java.util.List;
+
+import javax.jms.MessageFormatException;
+
+import org.apache.activemq.openwire.utils.CronParser;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CronParserTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(CronParserTest.class);
+
+ @Test
+ public void testgetNextTimeDayOfWeek() throws MessageFormatException {
+
+ // using an absolute date so that result will be absolute - Monday 15 Nov 2010
+ Calendar current = Calendar.getInstance();
+ current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
+ LOG.debug("start:" + current.getTime());
+
+ String test = "* * * * 5";
+ long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+
+ Calendar result = Calendar.getInstance();
+ result.setTimeInMillis(next);
+ LOG.debug("next:" + result.getTime());
+
+ assertEquals(0,result.get(Calendar.SECOND));
+ assertEquals(0,result.get(Calendar.MINUTE));
+ assertEquals(0,result.get(Calendar.HOUR));
+ // expecting Friday 19th
+ assertEquals(19,result.get(Calendar.DAY_OF_MONTH));
+ assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
+ assertEquals(2010,result.get(Calendar.YEAR));
+ }
+
+ @Test
+ public void testgetNextTimeDayOfWeekVariant() throws MessageFormatException {
+
+ // using an absolute date so that result will be absolute - Monday 7 March 2011
+ Calendar current = Calendar.getInstance();
+ current.set(2011, Calendar.MARCH, 7, 9, 15, 30);
+ LOG.debug("start:" + current.getTime());
+
+ String test = "50 20 * * 5";
+ long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+
+ Calendar result = Calendar.getInstance();
+ result.setTimeInMillis(next);
+ LOG.debug("next:" + result.getTime());
+
+ assertEquals(0,result.get(Calendar.SECOND));
+ assertEquals(50,result.get(Calendar.MINUTE));
+ assertEquals(20,result.get(Calendar.HOUR_OF_DAY));
+ // expecting Friday 11th
+ assertEquals(11,result.get(Calendar.DAY_OF_MONTH));
+ assertEquals(Calendar.FRIDAY,result.get(Calendar.DAY_OF_WEEK));
+ assertEquals(Calendar.MARCH,result.get(Calendar.MONTH));
+ assertEquals(2011,result.get(Calendar.YEAR));
+
+ // Match to the day of week, but to late to run, should just a week forward.
+ current = Calendar.getInstance();
+ current.set(2011, Calendar.MARCH, 11, 22, 0, 30);
+ LOG.debug("update:" + current.getTime());
+
+ next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+
+ result = Calendar.getInstance();
+ result.setTimeInMillis(next);
+ LOG.debug("next:" + result.getTime());
+
+ //assertEquals(0,result.get(Calendar.SECOND));
+ assertEquals(50,result.get(Calendar.MINUTE));
+ assertEquals(20,result.get(Calendar.HOUR_OF_DAY));
+ // expecting Friday 18th
+ assertEquals(18,result.get(Calendar.DAY_OF_MONTH));
+ assertEquals(Calendar.FRIDAY,result.get(Calendar.DAY_OF_WEEK));
+ assertEquals(Calendar.MARCH,result.get(Calendar.MONTH));
+ assertEquals(2011,result.get(Calendar.YEAR));
+ }
+
+ @Test
+ public void testgetNextTimeMonthVariant() throws MessageFormatException {
+
+ // using an absolute date so that result will be absolute - Monday 7 March 2011
+ Calendar current = Calendar.getInstance();
+ current.set(2011, Calendar.MARCH, 7, 9, 15, 30);
+ LOG.debug("start:" + current.getTime());
+
+ String test = "0 20 * 4,5 0";
+ long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+
+ Calendar result = Calendar.getInstance();
+ result.setTimeInMillis(next);
+ LOG.debug("next:" + result.getTime());
+
+ assertEquals(0,result.get(Calendar.SECOND));
+ assertEquals(0,result.get(Calendar.MINUTE));
+ assertEquals(20,result.get(Calendar.HOUR_OF_DAY));
+ // expecting Sunday 3rd of April
+ assertEquals(Calendar.APRIL,result.get(Calendar.MONTH));
+ assertEquals(3,result.get(Calendar.DAY_OF_MONTH));
+ assertEquals(Calendar.SUNDAY,result.get(Calendar.DAY_OF_WEEK));
+ assertEquals(2011,result.get(Calendar.YEAR));
+
+ current = Calendar.getInstance();
+ current.set(2011, Calendar.APRIL, 30, 22, 0, 30);
+ LOG.debug("update:" + current.getTime());
+
+ next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+
+ result = Calendar.getInstance();
+ result.setTimeInMillis(next);
+ LOG.debug("next:" + result.getTime());
+
+ assertEquals(0,result.get(Calendar.SECOND));
+ assertEquals(0,result.get(Calendar.MINUTE));
+ assertEquals(20,result.get(Calendar.HOUR_OF_DAY));
+ // expecting Sunday 1st of May
+ assertEquals(1,result.get(Calendar.DAY_OF_MONTH));
+ assertEquals(Calendar.SUNDAY,result.get(Calendar.DAY_OF_WEEK));
+ assertEquals(Calendar.MAY,result.get(Calendar.MONTH));
+ assertEquals(2011,result.get(Calendar.YEAR));
+
+ // Move past last time and see if reschedule to next year works.
+ current = Calendar.getInstance();
+ current.set(2011, Calendar.MAY, 30, 22, 0, 30);
+ LOG.debug("update:" + current.getTime());
+
+ next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+
+ result = Calendar.getInstance();
+ result.setTimeInMillis(next);
+ LOG.debug("next:" + result.getTime());
+
+ assertEquals(0,result.get(Calendar.SECOND));
+ assertEquals(0,result.get(Calendar.MINUTE));
+ assertEquals(20,result.get(Calendar.HOUR_OF_DAY));
+ // expecting Sunday 1st of April - 2012
+ assertEquals(1,result.get(Calendar.DAY_OF_MONTH));
+ assertEquals(Calendar.SUNDAY,result.get(Calendar.DAY_OF_WEEK));
+ assertEquals(Calendar.APRIL,result.get(Calendar.MONTH));
+ assertEquals(2012,result.get(Calendar.YEAR));
+ }
+
+ @Test
+ public void testgetNextTimeMonth() throws MessageFormatException {
+
+ // using an absolute date so that result will be absolute - Monday 15 Nov 2010
+ Calendar current = Calendar.getInstance();
+ current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
+ LOG.debug("start:" + current.getTime());
+
+ String test = "* * * 12 *";
+ long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+
+ Calendar result = Calendar.getInstance();
+ result.setTimeInMillis(next);
+ LOG.debug("next:" + result.getTime());
+
+ assertEquals(0,result.get(Calendar.SECOND));
+ assertEquals(0,result.get(Calendar.MINUTE));
+ assertEquals(0,result.get(Calendar.HOUR_OF_DAY));
+ assertEquals(1,result.get(Calendar.DAY_OF_MONTH));
+ assertEquals(Calendar.DECEMBER,result.get(Calendar.MONTH));
+ assertEquals(2010,result.get(Calendar.YEAR));
+ }
+
+ @Test
+ public void testgetNextTimeDays() throws MessageFormatException {
+
+ // using an absolute date so that result will be absolute - Monday 15 Nov 2010
+ Calendar current = Calendar.getInstance();
+ current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
+ LOG.debug("start:" + current.getTime());
+
+ String test = "* * 16 * *";
+ long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+
+ Calendar result = Calendar.getInstance();
+ result.setTimeInMillis(next);
+ LOG.debug("next:" + result.getTime());
+
+ assertEquals(0,result.get(Calendar.SECOND));
+ assertEquals(0,result.get(Calendar.MINUTE));
+ assertEquals(0,result.get(Calendar.HOUR));
+ assertEquals(16,result.get(Calendar.DAY_OF_MONTH));
+ assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
+ assertEquals(2010,result.get(Calendar.YEAR));
+ }
+
+ @Test
+ public void testgetNextTimeMinutes() throws MessageFormatException {
+ String test = "30 * * * *";
+ long current = 20*60*1000;
+ Calendar calender = Calendar.getInstance();
+ calender.setTimeInMillis(current);
+ LOG.debug("start:" + calender.getTime());
+ long next = CronParser.getNextScheduledTime(test, current);
+
+ calender.setTimeInMillis(next);
+ LOG.debug("next:" + calender.getTime());
+ long result = next - current;
+ assertEquals(60*10*1000,result);
+ }
+
+ @Test
+ public void testgetNextTimeHours() throws MessageFormatException {
+ String test = "* 1 * * *";
+
+ Calendar calender = Calendar.getInstance();
+ calender.set(1972, 2, 2, 17, 10, 0);
+ long current = calender.getTimeInMillis();
+ long next = CronParser.getNextScheduledTime(test, current);
+
+ calender.setTimeInMillis(next);
+ long result = next - current;
+ long expected = 60*1000*60*8 + 60 * 1000;
+ assertEquals(expected,result);
+ }
+
+ @Test
+ public void testgetNextTimeHoursZeroMin() throws MessageFormatException {
+ String test = "0 1 * * *";
+
+ Calendar calender = Calendar.getInstance();
+ calender.set(1972, 2, 2, 17, 10, 0);
+ long current = calender.getTimeInMillis();
+ long next = CronParser.getNextScheduledTime(test, current);
+
+ calender.setTimeInMillis(next);
+ long result = next - current;
+ long expected = 60*1000*60*7 + 60*1000*50;
+ assertEquals(expected,result);
+ }
+
+ @Test
+ public void testValidate() {
+ try {
+ CronParser.validate("30 08 10 06 ? ");
+ CronParser.validate("30 08 ? 06 5 ");
+ CronParser.validate("30 08 ? 06 * ");
+ CronParser.validate("* * * * * ");
+ CronParser.validate("* * * * 1-6 ");
+ CronParser.validate("* * * * 1,2,5 ");
+ CronParser.validate("*/10 0-4,8-12 * * 1-2,3-6/2 ");
+
+ } catch (Exception e) {
+ fail("Should be valid ");
+ }
+
+ try {
+ CronParser.validate("61 08 10 06 * ");
+ fail("Should not be valid ");
+ } catch (Exception e) {
+ }
+ try {
+ CronParser.validate("61 08 06 * ");
+ fail("Should not be valid ");
+ } catch (Exception e) {
+ }
+ }
+
+ @Test
+ public void testGetNextCommaSeparated() throws MessageFormatException {
+ String token = "3,5,7";
+ // test minimum values
+ int next = CronParser.getNext(createEntry(token, 1, 10), 3);
+ assertEquals(2, next);
+ next = CronParser.getNext(createEntry(token, 1, 10), 8);
+ assertEquals(4, next);
+ next = CronParser.getNext(createEntry(token, 1, 10), 1);
+ assertEquals(2, next);
+ }
+
+ @Test
+ public void testGetNextRange() throws MessageFormatException {
+ String token = "3-5";
+ // test minimum values
+ int next = CronParser.getNext(createEntry(token, 1, 10), 3);
+ assertEquals(1, next);
+ next = CronParser.getNext(createEntry(token, 1, 10), 5);
+ assertEquals(7, next);
+ next = CronParser.getNext(createEntry(token, 1, 10), 6);
+ assertEquals(6, next);
+ next = CronParser.getNext(createEntry(token, 1, 10), 1);
+ assertEquals(2, next);
+ }
+
+ @Test
+ public void testGetNextExact() throws MessageFormatException {
+ String token = "3";
+ int next = CronParser.getNext(createEntry(token, 0, 10), 2);
+ assertEquals(1, next);
+ next = CronParser.getNext(createEntry(token, 0, 10), 3);
+ assertEquals(10, next);
+ next = CronParser.getNext(createEntry(token, 0, 10), 1);
+ assertEquals(2, next);
+ }
+
+ @Test
+ public void testTokenize() {
+ String test = "*/5 * * * *";
+ List<String> list = CronParser.tokenize(test);
+ assertEquals(list.size(), 5);
+
+ test = "*/5 * * * * *";
+ try {
+ list = CronParser.tokenize(test);
+ fail("Should have throw an exception");
+ } catch (Throwable e) {
+ }
+
+ test = "*/5 * * * *";
+ try {
+ list = CronParser.tokenize(test);
+ fail("Should have throw an exception");
+ } catch (Throwable e) {
+ }
+
+ test = "0 1 2 3 4";
+ list = CronParser.tokenize(test);
+ assertEquals(list.size(), 5);
+
+ assertEquals(list.get(0), "0");
+ assertEquals(list.get(1), "1");
+ assertEquals(list.get(2), "2");
+ assertEquals(list.get(3), "3");
+ assertEquals(list.get(4), "4");
+ }
+
+ public void testGetNextScheduledTime() {
+ fail("Not yet implemented");
+ }
+
+ CronParser.CronEntry createEntry(String str, int start, int end) {
+ return new CronParser.CronEntry("test", str, start, end);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/java/org/apache/activemq/openwire/utils/OpenWireMarshallingSupportTest.java
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/utils/OpenWireMarshallingSupportTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/utils/OpenWireMarshallingSupportTest.java
new file mode 100644
index 0000000..f40a31a
--- /dev/null
+++ b/openwire-core/src/test/java/org/apache/activemq/openwire/utils/OpenWireMarshallingSupportTest.java
@@ -0,0 +1,43 @@
+/**
+ * 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.activemq.openwire.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.DataInputStream;
+
+import org.apache.activemq.openwire.utils.OpenWireMarshallingSupport;
+import org.fusesource.hawtbuf.DataByteArrayInputStream;
+import org.fusesource.hawtbuf.DataByteArrayOutputStream;
+import org.junit.Test;
+
+public class OpenWireMarshallingSupportTest {
+
+ @Test
+ public void testMarshalBoolean() throws Exception {
+ DataByteArrayOutputStream dataOut = new DataByteArrayOutputStream();
+ OpenWireMarshallingSupport.marshalBoolean(dataOut, false);
+ OpenWireMarshallingSupport.marshalBoolean(dataOut, true);
+ DataByteArrayInputStream input = new DataByteArrayInputStream(dataOut.toBuffer());
+ DataInputStream dataIn = new DataInputStream(input);
+ Boolean result = (Boolean) OpenWireMarshallingSupport.unmarshalPrimitive(dataIn);
+ assertFalse(result);
+ result = (Boolean) OpenWireMarshallingSupport.unmarshalPrimitive(dataIn);
+ assertTrue(result);
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-core/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/openwire-core/src/test/resources/log4j.properties b/openwire-core/src/test/resources/log4j.properties
new file mode 100644
index 0000000..0588275
--- /dev/null
+++ b/openwire-core/src/test/resources/log4j.properties
@@ -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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, out, stdout
+
+log4j.logger.org.apache.activemq.openwire=DEBUG
+
+# Tune the ActiveMQ and it's OpenWire transport as needed for debugging.
+log4j.logger.org.apache.activemq=INFO
+log4j.logger.org.apache.activemq.broker=DEBUG
+log4j.logger.org.apache.activemq.transport.openwire=TRACE
+log4j.logger.org.apache.activemq.transport.openwire.FRAMES=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/activemq-test.log
+log4j.appender.out.append=true
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-generator/.gitignore
----------------------------------------------------------------------
diff --git a/openwire-generator/.gitignore b/openwire-generator/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/openwire-generator/.gitignore
@@ -0,0 +1 @@
+/target
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-generator/pom.xml
----------------------------------------------------------------------
diff --git a/openwire-generator/pom.xml b/openwire-generator/pom.xml
new file mode 100644
index 0000000..1cde472
--- /dev/null
+++ b/openwire-generator/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.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.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>openwire-protocol</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>openwire-generator</artifactId>
+ <name>openwire-generator</name>
+ <description>An OpenWire marshaller generator for the OpenWire Protocol library</description>
+ <packaging>jar</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <!-- =================================== -->
+ <!-- Required Dependencies -->
+ <!-- =================================== -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>groovy</groupId>
+ <artifactId>gram</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.0-jsr-04</version>
+ </dependency>
+ <dependency>
+ <groupId>annogen</groupId>
+ <artifactId>annogen</artifactId>
+ <version>0.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>default-tools.jar</id>
+ <activation>
+ <property>
+ <name>java.vendor</name>
+ <value>Sun Microsystems Inc.</value>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>com.sun</groupId>
+ <artifactId>tools</artifactId>
+ <version>1.6.0</version>
+ <scope>system</scope>
+ <systemPath>${java.home}/../lib/tools.jar</systemPath>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/GeneratorTask.java
----------------------------------------------------------------------
diff --git a/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/GeneratorTask.java b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/GeneratorTask.java
new file mode 100644
index 0000000..24573d1
--- /dev/null
+++ b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/GeneratorTask.java
@@ -0,0 +1,206 @@
+/**
+ * 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.activemq.openwire.generator;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.codehaus.jam.JamService;
+import org.codehaus.jam.JamServiceFactory;
+import org.codehaus.jam.JamServiceParams;
+
+/**
+ * The main task that controls the OpenWire code generation routines.
+ */
+public class GeneratorTask extends Task {
+
+ protected int fromVersion = 1;
+ protected int toVersion = 1;
+ protected boolean rangedGenerate = true;
+ protected File sourceDir = new File("./src/main/java");
+ protected File targetDir = new File("./src/main/java");
+ protected boolean generateMarshalers = true;
+ protected boolean generateTests = false;
+ protected String commandsPackage;
+ protected String codecPackageRoot;
+
+ public static void main(String[] args) {
+
+ Project project = new Project();
+ project.init();
+ GeneratorTask generator = new GeneratorTask();
+ generator.setProject(project);
+
+ if (args.length > 0) {
+ generator.fromVersion = Integer.parseInt(args[0]);
+ }
+
+ if (args.length > 0) {
+ generator.toVersion = Integer.parseInt(args[0]);
+ }
+
+ if (args.length > 1) {
+ generator.sourceDir = new File(args[1]);
+ }
+
+ if (args.length > 2) {
+ generator.targetDir = new File(args[1]);
+ }
+
+ if (args.length > 3) {
+ generator.commandsPackage = args[2];
+ }
+
+ if (args.length > 4) {
+ generator.codecPackageRoot = args[3];
+ }
+
+ generator.execute();
+ }
+
+ @Override
+ public void execute() throws BuildException {
+ try {
+ System.out.println("======================================================");
+ System.out.println("OpenWire Generator: Command source files in: ");
+ System.out.println("" + sourceDir);
+ System.out.println("======================================================");
+
+ JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
+ JamServiceParams params = jamServiceFactory.createServiceParams();
+ File[] dirs = new File[] { sourceDir };
+ params.includeSourcePattern(dirs, "**/*.java");
+ JamService jam = jamServiceFactory.createService(params);
+
+ if (generateMarshalers) {
+ if (!isRangedGenerate()) {
+ runMarshalerGenerateScript(jam, fromVersion);
+ if (toVersion != fromVersion) {
+ runMarshalerGenerateScript(jam, toVersion);
+ }
+ } else {
+ for (int i = fromVersion; i <= toVersion; ++i) {
+ runMarshalerGenerateScript(jam, i);
+ }
+ }
+ }
+
+ if (generateTests) {
+ if (!isRangedGenerate()) {
+ runTestGenerateScript(jam, fromVersion);
+ if (toVersion != fromVersion) {
+ runTestGenerateScript(jam, toVersion);
+ }
+ } else {
+ for (int i = fromVersion; i <= toVersion; ++i) {
+ runTestGenerateScript(jam, i);
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ throw new BuildException(e);
+ }
+ }
+
+ protected void runMarshalerGenerateScript(JamService jam, int version) throws Exception {
+ System.out.println("======================================================");
+ System.out.println(" Generating Marshallers for OpenWire version: " + version);
+ System.out.println("======================================================");
+ MarshallingGenerator script = new MarshallingGenerator();
+ runScript(script, jam, version);
+ }
+
+ protected void runTestGenerateScript(JamService jam, int version) throws Exception {
+ System.out.println("======================================================");
+ System.out.println(" Generating Test Cases for OpenWire version: " + version);
+ System.out.println("======================================================");
+ TestsGenerator script = new TestsGenerator();
+ runScript(script, jam, version);
+ }
+
+ protected void runScript(MultiSourceGenerator script, JamService jam, int version) throws Exception {
+ script.setJam(jam);
+ script.setTargetDir(targetDir.getCanonicalPath());
+ script.setOpenwireVersion(version);
+ if (commandsPackage != null) {
+ script.setCommandsPackage(commandsPackage);
+ }
+ if (codecPackageRoot != null) {
+ script.setCodecPackageRoot(codecPackageRoot);
+ }
+ script.run();
+ }
+
+ public int getFromVersion() {
+ return fromVersion;
+ }
+
+ public void setFromVersion(int version) {
+ this.fromVersion = version;
+ }
+
+ public int getToVersion() {
+ return toVersion;
+ }
+
+ public void setToVersion(int version) {
+ this.toVersion = version;
+ }
+
+ public File getSourceDir() {
+ return sourceDir;
+ }
+
+ public void setSourceDir(File sourceDir) {
+ this.sourceDir = sourceDir;
+ }
+
+ public File getTargetDir() {
+ return targetDir;
+ }
+
+ public void setTargetDir(File targetDir) {
+ this.targetDir = targetDir;
+ }
+
+ public boolean isGenerateMarshalers() {
+ return generateMarshalers;
+ }
+
+ public void setGenerateMarshalers(boolean generateMarshalers) {
+ this.generateMarshalers = generateMarshalers;
+ }
+
+ public boolean isGenerateTests() {
+ return generateTests;
+ }
+
+ public void setGenerateTests(boolean generateTests) {
+ this.generateTests = generateTests;
+ }
+
+ public boolean isRangedGenerate() {
+ return this.rangedGenerate;
+ }
+
+ public void setRangedGenerate(boolean rangedGenerate) {
+ this.rangedGenerate = rangedGenerate;
+ }
+}