summaryrefslogtreecommitdiffstats
path: root/sandbox/old/contrib/binding-celtix/binding/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/old/contrib/binding-celtix/binding/src/test/java')
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/BootstrapTestCase.java35
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java134
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java152
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/Greeter.java32
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/GreeterImpl.java33
5 files changed, 386 insertions, 0 deletions
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/BootstrapTestCase.java b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/BootstrapTestCase.java
new file mode 100644
index 0000000000..cba83a7792
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/BootstrapTestCase.java
@@ -0,0 +1,35 @@
+/*
+ * 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.binding.celtix;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BootstrapTestCase extends TestCase {
+
+ public void testReference() throws Exception {
+// BusServiceImpl busService = new BusServiceImpl();
+// WSDLDefinitionRegistry wsdlRegistry = new WSDLDefinitionRegistryImpl();
+// busService.setWsdlRegistry(wsdlRegistry);
+// busService.init();
+// CeltixReference reference = new CeltixReference("reference",);
+ }
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java
new file mode 100644
index 0000000000..235144ffbb
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java
@@ -0,0 +1,134 @@
+/*
+ * 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.binding.celtix;
+
+import java.net.URL;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+
+import org.xml.sax.InputSource;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.binding.celtix.io.SCADataBindingCallback;
+import org.easymock.classextension.EasyMock;
+import org.objectweb.celtix.Bus;
+import org.objectweb.celtix.bindings.BindingManager;
+import org.objectweb.celtix.bus.bindings.soap.SOAPBindingFactory;
+import org.objectweb.celtix.bus.bindings.soap.SOAPClientBinding;
+import org.objectweb.celtix.context.ObjectMessageContextImpl;
+import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CeltixInvokerTestCase extends TestCase {
+
+ public void testProcessingInputWithoutInOut() throws Exception {
+ String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl";
+ String operationName = "greetMe";
+ ObjectMessageContextImpl inputCtx = new ObjectMessageContextImpl();
+ CeltixInvoker invoker = createCeltixInvoker(wsdlLocation,
+ operationName, inputCtx);
+
+ Object[] args = new Object[1];
+ args[0] = new String("hello");
+ invoker.invokeTarget(args, CeltixInvoker.NONE);
+
+ // Check the input object after processing is correct
+ // Should be no change for input if only IN parameters involved
+ Object[] myrtn = (Object[]) inputCtx.getMessageObjects();
+
+ assertEquals("hello", myrtn[0]);
+ }
+
+ public void testProcessingInputWithInOut() throws Exception {
+ String wsdlLocation = "/wsdl/hello_world_doc_lit_inout.wsdl";
+ String operationName = "greetMe";
+ ObjectMessageContextImpl inputCtx = new ObjectMessageContextImpl();
+ CeltixInvoker invoker = createCeltixInvoker(wsdlLocation,
+ operationName, inputCtx);
+
+ Object[] args = new Object[1];
+ String inputvalue = new String("hello");
+ args[0] = inputvalue;
+ Object result = invoker.invokeTarget(args, CeltixInvoker.NONE);
+
+ // Check the input object after processing is correct
+ // input should be wrapped as Holder type if it is INOUT parameter
+ Object[] myrtn = (Object[]) inputCtx.getMessageObjects();
+
+ //FIXME: this does not work for the wrapped doc/lit case due to a bug in Celtix
+ //assertTrue("input is not Holder type", myrtn[0] instanceof Holder);
+ }
+
+ // NOTE: For convenience this method presumes the soap service name is
+ // SOAPService and port name is SoapPort
+ private CeltixInvoker createCeltixInvoker(String wsdlLocation,
+ String operationName,
+ ObjectMessageContextImpl inputCtx)
+ throws Exception {
+
+ // Make following call to return a mocked SOAPClientBinding:
+ // bus.getBindingManager().getBindingFactory(bindingId).createClientBinding(reference)
+ SOAPClientBinding clientBinding = EasyMock
+ .createMock(SOAPClientBinding.class);
+ clientBinding.createObjectContext();
+ EasyMock.expectLastCall().andReturn(inputCtx);
+ clientBinding.invoke(EasyMock.isA(ObjectMessageContextImpl.class),
+ EasyMock.isA(SCADataBindingCallback.class));
+ EasyMock.expectLastCall().andReturn(new ObjectMessageContextImpl());
+ EasyMock.replay(clientBinding);
+
+ SOAPBindingFactory bindingFactory = EasyMock.createNiceMock(SOAPBindingFactory.class);
+ bindingFactory.createClientBinding(EasyMock.isA(EndpointReferenceType.class));
+ EasyMock.expectLastCall().andReturn(clientBinding);
+ EasyMock.replay(bindingFactory);
+
+ BindingManager bindingManager = EasyMock.createNiceMock(BindingManager.class);
+ String bindingId = "http://schemas.xmlsoap.org/wsdl/soap/";
+ bindingManager.getBindingFactory(bindingId);
+ EasyMock.expectLastCall().andReturn(bindingFactory);
+
+ Bus bus = EasyMock.createNiceMock(Bus.class);
+ bus.getBindingManager();
+ EasyMock.expectLastCall().andReturn(bindingManager);
+ EasyMock.replay(bindingManager);
+ EasyMock.replay(bus);
+
+ // Create WSDL Definition
+ URL url = getClass().getResource(wsdlLocation);
+ assertNotNull("Could not find wsdl " + url.toString(), url);
+
+ WSDLFactory factory = WSDLFactory.newInstance();
+ WSDLReader reader = factory.newWSDLReader();
+ reader.setFeature("javax.wsdl.verbose", false);
+ InputSource input = new InputSource(url.openStream());
+ Definition wsdlDef = reader.readWSDL(url.toString(), input);
+ QName qName = new QName("http://objectweb.org/hello_world_soap_http", "SOAPService");
+ Service wsdlService = wsdlDef.getService(qName);
+ Port port = wsdlService.getPort("SoapPort");
+
+ return new CeltixInvoker(operationName, bus, port, wsdlService, wsdlDef, null);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java
new file mode 100644
index 0000000000..c667ed2ba2
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * 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.binding.celtix;
+
+import java.lang.reflect.Type;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+
+import org.xml.sax.InputSource;
+
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.WireService;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+import org.objectweb.celtix.Bus;
+import org.objectweb.celtix.bindings.BindingManager;
+import static org.objectweb.celtix.bindings.DataBindingCallback.Mode.PARTS;
+import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
+import org.objectweb.celtix.bindings.ServerDataBindingCallback;
+import org.objectweb.celtix.bus.bindings.soap.SOAPBindingFactory;
+import org.objectweb.celtix.bus.bindings.soap.SOAPServerBinding;
+import org.objectweb.celtix.context.ObjectMessageContextImpl;
+import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CeltixServiceTestCase extends TestCase {
+
+ public void testGetDataBindingCallback() throws Exception {
+ CeltixServiceBinding celtixService = createCeltixService();
+ Message msg = new MessageImpl();
+ msg.setBody("Hello Celtix");
+ Interceptor interceptor = EasyMock.createMock(Interceptor.class);
+ EasyMock.expect(interceptor.invoke(EasyMock.isA(Message.class))).andReturn(msg);
+ EasyMock.replay(interceptor);
+ InboundInvocationChain chain = EasyMock.createMock(InboundInvocationChain.class);
+ EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor);
+ EasyMock.replay(chain);
+ Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>();
+ Operation<?> op = new Operation<Type>("greetMe", null, null, null);
+ chains.put(op, chain);
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+ EasyMock.expect(wire.getInvocationChains()).andReturn(chains);
+ EasyMock.replay(wire);
+ celtixService.setInboundWire(wire);
+ QName operationName = new QName("greetMe");
+ ObjectMessageContextImpl ctx = new ObjectMessageContextImpl();
+ ctx.setMessageObjects(new String[]{"Celtix"});
+ ServerDataBindingCallback callback1 = celtixService.getDataBindingCallback(operationName, ctx, PARTS);
+ assertNotNull(callback1);
+
+ callback1.invoke(ctx);
+ Message rtn = (Message) ctx.getReturn();
+ assertEquals("Hello Celtix", rtn.getBody());
+
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private CeltixServiceBinding createCeltixService() throws Exception {
+ //Make following call to return a mocked SOAPClientBinding:
+ //bus.getBindingManager().getBindingFactory(bindingId).createClientBinding(reference)
+ SOAPServerBinding serverBinding = EasyMock.createMock(SOAPServerBinding.class);
+ serverBinding.activate();
+ EasyMock.replay(serverBinding);
+
+ //ServerBindingEndpointCallback callback = EasyMock.createNiceMock(ServerBindingEndpointCallback.class);
+
+ SOAPBindingFactory bindingFactory = EasyMock.createNiceMock(SOAPBindingFactory.class);
+ bindingFactory.createServerBinding(EasyMock.isA(EndpointReferenceType.class),
+ EasyMock.isA(ServerBindingEndpointCallback.class));
+ EasyMock.expectLastCall().andReturn(serverBinding);
+ EasyMock.replay(bindingFactory);
+
+ BindingManager bindingManager = EasyMock.createNiceMock(BindingManager.class);
+ String bindingId = "http://schemas.xmlsoap.org/wsdl/soap/";
+ bindingManager.getBindingFactory(bindingId);
+ EasyMock.expectLastCall().andReturn(bindingFactory);
+
+ Bus bus = EasyMock.createNiceMock(Bus.class);
+ bus.getBindingManager();
+ EasyMock.expectLastCall().andReturn(bindingManager);
+ EasyMock.replay(bindingManager);
+ EasyMock.replay(bus);
+
+ //Create WSDL Definition
+ String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl";
+ URL url = getClass().getResource(wsdlLocation);
+ assertNotNull("Could not find wsdl " + url.toString(), url);
+
+ WSDLFactory factory = WSDLFactory.newInstance();
+ WSDLReader reader = factory.newWSDLReader();
+ reader.setFeature("javax.wsdl.verbose", false);
+ InputSource input = new InputSource(url.openStream());
+ Definition wsdlDef = reader.readWSDL(url.toString(), input);
+ Service wsdlService = wsdlDef.getService(new QName("http://objectweb.org/hello_world_soap_http",
+ "SOAPService"));
+ Port port = wsdlService.getPort("SoapPort");
+
+ WebServiceBindingDefinition wsBinding = new WebServiceBindingDefinition(wsdlDef, port, "uri", "portURI", wsdlService);
+
+ //Create mocked InboundWire, for ServiceBindingExtension.getInterface()
+ InboundWire inboundWire = EasyMock.createNiceMock(InboundWire.class);
+ JavaServiceContract contract = new JavaServiceContract(Greeter.class);
+ EasyMock.expect(inboundWire.getServiceContract()).andReturn(contract).anyTimes();
+ EasyMock.replay(inboundWire);
+
+ //Create mocked WireService, for ServiceBindingExtension.getServiceInstance()
+ WireService wireService = EasyMock.createNiceMock(WireService.class);
+ wireService.createProxy(EasyMock.isA(Class.class), EasyMock.isA(InboundWire.class));
+ EasyMock.expectLastCall().andReturn(new GreeterImpl()).anyTimes();
+ EasyMock.replay(wireService);
+
+ CeltixServiceBinding celtixService = new CeltixServiceBinding("name", null, wsBinding, bus, null);
+ //Not sure how InboundWire is set to CeltixServiceBinding, is the following way correct?
+ celtixService.setInboundWire(inboundWire);
+ celtixService.start();
+
+ return celtixService;
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/Greeter.java b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/Greeter.java
new file mode 100644
index 0000000000..56de472774
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/Greeter.java
@@ -0,0 +1,32 @@
+/*
+ * 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.binding.celtix;
+
+public interface Greeter {
+ java.lang.String sayHi();
+
+ java.lang.String greetMe(
+ java.lang.String requestType
+ );
+
+ void greetMeOneWay(
+ java.lang.String requestType
+ );
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/GreeterImpl.java b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/GreeterImpl.java
new file mode 100644
index 0000000000..38237ad81a
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/test/java/org/apache/tuscany/binding/celtix/GreeterImpl.java
@@ -0,0 +1,33 @@
+/*
+ * 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.binding.celtix;
+
+public class GreeterImpl implements Greeter {
+ public java.lang.String sayHi() {
+ return "sayHi";
+ }
+
+ public java.lang.String greetMe(String requestType) {
+ return "Hello " + requestType;
+ }
+
+ public void greetMeOneWay(String requestType) {
+ }
+
+}