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.jaxb;
019:
020: import java.io.InputStream;
021: import java.io.OutputStream;
022: import java.lang.reflect.Method;
023: import java.util.ArrayList;
024:
025: import javax.xml.bind.JAXBContext;
026: import javax.xml.namespace.QName;
027: import javax.xml.stream.XMLStreamReader;
028: import javax.xml.stream.XMLStreamWriter;
029:
030: import org.apache.cxf.Bus;
031: import org.apache.cxf.BusFactory;
032: import org.apache.cxf.binding.Binding;
033: import org.apache.cxf.binding.BindingFactory;
034: import org.apache.cxf.binding.BindingFactoryManager;
035: import org.apache.cxf.endpoint.Endpoint;
036: import org.apache.cxf.endpoint.EndpointImpl;
037: import org.apache.cxf.interceptor.Interceptor;
038: import org.apache.cxf.message.Exchange;
039: import org.apache.cxf.message.ExchangeImpl;
040: import org.apache.cxf.message.MessageImpl;
041: import org.apache.cxf.phase.PhaseInterceptorChain;
042: import org.apache.cxf.service.Service;
043: import org.apache.cxf.service.model.BindingInfo;
044: import org.apache.cxf.service.model.BindingOperationInfo;
045: import org.apache.cxf.service.model.EndpointInfo;
046: import org.apache.cxf.service.model.ServiceInfo;
047: import org.apache.cxf.staxutils.StaxUtils;
048: import org.apache.cxf.wsdl11.WSDLServiceFactory;
049: import org.apache.hello_world_soap_http.types.GreetMe;
050: import org.apache.hello_world_soap_http.types.GreetMeResponse;
051: import org.easymock.classextension.IMocksControl;
052: import org.junit.After;
053: import org.junit.Assert;
054: import org.junit.Before;
055:
056: import static org.easymock.EasyMock.expect;
057: import static org.easymock.classextension.EasyMock.createNiceControl;
058:
059: public class TestBase extends Assert {
060:
061: PhaseInterceptorChain chain;
062: MessageImpl message;
063: Bus bus;
064: ServiceInfo serviceInfo;
065: BindingInfo bindingInfo;
066: Service service;
067: EndpointInfo endpointInfo;
068: EndpointImpl endpoint;
069: BindingOperationInfo operation;
070:
071: @Before
072: public void setUp() throws Exception {
073: bus = BusFactory.newInstance().createBus();
074:
075: BindingFactoryManager bfm = bus
076: .getExtension(BindingFactoryManager.class);
077:
078: IMocksControl control = createNiceControl();
079: BindingFactory bf = control.createMock(BindingFactory.class);
080: Binding binding = control.createMock(Binding.class);
081: expect(bf.createBinding(null)).andStubReturn(binding);
082: expect(binding.getInFaultInterceptors()).andStubReturn(
083: new ArrayList<Interceptor>());
084: expect(binding.getOutFaultInterceptors()).andStubReturn(
085: new ArrayList<Interceptor>());
086:
087: bfm.registerBindingFactory(
088: "http://schemas.xmlsoap.org/wsdl/soap/", bf);
089:
090: String ns = "http://apache.org/hello_world_soap_http";
091: WSDLServiceFactory factory = new WSDLServiceFactory(
092: bus,
093: getClass()
094: .getResource(
095: "/org/apache/cxf/jaxb/resources/wsdl/hello_world.wsdl"),
096: new QName(ns, "SOAPService"));
097:
098: service = factory.create();
099: endpointInfo = service
100: .getEndpointInfo(new QName(ns, "SoapPort"));
101: endpoint = new EndpointImpl(bus, service, endpointInfo);
102: JAXBDataBinding db = new JAXBDataBinding();
103: db.setContext(JAXBContext.newInstance(new Class[] {
104: GreetMe.class, GreetMeResponse.class }));
105: service.setDataBinding(db);
106:
107: operation = endpointInfo.getBinding().getOperation(
108: new QName(ns, "greetMe"));
109: operation.getOperationInfo().getInput()
110: .getMessagePartByIndex(0).setTypeClass(GreetMe.class);
111: operation.getOperationInfo().getOutput().getMessagePartByIndex(
112: 0).setTypeClass(GreetMeResponse.class);
113:
114: message = new MessageImpl();
115: Exchange exchange = new ExchangeImpl();
116: message.setExchange(exchange);
117:
118: exchange.put(Service.class, service);
119: exchange.put(Endpoint.class, endpoint);
120: exchange.put(Binding.class, endpoint.getBinding());
121: }
122:
123: @After
124: public void tearDown() throws Exception {
125: }
126:
127: public InputStream getTestStream(Class<?> clz, String file) {
128: return clz.getResourceAsStream(file);
129: }
130:
131: public XMLStreamReader getXMLStreamReader(InputStream is) {
132: return StaxUtils.createXMLStreamReader(is);
133: }
134:
135: public XMLStreamWriter getXMLStreamWriter(OutputStream os) {
136: return StaxUtils.createXMLStreamWriter(os);
137: }
138:
139: public Method getTestMethod(Class<?> sei, String methodName) {
140: Method[] iMethods = sei.getMethods();
141: for (Method m : iMethods) {
142: if (methodName.equals(m.getName())) {
143: return m;
144: }
145: }
146: return null;
147: }
148: }
|