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.frontend.spring;
019:
020: import java.util.List;
021:
022: import junit.framework.Assert;
023:
024: import org.apache.cxf.binding.BindingConfiguration;
025: import org.apache.cxf.binding.soap.Soap12;
026: import org.apache.cxf.binding.soap.SoapBindingConfiguration;
027: import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
028: import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
029: import org.apache.cxf.endpoint.Client;
030: import org.apache.cxf.endpoint.NullConduitSelector;
031: import org.apache.cxf.frontend.ClientProxy;
032: import org.apache.cxf.frontend.ClientProxyFactoryBean;
033: import org.apache.cxf.frontend.ServerFactoryBean;
034: import org.apache.cxf.interceptor.Interceptor;
035: import org.apache.cxf.interceptor.LoggingInInterceptor;
036: import org.apache.cxf.interceptor.LoggingOutInterceptor;
037: import org.apache.cxf.service.factory.HelloService;
038: import org.apache.cxf.service.factory.HelloServiceImpl;
039: import org.junit.Test;
040: import org.springframework.context.support.ClassPathXmlApplicationContext;
041:
042: public class SpringBeansTest extends Assert {
043:
044: @Test
045: public void testServers() throws Exception {
046: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
047: new String[] { "/org/apache/cxf/frontend/spring/servers.xml" });
048:
049: ServerFactoryBean bean = (ServerFactoryBean) ctx
050: .getBean("simple");
051: assertNotNull(bean);
052:
053: if (!(bean.getServiceBean() instanceof HelloServiceImpl)) {
054: fail("can't get the right serviceBean");
055: }
056: bean = (ServerFactoryBean) ctx.getBean("inlineImplementor");
057: if (!(bean.getServiceBean() instanceof HelloServiceImpl)) {
058: fail("can't get the right serviceBean");
059: }
060:
061: bean = (ServerFactoryBean) ctx.getBean("inlineSoapBinding");
062: assertNotNull(bean);
063:
064: BindingConfiguration bc = bean.getBindingConfig();
065: assertTrue(bc instanceof SoapBindingConfiguration);
066: SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
067: assertTrue(sbc.getVersion() instanceof Soap12);
068:
069: bean = (ServerFactoryBean) ctx.getBean("simpleWithBindingId");
070: assertEquals("get the wrong BindingId", bean.getBindingId(),
071: "http://cxf.apache.org/bindings/xformat");
072:
073: }
074:
075: @Test
076: public void testClients() throws Exception {
077: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
078: new String[] { "/org/apache/cxf/frontend/spring/clients.xml" });
079:
080: Object bean = ctx.getBean("client1.proxyFactory");
081: assertNotNull(bean);
082:
083: ClientProxyFactoryBean cpfbean = (ClientProxyFactoryBean) bean;
084: BindingConfiguration bc = cpfbean.getBindingConfig();
085: assertTrue(bc instanceof SoapBindingConfiguration);
086: SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
087: assertTrue(sbc.getVersion() instanceof Soap12);
088:
089: HelloService greeter = (HelloService) ctx.getBean("client1");
090: assertNotNull(greeter);
091:
092: Client client = ClientProxy.getClient(greeter);
093: assertNotNull("expected ConduitSelector", client
094: .getConduitSelector());
095: assertTrue("unexpected ConduitSelector", client
096: .getConduitSelector() instanceof NullConduitSelector);
097:
098: List<Interceptor> inInterceptors = client.getInInterceptors();
099: boolean saaj = false;
100: boolean logging = false;
101: for (Interceptor<?> i : inInterceptors) {
102: if (i instanceof SAAJInInterceptor) {
103: saaj = true;
104: } else if (i instanceof LoggingInInterceptor) {
105: logging = true;
106: }
107: }
108: assertTrue(saaj);
109: assertTrue(logging);
110:
111: saaj = false;
112: logging = false;
113: for (Interceptor<?> i : client.getOutInterceptors()) {
114: if (i instanceof SAAJOutInterceptor) {
115: saaj = true;
116: } else if (i instanceof LoggingOutInterceptor) {
117: logging = true;
118: }
119: }
120: assertTrue(saaj);
121: assertTrue(logging);
122:
123: ClientProxyFactoryBean clientProxyFactoryBean = (ClientProxyFactoryBean) ctx
124: .getBean("client2.proxyFactory");
125: assertNotNull(clientProxyFactoryBean);
126:
127: assertEquals("get the wrong bindingId", clientProxyFactoryBean
128: .getBindingId(),
129: "http://cxf.apache.org/bindings/xformat");
130: }
131: }
|