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.coloc;
019:
020: import java.net.URL;
021:
022: import javax.xml.namespace.QName;
023: import javax.xml.ws.Endpoint;
024: import javax.xml.ws.Service;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.cxf.Bus;
028: import org.apache.cxf.BusFactory;
029: import org.apache.cxf.bus.spring.SpringBusFactory;
030: import org.apache.cxf.common.classloader.ClassLoaderUtils;
031:
032: import org.junit.After;
033: import org.junit.Assert;
034: import org.junit.Before;
035:
036: public abstract class AbstractColocTest extends Assert {
037: /**
038: * Cxf Bus
039: */
040: protected Bus bus;
041:
042: /**
043: * WS endpoint object
044: */
045: protected Endpoint endpoint;
046:
047: /**
048: * Setup this test case
049: */
050: @Before
051: public void setUp() throws Exception {
052: // initialize Mule Manager
053: URL cxfConfig = null;
054: if (getCxfConfig() != null) {
055: cxfConfig = ClassLoaderUtils.getResource(getCxfConfig(),
056: AbstractColocTest.class);
057: if (cxfConfig == null) {
058: throw new Exception("Make sure " + getCxfConfig()
059: + " is in the CLASSPATH");
060: }
061: assertTrue(cxfConfig.toExternalForm() != null);
062: }
063:
064: //Bus is shared by client, router and server.
065: SpringBusFactory bf = new SpringBusFactory();
066: bus = bf.createBus(cxfConfig);
067: BusFactory.setDefaultBus(bus);
068:
069: //Start the Remote Server
070: // the endpoint of the "real" cxf server
071: endpoint = Endpoint
072: .publish(getTransportURI(), getServiceImpl());
073: }
074:
075: /**
076: * Tear down this test case
077: */
078: @After
079: public void tearDown() throws Exception {
080:
081: getLogger().debug("tearDown ...");
082:
083: if (endpoint != null) {
084: endpoint.stop();
085: }
086:
087: if (bus != null) {
088: bus.shutdown(true);
089: }
090: }
091:
092: /**
093: * @return cxf configuration file name
094: */
095: protected String getCxfConfig() {
096: return "org/apache/cxf/systest/coloc/cxf.xml";
097: }
098:
099: /**
100: * Create client and return the port
101: * @return port for a interface represented by cls.
102: */
103: protected <T> T getPort(QName serviceName, QName portName,
104: String wsdlLocation, Class<T> cls) {
105: Service srv = Service.create(AbstractColocTest.class
106: .getResource(wsdlLocation), serviceName);
107: return srv.getPort(portName, cls);
108: }
109:
110: /**
111: * @return the greeter impl object
112: */
113: protected abstract Object getServiceImpl();
114:
115: /**
116: * @return logger object
117: */
118: protected abstract Log getLogger();
119:
120: /**
121: * @return transport URI for the WS Endpoint
122: */
123: protected abstract String getTransportURI();
124:
125: }
|