01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.sample;
20:
21: import java.util.Map;
22:
23: import javax.xml.ws.BindingProvider;
24: import javax.xml.ws.handler.MessageContext;
25:
26: import junit.framework.TestCase;
27: import org.apache.axis2.jaxws.sample.addnumbers.AddNumbersPortType;
28: import org.apache.axis2.jaxws.sample.addnumbers.AddNumbersService;
29: import org.apache.axis2.jaxws.TestLogger;
30:
31: public class AddNumbersTests extends TestCase {
32:
33: String axisEndpoint = "http://localhost:8080/axis2/services/AddNumbersService";
34:
35: public void testAddNumbers() throws Exception {
36: TestLogger.logger.debug("----------------------------------");
37: TestLogger.logger.debug("test: " + getName());
38:
39: AddNumbersService service = new AddNumbersService();
40: AddNumbersPortType proxy = service.getAddNumbersPort();
41:
42: BindingProvider p = (BindingProvider) proxy;
43: p.getRequestContext()
44: .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
45: axisEndpoint);
46: int total = proxy.addNumbers(10, 10);
47:
48: TestLogger.logger.debug("Total =" + total);
49: TestLogger.logger.debug("----------------------------------");
50:
51: assertEquals("sum", 20, total);
52: assertEquals("http response code", new Integer(200), p
53: .getResponseContext().get(
54: MessageContext.HTTP_RESPONSE_CODE));
55: Map headers = (Map) p.getResponseContext().get(
56: MessageContext.HTTP_RESPONSE_HEADERS);
57: // the map should contain some headers
58: assertTrue("http response headers", headers != null
59: && !headers.isEmpty());
60: }
61:
62: public void testOneWay() {
63: try {
64: TestLogger.logger
65: .debug("----------------------------------");
66: TestLogger.logger.debug("test: " + getName());
67:
68: AddNumbersService service = new AddNumbersService();
69: AddNumbersPortType proxy = service.getAddNumbersPort();
70:
71: BindingProvider bp = (BindingProvider) proxy;
72: bp.getRequestContext().put(
73: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
74: axisEndpoint);
75: proxy.oneWayInt(11);
76: TestLogger.logger
77: .debug("----------------------------------");
78: } catch (Exception e) {
79: e.printStackTrace();
80: fail();
81: }
82: }
83: }
|