001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.provider;
020:
021: import org.apache.axis2.jaxws.TestLogger;
022:
023: import javax.xml.namespace.QName;
024: import javax.xml.soap.SOAPFault;
025: import javax.xml.ws.BindingProvider;
026: import javax.xml.ws.Dispatch;
027: import javax.xml.ws.Service;
028: import javax.xml.ws.soap.SOAPFaultException;
029:
030: public class StringProviderTests extends ProviderTestCase {
031:
032: String endpointUrl = "http://localhost:8080/axis2/services/StringProviderService";
033: String xmlString = "<invoke>test input</invoke>";
034: private QName serviceName = new QName("http://ws.apache.org/axis2",
035: "StringProviderService");
036:
037: protected void setUp() throws Exception {
038: super .setUp();
039: }
040:
041: protected void tearDown() throws Exception {
042: super .tearDown();
043: }
044:
045: public StringProviderTests(String name) {
046: super (name);
047: }
048:
049: private Dispatch<String> getDispatch() {
050: Service svc = Service.create(serviceName);
051: svc.addPort(portName, null, endpointUrl);
052:
053: Dispatch<String> dispatch = svc.createDispatch(portName,
054: String.class, Service.Mode.PAYLOAD);
055:
056: // Force soap action because we are passing junk over the wire
057: dispatch.getRequestContext().put(
058: BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
059: dispatch.getRequestContext().put(
060: BindingProvider.SOAPACTION_URI_PROPERTY,
061: "http://stringprovider.sample.test.org/echoString");
062:
063: return dispatch;
064:
065: }
066:
067: public void testNormal() throws Exception {
068: TestLogger.logger
069: .debug("---------------------------------------");
070: TestLogger.logger.debug("test: " + getName());
071:
072: Dispatch<String> dispatch = getDispatch();
073:
074: String request = "<invoke>hello world</invoke>";
075: String response = dispatch.invoke(request);
076: assertTrue(request.equals(response));
077: }
078:
079: public void testEmptyString() throws Exception {
080: TestLogger.logger
081: .debug("---------------------------------------");
082: TestLogger.logger.debug("test: " + getName());
083:
084: Dispatch<String> dispatch = getDispatch();
085:
086: String request = "";
087: String response = dispatch.invoke(request);
088:
089: // The current belief is that this should return a null indicating
090: // the nothing is echo'ed
091: assertTrue(response == null);
092:
093: //assertTrue(request.equals(response));
094: }
095:
096: public void testNullString() throws Exception {
097: TestLogger.logger
098: .debug("---------------------------------------");
099: TestLogger.logger.debug("test: " + getName());
100:
101: Dispatch<String> dispatch = getDispatch();
102:
103: String request = null;
104: String response = dispatch.invoke(request);
105:
106: // The current belief is that this should return a null indicating
107: // the nothing is echo'ed
108: assertTrue(response == null);
109: }
110:
111: public void testNonNullString() throws Exception {
112: TestLogger.logger
113: .debug("---------------------------------------");
114: TestLogger.logger.debug("test: " + getName());
115:
116: Dispatch<String> dispatch = getDispatch();
117:
118: String request = "mixedContent";
119: String response = dispatch.invoke(request);
120:
121: // The current implementation does not send the mixedContent over the wire, so the
122: // expectation is that the echo'd response is null
123: assertTrue(response == null);
124: }
125:
126: public void testCommentString() throws Exception {
127: TestLogger.logger
128: .debug("---------------------------------------");
129: TestLogger.logger.debug("test: " + getName());
130:
131: Dispatch<String> dispatch = getDispatch();
132:
133: String request = "<!--comment-->";
134: String response = dispatch.invoke(request);
135: // The current implementation does not send the comment over the wire, so the
136: // expectation is that the echo'd response is null
137: assertTrue(response == null);
138: }
139:
140: public void testTwoElementsString() throws Exception {
141: TestLogger.logger
142: .debug("---------------------------------------");
143: TestLogger.logger.debug("test: " + getName());
144:
145: Dispatch<String> dispatch = getDispatch();
146:
147: String request = "<a>hello</a><b>world</b>";
148: String response = dispatch.invoke(request);
149:
150: // The current implementatin only sends the first element
151: // So the echo'd response is just the first one.
152: assertTrue("<a>hello</a>".equals(response));
153: }
154:
155: public void testTwoElementsAndMixedContentString() throws Exception {
156: TestLogger.logger
157: .debug("---------------------------------------");
158: TestLogger.logger.debug("test: " + getName());
159:
160: Dispatch<String> dispatch = getDispatch();
161:
162: String request = "mixed1<a>hello</a>mixed2<b>world</b>mixed3";
163: String response = dispatch.invoke(request);
164: // The current implementation only sends the first element.
165: // The mixed content (mixed1) interferes and thus nothing is sent.
166: assertTrue(response == null);
167: }
168:
169: public void testException() throws Exception {
170: TestLogger.logger
171: .debug("---------------------------------------");
172: TestLogger.logger.debug("test: " + getName());
173:
174: Dispatch<String> dispatch = getDispatch();
175:
176: String request = "<invoke>throwWebServiceException</invoke>";
177: try {
178: String response = dispatch.invoke(request);
179: fail("Expected Exception");
180: } catch (SOAPFaultException e) {
181: SOAPFault sf = e.getFault();
182: assertTrue(sf.getFaultString().equals("provider"));
183: }
184: }
185: }
|