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: */package org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11;
019:
020: import java.util.Iterator;
021: import java.util.List;
022: import javax.wsdl.Definition;
023: import javax.wsdl.Operation;
024: import javax.wsdl.PortType;
025: import javax.wsdl.extensions.ExtensibilityElement;
026: import javax.xml.namespace.QName;
027:
028: import org.apache.cxf.tools.common.ToolConstants;
029: import org.apache.cxf.tools.common.ToolContext;
030: import org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding;
031: import org.junit.Assert;
032: import org.junit.Before;
033: import org.junit.Test;
034:
035: public class JAXWSDefinitionBuilderTest extends Assert {
036: private ToolContext env;
037:
038: @Before
039: public void setUp() {
040: env = new ToolContext();
041: }
042:
043: @Test
044: public void testCustomization() {
045: env.put(ToolConstants.CFG_WSDLURL, getClass().getResource(
046: "resources/hello_world.wsdl").toString());
047: env.put(ToolConstants.CFG_BINDING, getClass().getResource(
048: "resources/binding2.xml").toString());
049: JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
050: builder.setContext(env);
051: builder.build();
052: builder.customize();
053:
054: Definition customizedDef = builder.getWSDLModel();
055: List defExtensionList = customizedDef
056: .getExtensibilityElements();
057: Iterator ite = defExtensionList.iterator();
058:
059: while (ite.hasNext()) {
060: ExtensibilityElement extElement = (ExtensibilityElement) ite
061: .next();
062: JAXWSBinding binding = (JAXWSBinding) extElement;
063: assertEquals(
064: "Customized package name does not been parsered",
065: "com.foo", binding.getPackage());
066: assertEquals("Customized enableAsync does not parsered",
067: true, binding.isEnableAsyncMapping());
068: }
069:
070: PortType portType = customizedDef.getPortType(new QName(
071: "http://apache.org/hello_world_soap_http", "Greeter"));
072:
073: List portTypeList = portType.getExtensibilityElements();
074: JAXWSBinding binding = (JAXWSBinding) portTypeList.get(0);
075:
076: assertEquals(
077: "Customized enable EnableWrapperStyle name does not been parsered",
078: true, binding.isEnableWrapperStyle());
079:
080: List opList = portType.getOperations();
081: Operation operation = (Operation) opList.get(0);
082: List extList = operation.getExtensibilityElements();
083: binding = (JAXWSBinding) extList.get(0);
084:
085: assertEquals("Customized method name does not parsered",
086: "echoMeOneWay", binding.getMethodName());
087:
088: assertEquals(
089: "Customized parameter element name does not parsered",
090: "tns:number1", binding.getJaxwsPara().getElementName());
091: assertEquals(
092: "Customized parameter message name does not parsered",
093: "greetMeOneWayRequest", binding.getJaxwsPara()
094: .getMessageName());
095: assertEquals("customized parameter name does not parsered",
096: "num1", binding.getJaxwsPara().getName());
097: }
098:
099: @Test
100: public void testCustomizationWithDifferentNS() {
101: env.put(ToolConstants.CFG_WSDLURL, getClass().getResource(
102: "resources/hello_world.wsdl").toString());
103: env.put(ToolConstants.CFG_BINDING, getClass().getResource(
104: "resources/binding3.xml").toString());
105: JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
106: builder.setContext(env);
107: builder.build();
108: builder.customize();
109:
110: Definition customizedDef = builder.getWSDLModel();
111: List defExtensionList = customizedDef
112: .getExtensibilityElements();
113: Iterator ite = defExtensionList.iterator();
114:
115: while (ite.hasNext()) {
116: ExtensibilityElement extElement = (ExtensibilityElement) ite
117: .next();
118: JAXWSBinding binding = (JAXWSBinding) extElement;
119: assertEquals(
120: "Customized package name does not been parsered",
121: "com.foo", binding.getPackage());
122: assertEquals("Customized enableAsync does not parsered",
123: true, binding.isEnableAsyncMapping());
124: }
125:
126: PortType portType = customizedDef.getPortType(new QName(
127: "http://apache.org/hello_world_soap_http", "Greeter"));
128:
129: List portTypeList = portType.getExtensibilityElements();
130: JAXWSBinding binding = (JAXWSBinding) portTypeList.get(0);
131:
132: assertEquals(
133: "Customized enable EnableWrapperStyle name does not been parsered",
134: true, binding.isEnableWrapperStyle());
135:
136: List opList = portType.getOperations();
137: Operation operation = (Operation) opList.get(0);
138: List extList = operation.getExtensibilityElements();
139: binding = (JAXWSBinding) extList.get(0);
140:
141: assertEquals("Customized method name does not parsered",
142: "echoMeOneWay", binding.getMethodName());
143:
144: assertEquals(
145: "Customized parameter element name does not parsered",
146: "tns:number1", binding.getJaxwsPara().getElementName());
147: assertEquals(
148: "Customized parameter message name does not parsered",
149: "greetMeOneWayRequest", binding.getJaxwsPara()
150: .getMessageName());
151: assertEquals("customized parameter name does not parsered",
152: "num1", binding.getJaxwsPara().getName());
153: }
154:
155: // tests the error case described in JIRA CXF-556
156: @Test
157: public void testCustomizationWhereURINotAnExactStringMatch() {
158: // set up a URI with ./../wsdl11/hello_world.wsdl instead of
159: // ./hello_world.wsdl
160: env.put(ToolConstants.CFG_WSDLURL, getClass().getResource(".")
161: .toString()
162: + "../wsdl11/resources/hello_world.wsdl");
163: env.put(ToolConstants.CFG_BINDING, getClass().getResource(
164: "resources/cxf556_binding.xml").toString());
165:
166: JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
167: builder.setContext(env);
168: builder.build();
169:
170: // this call will fail before CXF-556
171: builder.customize();
172:
173: assertTrue(true);
174: }
175:
176: }
|