1 package org.objectweb.celtix.systest.type_test.soap; 2 3 import java.net.URL ; 4 import java.util.List ; 5 6 import javax.xml.namespace.QName ; 7 import javax.xml.soap.SOAPElement ; 8 import javax.xml.soap.SOAPFactory ; 9 import javax.xml.ws.Holder; 10 11 import junit.framework.Test; 12 import junit.framework.TestSuite; 13 14 import org.objectweb.celtix.systest.common.ClientServerSetupBase; 15 import org.objectweb.celtix.systest.type_test.AbstractTypeTestClient4; 16 import org.objectweb.type_test.types2.StructWithAnyArrayLax; 17 import org.objectweb.type_test.types2.StructWithAnyStrict; 18 19 public class SOAPDocLitClientTypeTest extends AbstractTypeTestClient4 { 20 static final String WSDL_PATH = "/wsdl/type_test/type_test_doclit_soap.wsdl"; 21 static final QName SERVICE_NAME = new QName ("http://objectweb.org/type_test/doc", "SOAPService"); 22 static final QName PORT_NAME = new QName ("http://objectweb.org/type_test/doc", "SOAPPort"); 23 24 public SOAPDocLitClientTypeTest(String name) { 25 super(name, SERVICE_NAME, PORT_NAME, WSDL_PATH); 26 } 27 28 public static Test suite() throws Exception { 29 TestSuite suite = new TestSuite(SOAPDocLitClientTypeTest.class); 30 return new ClientServerSetupBase(suite) { 31 public void startServers() throws Exception { 32 boolean ok = launchServer(SOAPDocLitServerImpl.class); 33 assertTrue("failed to launch server", ok); 34 } 35 36 public void setUp() throws Exception { 37 URL url = getClass().getResource("../celtix-config.xml"); 39 assertNotNull("cannot find test resource", url); 40 configFileName = url.toString(); 41 super.setUp(); 42 } 43 }; 44 } 45 46 public void testStructWithAnyStrict() throws Exception { 47 SOAPFactory factory = SOAPFactory.newInstance(); 48 SOAPElement elem = factory.createElement("StringElementQualified", 49 "x1", "http://objectweb.org/type_test/types1"); 50 elem.addNamespaceDeclaration("x1", "http://objectweb.org/type_test/types1"); 51 elem.addTextNode("This is the text of the node"); 52 53 StructWithAnyStrict x = new StructWithAnyStrict(); 54 x.setName("Name x"); 55 x.setAddress("Some Address x"); 56 x.setAny(elem); 57 58 elem = factory.createElement("StringElementQualified", 59 "x1", "http://objectweb.org/type_test/types1"); 60 elem.addNamespaceDeclaration("x1", "http://objectweb.org/type_test/types1"); 61 elem.addTextNode("This is the text of the second node"); 62 63 StructWithAnyStrict yOrig = new StructWithAnyStrict(); 64 yOrig.setName("Name y"); 65 yOrig.setAddress("Some Address y"); 66 yOrig.setAny(elem); 67 68 Holder<StructWithAnyStrict> y = new Holder<StructWithAnyStrict>(yOrig); 69 Holder<StructWithAnyStrict> z = new Holder<StructWithAnyStrict>(); 70 StructWithAnyStrict ret = docClient.testStructWithAnyStrict(x, y, z); 71 if (!perfTestOnly) { 72 assertEqualsStructWithAnyStrict(x, y.value); 73 assertEqualsStructWithAnyStrict(yOrig, z.value); 74 assertEqualsStructWithAnyStrict(x, ret); 75 } 76 } 77 78 public void testStructWithAnyStrictComplex() throws Exception { 79 SOAPFactory factory = SOAPFactory.newInstance(); 80 SOAPElement elem = factory.createElement("AnonTypeElementQualified", 81 "x1", "http://objectweb.org/type_test/types1"); 82 elem.addNamespaceDeclaration("x1", "http://objectweb.org/type_test/types1"); 83 SOAPElement floatElem = factory.createElement("varFloat", "x1", 84 "http://objectweb.org/type_test/types1"); 85 floatElem.addTextNode("12.5"); 86 elem.addChildElement(floatElem); 87 SOAPElement intElem = factory.createElement("varInt", "x1", 88 "http://objectweb.org/type_test/types1"); 89 intElem.addTextNode("34"); 90 elem.addChildElement(intElem); 91 SOAPElement stringElem = factory.createElement("varString", "x1", 92 "http://objectweb.org/type_test/types1"); 93 stringElem.addTextNode("test string within any"); 94 elem.addChildElement(stringElem); 95 96 StructWithAnyStrict x = new StructWithAnyStrict(); 97 x.setName("Name x"); 98 x.setAddress("Some Address x"); 99 x.setAny(elem); 100 101 elem = factory.createElement("AnonTypeElementQualified", "x1", 102 "http://objectweb.org/type_test/types1"); 103 elem.addNamespaceDeclaration("x1", "http://objectweb.org/type_test/types1"); 104 floatElem = factory.createElement("varFloat", "x1", 105 "http://objectweb.org/type_test/types1"); 106 floatElem.addTextNode("12.76"); 107 elem.addChildElement(floatElem); 108 intElem = factory.createElement("varInt", "x1", 109 "http://objectweb.org/type_test/types1"); 110 intElem.addTextNode("56"); 111 elem.addChildElement(intElem); 112 stringElem = factory.createElement("varString", "x1", 113 "http://objectweb.org/type_test/types1"); 114 stringElem.addTextNode("test string"); 115 elem.addChildElement(stringElem); 116 117 StructWithAnyStrict yOrig = new StructWithAnyStrict(); 118 yOrig.setName("Name y"); 119 yOrig.setAddress("Some Address y"); 120 yOrig.setAny(elem); 121 122 Holder<StructWithAnyStrict> y = new Holder<StructWithAnyStrict>(yOrig); 123 Holder<StructWithAnyStrict> z = new Holder<StructWithAnyStrict>(); 124 StructWithAnyStrict ret = docClient.testStructWithAnyStrict(x, y, z); 125 if (!perfTestOnly) { 126 assertEqualsStructWithAnyStrict(x, y.value); 127 assertEqualsStructWithAnyStrict(yOrig, z.value); 128 assertEqualsStructWithAnyStrict(x, ret); 129 } 130 } 131 132 public void testStructWithAnyArrayLax() throws Exception { 133 SOAPFactory factory = SOAPFactory.newInstance(); 134 SOAPElement elem = factory.createElement("StringElementQualified", 135 "x1", "http://objectweb.org/type_test/types1"); 136 elem.addNamespaceDeclaration("x1", "http://objectweb.org/type_test/types1"); 137 elem.addTextNode("This is the text of the node"); 138 139 StructWithAnyArrayLax x = new StructWithAnyArrayLax(); 140 x.setName("Name x"); 141 x.setAddress("Some Address x"); 142 x.getAny().add(elem); 143 144 elem = factory.createElement("StringElementQualified", "x1", 145 "http://objectweb.org/type_test/types1"); 146 elem.addNamespaceDeclaration("x1", "http://objectweb.org/type_test/types1"); 147 elem.addTextNode("This is the text of the node for the second struct"); 148 149 StructWithAnyArrayLax yOrig = new StructWithAnyArrayLax(); 150 yOrig.setName("Name y"); 151 yOrig.setAddress("Some Other Address y"); 152 yOrig.getAny().add(elem); 153 154 Holder<StructWithAnyArrayLax> y = new Holder<StructWithAnyArrayLax>(yOrig); 155 Holder<StructWithAnyArrayLax> z = new Holder<StructWithAnyArrayLax>(); 156 StructWithAnyArrayLax ret = docClient.testStructWithAnyArrayLax(x, y, z); 157 if (!perfTestOnly) { 158 assertEqualsStructWithAnyArrayLax(x, y.value); 159 assertEqualsStructWithAnyArrayLax(yOrig, z.value); 160 assertEqualsStructWithAnyArrayLax(x, ret); 161 } 162 } 163 164 public void testStructWithAnyArrayLaxComplex() throws Exception { 165 SOAPFactory factory = SOAPFactory.newInstance(); 166 SOAPElement elem = factory.createElement("AnonTypeElementQualified", "x1", 167 "http://objectweb.org/type_test/types1"); 168 elem.addNamespaceDeclaration("x1", "http://objectweb.org/type_test/types1"); 169 SOAPElement floatElem = factory.createElement("varFloat", "x1", 170 "http://objectweb.org/type_test/types1"); 171 floatElem.addTextNode("12.76"); 172 elem.addChildElement(floatElem); 173 SOAPElement intElem = factory.createElement("varInt", "x1", 174 "http://objectweb.org/type_test/types1"); 175 intElem.addTextNode("56"); 176 elem.addChildElement(intElem); 177 SOAPElement stringElem = factory.createElement("varString", "x1", 178 "http://objectweb.org/type_test/types1"); 179 stringElem.addTextNode("test string"); 180 elem.addChildElement(stringElem); 181 182 StructWithAnyArrayLax x = new StructWithAnyArrayLax(); 183 x.setName("Name x"); 184 x.setAddress("Some Address x"); 185 x.getAny().add(elem); 186 StructWithAnyArrayLax yOrig = new StructWithAnyArrayLax(); 187 yOrig.setName("Name y"); 188 yOrig.setAddress("Some Other Address y"); 189 yOrig.getAny().add(elem); 190 191 Holder<StructWithAnyArrayLax> y = new Holder<StructWithAnyArrayLax>(yOrig); 192 Holder<StructWithAnyArrayLax> z = new Holder<StructWithAnyArrayLax>(); 193 StructWithAnyArrayLax ret = docClient.testStructWithAnyArrayLax(x, y, z); 194 if (!perfTestOnly) { 195 assertEqualsStructWithAnyArrayLax(x, y.value); 196 assertEqualsStructWithAnyArrayLax(yOrig, z.value); 197 assertEqualsStructWithAnyArrayLax(x, ret); 198 } 199 } 200 201 public void assertEqualsStructWithAnyStrict(StructWithAnyStrict a, 202 StructWithAnyStrict b) throws Exception { 203 assertEquals("StructWithAnyStrict names don't match", a.getName(), b.getName()); 204 assertEquals("StructWithAnyStrict addresses don't match", a.getAddress(), b.getAddress()); 205 if (a.getAny() instanceof SOAPElement && b.getAny() instanceof SOAPElement ) { 206 assertEquals((SOAPElement )a.getAny(), (SOAPElement )b.getAny()); 207 } 208 } 209 210 public void assertEqualsStructWithAnyArrayLax(StructWithAnyArrayLax a, 211 StructWithAnyArrayLax b) throws Exception { 212 assertEquals("StructWithAnyArrayLax names don't match", a.getName(), b.getName()); 213 assertEquals("StructWithAnyArrayLax addresses don't match", a.getAddress(), b.getAddress()); 214 215 List <Object > ae = a.getAny(); 216 List <Object > be = b.getAny(); 217 assertEquals("StructWithAnyArrayLax soap element lengths don't match", ae.size(), be.size()); 218 for (int i = 0; i < ae.size(); i++) { 219 if (ae.get(i) instanceof SOAPElement && be.get(i) instanceof SOAPElement ) { 220 assertEquals(ae.get(i), be.get(i)); 221 } 222 } 223 } 224 } 225 | Popular Tags |