diff options
Diffstat (limited to 'sca-java-2.x/contrib/itest/jms/src/test/java')
11 files changed, 804 insertions, 0 deletions
diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/DefaultsTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/DefaultsTestCase.java new file mode 100644 index 0000000000..dca9386637 --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/DefaultsTestCase.java @@ -0,0 +1,54 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * This shows how to test the JMS binding using a simple HelloWorld application. + */ +public class DefaultsTestCase { + + private static SCADomain scaDomain; + + @Before + public void init() { + scaDomain = + SCADomain.newInstance("http://localhost", "/", "defaults/client.composite", "defaults/service.composite"); + // scaDomain = SCADomain.newInstance("http://localhost", "/", "simple/client.composite"); + } + + @Test + public void testHelloWorldCreate() throws Exception { + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldClient"); + assertEquals("jmsHello Petra", helloWorldService.sayHello("Petra")); + } + + @After + public void end() { + if (scaDomain != null) { + scaDomain.close(); + } + } +} diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/DynamicReplyQTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/DynamicReplyQTestCase.java new file mode 100644 index 0000000000..f4750e5453 --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/DynamicReplyQTestCase.java @@ -0,0 +1,53 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * This shows how to test the JMS binding using a simple HelloWorld application. + */ +public class DynamicReplyQTestCase { + + private static SCADomain scaDomain; + + @Before + public void init() { + scaDomain = + SCADomain.newInstance("http://localhost", "/", "dynamic/client.composite", "simple/service.composite"); + } + + @Test + public void testHelloWorldCreate() throws Exception { + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldClient"); + assertEquals("jmsHello Beate", helloWorldService.sayHello("Beate")); + } + + @After + public void end() { + if (scaDomain != null) { + scaDomain.close(); + } + } +} diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExceptionsTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExceptionsTestCase.java new file mode 100644 index 0000000000..ba3e697e13 --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExceptionsTestCase.java @@ -0,0 +1,72 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +/** + * This shows how to test the JMS binding using a simple HelloWorld application. + */ +public class ExceptionsTestCase { + + private static SCADomain scaDomain; + + @Before + public void init() { + scaDomain = + SCADomain.newInstance("http://localhost", "/", "exceptions/client.composite", "exceptions/service.composite"); + } + + @Test + @Ignore // TUSCANY-2593, currently fails for some jaxws reason? + public void testChecked() { + ExceptionService service = scaDomain.getService(ExceptionService.class, "ExceptionServiceClient"); + try { + service.throwChecked(); + fail(); + } catch (CheckedExcpetion e) { + assertEquals("foo", e.getMessage()); + } + } + + @Test + public void testUnChecked() { + ExceptionService service = scaDomain.getService(ExceptionService.class, "ExceptionServiceClient"); + try { + service.throwUnChecked(); + fail(); + } catch (Exception e) { + assertEquals("bla", e.getCause().getCause().getMessage()); + } + } + + @After + public void end() { + if (scaDomain != null) { + scaDomain.close(); + } + } +} diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExternalBrokerTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExternalBrokerTestCase.java new file mode 100644 index 0000000000..c34ad07901 --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExternalBrokerTestCase.java @@ -0,0 +1,70 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; + +import org.apache.activemq.broker.BrokerService; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests using the JMS binding with an external JMS broker + */ +public class ExternalBrokerTestCase { + + private static SCADomain scaDomain; + private BrokerService broker; + + @Before + public void init() throws Exception { + startBroker(); + scaDomain = SCADomain.newInstance("http://localhost", "/", "external/client.composite", "external/service.composite"); + } + + @Test + public void testHelloWorldCreate() throws Exception { + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldClient"); + assertEquals("jmsHello Petra", helloWorldService.sayHello("Petra")); + } + + @After + public void end() throws Exception { + if (scaDomain != null) { + scaDomain.close(); + } + stopBroker(); + } + + protected void startBroker() throws Exception { + broker = new BrokerService(); + broker.setPersistent(false); + broker.setUseJmx(false); + broker.addConnector("tcp://localhost:61616"); + broker.start(); + } + protected void stopBroker() throws Exception { + if (broker != null) { + broker.stop(); + } + } + +} diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/MessageProcessorTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/MessageProcessorTestCase.java new file mode 100644 index 0000000000..9ec77ca440 --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/MessageProcessorTestCase.java @@ -0,0 +1,58 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * This shows how to test the JMS binding using a simple HelloWorld application. + */ +public class MessageProcessorTestCase { + + private static SCADomain scaDomain; + + @Before + public void init() { + scaDomain = + SCADomain.newInstance("http://localhost", "/", "simple/mpclient.composite", "simple/service.composite"); + // scaDomain = SCADomain.newInstance("http://localhost", "/", "simple/client.composite"); + } + + @Test + public void testHelloWorldCreate() throws Exception { + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldClient"); + assertEquals("jmsHello Petra", helloWorldService.sayHello("Petra")); + assertTrue(TestMessageProcessor.extractPayloadFromJMSMessageCalled); + assertTrue(TestMessageProcessor.insertPayloadIntoJMSMessageCalled); + assertTrue(TestMessageProcessor.setOperationNameCalled); + } + + @After + public void end() { + if (scaDomain != null) { + scaDomain.close(); + } + } +} diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/NonSCAClientTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/NonSCAClientTestCase.java new file mode 100644 index 0000000000..fc47211f46 --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/NonSCAClientTestCase.java @@ -0,0 +1,142 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.naming.NamingException; + +import org.apache.activemq.broker.BrokerService; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryImpl; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * This shows how to test the JMS binding using a simple HelloWorld application. + */ +public class NonSCAClientTestCase { + + private static SCADomain scaDomain; + + @Before + public void init() throws Exception { + startBroker(); + scaDomain = SCADomain.newInstance("http://localhost", "/", "nonSCAclient/service.composite"); + OneWayServiceImpl.name = null; + } + + @Test + public void testXMLText() throws Exception { + + synchronized (OneWayServiceImpl.mutex) { + + sendTextMessage("dynamicQueues/OneWayService", "<ns2:sayHello xmlns:ns2=\"http://jms.binding.sca.tuscany.apache.org/\"><arg0>Petra</arg0></ns2:sayHello>"); + + // wait up to 10 seconds but it will likely be a lot less + // as the service invocation will wake this up earlier + if (OneWayServiceImpl.name == null) { + OneWayServiceImpl.mutex.wait(10000); + } + } + assertEquals("Petra", OneWayServiceImpl.name); + } + + @Test + public void testText() throws Exception { + + synchronized (OneWayServiceImpl.mutex) { + + sendTextMessage("dynamicQueues/TextDest", "Petra"); + + // wait up to 10 seconds but it will likely be a lot less + // as the service invocation will wake this up earlier + OneWayServiceImpl.mutex.wait(10000); + } + assertEquals("Petra", OneWayServiceImpl.name); + } + + @Test + public void testObject() throws Exception { + + Set<Integer> arg = new HashSet<Integer>(); + arg.add(new Integer(3)); + + synchronized (OneWayObjectServiceImpl.mutex) { + + sendObjectMessage("dynamicQueues/ObjectDest", arg); + + // wait up to 10 seconds but it will likely be a lot less + // as the service invocation will wake this up earlier + OneWayObjectServiceImpl.mutex.wait(10000); + } + assertEquals(arg, OneWayObjectServiceImpl.name); + } + + @After + public void end() throws Exception { + if (scaDomain != null) { + scaDomain.close(); + } + stopBroker(); + } + + private BrokerService broker; + protected void startBroker() throws Exception { + broker = new BrokerService(); + broker.setPersistent(false); + broker.setUseJmx(false); + broker.addConnector("tcp://localhost:61618"); + broker.start(); + } + protected void stopBroker() throws Exception { + if (broker != null) { + broker.stop(); + } + } + + protected static void sendTextMessage(String destName, String payload) throws JMSException, NamingException { + JMSResourceFactory rf = new JMSResourceFactoryImpl(null, null, "tcp://localhost:61618"); + Session session = rf.getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageProducer p = session.createProducer(rf.lookupDestination(destName)); + rf.getConnection().start(); + session.run(); + p.send(session.createTextMessage(payload)); + rf.closeConnection(); + } + + protected static void sendObjectMessage(String destName, Object payload) throws JMSException, NamingException { + JMSResourceFactory rf = new JMSResourceFactoryImpl(null, null, "tcp://localhost:61618"); + Session session = rf.getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageProducer p = session.createProducer(rf.lookupDestination(destName)); + rf.getConnection().start(); + session.run(); + p.send(session.createObjectMessage((Serializable)payload)); + rf.closeConnection(); + } +} diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/OneWayTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/OneWayTestCase.java new file mode 100644 index 0000000000..26dda13cf9 --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/OneWayTestCase.java @@ -0,0 +1,58 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * This shows how to test the JMS binding using a simple HelloWorld application. + */ +public class OneWayTestCase { + + private static SCADomain scaDomain; + + @Before + public void init() { + scaDomain = SCADomain.newInstance("http://localhost", "/", "oneway/OneWayClient.composite", "oneway/OneWayService.composite"); + } + + @Test + public void testOneWayInvoked() throws Exception { + OneWayService oneWayService = scaDomain.getService(OneWayService.class, "OneWayClient"); + oneWayService.sayHello("Petra"); + synchronized (OneWayServiceImpl.mutex) { + // wait up to 10 seconds but it will likely be a lot less + // as the service invocation will wake this up earlier + OneWayServiceImpl.mutex.wait(10000); + } + assertEquals("Petra", OneWayServiceImpl.name); + } + + @After + public void end() { + if (scaDomain != null) { + scaDomain.close(); + } + } +} diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/PolicyHeadersTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/PolicyHeadersTestCase.java new file mode 100644 index 0000000000..c0c90cea95 --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/PolicyHeadersTestCase.java @@ -0,0 +1,97 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.jms.DeliveryMode; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +/** + */ +public class PolicyHeadersTestCase { + + private static SCADomain scaDomain; + + @Before + public void init() { + scaDomain = SCADomain.newInstance("http://localhost", "/", "policyHeaders/policyHeaders.composite"); + } + + @Test + public void testProps1() throws Exception { + JMSClient client = scaDomain.getService(JMSClient.class, "ClientComponent"); + + client.aClientMethod(); + + // wait for up to 5 seconds but should wake up as soon as done + synchronized(MsgServiceImpl.lock) { + if (MsgServiceImpl.msg == null) { + MsgServiceImpl.lock.wait(5000); + } + } + assertNotNull(MsgServiceImpl.msg); + + + assertEquals(4, MsgServiceImpl.msg.getJMSPriority()); // Doesn't seem to work with ActiveMQ + /* + assertEquals("myType", MsgServiceImpl.msg.getJMSType()); + assertEquals("xyz", MsgServiceImpl.msg.getJMSCorrelationID()); + assertEquals(DeliveryMode.PERSISTENT, MsgServiceImpl.msg.getJMSDeliveryMode()); + assertEquals("myHeadP1", MsgServiceImpl.msg.getStringProperty("headP1")); + */ + } + + @Test + @Ignore + public void testOp2() throws Exception { + MsgClient client = scaDomain.getService(MsgClient.class, "ClientComponent"); + + client.op2(); + + // wait for up to 5 seconds but should wake up as soon as done + synchronized(MsgServiceImpl.lock) { + if (MsgServiceImpl.msg == null) { + MsgServiceImpl.lock.wait(5000); + } + } + assertNotNull(MsgServiceImpl.msg); + + assertEquals("op2Type", MsgServiceImpl.msg.getJMSType()); + assertEquals("op2CID", MsgServiceImpl.msg.getJMSCorrelationID()); + // assertEquals(DeliveryMode.NON_PERSISTENT, MsgServiceImpl.msg.getJMSDeliveryMode()); // Doesn't seem to work with ActiveMQ + // assertEquals(3, MsgServiceImpl.msg.getJMSPriority()); // Doesn't seem to work with ActiveMQ + assertEquals("myHeadP1", MsgServiceImpl.msg.getStringProperty("headP1")); + assertEquals("foo", MsgServiceImpl.msg.getStringProperty("op2P2")); + assertEquals("nativeOp2", MsgServiceImpl.msg.getStringProperty("scaOperationName")); + } + + @After + public void end() { + if (scaDomain != null) { + scaDomain.close(); + } + } +} diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/PropertiesTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/PropertiesTestCase.java new file mode 100644 index 0000000000..4cc229422e --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/PropertiesTestCase.java @@ -0,0 +1,92 @@ +/*
+ * 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.tuscany.sca.binding.jms;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import javax.jms.DeliveryMode;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ */
+public class PropertiesTestCase {
+
+ private static SCADomain scaDomain;
+
+ @Before
+ public void init() {
+ scaDomain = SCADomain.newInstance("http://localhost", "/", "properties/properties.composite");
+ }
+
+ @Test
+ public void testProps1() throws Exception {
+ JMSClient client = scaDomain.getService(JMSClient.class, "ClientComponent");
+
+ client.aClientMethod();
+
+ // wait for up to 5 seconds but should wake up as soon as done
+ synchronized(MsgServiceImpl.lock) {
+ if (MsgServiceImpl.msg == null) {
+ MsgServiceImpl.lock.wait(5000);
+ }
+ }
+ assertNotNull(MsgServiceImpl.msg);
+
+ assertEquals("myType", MsgServiceImpl.msg.getJMSType());
+ assertEquals("xyz", MsgServiceImpl.msg.getJMSCorrelationID());
+ assertEquals(DeliveryMode.PERSISTENT, MsgServiceImpl.msg.getJMSDeliveryMode());
+ // assertEquals(3, MsgServiceImpl.msg.getJMSPriority()); // Doesn't seem to work with ActiveMQ
+ assertEquals("myHeadP1", MsgServiceImpl.msg.getStringProperty("headP1"));
+ }
+
+ @Test
+ public void testOp2() throws Exception {
+ MsgClient client = scaDomain.getService(MsgClient.class, "ClientComponent");
+
+ client.op2();
+
+ // wait for up to 5 seconds but should wake up as soon as done
+ synchronized(MsgServiceImpl.lock) {
+ if (MsgServiceImpl.msg == null) {
+ MsgServiceImpl.lock.wait(5000);
+ }
+ }
+ assertNotNull(MsgServiceImpl.msg);
+
+ assertEquals("op2Type", MsgServiceImpl.msg.getJMSType());
+ assertEquals("op2CID", MsgServiceImpl.msg.getJMSCorrelationID());
+ // assertEquals(DeliveryMode.NON_PERSISTENT, MsgServiceImpl.msg.getJMSDeliveryMode()); // Doesn't seem to work with ActiveMQ
+ // assertEquals(3, MsgServiceImpl.msg.getJMSPriority()); // Doesn't seem to work with ActiveMQ
+ assertEquals("myHeadP1", MsgServiceImpl.msg.getStringProperty("headP1"));
+ assertEquals("foo", MsgServiceImpl.msg.getStringProperty("op2P2"));
+ assertEquals("nativeOp2", MsgServiceImpl.msg.getStringProperty("scaOperationName"));
+ }
+
+ @After
+ public void end() {
+ if (scaDomain != null) {
+ scaDomain.close();
+ }
+ }
+}
diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/RPCTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/RPCTestCase.java new file mode 100644 index 0000000000..c1882a1e26 --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/RPCTestCase.java @@ -0,0 +1,54 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * This shows how to test the JMS binding using a simple HelloWorld application. + */ +public class RPCTestCase { + + private static SCADomain scaDomain; + + @Before + public void init() { + scaDomain = + SCADomain.newInstance("http://localhost", "/", "simple/client.composite", "simple/service.composite"); + // scaDomain = SCADomain.newInstance("http://localhost", "/", "simple/client.composite"); + } + + @Test + public void testHelloWorldCreate() throws Exception { + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldClient"); + assertEquals("jmsHello Petra", helloWorldService.sayHello("Petra")); + } + + @After + public void end() { + if (scaDomain != null) { + scaDomain.close(); + } + } +} diff --git a/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/URIRPCTestCase.java b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/URIRPCTestCase.java new file mode 100644 index 0000000000..bed5515d7f --- /dev/null +++ b/sca-java-2.x/contrib/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/URIRPCTestCase.java @@ -0,0 +1,54 @@ +/* + * 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.tuscany.sca.binding.jms; + +import static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * This shows how to test the JMS binding using a simple HelloWorld application. + */ +public class URIRPCTestCase { + + private static SCADomain scaDomain; + + @Before + public void init() { + scaDomain = + SCADomain.newInstance("http://localhost", "/", "simple/uriclient.composite", "simple/service.composite"); + // scaDomain = SCADomain.newInstance("http://localhost", "/", "simple/client.composite"); + } + + @Test + public void testHelloWorldCreate() throws Exception { + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldClient"); + assertEquals("jmsHello Petra", helloWorldService.sayHello("Petra")); + } + + @After + public void end() { + if (scaDomain != null) { + scaDomain.close(); + } + } +} |