1 package org.objectweb.celtix.axisinterop; 2 3 import java.math.BigDecimal ; 4 import java.util.Arrays ; 5 import java.util.Calendar ; 6 import java.util.Date ; 7 import java.util.TimeZone ; 8 9 import junit.framework.Test; 10 import junit.framework.TestCase; 11 import junit.framework.TestSuite; 12 13 import org.apache.axis.types.NegativeInteger; 15 import org.apache.axis.types.NonNegativeInteger; 16 import org.apache.axis.types.NonPositiveInteger; 17 import org.apache.axis.types.NormalizedString; 18 import org.apache.axis.types.PositiveInteger; 19 import org.apache.axis.types.Token; 20 import org.apache.axis.types.UnsignedByte; 21 import org.apache.axis.types.UnsignedInt; 22 import org.apache.axis.types.UnsignedLong; 23 import org.apache.axis.types.UnsignedShort; 24 25 import org.objectweb.celtix.testutil.common.AbstractClientServerSetupBase; 26 27 import org.soapinterop.axis.CeltixEchoServiceLocator; 28 import org.soapinterop.axis.InteropTestDocLitBindingStub; 29 import org.soapinterop.axis.InteropTestPortType; 30 import org.soapinterop.axis.SOAPStruct; 31 32 public class AxisClientEchoTest extends TestCase { 33 34 private static InteropTestPortType binding; 35 36 public AxisClientEchoTest() { 37 } 38 39 public static Test suite() throws Exception { 40 TestSuite suite = new TestSuite(AxisClientEchoTest.class); 41 return new AbstractClientServerSetupBase(suite) { 42 public void startServers() throws Exception { 43 boolean ok = launchServer(CeltixServer.class); 44 if (!ok) { 45 fail("Failed to launch celtix server."); 46 } 47 } 48 }; 49 } 50 51 public void setUp() throws Exception { 52 java.net.URL url = new java.net.URL ("http://localhost:9240/CeltixEchoService/Echo"); 53 binding = new CeltixEchoServiceLocator().getEcho(url); 54 assertNotNull("Could not create binding", binding); 55 ((InteropTestDocLitBindingStub)binding).setTimeout(30000); 56 ((InteropTestDocLitBindingStub)binding).setMaintainSession(true); 57 } 58 59 private boolean equalsDate(Calendar orig, Calendar actual) { 60 return orig.get(Calendar.YEAR) == actual.get(Calendar.YEAR) 61 && orig.get(Calendar.MONTH) == actual.get(Calendar.MONTH) 62 && orig.get(Calendar.DATE) == actual.get(Calendar.DATE); 63 } 64 65 public void testBoolean() throws Exception { 66 boolean in = true; 67 boolean out = binding.echoBoolean(in); 68 assertEquals("echoBoolean : incorrect return value : " 69 + out + " expected : " + in, in, out); 70 } 71 72 public void testFloat() throws Exception { 73 float in = 3.7F; 74 float out = binding.echoFloat(in); 75 assertEquals("echoFloat : incorrect return value : " 76 + out + " expected : " + in, in, out); 77 } 78 79 public void testInteger() throws Exception { 80 int in = 42; 81 int out = binding.echoInteger(in); 82 assertEquals("echoInteger : incorrect return value : " 83 + out + " expected : " + in, in, out); 84 } 85 86 public void testVoid() throws Exception { 87 binding.echoVoid(); 88 } 89 90 98 public void testNegativeInteger() throws Exception { 99 NegativeInteger in = new NegativeInteger("-12345678900987654321"); 101 NegativeInteger out = binding.echoNegativeInteger(in); 102 assertEquals("echoNegativeInteger : incorrect return value : " 103 + out + " expected : " + in, in, out); 104 } 105 106 public void testNonNegativeInteger() throws Exception { 107 NonNegativeInteger in = new NonNegativeInteger("12345678901234567890"); 109 NonNegativeInteger out = binding.echoNonNegativeInteger(in); 110 assertEquals("echoNonNegativeInteger : incorrect return value : " 111 + out + " expected : " + in, in, out); 112 } 113 114 public void testNonPositiveInteger() throws Exception { 115 NonPositiveInteger in = new NonPositiveInteger("-12345678901234567890"); 117 NonPositiveInteger out = binding.echoNonPositiveInteger(in); 118 assertEquals("echoNonPositiveInteger : incorrect return value : " 119 + out + " expected : " + in, in, out); 120 } 121 122 public void testPositiveInteger() throws Exception { 123 PositiveInteger in = new PositiveInteger("12345678900987654321"); 125 PositiveInteger out = binding.echoPositiveInteger(in); 126 assertEquals("echoPositiveInteger : incorrect return value : " 127 + out + " expected : " + in, in, out); 128 } 129 130 public void testNormalizedString() throws Exception { 131 NormalizedString in = new NormalizedString("abc-Normalized-def"); 133 NormalizedString out = binding.echoNormalizedString(in); 134 assertEquals("echoNormalizedString : incorrect return value : " 135 + out + " expected : " + in, in, out); 136 } 137 138 public void testToken() throws Exception { 139 Token in = new Token("abc-Token-def"); 141 Token out = binding.echoToken(in); 142 assertEquals("echoToken : incorrect return value : " + out + " expected : " + in, in, out); 143 } 144 145 public void testUnsignedByte() throws Exception { 146 UnsignedByte in = new UnsignedByte(103); 148 UnsignedByte out = binding.echoUnsignedByte(in); 149 assertEquals("echoUnsignedByte : incorrect return value : " 150 + out + " expected : " + in, in, out); 151 } 152 153 public void testUnsignedInt() throws Exception { 154 UnsignedInt in = new UnsignedInt(101); 156 UnsignedInt out = binding.echoUnsignedInt(in); 157 assertEquals("echoUnsignedInt : incorrect return value : " 158 + out + " expected : " + in, in, out); 159 } 160 161 public void testUnsignedLong() throws Exception { 162 UnsignedLong in = new UnsignedLong(100); 164 UnsignedLong out = binding.echoUnsignedLong(in); 165 assertEquals("echoUnsignedLong : incorrect return value : " 166 + out + " expected : " + in, in, out); 167 } 168 169 public void testUnsignedShort() throws Exception { 170 UnsignedShort in = new UnsignedShort(102); 172 UnsignedShort out = binding.echoUnsignedShort(in); 173 assertEquals("echoUnsignedShort : incorrect return value : " 174 + out + " expected : " + in, in, out); 175 } 176 177 public void testString() throws Exception { 178 String in = "abcdefg"; 179 String out = binding.echoString(in); 180 assertEquals("echoString : incorrect return value : " 181 + out + " expected : " + in, in, out); 182 } 183 184 199 public void testStruct() throws Exception { 200 SOAPStruct in = new SOAPStruct(); 201 in.setVarInt(5); 202 in.setVarString("Hello"); 203 in.setVarFloat(103F); 204 SOAPStruct out = binding.echoStruct(in); 205 assertEquals("echoStruct : incorrect return value : " 206 + out + " expected : " + in, in, out); 207 } 208 209 public void testBase64() throws Exception { 210 byte[] in = "Base64".getBytes(); 211 byte[] out = binding.echoBase64(in); 212 assertTrue("echoBase64 : incorrect return value : ", Arrays.equals(in, out)); 213 } 214 215 public void testDate() throws Exception { 216 Calendar inCalendar = Calendar.getInstance(); 217 Date out = binding.echoDate(inCalendar.getTime()); 218 Calendar outCalendar = Calendar.getInstance(); 219 outCalendar.setTime(out); 220 assertTrue("echoDate : incorrect return value", equalsDate(inCalendar, outCalendar)); 221 } 222 223 public void testDateTime() throws Exception { 225 Calendar in = Calendar.getInstance(); 226 in.setTimeZone(TimeZone.getTimeZone("GMT")); 227 in.setTime(new Date ()); 228 Calendar out = binding.echoDateTime(in); 229 assertTrue("echoDateTime : incorrect return value : " 230 + out + " expected : " + in, in.equals(out)); 231 } 232 233 public void testDecimal() throws Exception { 234 BigDecimal in = new BigDecimal ("3.14159"); 235 BigDecimal out = binding.echoDecimal(in); 236 assertEquals("echoDecimal : incorrect return value : " 237 + out + " expected : " + in, in, out); 238 } 239 240 public static void main(String [] args) { 241 junit.textui.TestRunner.run(AxisClientEchoTest.class); 242 } 243 244 } 245
| Popular Tags
|