1 package org.objectweb.celtix.axisinterop; 2 3 import java.math.BigDecimal ; 4 import java.math.BigInteger ; 5 import java.net.URL ; 6 import java.util.Arrays ; 7 9 import javax.xml.datatype.DatatypeConstants ; 10 import javax.xml.datatype.XMLGregorianCalendar ; 11 import javax.xml.namespace.QName ; 12 13 import junit.framework.Test; 14 import junit.framework.TestCase; 15 import junit.framework.TestSuite; 16 17 import org.objectweb.celtix.bus.jaxws.spi.ProviderImpl; 18 import org.objectweb.celtix.testutil.common.AbstractClientServerSetupBase; 19 20 import org.soapinterop.celtix.AxisEchoService; 21 import org.soapinterop.celtix.InteropTestPortType; 22 import org.soapinterop.celtix.SOAPStruct; 23 24 public class CeltixClientEchoTest extends TestCase { 25 26 private final QName serviceName = new QName ("http://soapinterop.org/celtix", 27 "AxisEchoService"); 28 private final QName portName = new QName ("http://soapinterop.org/celtix", 29 "Echo"); 30 31 private InteropTestPortType port; 32 33 static { 34 System.setProperty(ProviderImpl.JAXWSPROVIDER_PROPERTY, ProviderImpl.JAXWS_PROVIDER); 35 } 36 37 public CeltixClientEchoTest() { 38 } 39 40 public static Test suite() throws Exception { 41 TestSuite suite = new TestSuite(CeltixClientEchoTest.class); 42 return new AbstractClientServerSetupBase(suite) { 43 public void startServers() throws Exception { 44 boolean ok = launchServer(AxisServer.class); 45 if (!ok) { 46 fail("Failed to launch axis server."); 47 } 48 } 49 }; 50 } 51 52 public void setUp() throws Exception { 53 super.setUp(); 54 URL wsdl = getClass().getResource("/wsdl/axis_echo.wsdl"); 55 assertNotNull("Could not get axis_echo.wsdl resource.", wsdl); 56 57 AxisEchoService service = new AxisEchoService(wsdl, serviceName); 58 assertNotNull("Failed to create AxisEchoService.", service); 59 60 port = service.getPort(portName, InteropTestPortType.class); 61 } 62 63 protected boolean equalsDate(XMLGregorianCalendar orig, XMLGregorianCalendar actual) { 64 boolean result = false; 65 66 if ((orig.getYear() == actual.getYear()) 67 && (orig.getMonth() == actual.getMonth()) 68 && (orig.getDay() == actual.getDay()) 69 && (actual.getHour() == DatatypeConstants.FIELD_UNDEFINED) 70 && (actual.getMinute() == DatatypeConstants.FIELD_UNDEFINED) 71 && (actual.getSecond() == DatatypeConstants.FIELD_UNDEFINED) 72 && (actual.getMillisecond() == DatatypeConstants.FIELD_UNDEFINED)) { 73 74 result = orig.getTimezone() == actual.getTimezone(); 75 } 76 return result; 77 } 78 79 protected boolean equalsDateTime(XMLGregorianCalendar orig, XMLGregorianCalendar actual) { 80 if ((orig.getYear() == actual.getYear()) 81 && (orig.getMonth() == actual.getMonth()) 82 && (orig.getDay() == actual.getDay()) 83 && (orig.getHour() == actual.getHour()) 84 && (orig.getMinute() == actual.getMinute()) 85 && (orig.getSecond() == actual.getSecond())) { 86 return (orig.getMillisecond() == DatatypeConstants.FIELD_UNDEFINED 87 || actual.getMillisecond() == DatatypeConstants.FIELD_UNDEFINED 88 || orig.getMillisecond() == actual.getMillisecond()) 89 && (orig.getTimezone() == DatatypeConstants.FIELD_UNDEFINED 90 || actual.getTimezone() == DatatypeConstants.FIELD_UNDEFINED 91 || orig.getTimezone() == actual.getTimezone()); 92 } 93 return false; 94 } 95 96 protected boolean equals(SOAPStruct obj1, SOAPStruct obj2) { 97 if (null == obj1) { 98 return null == obj2; 99 } else { 100 return Float.floatToIntBits(obj1.getVarFloat()) == Float.floatToIntBits(obj2.getVarFloat()) 101 && obj1.getVarInt() == obj2.getVarInt() 102 && obj1.getVarString().equals(obj2.getVarString()); 103 } 104 } 105 106 public void testBoolean() throws Exception { 107 boolean in = true; 108 boolean out = port.echoBoolean(in); 109 assertEquals("echoBoolean : incorrect return value : " 110 + out + " expected : " + in, in, out); 111 } 112 113 public void testFloat() throws Exception { 114 float in = 3.7F; 115 float out = port.echoFloat(in); 116 assertEquals("echoFloat : incorrect return value : " 117 + out + " expected : " + in, in, out); 118 } 119 120 public void testInteger() throws Exception { 121 int in = 42; 122 int out = port.echoInteger(in); 123 assertEquals("echoInteger : incorrect return value : " 124 + out + " expected : " + in, in, out); 125 } 126 127 public void testVoid() throws Exception { 128 port.echoVoid(); 129 } 130 131 139 public void testNegativeInteger() throws Exception { 140 BigInteger in = new BigInteger ("-12345678900987654321"); 142 BigInteger out = port.echoNegativeInteger(in); 143 assertEquals("echoNegativeInteger : incorrect return value : " 144 + out + " expected : " + in, in, out); 145 } 146 147 public void testNonNegativeInteger() throws Exception { 148 BigInteger in = new BigInteger ("12345678901234567890"); 150 BigInteger out = port.echoNonNegativeInteger(in); 151 assertEquals("echoNonNegativeInteger : incorrect return value : " 152 + out + " expected : " + in, in, out); 153 } 154 155 public void testNonPositiveInteger() throws Exception { 156 BigInteger in = new BigInteger ("-12345678901234567890"); 158 BigInteger out = port.echoNonPositiveInteger(in); 159 assertEquals("echoNonPositiveInteger : incorrect return value : " 160 + out + " expected : " + in, in, out); 161 } 162 163 public void testPositiveInteger() throws Exception { 164 BigInteger in = new BigInteger ("12345678900987654321"); 166 BigInteger out = port.echoPositiveInteger(in); 167 assertEquals("echoPositiveInteger : incorrect return value : " 168 + out + " expected : " + in, in, out); 169 } 170 171 public void testNormalizedString() throws Exception { 172 String in = "abc-Normalized-def"; 174 String out = port.echoNormalizedString(in); 175 assertEquals("echoNormalizedString : incorrect return value : " 176 + out + " expected : " + in, in, out); 177 } 178 179 public void testToken() throws Exception { 180 String in = "abc-Token-def"; 182 String out = port.echoToken(in); 183 assertEquals("echoToken : incorrect return value : " + out + " expected : " + in, in, out); 184 } 185 186 public void testUnsignedByte() throws Exception { 187 short in = 103; 189 short out = port.echoUnsignedByte(in); 190 assertEquals("echoUnsignedByte : incorrect return value : " 191 + out + " expected : " + in, in, out); 192 } 193 194 public void testUnsignedInt() throws Exception { 195 long in = 101; 197 long out = port.echoUnsignedInt(in); 198 assertEquals("echoUnsignedInt : incorrect return value : " 199 + out + " expected : " + in, in, out); 200 } 201 202 public void testUnsignedLong() throws Exception { 203 BigInteger in = new BigInteger ("123456789"); 205 BigInteger out = port.echoUnsignedLong(in); 206 assertEquals("echoUnsignedLong : incorrect return value : " 207 + out + " expected : " + in, in, out); 208 } 209 210 public void testUnsignedShort() throws Exception { 211 int in = 102; 213 int out = port.echoUnsignedShort(in); 214 assertEquals("echoUnsignedShort : incorrect return value : " 215 + out + " expected : " + in, in, out); 216 } 217 218 public void testString() throws Exception { 219 String in = "abcdefg"; 220 String out = port.echoString(in); 221 assertEquals("echoString : incorrect return value : " 222 + out + " expected : " + in, in, out); 223 } 224 225 232 public void testStruct() throws Exception { 233 SOAPStruct in = new SOAPStruct(); 234 in.setVarInt(6); 235 in.setVarString("Rover"); 236 in.setVarFloat(1010F); 237 SOAPStruct out = port.echoStruct(in); 238 assertTrue("echoStruct : incorrect return value", equals(in, out)); 239 } 240 241 public void testBase64() throws Exception { 242 byte[] in = "Base64".getBytes(); 243 byte[] out = port.echoBase64(in); 244 assertTrue("echoBase64 : incorrect return value : ", Arrays.equals(in, out)); 245 } 246 247 259 public void testDateTime() throws Exception { 260 javax.xml.datatype.DatatypeFactory factory = javax.xml.datatype.DatatypeFactory.newInstance(); 261 XMLGregorianCalendar in = factory.newXMLGregorianCalendar(); 262 in.setYear(1975); 263 in.setMonth(5); 264 in.setDay(5); 265 in.setHour(12); 266 in.setMinute(30); 267 in.setSecond(15); 268 XMLGregorianCalendar out = port.echoDateTime(in); 269 assertTrue("echoDate : incorrect return value : " 270 + out + " expected : " + in, equalsDateTime(in, out)); 271 } 272 273 public void testDecimal() throws Exception { 274 BigDecimal in = new BigDecimal ("3.14159"); 275 BigDecimal out = port.echoDecimal(in); 276 assertEquals("echoDecimal : incorrect return value : " 277 + out + " expected : " + in, in, out); 278 } 279 280 public static void main(String [] args) { 281 junit.textui.TestRunner.run(CeltixClientEchoTest.class); 282 } 283 284 } 285
| Popular Tags
|