package org.acme; import static org.acme.jaxws.stubs.StatefulStub.*; import static org.acme.jaxws.stubs.StatelessStub.*; import static org.gcube.common.clients.stubs.jaxws.StubFactory.*; import static org.junit.Assert.*; import java.net.URI; import java.util.Arrays; import java.util.List; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.ws.EndpointReference; import javax.xml.ws.soap.SOAPFaultException; import javax.xml.ws.wsaddressing.W3CEndpointReference; import org.acme.jaxws.stubs.BarInput; import org.acme.jaxws.stubs.BarOutput; import org.acme.jaxws.stubs.FooException; import org.acme.jaxws.stubs.StatefulStub; import org.acme.jaxws.stubs.StatelessStub; import org.acme.jaxws.stubs.Types.AnyElement; import org.acme.jaxws.stubs.Types.ChoiceOne; import org.acme.jaxws.stubs.Types.PolyWrapped; import org.acme.jaxws.stubs.Types.Sometype; import org.acme.jaxws.stubs.Types.Subone; import org.acme.jaxws.stubs.Types.Subtwo; import org.acme.jaxws.stubs.VoidWrapper; import org.gcube.common.clients.stubs.jaxws.JAXWSUtils; import org.gcube.common.mycontainer.Deployment; import org.gcube.common.mycontainer.Gar; import org.gcube.common.mycontainer.MyContainerTestRunner; import org.gcube.common.scope.api.ScopeProvider; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.w3c.dom.Document; import org.w3c.dom.Element; @RunWith(MyContainerTestRunner.class) public class StubTest { @Deployment static Gar testservice = new Gar("test-service").addConfigurations("src/test/resources/test-service/etc").addInterfaces("src/test/resources/test-service/wsdl"); static StatelessStub stub; @BeforeClass public static void setup() { //setProxy("localhost",8081); //comment after on-the-wire analysis ScopeProvider.instance.set("/gcube/devsec"); stub = stubFor(stateless).at(URI.create("http://localhost:9999/wsrf/services/acme/service/stateless")); } @Test public void fooTest() { String input = "input"; String output = stub.foo(input); assertEquals(input, output); } @Test public void fooWrappedTest() { String input = "input"; String output = stub.fooWrapped(input); assertEquals(input, output); } @Test public void fooMixedTest() { String input = "input"; String output = stub.fooMixed(input).ret; assertEquals(input, output); } @Test public void fooBulkTest() { String[] input = new String[]{"1","2","3"}; String output = stub.fooBulk(Arrays.asList(input)); assertEquals(Arrays.deepToString(input), output); } @Test public void fooContingencyTest() { try { stub.fooFault("contingency"); fail(); } catch(FooException e) { } } @Test public void fooOutageTest() throws Exception { try { stub.fooFault("outage"); fail(); } catch(SOAPFaultException e) { } } @Test public void fooProperOutageTest() throws Exception { try { stub.fooFault("proper"); fail(); } catch(SOAPFaultException e) { new RuntimeException(JAXWSUtils.remoteCause(e)).printStackTrace(); } } @Test public void barTest() throws Exception { String input = "input"; BarInput request = new BarInput(); request.in1 = input; request.in2 = 3; BarOutput response = stub.bar(request); List expected = Arrays.asList(input,input); assertEquals(expected, response.output); } @Test public void bazTest() { String response = stub.baz(new VoidWrapper()); assertNotNull(response); } @Test public void nothingTest() { stub.nothing(); } @Test public void barWrappedTest() throws Exception { String in1 = "input"; Integer in2 = 3; List response = stub.barWrapped(in1,in2); List expected = Arrays.asList(in1,in1); assertEquals(expected, response); } @Test public void createWithEPRTest() throws Exception { W3CEndpointReference ref = stub.create("input"); assertNotNull(ref); } @Test public void callsTest() throws Exception { EndpointReference ref = stub.create("input"); StatefulStub stub = stubFor(stateful).at(ref); assertNotNull(stub.calls()); } @Test public void anyTypeTest() throws Exception { String ref = stub.any("input"); assertEquals(String.class.getName(),ref); Sometype st = new Sometype(); st.some="hello"; ref = stub.any(st); assertEquals(org.acme.sample.stubs.Sometype.class.getName(),ref); } @Test public void anyElementTest() throws Exception { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element root = d.createElement("root"); root.appendChild(d.createElement("empty")); root.setAttribute("foo", "val"); AnyElement e = new AnyElement(); e.some=root; stub.anyElement(e); } @Test public void poly() throws Exception { stub.poly(new Subone()); stub.poly(new Subtwo()); } @Test public void polyWrapped() throws Exception { Subone one = new Subone(); one.one="one"; PolyWrapped wrapped = new PolyWrapped(); wrapped.param=one; stub.polyWrapped(wrapped); } @Test public void choice() throws Exception { Subone sub = new Subone(); ChoiceOne one = new ChoiceOne(); one.one=sub; stub.choice(one); } }