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.jaxws.spring;
019:
020: import java.util.List;
021:
022: import javax.xml.namespace.QName;
023:
024: import junit.framework.Assert;
025:
026: import org.apache.cxf.binding.BindingConfiguration;
027: import org.apache.cxf.binding.soap.Soap12;
028: import org.apache.cxf.binding.soap.SoapBindingConfiguration;
029: import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
030: import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
031: import org.apache.cxf.databinding.source.SourceDataBinding;
032: import org.apache.cxf.endpoint.Client;
033: import org.apache.cxf.endpoint.NullConduitSelector;
034: import org.apache.cxf.frontend.ClientProxy;
035: import org.apache.cxf.interceptor.Interceptor;
036: import org.apache.cxf.interceptor.LoggingInInterceptor;
037: import org.apache.cxf.interceptor.LoggingOutInterceptor;
038: import org.apache.cxf.jaxws.EndpointImpl;
039: import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
040: import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
041: import org.apache.cxf.jaxws.service.Hello;
042: import org.apache.hello_world_soap_http.Greeter;
043: import org.junit.Test;
044: import org.springframework.context.support.ClassPathXmlApplicationContext;
045:
046: public class SpringBeansTest extends Assert {
047: @Test
048: public void testEndpoints() throws Exception {
049: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
050: new String[] { "/org/apache/cxf/jaxws/spring/endpoints.xml" });
051:
052: Object bean = ctx.getBean("simple");
053: assertNotNull(bean);
054:
055: EndpointImpl ep = (EndpointImpl) bean;
056: assertNotNull(ep.getImplementor());
057: assertNotNull(ep.getServer());
058:
059: bean = ctx.getBean("simpleWithAddress");
060: assertNotNull(bean);
061:
062: ep = (EndpointImpl) bean;
063: if (!(ep.getImplementor() instanceof org.apache.hello_world_soap_http.GreeterImpl)) {
064: fail("can't get the right implementor object");
065: }
066: assertEquals("http://localhost:8080/simpleWithAddress", ep
067: .getServer().getEndpoint().getEndpointInfo()
068: .getAddress());
069:
070: bean = ctx.getBean("inlineImplementor");
071: assertNotNull(bean);
072:
073: ep = (EndpointImpl) bean;
074: if (!(ep.getImplementor() instanceof org.apache.hello_world_soap_http.GreeterImpl)) {
075: fail("can't get the right implementor object");
076: }
077: org.apache.hello_world_soap_http.GreeterImpl impl = (org.apache.hello_world_soap_http.GreeterImpl) ep
078: .getImplementor();
079: assertEquals("The property was not injected rightly", impl
080: .getPrefix(), "hello");
081: assertNotNull(ep.getServer());
082:
083: bean = ctx.getBean("inlineInvoker");
084: assertNotNull(bean);
085: ep = (EndpointImpl) bean;
086: assertTrue(ep.getInvoker() instanceof NullInvoker);
087: assertTrue(ep.getService().getInvoker() instanceof NullInvoker);
088:
089: bean = ctx.getBean("simpleWithBindingUri");
090: assertNotNull(bean);
091: ep = (EndpointImpl) bean;
092: assertEquals("get the wrong bindingId", ep.getBindingUri(),
093: "http://cxf.apache.org/bindings/xformat");
094:
095: bean = ctx.getBean("simpleWithBinding");
096: assertNotNull(bean);
097: ep = (EndpointImpl) bean;
098: BindingConfiguration bc = ep.getBindingConfig();
099: assertTrue(bc instanceof SoapBindingConfiguration);
100: SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
101: assertTrue(sbc.getVersion() instanceof Soap12);
102: assertTrue(
103: "the soap configure should set isMtomEnabled to be true",
104: sbc.isMtomEnabled());
105:
106: bean = ctx.getBean("implementorClass");
107: assertNotNull(bean);
108: ep = (EndpointImpl) bean;
109: assertEquals(Hello.class, ep.getImplementorClass());
110: assertTrue(ep.getImplementor().getClass() == Object.class);
111:
112: bean = ctx.getBean("epWithProps");
113: assertNotNull(bean);
114:
115: ep = (EndpointImpl) bean;
116: assertEquals("bar", ep.getProperties().get("foo"));
117:
118: bean = ctx.getBean("classImpl");
119: assertNotNull(bean);
120:
121: ep = (EndpointImpl) bean;
122: assertTrue(ep.getImplementor() instanceof Hello);
123:
124: QName name = ep.getServer().getEndpoint().getService()
125: .getName();
126: assertEquals("http://service.jaxws.cxf.apache.org/service",
127: name.getNamespaceURI());
128: assertEquals("HelloServiceCustomized", name.getLocalPart());
129:
130: name = ep.getServer().getEndpoint().getEndpointInfo().getName();
131: assertEquals("http://service.jaxws.cxf.apache.org/endpoint",
132: name.getNamespaceURI());
133: assertEquals("HelloEndpointCustomized", name.getLocalPart());
134:
135: bean = ctx.getBean("wsdlLocation");
136: assertNotNull(bean);
137:
138: // test for existence of Endpoint without an id element
139: boolean found = false;
140: String[] names = ctx.getBeanNamesForType(EndpointImpl.class);
141: for (String n : names) {
142: if (n.startsWith(EndpointImpl.class.getName())) {
143: found = true;
144: }
145: }
146: assertTrue(
147: "Could not find server factory with autogenerated id",
148: found);
149:
150: testInterceptors(ctx);
151: }
152:
153: private void testInterceptors(ClassPathXmlApplicationContext ctx) {
154: EndpointImpl ep;
155: ep = (EndpointImpl) ctx.getBean("epWithInterceptors");
156: assertNotNull(ep);
157: List<Interceptor> inInterceptors = ep.getInInterceptors();
158: boolean saaj = false;
159: boolean logging = false;
160: for (Interceptor<?> i : inInterceptors) {
161: if (i instanceof SAAJInInterceptor) {
162: saaj = true;
163: } else if (i instanceof LoggingInInterceptor) {
164: logging = true;
165: }
166: }
167: assertTrue(saaj);
168: assertTrue(logging);
169:
170: saaj = false;
171: logging = false;
172: for (Interceptor<?> i : ep.getOutInterceptors()) {
173: if (i instanceof SAAJOutInterceptor) {
174: saaj = true;
175: } else if (i instanceof LoggingOutInterceptor) {
176: logging = true;
177: }
178: }
179: assertTrue(saaj);
180: }
181:
182: @Test
183: public void testServers() throws Exception {
184: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
185: new String[] { "/org/apache/cxf/jaxws/spring/servers.xml" });
186:
187: JaxWsServerFactoryBean bean = (JaxWsServerFactoryBean) ctx
188: .getBean("simple");
189: assertNotNull(bean);
190:
191: bean = (JaxWsServerFactoryBean) ctx
192: .getBean("inlineSoapBinding");
193: assertNotNull(bean);
194:
195: BindingConfiguration bc = bean.getBindingConfig();
196: assertTrue(bc instanceof SoapBindingConfiguration);
197: SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
198: assertTrue(sbc.getVersion() instanceof Soap12);
199:
200: bean = (JaxWsServerFactoryBean) ctx
201: .getBean("inlineDataBinding");
202:
203: boolean found = false;
204: String[] names = ctx
205: .getBeanNamesForType(JaxWsServerFactoryBean.class);
206: for (String n : names) {
207: if (n.startsWith(JaxWsServerFactoryBean.class.getName())) {
208: found = true;
209: }
210: }
211: assertTrue(
212: "Could not find server factory with autogenerated id",
213: found);
214: }
215:
216: @Test
217: public void testClients() throws Exception {
218: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
219: new String[] { "/org/apache/cxf/jaxws/spring/clients.xml" });
220:
221: Object bean = ctx.getBean("client1.proxyFactory");
222: assertNotNull(bean);
223:
224: Greeter greeter = (Greeter) ctx.getBean("client1");
225: assertNotNull(greeter);
226:
227: Client client = ClientProxy.getClient(greeter);
228: assertNotNull("expected ConduitSelector", client
229: .getConduitSelector());
230: assertTrue("unexpected ConduitSelector", client
231: .getConduitSelector() instanceof NullConduitSelector);
232:
233: List<Interceptor> inInterceptors = client.getInInterceptors();
234: boolean saaj = false;
235: boolean logging = false;
236: for (Interceptor<?> i : inInterceptors) {
237: if (i instanceof SAAJInInterceptor) {
238: saaj = true;
239: } else if (i instanceof LoggingInInterceptor) {
240: logging = true;
241: }
242: }
243: assertTrue(saaj);
244: assertTrue(logging);
245:
246: saaj = false;
247: logging = false;
248: for (Interceptor<?> i : client.getOutInterceptors()) {
249: if (i instanceof SAAJOutInterceptor) {
250: saaj = true;
251: } else if (i instanceof LoggingOutInterceptor) {
252: logging = true;
253: }
254: }
255: assertTrue(saaj);
256: assertTrue(logging);
257:
258: assertTrue(client.getEndpoint().getService().getDataBinding() instanceof SourceDataBinding);
259:
260: JaxWsProxyFactoryBean factory = (JaxWsProxyFactoryBean) ctx
261: .getBean("wsdlLocation.proxyFactory");
262: assertNotNull(factory);
263: String wsdlLocation = factory.getWsdlLocation();
264: assertEquals("We should get the right wsdl location",
265: wsdlLocation, "wsdl/hello_world.wsdl");
266:
267: }
268: }
|