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.systest.jaxws;
019:
020: import java.net.URL;
021:
022: import javax.wsdl.WSDLException;
023: import javax.wsdl.factory.WSDLFactory;
024: import javax.wsdl.xml.WSDLReader;
025: import javax.xml.namespace.QName;
026: import javax.xml.ws.WebServiceException;
027:
028: import org.apache.cxf.Bus;
029: import org.apache.cxf.BusFactory;
030: import org.apache.cxf.catalog.CatalogWSDLLocator;
031: import org.apache.cxf.catalog.OASISCatalogManager;
032:
033: import org.apache.hello_world.Greeter;
034: import org.apache.hello_world.services.SOAPService;
035:
036: import org.junit.Assert;
037: import org.junit.Test;
038:
039: public class OASISCatalogTest extends Assert {
040:
041: private final QName serviceName = new QName(
042: "http://apache.org/hello_world/services", "SOAPService");
043:
044: private final QName portName = new QName(
045: "http://apache.org/hello_world/services", "SoapPort");
046:
047: @Test
048: public void testClientWithDefaultCatalog() throws Exception {
049: URL wsdl = getClass().getResource(
050: "/wsdl/catalog/hello_world_services.wsdl");
051: assertNotNull(wsdl);
052:
053: SOAPService service = new SOAPService(wsdl, serviceName);
054: assertNotNull(service);
055:
056: Greeter greeter = service.getPort(portName, Greeter.class);
057: assertNotNull(greeter);
058: }
059:
060: @Test
061: public void testClientWithoutCatalog() throws Exception {
062: URL wsdl = getClass().getResource(
063: "/wsdl/catalog/hello_world_services.wsdl");
064: assertNotNull(wsdl);
065:
066: // set Catalog on the Bus
067: Bus bus = BusFactory.getDefaultBus();
068: OASISCatalogManager catalog = new OASISCatalogManager();
069: bus.setExtension(catalog, OASISCatalogManager.class);
070:
071: try {
072: SOAPService service = new SOAPService(wsdl, serviceName);
073: service.getPort(portName, Greeter.class);
074: fail("Test did not fail as expected");
075: } catch (WebServiceException e) {
076: // ignore
077: }
078:
079: // update catalog dynamically now
080: URL jaxwscatalog = getClass().getResource(
081: "/META-INF/jax-ws-catalog.xml");
082: assertNotNull(jaxwscatalog);
083:
084: catalog.loadCatalog(jaxwscatalog);
085:
086: SOAPService service = new SOAPService(wsdl, serviceName);
087: Greeter greeter = service.getPort(portName, Greeter.class);
088: assertNotNull(greeter);
089: }
090:
091: @Test
092: public void testWSDLLocatorWithDefaultCatalog() throws Exception {
093: URL wsdl = getClass().getResource(
094: "/wsdl/catalog/hello_world_services.wsdl");
095: assertNotNull(wsdl);
096:
097: WSDLFactory wsdlFactory = WSDLFactory.newInstance();
098: WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
099:
100: CatalogWSDLLocator wsdlLocator = new CatalogWSDLLocator(wsdl
101: .toString(), OASISCatalogManager
102: .getCatalogManager(null));
103: wsdlReader.setFeature("javax.wsdl.verbose", false);
104: wsdlReader.readWSDL(wsdlLocator);
105: }
106:
107: @Test
108: public void testWSDLLocatorWithoutCatalog() throws Exception {
109: URL wsdl = getClass().getResource(
110: "/wsdl/catalog/hello_world_services.wsdl");
111: assertNotNull(wsdl);
112:
113: WSDLFactory wsdlFactory = WSDLFactory.newInstance();
114: WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
115: wsdlReader.setFeature("javax.wsdl.verbose", false);
116:
117: OASISCatalogManager catalog = new OASISCatalogManager();
118: CatalogWSDLLocator wsdlLocator = new CatalogWSDLLocator(wsdl
119: .toString(), catalog);
120: try {
121: wsdlReader.readWSDL(wsdlLocator);
122: fail("Test did not fail as expected");
123: } catch (WSDLException e) {
124: // ignore
125: }
126: }
127:
128: }
|