File: GetPortTestCase.java

package info (click to toggle)
axis 1.4-29
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 52,100 kB
  • sloc: java: 129,124; xml: 10,602; jsp: 983; sh: 84; cs: 36; makefile: 18
file content (276 lines) | stat: -rw-r--r-- 12,394 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package test.wsdl.getPort;

import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.Stub;
import java.util.Iterator;

// This test makes sure that the getPort method works in various service classes.

public class GetPortTestCase extends junit.framework.TestCase {

    private static final QName portAOne = new QName("portAOne");
    private static final QName portATwo = new QName("portATwo");
    private static final QName portAThree = new QName("portAThree");

    private static final QName portBOne = new QName("portBOne");
    private static final QName portBTwo = new QName("portBTwo");
    private static final QName portBTwoA = new QName("portBTwoA");
    
    private static final QName portCOne = new QName("portCOne");
    private static final QName portCTwo = new QName("portCTwo");
    private static final QName portCThree = new QName("portCThree");
    
    private static final String ADR_PORTAONE = "http://localhost:8080/axis/services/portAOne";
    private static final String ADR_PORTATWO = "http://localhost:8080/axis/services/portATwo";
    private static final String ADR_PORTATHREE = "http://localhost:8080/axis/services/portAThree";
    

    public GetPortTestCase(String name) {
        super(name);
    } // ctor

    public void testEmptyService() {
        Empty empty = new EmptyLocator();
        try {
            empty.getPort(null);
            fail("empty.getPort(null) should have failed.");
        }
        catch (ServiceException se) {
            assertTrue("Wrong exception!  " + se.getLinkedCause(),
                    se.getLinkedCause() == null);
        }
    } // testEmptyService


/*

   <service name="serviceA">
    <documentation>
    Service with all ports unique. /-- Test Bug 13407 - embedded comments --/
    </documentation>
    <port name="portAOne" binding="tns:bindingOne">
      <soap:address location="http://localhost:8080/axis/services/portAOne"/>
    </port>
    <port name="portATwo" binding="tns:bindingTwo">
      <soap:address location="http://localhost:8080/axis/services/portATwo"/>
    </port>
    <port name="portAThree" binding="tns:bindingThree">
      <soap:address location="http://localhost:8080/axis/services/portAThree"/>
    </port>
  </service>

 */
    public void testNormalService() {
        ServiceA service = new ServiceALocator();
        try {
            One one = (One) service.getPort(One.class);
            Two two = (Two) service.getPort(Two.class);
            Three three = (Three) service.getPort(Three.class);
        }
        catch (Throwable t) {
            fail("Should not have gotten an exception:  " + t);
        }
        try {
            service.getPort(java.util.Vector.class);
            fail("service.getPort(Vector.class) should have failed.");
        }
        catch (ServiceException se) {
            assertTrue("Wrong exception!  " + se.getLinkedCause(),
                    se.getLinkedCause() == null);
        }

        // Make sure we get the proper ports
        try {
            Stub one = (Stub) service.getPort(portAOne, One.class);
            Stub two = (Stub) service.getPort(portATwo, Two.class);
            Stub three = (Stub) service.getPort(portAThree, Three.class);
            assertTrue("getPort(portAOne) should be of type One, instead it is " + one.getClass().getName(), one instanceof One);
            assertTrue("getPort(portAOne) should have " + ADR_PORTAONE + ", instead it has " + one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 
                ADR_PORTAONE.equals(one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)));
         
            assertTrue("getPort(portATwo) should be of type Two, instead it is " + two.getClass().getName(), two instanceof Two);
            assertTrue("getPort(portATwo) should have address " + ADR_PORTATWO + ", instead it has " + two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 
               ADR_PORTATWO.equals(two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)));
         
            assertTrue("getPort(portAThree) should be of type Three, instead it is " + three.getClass().getName(), three instanceof Three);
            assertTrue("getPort(portAThree) should have address " + 
                       ADR_PORTATHREE + ", instead it has " + 
                       three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 
                       ADR_PORTATHREE.equals(three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)));
        }
        catch (ServiceException se) {
            fail("unexpected failure:  " + se);
        }
    } // testNormalService

