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.description;
020:
021: import junit.framework.TestCase;
022: import org.apache.axis2.AxisFault;
023: import org.apache.axis2.context.ConfigurationContext;
024: import org.apache.axis2.context.ConfigurationContextFactory;
025: import org.apache.axis2.engine.ListenerManager;
026:
027: import java.io.File;
028: import java.io.FileInputStream;
029: import java.util.Iterator;
030: import java.util.List;
031:
032: /**
033: * Tests the WSDL11ToAllServicesBuilder class.
034: */
035: public class WSDLToAllServicesBuilderTest extends TestCase {
036: private static final String[] expectedService11 = {
037: "EchoServicePortOne", "EchoServicePortTwo",
038: "EchoServicePortThree" };
039: private static final String[] expectedService20 = {
040: "echoService1$echoServiceSOAPBinding_http",
041: "echoService1$echoServiceEndpoint2SOAPBinding_http",
042: "echoService2$echoServiceSOAPBinding_http" };
043: private ConfigurationContext configContext;
044: ListenerManager lm;
045:
046: protected void setUp() throws Exception {
047: configContext = ConfigurationContextFactory
048: .createConfigurationContextFromFileSystem(null, null);
049: lm = new ListenerManager();
050: lm.init(configContext);
051: lm.start();
052: }
053:
054: protected void tearDown() throws AxisFault {
055: configContext.terminate();
056: }
057:
058: private void checkResults(List axisServices,
059: String expectedService[]) {
060:
061: Iterator asi = axisServices.iterator();
062: int i = 0;
063: while (asi.hasNext() && i < expectedService.length) {
064: AxisService as = (AxisService) asi.next();
065: System.out.println("AxisService : " + as.getName());
066: assertEquals(
067: "Unexpected service name in AxisService List: expected "
068: + expectedService[i] + " but found "
069: + as.getName() + ".", as.getName(),
070: expectedService[i]);
071: i++;
072: }
073: }
074:
075: public void testWSDL11toAllAxisServices() throws Exception {
076: File testResourceFile = new File(
077: "target/test-classes/wsdl/EchoServiceWsdl11.wsdl");
078: File outLocation = new File("target/test-resources");
079: outLocation.mkdirs();
080: if (testResourceFile.exists()) {
081: List axisServices = null;
082: try {
083: WSDL11ToAllAxisServicesBuilder builder = new WSDL11ToAllAxisServicesBuilder(
084: new FileInputStream(testResourceFile));
085: axisServices = builder.populateAllServices();
086: System.out.println("WSDL file: "
087: + testResourceFile.getName());
088: } catch (Exception e) {
089: System.out.println("Error in WSDL : "
090: + testResourceFile.getName());
091: System.out.println("Exception: " + e.toString());
092: throw e;
093: }
094: checkResults(axisServices, expectedService11);
095:
096: }
097: }
098:
099: public void testWSDL20toAllAxisServices() throws Exception {
100: File testResourceFile = new File(
101: "target/test-classes/wsdl/EchoServiceWsdl20.wsdl");
102: File outLocation = new File("target/test-resources");
103: outLocation.mkdirs();
104: if (testResourceFile.exists()) {
105: List axisServices = null;
106: try {
107: WSDL20ToAllAxisServicesBuilder builder = new WSDL20ToAllAxisServicesBuilder(
108: new FileInputStream(testResourceFile));
109: axisServices = builder.populateAllServices();
110: System.out.println("WSDL file: "
111: + testResourceFile.getName());
112: } catch (Exception e) {
113: System.out.println("Error in WSDL : "
114: + testResourceFile.getName());
115: System.out.println("Exception: " + e.toString());
116: throw e;
117: }
118: checkResults(axisServices, expectedService20);
119:
120: }
121: }
122:
123: }
|