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.binding.soap;
019:
020: import java.io.InputStream;
021: import java.io.OutputStream;
022: import java.lang.reflect.Method;
023: import java.util.Iterator;
024: import java.util.SortedSet;
025: import java.util.TreeSet;
026:
027: import javax.wsdl.Definition;
028: import javax.wsdl.Service;
029: import javax.wsdl.factory.WSDLFactory;
030: import javax.wsdl.xml.WSDLReader;
031: import javax.xml.namespace.QName;
032: import javax.xml.stream.XMLStreamReader;
033: import javax.xml.stream.XMLStreamWriter;
034:
035: import org.apache.cxf.Bus;
036: import org.apache.cxf.binding.BindingFactoryManager;
037: import org.apache.cxf.phase.Phase;
038: import org.apache.cxf.phase.PhaseInterceptorChain;
039: import org.apache.cxf.service.model.BindingInfo;
040: import org.apache.cxf.service.model.ServiceInfo;
041: import org.apache.cxf.staxutils.StaxUtils;
042: import org.apache.cxf.transport.DestinationFactoryManager;
043: import org.apache.cxf.wsdl11.WSDLServiceBuilder;
044: import org.easymock.classextension.EasyMock;
045: import org.easymock.classextension.IMocksControl;
046: import org.junit.After;
047: import org.junit.Assert;
048: import org.junit.Before;
049:
050: public class TestBase extends Assert {
051:
052: protected PhaseInterceptorChain chain;
053: protected SoapMessage soapMessage;
054:
055: @Before
056: public void setUp() throws Exception {
057: SortedSet<Phase> phases = new TreeSet<Phase>();
058: Phase phase1 = new Phase("phase1", 1);
059: Phase phase2 = new Phase("phase2", 2);
060: Phase phase3 = new Phase("phase3", 3);
061: Phase phase4 = new Phase(Phase.WRITE_ENDING, 4);
062: phases.add(phase1);
063: phases.add(phase2);
064: phases.add(phase3);
065: phases.add(phase4);
066: chain = new PhaseInterceptorChain(phases);
067:
068: soapMessage = TestUtil.createEmptySoapMessage(Soap11
069: .getInstance(), chain);
070: }
071:
072: @After
073: public void tearDown() throws Exception {
074: }
075:
076: public InputStream getTestStream(Class<?> clz, String file) {
077: return clz.getResourceAsStream(file);
078: }
079:
080: public XMLStreamReader getXMLStreamReader(InputStream is) {
081: return StaxUtils.createXMLStreamReader(is);
082: }
083:
084: public XMLStreamWriter getXMLStreamWriter(OutputStream os) {
085: return StaxUtils.createXMLStreamWriter(os);
086: }
087:
088: public Method getTestMethod(Class<?> sei, String methodName) {
089: Method[] iMethods = sei.getMethods();
090: for (Method m : iMethods) {
091: if (methodName.equals(m.getName())) {
092: return m;
093: }
094: }
095: return null;
096: }
097:
098: public ServiceInfo getTestService(Class<?> clz) {
099: // FIXME?!?!?!?? There should NOT be JAX-WS stuff here
100: return null;
101: }
102:
103: protected BindingInfo getTestService(String wsdlUrl, String port)
104: throws Exception {
105: ServiceInfo service = getMockedServiceModel(getClass()
106: .getResource(wsdlUrl).toString());
107: assertNotNull(service);
108: BindingInfo binding = service.getEndpoint(
109: new QName(service.getName().getNamespaceURI(), port))
110: .getBinding();
111: assertNotNull(binding);
112: return binding;
113: }
114:
115: protected ServiceInfo getMockedServiceModel(String wsdlUrl)
116: throws Exception {
117: WSDLReader wsdlReader = WSDLFactory.newInstance()
118: .newWSDLReader();
119: wsdlReader.setFeature("javax.wsdl.verbose", false);
120: Definition def = wsdlReader.readWSDL(wsdlUrl);
121:
122: IMocksControl control = EasyMock.createNiceControl();
123: Bus bus = control.createMock(Bus.class);
124: BindingFactoryManager bindingFactoryManager = control
125: .createMock(BindingFactoryManager.class);
126: DestinationFactoryManager dfm = control
127: .createMock(DestinationFactoryManager.class);
128: WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(
129: bus);
130:
131: Service service = null;
132: for (Iterator<?> it = def.getServices().values().iterator(); it
133: .hasNext();) {
134: Object obj = it.next();
135: if (obj instanceof Service) {
136: service = (Service) obj;
137: break;
138: }
139: }
140:
141: EasyMock.expect(bus.getExtension(BindingFactoryManager.class))
142: .andReturn(bindingFactoryManager);
143: EasyMock.expect(
144: bus.getExtension(DestinationFactoryManager.class))
145: .andStubReturn(dfm);
146: control.replay();
147:
148: ServiceInfo serviceInfo = wsdlServiceBuilder.buildServices(def,
149: service).get(0);
150: serviceInfo.setProperty(WSDLServiceBuilder.WSDL_DEFINITION,
151: null);
152: serviceInfo.setProperty(WSDLServiceBuilder.WSDL_SERVICE, null);
153: return serviceInfo;
154: }
155: }
|