001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.assembler;
038:
039: import com.sun.xml.ws.api.BindingID;
040: import com.sun.xml.ws.api.EndpointAddress;
041: import com.sun.xml.ws.api.WSBinding;
042: import com.sun.xml.ws.api.WSService;
043: import com.sun.xml.ws.api.client.WSPortInfo;
044: import com.sun.xml.ws.api.model.wsdl.WSDLModel;
045: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
046: import com.sun.xml.ws.api.pipe.ClientPipeAssemblerContext;
047: import com.sun.xml.ws.api.pipe.Pipe;
048: import com.sun.xml.ws.api.pipe.PipelineAssembler;
049: import com.sun.xml.ws.api.server.Container;
050: import com.sun.xml.ws.client.WSServiceDelegate;
051: import com.sun.xml.ws.policy.PolicyException;
052: import com.sun.xml.ws.policy.PolicyMap;
053: import com.sun.xml.ws.policy.jaxws.PolicyConfigParser;
054: import com.sun.xml.ws.policy.jaxws.WSDLPolicyMapWrapper;
055: import com.sun.xml.ws.policy.jaxws.client.PolicyFeature;
056: import com.sun.xml.ws.policy.privateutil.PolicyUtils;
057: import java.net.URI;
058: import java.net.URISyntaxException;
059: import java.net.URL;
060: import javax.xml.namespace.QName;
061: import javax.xml.ws.Service;
062: import junit.framework.TestCase;
063:
064: /**
065: * @author Fabian Ritzmann
066: */
067: public class PipelineAssemblerFactoryImplTest extends TestCase {
068:
069: private static final String NAMESPACE = "http://service1.test.ws.xml.sun.com/";
070: private static final URI ADDRESS_URL;
071: static {
072: try {
073: ADDRESS_URL = new URI(
074: "http://localhost:8080/dispatch/Service1Service");
075: } catch (URISyntaxException e) {
076: throw new IllegalArgumentException(
077: "Failed to initialize address URI", e);
078: }
079: }
080:
081: public PipelineAssemblerFactoryImplTest(String testName) {
082: super (testName);
083: }
084:
085: public void testCreateClientNull() {
086: try {
087: final BindingID bindingId = BindingID.SOAP11_HTTP;
088: final PipelineAssemblerFactoryImpl factory = new PipelineAssemblerFactoryImpl();
089: final PipelineAssembler assembler = factory
090: .doCreate(bindingId);
091: final Pipe pipe = assembler.createClient(null);
092: fail("Expected NullPointerException");
093: } catch (NullPointerException e) {
094: }
095: }
096:
097: public void testCreateServerNull() {
098: try {
099: final BindingID bindingId = BindingID.SOAP11_HTTP;
100: final PipelineAssemblerFactoryImpl factory = new PipelineAssemblerFactoryImpl();
101: final PipelineAssembler assembler = factory
102: .doCreate(bindingId);
103: final Pipe pipe = assembler.createServer(null);
104: fail("Expected NullPointerException");
105: } catch (NullPointerException e) {
106: }
107: }
108:
109: /**
110: * Test client creation with parameters that correspond to a dispatch client
111: * with no wsit-client.xml.
112: */
113: public void testCreateDispatchClientNoConfig() throws Exception {
114: final BindingID bindingId = BindingID.SOAP11_HTTP;
115: final WSBinding binding = bindingId.createBinding();
116: final EndpointAddress address = new EndpointAddress(ADDRESS_URL);
117: final WSDLPort port = null;
118: final WSService service = null;
119: final Container container = Container.NONE;
120: final ClientPipeAssemblerContext context = new ClientPipeAssemblerContext(
121: address, port, service, binding, container);
122: final PipelineAssemblerFactoryImpl factory = new PipelineAssemblerFactoryImpl();
123: final PipelineAssembler assembler = factory.doCreate(bindingId);
124: final Pipe pipe = assembler.createClient(context);
125: assertNotNull(pipe);
126: }
127:
128: /**
129: * Test client creation with parameters that correspond to a dispatch client
130: * with wsit-client.xml.
131: */
132: public void testCreateDispatchClientNoPoliciesConfig()
133: throws PolicyException {
134: Pipe pipe = testDispatch("nopolicies.xml");
135: assertNotNull(pipe);
136: }
137:
138: /**
139: * Test client creation with parameters that correspond to a dispatch client
140: * with wsit-client.xml.
141: */
142: public void testCreateDispatchClientAllFeaturesConfig()
143: throws PolicyException {
144: Pipe pipe = testDispatch("allfeatures.xml");
145: assertNotNull(pipe);
146: }
147:
148: /**
149: * Test client creation with parameters that correspond to a dispatch client
150: * with wsit-client.xml.
151: */
152: public void testCreateDispatchClientNoServiceMatchConfig()
153: throws PolicyException {
154: Pipe pipe = testDispatch("noservicematch.xml");
155: assertNotNull(pipe);
156: }
157:
158: /**
159: * Execute a sequence that corresponds to:
160: * <pre>
161: Service.createService(null, serviceName);
162: Service.addPort(portName, bindingId, address);</pre>
163: */
164: private Pipe testDispatch(String configFileName)
165: throws PolicyException {
166: final URL wsdlLocation = null;
167: final QName serviceName = new QName(NAMESPACE,
168: "Service1Service");
169: // Corresponds to Service.createService(wsdlLocation, serviceName)
170: final WSServiceDelegate serviceDelegate = new WSServiceDelegate(
171: wsdlLocation, serviceName, Service.class);
172:
173: final QName portName = new QName(NAMESPACE, "Service1Port");
174: final BindingID bindingId = BindingID.SOAP11_HTTP;
175: // Corresponds to Service.addPort(portName, bindingId, address)
176: serviceDelegate.addPort(portName, bindingId.toString(),
177: ADDRESS_URL.toString());
178:
179: final EndpointAddress address = new EndpointAddress(ADDRESS_URL);
180: final WSDLPort port = null;
181: final WSDLModel clientModel = parseConfigFile(configFileName);
182: final WSDLPolicyMapWrapper mapWrapper = clientModel
183: .getExtension(WSDLPolicyMapWrapper.class);
184: final PolicyMap map = mapWrapper.getPolicyMap();
185: final WSPortInfo portInfo = serviceDelegate
186: .safeGetPort(portName);
187: final PolicyFeature feature = new PolicyFeature(map,
188: clientModel, portInfo);
189: final WSBinding binding = bindingId.createBinding(feature);
190: final Container container = Container.NONE;
191: final ClientPipeAssemblerContext context = new ClientPipeAssemblerContext(
192: address, port, serviceDelegate, binding, container);
193:
194: final PipelineAssemblerFactoryImpl factory = new PipelineAssemblerFactoryImpl();
195: final PipelineAssembler assembler = factory.doCreate(bindingId);
196: return assembler.createClient(context);
197: }
198:
199: private WSDLModel parseConfigFile(String configFile)
200: throws PolicyException {
201: URL url = PolicyUtils.ConfigFile.loadFromClasspath("assembler/"
202: + configFile);
203: return PolicyConfigParser.parseModel(url, true);
204: }
205:
206: }
|