From 07b7dfd1a70ba222b899d9813f8c449dbf3b785f Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:07:28 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835124 13f79535-47bb-0310-9956-ffa450edef68 --- .../bpel/BPELDocumentProcessorTestCase.java | 67 +++++++++++ .../bpel/BPELHelloWorldTestCase.java | 59 ++++++++++ .../bpel/BPELImplementationProcessorTestCase.java | 122 ++++++++++++++++++++ .../implementation/bpel/BPELPingPongTestCase.java | 60 ++++++++++ .../sca/implementation/bpel/BPELPingTestCase.java | 63 ++++++++++ .../sca/implementation/bpel/BPELPongTestCase.java | 62 ++++++++++ .../bpel/EmbeddedODEServerTestCase.java | 128 +++++++++++++++++++++ 7 files changed, 561 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPingPongTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPongTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/EmbeddedODEServerTestCase.java (limited to 'sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache') diff --git a/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java new file mode 100644 index 0000000000..6aba1f27d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java @@ -0,0 +1,67 @@ +/* + * 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.implementation.bpel; + +import java.net.URI; +import java.net.URL; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.implementation.bpel.impl.BPELDocumentProcessor; +import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory; + +/** + * @version $Rev$ $Date$ + */ +public class BPELDocumentProcessorTestCase extends TestCase { + + protected static final String BPEL_PROCESS_FILE = "helloworld/helloworld.bpel"; + + private ModelFactoryExtensionPoint modelFactories; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + modelFactories = new DefaultModelFactoryExtensionPoint(); + modelFactories.addFactory(new DefaultAssemblyFactory()); + modelFactories.addFactory(new DefaultWSDLFactory()); + + BPELFactory bpelFactory = new DefaultBPELFactory(modelFactories); + modelFactories.addFactory(bpelFactory); + } + + public void testLoadBPELProcessDefinition() throws Exception { + BPELDocumentProcessor bpelDocumentProcessor = new BPELDocumentProcessor(modelFactories); + + URI processURI = getClass().getClassLoader().getResource(BPEL_PROCESS_FILE).toURI(); + URL processLocation = getClass().getClassLoader().getResource(BPEL_PROCESS_FILE); + BPELProcessDefinition bpelProcessDefinition = bpelDocumentProcessor.read(null, processURI, processLocation); + + assertNotNull(bpelProcessDefinition); + assertEquals(new QName("http://tuscany.apache.org/implementation/bpel/example/helloworld", "HelloWorld"), bpelProcessDefinition.getName()); + assertEquals(processLocation, bpelProcessDefinition.getLocation()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELHelloWorldTestCase.java b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELHelloWorldTestCase.java new file mode 100644 index 0000000000..208af4ca2f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELHelloWorldTestCase.java @@ -0,0 +1,59 @@ +/* + * 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.implementation.bpel; + +import junit.framework.TestCase; + +import org.apache.tuscany.implementation.bpel.example.helloworld.HelloPortType; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Tests the BPEL service + * + * @version $Rev$ $Date$ + */ +public class BPELHelloWorldTestCase extends TestCase { + + private SCADomain scaDomain; + HelloPortType bpelService = null; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("helloworld/helloworld.composite"); + bpelService = scaDomain.getService(HelloPortType.class, "BPELHelloWorldComponent"); + + } + + /** + * @throws java.lang.Exception + */ + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testInvoke() { + String response = bpelService.hello("Hello"); + assertEquals("Hello World", response); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java new file mode 100644 index 0000000000..b52a75012f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java @@ -0,0 +1,122 @@ +/* + * 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.implementation.bpel; + +import java.io.StringReader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.implementation.bpel.impl.BPELImplementationProcessor; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + +/** + * @version $Rev$ $Date$ + */ +public class BPELImplementationProcessorTestCase extends TestCase { + + protected static final QName IMPLEMENTATION_BPEL = new QName(Constants.SCA10_NS, "implementation.bpel"); + + private static final String COMPOSITE = + "" + + "" + + " " + + " " + + ""; + + private static final String COMPOSITE_INVALID = + "" + + "" + + " " + + " " + + ""; + + private XMLInputFactory xmlFactory; + private ModelFactoryExtensionPoint modelFactories; + + @Override + protected void setUp() throws Exception { + super.setUp(); + xmlFactory = XMLInputFactory.newInstance(); + + modelFactories = new DefaultModelFactoryExtensionPoint(); + AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(); + modelFactories.addFactory(assemblyFactory); + JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(); + modelFactories.addFactory(javaFactory); + } + + /** + * Test parsing valid composite definition. Valid coposite populated with correct values expected. + * @throws Exception + */ + public void testLoadValidComposite() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(COMPOSITE)); + + BPELImplementationProcessor bpelProcessor = new BPELImplementationProcessor(modelFactories); + + while(true) { + int event = reader.next(); + if(event == XMLStreamConstants.START_ELEMENT && IMPLEMENTATION_BPEL.equals(reader.getName())) { + break; + } + } + + BPELImplementation implementation = bpelProcessor.read(reader); + + assertNotNull(implementation); + assertEquals(new QName("http://tuscany.apache.org/implementation/bpel/example/helloworld", "HelloWorld"), implementation.getProcess()); + } + + /** + * Test parsing invalid composite definition. Exception should be thrown + * @throws Exception + */ + public void testLoadInvalidComposite() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID)); + + BPELImplementationProcessor bpelProcessor = new BPELImplementationProcessor(modelFactories); + + while(true) { + int event = reader.next(); + if(event == XMLStreamConstants.START_ELEMENT && IMPLEMENTATION_BPEL.equals(reader.getName())) { + break; + } + } + + try { + bpelProcessor.read(reader); + + fail("InvalidException should have been thrown"); + } catch(Exception e) { + assertTrue(true); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPingPongTestCase.java b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPingPongTestCase.java new file mode 100644 index 0000000000..1ab2ba3d5d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPingPongTestCase.java @@ -0,0 +1,60 @@ +/* + * 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.implementation.bpel; + +import junit.framework.TestCase; + +import org.apache.tuscany.implementation.bpel.example.ping.PingPortType; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Tests the BPEL service + * + * @version $Rev$ $Date$ + */ +public class BPELPingPongTestCase extends TestCase { + + private SCADomain scaDomain; + PingPortType bpelPing = null; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + //scaDomain = SCADomain.newInstance("ping-pong/ping-pong.composite"); + //bpelPing = scaDomain.getService(PingPortType.class, "BPELPingPong-PingComponent/PingService"); + } + + /** + * @throws java.lang.Exception + */ + @Override + protected void tearDown() throws Exception { + //scaDomain.close(); + } + + public void testPing() { + //String response = bpelPing.Ping("Ping"); + //System.out.println("response:" + response); + //assertNotNull(response); + // assertEquals("Hello World", response); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPingTestCase.java b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPingTestCase.java new file mode 100644 index 0000000000..34f82318a3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPingTestCase.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.bpel; + +import junit.framework.TestCase; + +import org.apache.tuscany.implementation.bpel.example.ping.PingPortType; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Tests the BPEL service + * + * @version $Rev$ $Date$ + */ +public class BPELPingTestCase extends TestCase { + + private SCADomain scaDomain; + PingPortType bpelService = null; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + //scaDomain = SCADomain.newInstance("ping/ping.composite"); + //bpelService = scaDomain.getService(PingPortType.class, "BPELPingComponent"); + + } + + /** + * @throws java.lang.Exception + */ + @Override + protected void tearDown() throws Exception { + //scaDomain.close(); + } + + public void testInvoke() { + /* + String response = bpelService.Ping("Ping"); + System.out.println("response:" + response); + assertNotNull(response); + */ + // assertEquals("Hello World", response); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPongTestCase.java b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPongTestCase.java new file mode 100644 index 0000000000..313bd66850 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELPongTestCase.java @@ -0,0 +1,62 @@ +/* + * 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.implementation.bpel; + +import junit.framework.TestCase; + +import org.apache.tuscany.implementation.bpel.example.pong.PongPortType; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Tests the BPEL service + * + * @version $Rev$ $Date$ + */ +public class BPELPongTestCase extends TestCase { + + private SCADomain scaDomain; + PongPortType bpelService = null; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("pong/pong.composite"); + bpelService = scaDomain.getService(PongPortType.class, "BPELPongComponent"); + + } + + /** + * @throws java.lang.Exception + */ + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testInvoke() { + String response = bpelService.Pong("Pong"); + System.out.println("response:" + response); + assertNotNull(response); + + // assertEquals("Hello World", response); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/EmbeddedODEServerTestCase.java b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/EmbeddedODEServerTestCase.java new file mode 100644 index 0000000000..29f5cb74fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.1/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/EmbeddedODEServerTestCase.java @@ -0,0 +1,128 @@ +/* + * 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.implementation.bpel; + +import java.io.File; +import java.net.URL; +import java.util.concurrent.Future; + +import javax.transaction.TransactionManager; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.ode.bpel.iapi.Message; +import org.apache.ode.bpel.iapi.MyRoleMessageExchange; +import org.apache.ode.bpel.iapi.MessageExchange.Status; +import org.apache.ode.utils.DOMUtils; +import org.apache.ode.utils.GUID; +import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; +import org.apache.tuscany.sca.implementation.bpel.ode.GeronimoTxFactory; +import org.apache.tuscany.sca.implementation.bpel.ode.ODEDeployment; +import org.w3c.dom.Element; + +/** + * Test to Deploy and Invoke a HelloWorld BPEL process using EmbeddedODEServer + * + * @version $Rev$ $Date$ + */ +public class EmbeddedODEServerTestCase extends TestCase { + + private EmbeddedODEServer odeServer; + + private TransactionManager txMgr; + + @Override + protected void setUp() throws Exception { + GeronimoTxFactory txFactory = new GeronimoTxFactory(); + txMgr = txFactory.getTransactionManager(); + + this.odeServer = new EmbeddedODEServer(txMgr); + odeServer.init(); + } + + @Override + protected void tearDown() throws Exception { + odeServer.stop(); + } + + public void testProcessInvocation() throws Exception { + if (!odeServer.isInitialized()) { + fail("Server did not start !"); + } + + URL deployURL = getClass().getClassLoader().getResource("helloworld/deploy.xml"); + File deploymentDir = new File(deployURL.toURI().getPath()).getParentFile(); + System.out.println("Deploying : " + deploymentDir.toString()); + System.out.println(deploymentDir); + if (odeServer.isInitialized()) { + try { + txMgr.begin(); + odeServer.deploy(new ODEDeployment(deploymentDir)); + txMgr.commit(); + } catch (Exception e) { + e.printStackTrace(); + txMgr.rollback(); + } + + // transaction one + MyRoleMessageExchange mex = null; + Future onhold = null; + try { + // invoke the process + txMgr.begin(); + mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(), + new QName("http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl", "HelloService"), "hello"); + + Message request = mex.createMessage(new QName("", "")); + request.setMessage(DOMUtils.stringToDOM("Hello")); + onhold = mex.invoke(request); + txMgr.commit(); + } catch (Exception e) { + e.printStackTrace(); + txMgr.rollback(); + } + // - end of transaction one + + // Waiting until the reply is ready in case the engine needs to continue in a different thread + if (onhold != null) + onhold.get(); + + // transaction two + try { + txMgr.begin(); + // Reloading the mex in the current transaction, otherwise we can't be sure we have + // the "freshest" one. + mex = (MyRoleMessageExchange) odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId()); + + Status status = mex.getStatus(); + System.out.println("Status: " + status.name()); + Element response = mex.getResponse().getMessage(); + System.out.println("Response: " + DOMUtils.domToString(response)); + txMgr.commit(); + // end of transaction two + } catch (Exception e) { + e.printStackTrace(); + txMgr.rollback(); + } + } + } + +} -- cgit v1.2.3