You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2009/05/30 04:45:23 UTC
svn commit: r780166 - in
/servicemix/smx4/features/trunk/cxf/cxf-transport-osgi: ./
src/main/java/org/apache/servicemix/cxf/transport/http_osgi/ src/test/
src/test/java/ src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/servicemix/ ...
Author: ffang
Date: Sat May 30 02:45:23 2009
New Revision: 780166
URL: http://svn.apache.org/viewvc?rev=780166&view=rev
Log:
[SMX4-281]Improve test coverage :: SMX4 :: cxf-transport-osgi
Added:
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationTest.java (with props)
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServletTest.java (with props)
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactoryTest.java (with props)
Modified:
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/pom.xml
servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java
Modified: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/pom.xml?rev=780166&r1=780165&r2=780166&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/pom.xml (original)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/pom.xml Sat May 30 02:45:23 2009
@@ -69,6 +69,18 @@
<artifactId>org.apache.servicemix.specs.jaxb-api-2.0</artifactId>
<version>${servicemix.specs.version}</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java?rev=780166&r1=780165&r2=780166&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java (original)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java Sat May 30 02:45:23 2009
@@ -180,9 +180,9 @@
}
}
}
+ } else {
+ invokeDestination(request, res, d);
}
-
- invokeDestination(request, res, d);
}
} catch (IOException e) {
throw new ServletException(e);
@@ -244,7 +244,7 @@
}
try {
- MessageImpl inMessage = new MessageImpl();
+ MessageImpl inMessage = createInMessage();
inMessage.setContent(InputStream.class, request.getInputStream());
inMessage.put(AbstractHTTPDestination.HTTP_REQUEST, request);
inMessage.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
@@ -284,7 +284,7 @@
inMessage.put(Message.ENCODING, normalizedEncoding);
SSLUtils.propogateSecureSession(request, inMessage);
- ExchangeImpl exchange = new ExchangeImpl();
+ ExchangeImpl exchange = createExchange();
exchange.setInMessage(inMessage);
exchange.setSession(new HTTPSession(request));
@@ -294,4 +294,12 @@
}
}
+
+ protected MessageImpl createInMessage() {
+ return new MessageImpl();
+ }
+
+ protected ExchangeImpl createExchange() {
+ return new ExchangeImpl();
+ }
}
Added: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationTest.java?rev=780166&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationTest.java (added)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationTest.java Sat May 30 02:45:23 2009
@@ -0,0 +1,127 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.servicemix.cxf.transport.http_osgi;
+
+import java.util.StringTokenizer;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transport.ConduitInitiator;
+
+import static org.easymock.classextension.EasyMock.*;
+import org.easymock.classextension.IMocksControl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class OsgiDestinationTest extends Assert {
+
+ private static final String ADDRESS = "http://bar/snafu";
+ private IMocksControl control;
+ private Bus bus;
+ private ConduitInitiator ci;
+ private OsgiDestinationRegistryIntf registry;
+ private MessageObserver observer;
+ private EndpointInfo endpoint;
+
+ @Before
+ public void setUp() {
+ control = createNiceControl();
+ bus = control.createMock(Bus.class);
+ ci = control.createMock(ConduitInitiator.class);
+ registry = control.createMock(OsgiDestinationRegistryIntf.class);
+ observer = control.createMock(MessageObserver.class);
+ endpoint = new EndpointInfo();
+ endpoint.setAddress(ADDRESS);
+ }
+
+ @After
+ public void tearDown() {
+ bus = null;
+ ci = null;
+ registry = null;
+ observer = null;
+ }
+
+ @Test
+ public void testCtor() throws Exception {
+ OsgiDestination destination =
+ new OsgiDestination(bus, ci, endpoint, registry, "snafu");
+
+ assertNull(destination.getMessageObserver());
+ assertNotNull(destination.getAddress());
+ assertNotNull(destination.getAddress().getAddress());
+ assertEquals(ADDRESS,
+ destination.getAddress().getAddress().getValue());
+ }
+
+ @Test
+ public void testMessage() throws Exception {
+ MessageImpl message = setUpMessage();
+
+ control.replay();
+
+ OsgiDestination destination =
+ new OsgiDestination(bus, ci, endpoint, registry, "snafu");
+ destination.setMessageObserver(observer);
+
+ destination.doMessage(message);
+
+ control.verify();
+ }
+
+ @Test
+ public void testShutdown() throws Exception {
+ registry.removeDestination("snafu");
+ expectLastCall();
+ control.replay();
+
+ OsgiDestination destination =
+ new OsgiDestination(bus, ci, endpoint, registry, "snafu");
+
+ destination.shutdown();
+
+ control.verify();
+ }
+
+ private MessageImpl setUpMessage() {
+ MessageImpl message = control.createMock(MessageImpl.class);
+ HttpServletRequest request =
+ control.createMock(HttpServletRequest.class);
+ message.get("HTTP.REQUEST");
+ expectLastCall().andReturn(request);
+ request.getHeaderNames();
+ expectLastCall().andReturn(new StringTokenizer("content-type content-length"));
+ request.getHeaders("content-type");
+ expectLastCall().andReturn(new StringTokenizer("text/xml"));
+ request.getHeaders("content-length");
+ expectLastCall().andReturn(new StringTokenizer("1234"));
+ observer.onMessage(message);
+ expectLastCall();
+ return message;
+ }
+}
Propchange: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServletTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServletTest.java?rev=780166&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServletTest.java (added)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServletTest.java Sat May 30 02:45:23 2009
@@ -0,0 +1,344 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.servicemix.cxf.transport.http_osgi;
+
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.TreeSet;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.security.SecurityContext;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.HTTPSession;
+import org.apache.cxf.transports.http.QueryHandlerRegistry;
+import org.apache.cxf.transports.http.QueryHandler;
+import org.apache.cxf.wsdl.EndpointReferenceUtils;
+import org.apache.cxf.wsdl.http.AddressType;
+
+import static org.easymock.classextension.EasyMock.*;
+import org.easymock.classextension.IMocksControl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class OsgiServletTest extends Assert {
+
+ private static final String ADDRESS = "http://bar/snafu";
+ private static final String ROOT = "http://localhost:8080/";
+ private static final QName QNAME = new QName(ADDRESS, "foobar");
+ private static final String PATH ="/SoapContext/SoapPort";
+ private static final String URI = "/cxf" + PATH;
+ private static final String SERVICES = "/cxf/services";
+ private static final String QUERY = "wsdl";
+ private static final String VERB = "POST";
+ private static final String TEXT = "text/html";
+ private static final String XML = "text/xml";
+ private static final String ENCODING = "UTF-8";
+ private static final String NO_SERVICE =
+ "<html><body>No service was found.</body></html>";
+ private static final String HEADER = "<html><body>";
+ private static final String SERVICE = "<p> <a href=\"" + ADDRESS + "?wsdl\">";
+ private static final String NAME = QNAME.toString() + "</a> </p>";
+ private static final String FOOTER = "</body></html>";
+ private IMocksControl control;
+ private Bus bus;
+ private OsgiDestinationRegistryIntf registry;
+ private OsgiDestination destination;
+ private ServletConfig config;
+ private ServletContext context;
+ private HttpServletRequest request;
+ private HttpServletResponse response;
+ private MessageImpl message;
+ private MessageObserver observer;
+ private AddressType extensor;
+ private ExchangeImpl exchange;
+ private EndpointInfo endpoint;
+ private TreeSet<String> paths;
+
+ @Before
+ public void setUp() {
+ control = createNiceControl();
+ bus = control.createMock(Bus.class);
+ registry = control.createMock(OsgiDestinationRegistryIntf.class);
+ destination = control.createMock(OsgiDestination.class);
+ context = control.createMock(ServletContext.class);
+ config = control.createMock(ServletConfig.class);
+ request = control.createMock(HttpServletRequest.class);
+ response = control.createMock(HttpServletResponse.class);
+ message = control.createMock(MessageImpl.class);
+ exchange = control.createMock(ExchangeImpl.class);
+ observer = control.createMock(MessageObserver.class);
+ extensor = control.createMock(AddressType.class);
+ endpoint = new EndpointInfo();
+ endpoint.setAddress(ADDRESS);
+ endpoint.setName(QNAME);
+ paths = new TreeSet<String>();
+ }
+
+ @After
+ public void tearDown() {
+ bus = null;
+ registry = null;
+ destination = null;
+ context = null;
+ config = null;
+ request = null;
+ response = null;
+ message = null;
+ exchange = null;
+ destination = null;
+ exchange = null;
+ observer = null;
+ extensor = null;
+ }
+
+ @Test
+ public void testInvokeNoDestination() throws Exception {
+ setUpRequest(URI, null, -1);
+ setUpResponse(404, TEXT, NO_SERVICE);
+
+ control.replay();
+
+ OsgiServlet servlet = setUpServlet();
+
+ servlet.invoke(request, response);
+
+ control.verify();
+ }
+
+ @Test
+ public void testInvokeGetServices() throws Exception {
+ setUpRequest(SERVICES, null, 1);
+ setUpResponse(0, TEXT, HEADER, SERVICE, NAME, FOOTER);
+
+ control.replay();
+
+ OsgiServlet servlet = setUpServlet();
+
+ servlet.invoke(request, response);
+
+ control.verify();
+ }
+
+ @Test
+ public void testInvokeGetServicesNoService() throws Exception {
+ setUpRequest(SERVICES, null, 0);
+ setUpResponse(0, TEXT, HEADER, FOOTER);
+
+ control.replay();
+
+ OsgiServlet servlet = setUpServlet();
+
+ servlet.invoke(request, response);
+
+ control.verify();
+ }
+
+ @Test
+ public void testInvokeWsdlQuery() throws Exception {
+ setUpRequest(URI, PATH, -2);
+ setUpQuery();
+
+ control.replay();
+
+ OsgiServlet servlet = setUpServlet();
+
+ servlet.invoke(request, response);
+
+ control.verify();
+ }
+
+ @Test
+ public void testInvokeDestination() throws Exception {
+ setUpRequest(URI, PATH, -2);
+ setUpMessage();
+
+ control.replay();
+
+ OsgiServlet servlet = setUpServlet();
+
+ servlet.invoke(request, response);
+
+ control.verify();
+ }
+
+ @Test
+ public void testInvokeRestful() throws Exception {
+ setUpRequest(URI, null, -1);
+ setUpRestful();
+ setUpMessage();
+
+ control.replay();
+
+ OsgiServlet servlet = setUpServlet();
+
+ servlet.invoke(request, response);
+
+ control.verify();
+ }
+
+ private void setUpRequest(String requestURI,
+ String path,
+ int destinationCount) throws Exception {
+ expect(request.getRequestURI()).andReturn(requestURI).anyTimes();
+ StringBuffer url = new StringBuffer(ROOT + requestURI);
+ expect(request.getRequestURL()).andReturn(url).anyTimes();
+ expect(request.getQueryString()).andReturn(QUERY).anyTimes();
+ expect(destination.getEndpointInfo()).andReturn(endpoint).anyTimes();
+ expect(destination.getBus()).andReturn(bus).anyTimes();
+
+ expect(request.getPathInfo()).andReturn(path != null
+ ? path
+ : ADDRESS).anyTimes();
+ if (path != null) {
+ expect(registry.getDestinationForPath(path)).andReturn(destination);
+ }
+
+ if (destinationCount == -1) {
+ expect(registry.getDestinationsPaths()).andReturn(paths).anyTimes();
+ } else if (destinationCount >= 0) {
+ expect(registry.getDestinationsPaths()).andReturn(paths);
+ ArrayList<OsgiDestination> destinations =
+ new ArrayList<OsgiDestination>();
+ for (int i = 0; i < destinationCount; i++) {
+ destinations.add(destination);
+ }
+ expect(registry.getDestinations()).andReturn(destinations);
+ }
+ }
+
+ private void setUpMessage() throws Exception {
+ ServletInputStream sis = control.createMock(ServletInputStream.class);
+ expect(request.getInputStream()).andReturn(sis);
+ message.setContent(eq(InputStream.class), same(sis));
+ expectLastCall();
+ setUpProperty(AbstractHTTPDestination.HTTP_REQUEST, request);
+ setUpProperty(AbstractHTTPDestination.HTTP_RESPONSE, response);
+ setUpProperty(AbstractHTTPDestination.HTTP_CONTEXT, context);
+ setUpProperty(AbstractHTTPDestination.HTTP_CONFIG, config);
+ expect(request.getMethod()).andReturn(VERB);
+ setUpProperty(Message.HTTP_REQUEST_METHOD, VERB);
+ setUpProperty(Message.REQUEST_URI, URI);
+ setUpProperty(Message.QUERY_STRING, QUERY);
+ expect(request.getContentType()).andReturn(XML);
+ setUpProperty(Message.CONTENT_TYPE, XML);
+ expect(request.getHeader("Accept")).andReturn(XML);
+ setUpProperty(Message.ACCEPT_CONTENT_TYPE, XML);
+ destination.getAddress();
+ expectLastCall().andReturn(EndpointReferenceUtils.getEndpointReference(PATH));
+ setUpProperty(Message.BASE_PATH, PATH);
+ message.put(eq(SecurityContext.class), isA(SecurityContext.class));
+ expect(request.getCharacterEncoding()).andReturn(ENCODING);
+ setUpProperty(Message.ENCODING, ENCODING);
+ exchange.setSession(isA(HTTPSession.class));
+ expectLastCall();
+ }
+
+ private void setUpProperty(String name, Object value) {
+ message.put(eq(name), same(value));
+ expectLastCall().andReturn(null).anyTimes();
+ }
+
+ private void setUpResponse(int status,
+ String responseType,
+ String ... responseMsgs) throws Exception {
+ if (status != 0) {
+ response.setStatus(status);
+ expectLastCall();
+ }
+ if (responseType != null) {
+ response.setContentType(responseType);
+ expectLastCall();
+ }
+ if (responseMsgs != null) {
+ PrintWriter writer = control.createMock(PrintWriter.class);
+ expect(response.getWriter()).andReturn(writer).anyTimes();
+ for (String msg : responseMsgs) {
+ writer.write(msg);
+ expectLastCall();
+ }
+ }
+ }
+
+ private void setUpQuery() throws Exception {
+ QueryHandlerRegistry qrh =
+ control.createMock(QueryHandlerRegistry.class);
+ expect(bus.getExtension(QueryHandlerRegistry.class)).andReturn(qrh).anyTimes();
+ QueryHandler qh = control.createMock(QueryHandler.class);
+ ArrayList<QueryHandler> handlers = new ArrayList<QueryHandler>();
+ handlers.add(qh);
+ expect(qrh.getHandlers()).andReturn(handlers);
+ String base = ROOT + URI + "?" + QUERY;
+ expect(qh.isRecognizedQuery(eq(base),
+ eq(PATH),
+ same(endpoint))).andReturn(Boolean.TRUE);
+ expect(qh.getResponseContentType(eq(base), eq(PATH))).andReturn(XML);
+ ServletOutputStream sos = control.createMock(ServletOutputStream.class);
+ expect(response.getOutputStream()).andReturn(sos);
+ qh.writeResponse(eq(base), eq(PATH), same(endpoint), (same(sos)));
+ expectLastCall();
+ sos.flush();
+ expectLastCall();
+ }
+
+ private void setUpRestful() {
+ paths.add(ADDRESS);
+ expect(registry.getDestinationForPath(ADDRESS)).andReturn(null);
+ expect(registry.getDestinationForPath(ADDRESS)).andReturn(destination).times(2);
+ expect(destination.getMessageObserver()).andReturn(observer);
+ endpoint.addExtensor(extensor);
+ extensor.setLocation(eq(ROOT + "/cxf/Soap" + ADDRESS));
+ expectLastCall();
+ }
+
+ private OsgiServlet setUpServlet() {
+ return new OsgiServlet(registry) {
+ public ServletContext getServletContext() {
+ return context;
+ }
+ public ServletConfig getServletConfig() {
+ return config;
+ }
+ protected MessageImpl createInMessage() {
+ return message;
+ }
+ protected ExchangeImpl createExchange() {
+ return exchange;
+ }
+ };
+ }
+}
Propchange: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServletTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServletTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactoryTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactoryTest.java?rev=780166&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactoryTest.java (added)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactoryTest.java Sat May 30 02:45:23 2009
@@ -0,0 +1,131 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.servicemix.cxf.transport.http_osgi;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.transport.DestinationFactoryManager;
+
+import static org.easymock.classextension.EasyMock.*;
+import org.easymock.classextension.IMocksControl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class OsgiTransportFactoryTest extends Assert {
+
+ private static final List<String> TRANSPORT_IDS = (List<String>)
+ Arrays.asList("http://cxf.apache.org/bindings/xformat",
+ "http://schemas.xmlsoap.org/soap/http",
+ "http://schemas.xmlsoap.org/wsdl/http/",
+ "http://schemas.xmlsoap.org/wsdl/soap/http",
+ "http://www.w3.org/2003/05/soap/bindings/HTTP/",
+ "http://cxf.apache.org/transports/http/configuration");
+
+ private IMocksControl control;
+ private OsgiTransportFactory factory;
+ private Bus bus;
+ private DestinationFactoryManager dfm;
+ private OsgiDestinationRegistryIntf registry;
+
+ @Before
+ public void setUp() {
+ control = createNiceControl();
+ factory = new OsgiTransportFactory();
+ registry = control.createMock(OsgiDestinationRegistryIntf.class);
+ bus = control.createMock(Bus.class);
+ dfm = control.createMock(DestinationFactoryManager.class);
+ }
+
+ @After
+ public void tearDown() {
+ factory = null;
+ registry = null;
+ bus = null;
+ dfm = null;
+ }
+
+ @Test
+ public void testInit() throws Exception {
+ try {
+ factory.init();
+ fail("expected IllegalStateException on null bus");
+ } catch (IllegalStateException ise) {
+ // expected
+ }
+ factory.setBus(bus);
+
+ try {
+ factory.init();
+ fail("expected IllegalStateException on null registry");
+ } catch (IllegalStateException ise) {
+ // expected
+ }
+ factory.setRegistry(registry);
+
+ bus.getExtension(DestinationFactoryManager.class);
+ expectLastCall().andReturn(dfm);
+ factory.setTransportIds(TRANSPORT_IDS);
+ for (String ns : TRANSPORT_IDS) {
+ dfm.registerDestinationFactory(ns, factory);
+ expectLastCall();
+ }
+ control.replay();
+
+ factory.init();
+
+ control.verify();
+ }
+
+ @Test
+ public void testGetDestination() throws Exception {
+ factory.setBus(bus);
+ factory.setRegistry(registry);
+
+ EndpointInfo endpoint = new EndpointInfo();
+ endpoint.setAddress("http://bar/snafu");
+ try {
+ factory.getDestination(endpoint);
+ fail("expected IllegalStateException on absolute URI");
+ } catch (IllegalStateException ise) {
+ // expected
+ }
+
+ endpoint.setAddress("snafu");
+ registry.addDestination(eq("/snafu"), isA(OsgiDestination.class));
+
+ control.replay();
+
+ Destination d = factory.getDestination(endpoint);
+ assertNotNull(d);
+ assertNotNull(d.getAddress());
+ assertNotNull(d.getAddress().getAddress());
+ assertEquals("snafu", d.getAddress().getAddress().getValue());
+
+ control.verify();
+ }
+}
Propchange: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactoryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/features/trunk/cxf/cxf-transport-osgi/src/test/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactoryTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date