/*
  
 <service name="serviceB">
    <documentation>
    Service with two ports (portBTwo, portBTwoA) that share the same portType via the same binding.
    </documentation>
    <port name="portBOne" binding="tns:bindingOne">
      <soap:address location="http://localhost:8080/axis/services/portOne"/>
    </port>
    <port name="portBTwo" binding="tns:bindingTwo">
      <soap:address location="http://localhost:8080/axis/services/portBTwo"/>
    </port>
    <port name="portBTwoA" binding="tns:bindingTwo">
      <soap:address location="http://localhost:8080/axis/services/portBTwoA"/>
    </port>
  </service>
*/
    public void testDoublePortService1() {
        ServiceB service = new ServiceBLocator();
        try {
            One one = (One) service.getPort(One.class);
            Two two = (Two) service.getPort(Two.class);
        }
        catch (Throwable t) {
            fail("Should not have gotten an exception:  " + t);
        }
        try {
            service.getPort(Three.class);
            fail("service.getPort(Three.class) should have failed.");
        }
        catch (ServiceException se) {
            assertTrue("Wrong exception!  " + se.getLinkedCause(),
                    se.getLinkedCause() == null);
        }

        // Make sure we get the proper ports
        try {
            Stub one = (Stub) service.getPort(portBOne, One.class);
            Stub two = (Stub) service.getPort(portBTwo, Two.class);
            Stub three = (Stub) service.getPort(portBTwoA, Two.class);
            assertTrue("getPort(portBOne) should be of type One, instead it is " + one.getClass().getName(), one instanceof One);
            assertTrue("getPort(portBOne) should have address http://localhost:8080/axis/services/portBOne," 
                       + " instead it has " + one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY),
                       "http://localhost:8080/axis/services/portBOne".equals(one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)));

            assertTrue("getPort(portBTwo) should be of type Two, instead it is " + two.getClass().getName(), two instanceof Two);
            assertTrue("getPort(portBTwo) should have address"
                       + "http://localhost:8080/axis/services/portBTwo," 
                       + "instead it has " + two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)
                       + ", port is " + two.toString(),
                       "http://localhost:8080/axis/services/portBTwo".equals(two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)));

            assertTrue("getPort(portBTwoA) should be of type Two, instead it is " + three.getClass().getName(), three instanceof Two);
            assertTrue("getPort(portBTwoA) should have address "
            			+ "http://localhost:8080/axis/services/portBTwoA, "
            			+ "instead it has " + three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 
            			"http://localhost:8080/axis/services/portBTwoA".equals(three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)));
        }
        catch (ServiceException se) {
            fail("unexpected failure:  " + se);
        }
    } // testDoublePortService1


/*
 *   <service name="serviceC">
    <documentation>
    Service with two ports (portCTwo, portCThree) that share the same portType via different bindings.
    </documentation>
    <port name="portCOne" binding="tns:bindingOne">
      <soap:address location="http://localhost:8080/axis/services/portCOne"/>
    </port>
    <port name="portCTwo" binding="tns:bindingTwo">
      <soap:address location="http://localhost:8080/axis/services/portCTwo"/>
    </port>
    <port name="portCThree" binding="tns:bindingAnotherOne">
      <soap:address location="http://localhost:8080/axis/services/portCThree"/>
    </port>
  </service>

*/
    public void testDoublePortService2() {
        ServiceC service = new ServiceCLocator();
        try {
            One one = (One) service.getPort(One.class);
            Two two = (Two) service.getPort(Two.class);
        }
        catch (Throwable t) {
            fail("Should not have gotten an exception:  " + t);
        }
        try {
            service.getPort(Three.class);
            fail("service.getPort(Three.class) should have failed.");
        }
        catch (ServiceException se) {
            assertTrue("Wrong exception!  " + se.getLinkedCause(),
                    se.getLinkedCause() == null);
        }

        // Make sure we get the proper ports
        try {
            Stub one = (Stub) service.getPort(portCOne, One.class);
            Stub two = (Stub) service.getPort(portCTwo, Two.class);
            Stub three = (Stub) service.getPort(portCThree, Three.class);
            assertTrue("getPort(portCOne) should be of type One, instead it is " + one.getClass().getName(), one instanceof One);
            assertTrue("getPort(portCOne) should have address "
            	 + "http://localhost:8080/axis/services/portCOne, "
            	 + "instead it has " + one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 
            	 "http://localhost:8080/axis/services/portCOne".equals(one._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)));
            	 
            	 
            assertTrue("getPort(portCTwo) should be of type Two, instead it is " + two.getClass().getName(), two instanceof Two);
            assertTrue("getPort(portCTwo) should have address " 
                 + "http://localhost:8080/axis/services/portCTwo, "
                 + "instead it has " + two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 
                 "http://localhost:8080/axis/services/portCTwo".equals(two._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)));
                 
                 
            assertTrue("getPort(portCThree) should be of type One, instead it is " + three.getClass().getName(), three instanceof One);
            assertTrue("getPort(portCThree) should have address "
                 + "http://localhost:8080/axis/services/portCThree,"
                 + " instead it has " + three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY), 
                 "http://localhost:8080/axis/services/portCThree".equals(three._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY)));
        }
        catch (ServiceException se) {
            fail("unexpected failure:  " + se);
        }
    } // testDoublePortService2

    public void testGetPorts() {
        Service service = null;
        try {
            service = new EmptyLocator();
            verifyNumberOfPorts("Empty", service.getPorts(), 0);
        }
        catch (ServiceException se) {
            fail("EmptyLocator.getPorts() should not have failed:  " + se);
        }
        try {
            service = new ServiceALocator();
            verifyNumberOfPorts("ServiceA", service.getPorts(), 3);
        }
        catch (ServiceException se) {
            fail("ServiceA.getPorts() should not have failed:  " + se);
        }
        try {
            service = new ServiceBLocator();
            verifyNumberOfPorts("ServiceB", service.getPorts(), 3);
        }
        catch (ServiceException se) {
            fail("ServiceB.getPorts() should not have failed:  " + se);
        }
        try {
            service = new ServiceCLocator();
            verifyNumberOfPorts("ServiceC", service.getPorts(), 3);
        }
        catch (ServiceException se) {
            fail("ServiceC.getPorts() should not have failed:  " + se);
        }
    } // testGetPorts

    private void verifyNumberOfPorts(String service, Iterator i, int shouldHave) {
        int count = 0;
        for (;i.hasNext();count++,i.next());
        assertTrue("Service " + service + " should have " + shouldHave + " ports but instead has " + count, shouldHave == count);
    } // verifyNumberOfPorts

} // class VerifyTestCase