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:
020: /**
021: *
022: */package org.apache.axis2.jaxws.sample;
023:
024: import java.util.concurrent.Future;
025:
026: import javax.xml.ws.Holder;
027: import javax.xml.ws.WebServiceException;
028:
029: import junit.framework.TestCase;
030: import org.apache.axis2.jaxws.sample.nonwrap.sei.DocLitNonWrapPortType;
031: import org.apache.axis2.jaxws.sample.nonwrap.sei.DocLitNonWrapService;
032: import org.apache.axis2.jaxws.TestLogger;
033: import org.test.sample.nonwrap.ObjectFactory;
034: import org.test.sample.nonwrap.ReturnType;
035: import org.test.sample.nonwrap.TwoWay;
036: import org.test.sample.nonwrap.TwoWayHolder;
037:
038: public class NonWrapTests extends TestCase {
039:
040: public NonWrapTests() {
041: super ();
042: // TODO Auto-generated constructor stub
043: }
044:
045: /**
046: * @param arg0
047: */
048: public NonWrapTests(String arg0) {
049: super (arg0);
050: // TODO Auto-generated constructor stub
051: }
052:
053: public void testTwoWaySync() {
054: TestLogger.logger.debug("------------------------------");
055: TestLogger.logger.debug("Test : " + getName());
056: try {
057: TwoWay twoWay = new ObjectFactory().createTwoWay();
058: twoWay
059: .setTwowayStr("testing sync call for java bean non wrap endpoint");
060: DocLitNonWrapService service = new DocLitNonWrapService();
061: DocLitNonWrapPortType proxy = service
062: .getDocLitNonWrapPort();
063: ReturnType returnValue = proxy.twoWay(twoWay);
064: TestLogger.logger.debug(returnValue.getReturnStr());
065: TestLogger.logger.debug("------------------------------");
066: } catch (Exception e) {
067: e.printStackTrace();
068: fail();
069: }
070: }
071:
072: public void testTwoWaySyncNull() throws Exception {
073: TestLogger.logger.debug("------------------------------");
074: TestLogger.logger.debug("Test : " + getName());
075: try {
076: TwoWay twoWay = null; // This should cause an WebServiceException
077: DocLitNonWrapService service = new DocLitNonWrapService();
078: DocLitNonWrapPortType proxy = service
079: .getDocLitNonWrapPort();
080: ReturnType returnValue = proxy.twoWay(twoWay);
081:
082: // TODO Revisit JAXB validation
083: // JAXWS does not make the decision of whether a
084: // null parameter can be marshalled. This decision is
085: // delegated to JAXB. In this case, the schema indicates
086: // that this is not a nillable element. The assumption is
087: // that JAXB will fail. However the current version of
088: // JAXB considers this as 'validation checking' and is not
089: // supported. Thus JAXB will marshal the element without
090: // an exception (and unmarshal without exception) even though
091: // this is a violation of the schema.
092:
093: //fail("Expected WebServiceException");
094:
095: } catch (WebServiceException e) {
096: TestLogger.logger.debug(e.toString());
097: }
098: }
099:
100: public void testTwoWayASyncCallback() {
101: TestLogger.logger.debug("------------------------------");
102: TestLogger.logger.debug("Test : " + getName());
103: try {
104: TwoWay twoWay = new ObjectFactory().createTwoWay();
105: twoWay
106: .setTwowayStr("testing Async call for java bean non wrap endpoint");
107: DocLitNonWrapService service = new DocLitNonWrapService();
108: DocLitNonWrapPortType proxy = service
109: .getDocLitNonWrapPort();
110: AsyncCallback callback = new AsyncCallback();
111: Future<?> monitor = proxy.twoWayAsync(twoWay, callback);
112: assertNotNull(monitor);
113: TestLogger.logger.debug("------------------------------");
114: } catch (Exception e) {
115: e.printStackTrace();
116: fail();
117: }
118: }
119:
120: public void testTwoWayHolder() {
121: TestLogger.logger.debug("------------------------------");
122: TestLogger.logger.debug("Test : " + getName());
123: try {
124: TwoWayHolder twh = new TwoWayHolder();
125: twh.setTwoWayHolderInt(new Integer(0));
126: twh.setTwoWayHolderStr(new String("Request Holder String"));
127: Holder<TwoWayHolder> holder = new Holder<TwoWayHolder>(twh);
128: TwoWay twoWay = new ObjectFactory().createTwoWay();
129: twoWay
130: .setTwowayStr("testing sync call for java bean non wrap endpoint");
131: DocLitNonWrapService service = new DocLitNonWrapService();
132: DocLitNonWrapPortType proxy = service
133: .getDocLitNonWrapPort();
134: proxy.twoWayHolder(holder);
135: twh = holder.value;
136: TestLogger.logger.debug("Holder string ="
137: + twh.getTwoWayHolderStr());
138: TestLogger.logger.debug("Holder int ="
139: + twh.getTwoWayHolderInt());
140:
141: TestLogger.logger.debug("------------------------------");
142: } catch (Exception e) {
143: e.printStackTrace();
144: fail();
145: }
146: }
147:
148: public void testTwoWayHolderAsync() {
149: TestLogger.logger.debug("------------------------------");
150: TestLogger.logger.debug("Test : " + getName());
151: try {
152: TwoWayHolder twh = new TwoWayHolder();
153: twh.setTwoWayHolderInt(new Integer(0));
154: twh.setTwoWayHolderStr(new String("Request Holder String"));
155: Holder<TwoWayHolder> holder = new Holder<TwoWayHolder>(twh);
156: TwoWay twoWay = new ObjectFactory().createTwoWay();
157: twoWay
158: .setTwowayStr("testing sync call for java bean non wrap endpoint");
159: DocLitNonWrapService service = new DocLitNonWrapService();
160: DocLitNonWrapPortType proxy = service
161: .getDocLitNonWrapPort();
162: AsyncCallback callback = new AsyncCallback();
163: Future<?> monitor = proxy.twoWayHolderAsync(twh, callback);
164: while (!monitor.isDone()) {
165: Thread.sleep(1000);
166: }
167:
168: TestLogger.logger.debug("------------------------------");
169: } catch (Exception e) {
170: e.printStackTrace();
171: fail();
172: }
173: }
174: }
|