1 package test.wsdl.getPort; 2 3 import javax.xml.namespace.QName ; 4 import javax.xml.rpc.Service ; 5 import javax.xml.rpc.ServiceException ; 6 import javax.xml.rpc.Stub ; 7 import java.util.Iterator ; 8 9 11 public class GetPortTestCase extends junit.framework.TestCase { 12 13 private static final QName portAOne = new QName ("portAOne"); 14 private static final QName portATwo = new QName ("portATwo"); 15 private static final QName portAThree = new QName ("portAThree"); 16 17 private static final QName portBOne = new QName ("portBOne"); 18 private static final QName portBTwo = new QName ("portBTwo"); 19 private static final QName portBTwoA = new QName ("portBTwoA"); 20 21 private static final QName portCOne = new QName ("portCOne"); 22 private static final QName portCTwo = new QName ("portCTwo"); 23 private static final QName portCThree = new QName ("portCThree"); 24 25 private static final String ADR_PORTAONE = "http://localhost:8080/axis/services/portAOne"; 26 private static final String ADR_PORTATWO = "http://localhost:8080/axis/services/portATwo"; 27 private static final String ADR_PORTATHREE = "http://localhost:8080/axis/services/portAThree"; 28 29 30 public GetPortTestCase(String name) { 31 super(name); 32 } 34 public void testEmptyService() { 35 Empty empty = new EmptyLocator(); 36 try { 37 empty.getPort(null); 38 fail("empty.getPort(null) should have failed."); 39 } 40 catch (ServiceException se) { 41 assertTrue("Wrong exception! " + se.getLinkedCause(), 42 se.getLinkedCause() == null); 43 } 44 } 46 47 65 public void testNormalService() { 66 ServiceA service = new ServiceALocator(); 67 try { 68 One one = (One) service.getPort(One.class); 69 Two two = (Two) service.getPort(Two.class); 70 Three three = (Three) service.getPort(Three.class); 71 } 72 catch (Throwable t) { 73 fail("Should not have gotten an exception: " + t); 74 } 75 try { 76 service.getPort(java.util.Vector .class); 77 fail("service.getPort(Vector.class) should have failed."); 78 } 79 catch (ServiceException se) { 80 assertTrue("Wrong exception! " + se.getLinkedCause(), 81 se.getLinkedCause() == null); 82 } 83 84 try { 86 Stub one = (Stub ) service.getPort(portAOne, One.class); 87 Stub two = (Stub ) service.getPort(portATwo, Two.class); 88 Stub three = (Stub ) service.getPort(portAThree, Three.class); 89 assertTrue("getPort(portAOne) should be of type One, instead it is " + one.getClass().getName(), one instanceof One); 90 assertTrue("getPort(portAOne) should have " + ADR_PORTAONE + ", instead it has " + one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 91 ADR_PORTAONE.equals(one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY))); 92 93 assertTrue("getPort(portATwo) should be of type Two, instead it is " + two.getClass().getName(), two instanceof Two); 94 assertTrue("getPort(portATwo) should have address " + ADR_PORTATWO + ", instead it has " + two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 95 ADR_PORTATWO.equals(two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY))); 96 97 assertTrue("getPort(portAThree) should be of type Three, instead it is " + three.getClass().getName(), three instanceof Three); 98 assertTrue("getPort(portAThree) should have address " + 99 ADR_PORTATHREE + ", instead it has " + 100 three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 101 ADR_PORTATHREE.equals(three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY))); 102 } 103 catch (ServiceException se) { 104 fail("unexpected failure: " + se); 105 } 106 } 108 125 public void testDoublePortService1() { 126 ServiceB service = new ServiceBLocator(); 127 try { 128 One one = (One) service.getPort(One.class); 129 Two two = (Two) service.getPort(Two.class); 130 } 131 catch (Throwable t) { 132 fail("Should not have gotten an exception: " + t); 133 } 134 try { 135 service.getPort(Three.class); 136 fail("service.getPort(Three.class) should have failed."); 137 } 138 catch (ServiceException se) { 139 assertTrue("Wrong exception! " + se.getLinkedCause(), 140 se.getLinkedCause() == null); 141 } 142 143 try { 145 Stub one = (Stub ) service.getPort(portBOne, One.class); 146 Stub two = (Stub ) service.getPort(portBTwo, Two.class); 147 Stub three = (Stub ) service.getPort(portBTwoA, Two.class); 148 assertTrue("getPort(portBOne) should be of type One, instead it is " + one.getClass().getName(), one instanceof One); 149 assertTrue("getPort(portBOne) should have address http://localhost:8080/axis/services/portBOne," 150 + " instead it has " + one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 151 "http://localhost:8080/axis/services/portBOne".equals(one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY))); 152 153 assertTrue("getPort(portBTwo) should be of type Two, instead it is " + two.getClass().getName(), two instanceof Two); 154 assertTrue("getPort(portBTwo) should have address" 155 + "http://localhost:8080/axis/services/portBTwo," 156 + "instead it has " + two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY) 157 + ", port is " + two.toString(), 158 "http://localhost:8080/axis/services/portBTwo".equals(two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY))); 159 160 assertTrue("getPort(portBTwoA) should be of type Two, instead it is " + three.getClass().getName(), three instanceof Two); 161 assertTrue("getPort(portBTwoA) should have address " 162 + "http://localhost:8080/axis/services/portBTwoA, " 163 + "instead it has " + three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 164 "http://localhost:8080/axis/services/portBTwoA".equals(three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY))); 165 } 166 catch (ServiceException se) { 167 fail("unexpected failure: " + se); 168 } 169 } 171 172 189 public void testDoublePortService2() { 190 ServiceC service = new ServiceCLocator(); 191 try { 192 One one = (One) service.getPort(One.class); 193 Two two = (Two) service.getPort(Two.class); 194 } 195 catch (Throwable t) { 196 fail("Should not have gotten an exception: " + t); 197 } 198 try { 199 service.getPort(Three.class); 200 fail("service.getPort(Three.class) should have failed."); 201 } 202 catch (ServiceException se) { 203 assertTrue("Wrong exception! " + se.getLinkedCause(), 204 se.getLinkedCause() == null); 205 } 206 207 try { 209 Stub one = (Stub ) service.getPort(portCOne, One.class); 210 Stub two = (Stub ) service.getPort(portCTwo, Two.class); 211 Stub three = (Stub ) service.getPort(portCThree, Three.class); 212 assertTrue("getPort(portCOne) should be of type One, instead it is " + one.getClass().getName(), one instanceof One); 213 assertTrue("getPort(portCOne) should have address " 214 + "http://localhost:8080/axis/services/portCOne, " 215 + "instead it has " + one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 216 "http://localhost:8080/axis/services/portCOne".equals(one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY))); 217 218 219 assertTrue("getPort(portCTwo) should be of type Two, instead it is " + two.getClass().getName(), two instanceof Two); 220 assertTrue("getPort(portCTwo) should have address " 221 + "http://localhost:8080/axis/services/portCTwo, " 222 + "instead it has " + two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 223 "http://localhost:8080/axis/services/portCTwo".equals(two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY))); 224 225 226 assertTrue("getPort(portCThree) should be of type One, instead it is " + three.getClass().getName(), three instanceof One); 227 assertTrue("getPort(portCThree) should have address " 228 + "http://localhost:8080/axis/services/portCThree," 229 + " instead it has " + three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 230 "http://localhost:8080/axis/services/portCThree".equals(three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY))); 231 } 232 catch (ServiceException se) { 233 fail("unexpected failure: " + se); 234 } 235 } 237 public void testGetPorts() { 238 Service service = null; 239 try { 240 service = new EmptyLocator(); 241 verifyNumberOfPorts("Empty", service.getPorts(), 0); 242 } 243 catch (ServiceException se) { 244 fail("EmptyLocator.getPorts() should not have failed: " + se); 245 } 246 try { 247 service = new ServiceALocator(); 248 verifyNumberOfPorts("ServiceA", service.getPorts(), 3); 249 } 250 catch (ServiceException se) { 251 fail("ServiceA.getPorts() should not have failed: " + se); 252 } 253 try { 254 service = new ServiceBLocator(); 255 verifyNumberOfPorts("ServiceB", service.getPorts(), 3); 256 } 257 catch (ServiceException se) { 258 fail("ServiceB.getPorts() should not have failed: " + se); 259 } 260 try { 261 service = new ServiceCLocator(); 262 verifyNumberOfPorts("ServiceC", service.getPorts(), 3); 263 } 264 catch (ServiceException se) { 265 fail("ServiceC.getPorts() should not have failed: " + se); 266 } 267 } 269 private void verifyNumberOfPorts(String service, Iterator i, int shouldHave) { 270 int count = 0; 271 for (;i.hasNext();count++,i.next()); 272 assertTrue("Service " + service + " should have " + shouldHave + " ports but instead has " + count, shouldHave == count); 273 } 275 } 277 | Popular Tags |