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: package org.apache.axis2.addressing.wsdl;
021:
022: import junit.framework.TestCase;
023:
024: import javax.wsdl.Definition;
025: import javax.wsdl.Fault;
026: import javax.wsdl.Input;
027: import javax.wsdl.Operation;
028: import javax.wsdl.Output;
029: import javax.wsdl.PortType;
030: import javax.wsdl.factory.WSDLFactory;
031: import javax.wsdl.xml.WSDLReader;
032: import javax.xml.namespace.QName;
033: import java.io.File;
034: import java.net.URL;
035: import java.util.List;
036:
037: import org.apache.axis2.AbstractTestCase;
038:
039: public class WSDL11ActionHelperTest extends TestCase {
040:
041: String testWSDLFile = "/target/test-resources/wsdl/actionTests.wsdl";
042:
043: Definition definition;
044:
045: protected void setUp() throws Exception {
046: super .setUp();
047: WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
048: reader.setFeature("javax.wsdl.importDocuments", false);
049: reader.setFeature("javax.wsdl.verbose", false);
050:
051: URL wsdlFile = new File(AbstractTestCase.basedir + testWSDLFile)
052: .toURL();//getClass().getClassLoader().getResource(testWSDLFile);
053: definition = reader.readWSDL(wsdlFile.toString());
054: }
055:
056: // Test DefaultActionPattern (no names in WSDL)
057: // Test not required for Fault as Fault elements MUST have naes per the WSDL 1.1 spec
058: // portType=withoutWSAWActionNoName
059: // operation=echo
060: public void testGenerateInputActionNoNames() {
061: String expectedAction = "http://ws.apache.org/axis2/actiontest/withoutWSAWActionNoName/echoRequest";
062: PortType pt = definition.getPortType(new QName(
063: "http://ws.apache.org/axis2/actiontest/",
064: "withoutWSAWActionNoName"));
065: List operations = pt.getOperations();
066: Operation op = (Operation) operations.get(0);
067: Input in = op.getInput();
068: String actualAction = WSDL11ActionHelper
069: .getActionFromInputElement(definition, pt, op, in);
070: assertEquals(expectedAction, actualAction);
071: }
072:
073: public void testGenerateOutputActionNoNames() {
074: String expectedAction = "http://ws.apache.org/axis2/actiontest/withoutWSAWActionNoName/echoResponse";
075: PortType pt = definition.getPortType(new QName(
076: "http://ws.apache.org/axis2/actiontest/",
077: "withoutWSAWActionNoName"));
078: List operations = pt.getOperations();
079: Operation op = (Operation) operations.get(0);
080: Output out = op.getOutput();
081: String actualAction = WSDL11ActionHelper
082: .getActionFromOutputElement(definition, pt, op, out);
083: assertEquals(expectedAction, actualAction);
084: }
085:
086: // Test DefaultActionPattern (names explicitly set in WSDL)
087: // portType=withoutWSAWAction
088: // operation=echo
089: public void testGenerateInputAction() {
090: String expectedAction = "http://ws.apache.org/axis2/actiontest/withoutWSAWAction/NamedInput";
091: PortType pt = definition.getPortType(new QName(
092: "http://ws.apache.org/axis2/actiontest/",
093: "withoutWSAWAction"));
094: List operations = pt.getOperations();
095: Operation op = (Operation) operations.get(0);
096: Input in = op.getInput();
097: String actualAction = WSDL11ActionHelper
098: .getActionFromInputElement(definition, pt, op, in);
099: assertEquals(expectedAction, actualAction);
100: }
101:
102: public void testGenerateOutputAction() {
103: String expectedAction = "http://ws.apache.org/axis2/actiontest/withoutWSAWAction/NamedOutput";
104: PortType pt = definition.getPortType(new QName(
105: "http://ws.apache.org/axis2/actiontest/",
106: "withoutWSAWAction"));
107: List operations = pt.getOperations();
108: Operation op = (Operation) operations.get(0);
109: Output out = op.getOutput();
110: String actualAction = WSDL11ActionHelper
111: .getActionFromOutputElement(definition, pt, op, out);
112: assertEquals(expectedAction, actualAction);
113: }
114:
115: public void testGenerateFaultAction() {
116: String expectedAction = "http://ws.apache.org/axis2/actiontest/withoutWSAWAction/echo/Fault/echoFault";
117: PortType pt = definition.getPortType(new QName(
118: "http://ws.apache.org/axis2/actiontest/",
119: "withoutWSAWAction"));
120: List operations = pt.getOperations();
121: Operation op = (Operation) operations.get(0);
122: Fault fault = op.getFault("echoFault");
123: String actualAction = WSDL11ActionHelper
124: .getActionFromFaultElement(definition, pt, op, fault);
125: assertEquals(expectedAction, actualAction);
126: }
127:
128: // Test reading wsaw:Action values
129: // portType=withWSAWAction
130: // operation=echo
131: public void testGetWSAWInputAction() {
132: String expectedAction = "http://example.org/action/echoIn";
133: PortType pt = definition.getPortType(new QName(
134: "http://ws.apache.org/axis2/actiontest/",
135: "withWSAWAction"));
136: List operations = pt.getOperations();
137: Operation op = (Operation) operations.get(0);
138: Input in = op.getInput();
139: String actualAction = WSDL11ActionHelper
140: .getActionFromInputElement(definition, pt, op, in);
141: assertEquals(expectedAction, actualAction);
142: }
143:
144: public void testGetWSAWOutputAction() {
145: String expectedAction = "http://example.org/action/echoOut";
146: PortType pt = definition.getPortType(new QName(
147: "http://ws.apache.org/axis2/actiontest/",
148: "withWSAWAction"));
149: List operations = pt.getOperations();
150: Operation op = (Operation) operations.get(0);
151: Output out = op.getOutput();
152: String actualAction = WSDL11ActionHelper
153: .getActionFromOutputElement(definition, pt, op, out);
154: assertEquals(expectedAction, actualAction);
155: }
156:
157: public void testGetWSAWFaultAction() {
158: String expectedAction = "http://example.org/action/echoFault";
159: PortType pt = definition.getPortType(new QName(
160: "http://ws.apache.org/axis2/actiontest/",
161: "withWSAWAction"));
162: List operations = pt.getOperations();
163: Operation op = (Operation) operations.get(0);
164: Fault fault = op.getFault("echoFault");
165: String actualAction = WSDL11ActionHelper
166: .getActionFromFaultElement(definition, pt, op, fault);
167: assertEquals(expectedAction, actualAction);
168: }
169: }
|