You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by en...@apache.org on 2009/06/03 16:26:31 UTC

svn commit: r781404 - in /servicemix/components/bindings/servicemix-http/trunk/src: main/java/org/apache/servicemix/http/ test/java/org/apache/servicemix/http/ test/java/org/apache/servicemix/http/endpoints/ test/java/org/apache/servicemix/http/jetty/ ...

Author: enolan
Date: Wed Jun  3 14:26:30 2009
New Revision: 781404

URL: http://svn.apache.org/viewvc?rev=781404&view=rev
Log:
SMXCOMP-544 - createContext method in ManagedContextManager is not normalizing paths properly
SMXCOMP-528 - new tests for HTTP component

Added:
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpBridgeServletTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpConfigurationTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpEndpointTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ManagedContextManagerTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ProxyParametersTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/SslParametersTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshalerTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerEndpointTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpointTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/jetty/
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/jetty/SmxHttpExchangeTest.java   (with props)
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/packaging/
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/packaging/HttpServiceUnitAnalyzerTest.java   (with props)
Modified:
    servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/ManagedContextManager.java
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ConsumerEndpointTest.java
    servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ServerManagerTest.java

Modified: servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/ManagedContextManager.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/ManagedContextManager.java?rev=781404&r1=781403&r2=781404&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/ManagedContextManager.java (original)
+++ servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/ManagedContextManager.java Wed Jun  3 14:26:30 2009
@@ -35,13 +35,13 @@
 public class ManagedContextManager implements ContextManager {
 
     private HttpConfiguration configuration;
-    private Map managedContexts;
+    private Map<String, HttpProcessor> managedContexts;
 
     public void init() throws Exception {
         if (configuration == null) {
             configuration = new HttpConfiguration();
         }
-        managedContexts = new ConcurrentHashMap();
+        managedContexts = new ConcurrentHashMap<String, HttpProcessor>();
     }
 
     public void shutDown() throws Exception {
@@ -58,7 +58,7 @@
         URI uri = new URI(strUrl);
         String path = uri.getPath();
         if (!path.startsWith("/")) {
-            path = path + "/";
+            path = "/" + path;
         }
         if (!path.endsWith("/")) {
             path = path + "/";
@@ -107,8 +107,8 @@
                 displayServices(request, response);
                 return;
             }
-            Set urls = managedContexts.keySet();
-            for (Iterator iter = urls.iterator(); iter.hasNext();) {
+            Set<String> urls = managedContexts.keySet();
+            for (Iterator<String> iter = urls.iterator(); iter.hasNext();) {
                 String url = (String) iter.next();
                 if (uri.startsWith(request.getContextPath() + mapping + url)) {
                     HttpProcessor proc = (HttpProcessor) managedContexts.get(url);
@@ -134,8 +134,8 @@
             writer.write("No service matched or handled this request.<BR>");
             writer.write("Known services are: <ul>");
 
-            Set servers = ManagedContextManager.this.managedContexts.keySet();
-            for (Iterator iter = servers.iterator(); iter.hasNext();) {
+            Set<String> servers = ManagedContextManager.this.managedContexts.keySet();
+            for (Iterator<String> iter = servers.iterator(); iter.hasNext();) {
                 String context = (String) iter.next();
                 if (!context.endsWith("/")) {
                     context += "/";

Modified: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ConsumerEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ConsumerEndpointTest.java?rev=781404&r1=781403&r2=781404&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ConsumerEndpointTest.java (original)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ConsumerEndpointTest.java Wed Jun  3 14:26:30 2009
@@ -149,6 +149,9 @@
         }
 
         recv.getMessageList().assertMessagesReceived(1);
+        post.releaseConnection();
+        container.deactivateComponent("recv");
+        container.deactivateComponent("http");
     }
 
     public void testHttpInOutWithTimeout() throws Exception {
@@ -191,6 +194,10 @@
             throw new InvalidStatusResponseException(post.getStatusCode());
         }
         Thread.sleep(1000);
+        
+        post.releaseConnection();
+        container.deactivateComponent("echo");
+        container.deactivateComponent("http");
     }
 
     public void testHttpInOut() throws Exception {
@@ -221,6 +228,10 @@
         if (post.getStatusCode() != 200) {
             throw new InvalidStatusResponseException(post.getStatusCode());
         }
+        
+        post.releaseConnection();
+        container.deactivateComponent("echo");
+        container.deactivateComponent("http");
     }
 
     protected void initSoapEndpoints(boolean useJbiWrapper) throws Exception {
@@ -264,6 +275,9 @@
         assertEquals(SoapConstants.SOAP_11_FAULTCODE, DomUtil.getQName(elem));
         assertEquals(SoapConstants.SOAP_11_CODE_VERSIONMISMATCH, DomUtil.createQName(elem, elem.getTextContent()));
         assertEquals(500, post.getStatusCode());
+        
+        post.releaseConnection();
+        container.deactivateComponent("http");
     }
 
     public void testHttpSoap12FaultOnEnvelope() throws Exception {
@@ -289,6 +303,9 @@
         assertEquals(SoapConstants.SOAP_12_FAULTSUBCODE, DomUtil.getQName(elem));
         assertEquals(SoapConstants.SOAP_12_CODE_VERSIONMISMATCH, DomUtil.createQName(elem, elem.getTextContent()));
         assertEquals(500, post.getStatusCode());
+        
+        post.releaseConnection();
+        container.deactivateComponent("http");
     }
 
     public void testHttpSoap11UnkownOp() throws Exception {
@@ -311,6 +328,9 @@
         assertEquals(SoapConstants.SOAP_11_FAULTCODE, DomUtil.getQName(elem));
         assertEquals(SoapConstants.SOAP_11_CODE_CLIENT, DomUtil.createQName(elem, elem.getTextContent()));
         assertEquals(500, post.getStatusCode());
+        
+        post.releaseConnection();
+        container.deactivateComponent("http");
     }
 
     /*
@@ -368,6 +388,10 @@
         elem = DomUtil.getFirstChildElement(elem);
         assertEquals(new QName("uri:HelloWorld", "HelloResponse"), DomUtil.getQName(elem));
         assertEquals(200, post.getStatusCode());
+        
+        post.releaseConnection();
+        container.deactivateComponent("echo");
+        container.deactivateComponent("http");
     }
 
     public void testHttpSoap12() throws Exception {
@@ -411,6 +435,10 @@
         elem = DomUtil.getFirstChildElement(elem);
         assertEquals(new QName("uri:HelloWorld", "HelloResponse"), DomUtil.getQName(elem));
         assertEquals(200, post.getStatusCode());
+        
+        post.releaseConnection();
+        container.deactivateComponent("mock");
+        container.deactivateComponent("http");
     }
 
     public void testHttpSoap12WithoutJbiWrapper() throws Exception {
@@ -452,6 +480,10 @@
         elem = DomUtil.getFirstChildElement(elem);
         assertEquals(new QName("uri:HelloWorld", "HelloResponse"), DomUtil.getQName(elem));
         assertEquals(200, post.getStatusCode());
+        
+        post.releaseConnection();
+        container.deactivateComponent("mock");
+        container.deactivateComponent("http");
     }
 
     public void testGzipEncodingNonSoap() throws Exception {
@@ -495,6 +527,10 @@
         if (post.getStatusCode() != 200) {
             throw new InvalidStatusResponseException(post.getStatusCode());
         }
+        
+        post.releaseConnection();
+        container.deactivateComponent("echo");
+        container.deactivateComponent("http");
     }
 
     public void testGzipEncodingSoap() throws Exception {
@@ -552,6 +588,10 @@
         elem = DomUtil.getFirstChildElement(elem);
         assertEquals(new QName("uri:HelloWorld", "HelloResponse"), DomUtil.getQName(elem));
         assertEquals(200, post.getStatusCode());
+        
+        post.releaseConnection();
+        container.deactivateComponent("mock");
+        container.deactivateComponent("http");
     }
 
     /*
@@ -595,7 +635,7 @@
         echo.setService(new QName("urn:test", "echo"));
         echo.setEndpoint("endpoint");
         container.activateComponent(echo, "echo");
-
+        
         ((ExecutorFactoryImpl) container.getExecutorFactory()).getDefaultConfig().setMaximumPoolSize(16);
 
         container.start();
@@ -609,8 +649,9 @@
                     final HttpClient client = new HttpClient();
                     client.getParams().setSoTimeout(soTimeout);
                     for (int i = 0; i < nbRequests; i++) {
+                    	PostMethod post = null;
                         try {
-                            PostMethod post = new PostMethod("http://localhost:8192/ep1/");
+                            post = new PostMethod("http://localhost:8192/ep1/");
                             post.setRequestEntity(new StringRequestEntity("<hello>world</hello>"));
                             client.executeMethod(post);
                             if (post.getStatusCode() != 200) {
@@ -623,6 +664,9 @@
                             throwables.add(t);
                         } finally {
                             latchSent.countDown();
+                            if (post != null) {
+                            	post.releaseConnection();
+                            }
                             //System.out.println("[" + System.currentTimeMillis() + "] Request " + latch.getCount() + " processed");
                         }
                     }
@@ -634,7 +678,10 @@
         listener.assertExchangeCompleted();
         for (Throwable t : throwables) {
             t.printStackTrace();
-        }
+        }        
+        
+        container.deactivateComponent("echo");
+        container.deactivateComponent("http");
     }
 
     public void testProxyWsl() throws Exception {
@@ -654,7 +701,7 @@
         ep1.setService(new QName("uri:HelloWorld", "HelloService"));
         ep1.setEndpoint("HelloPortSoap11");
         ep1.setTargetService(new QName("http://test", "MyConsumerService"));
-        ep1.setLocationURI("http://localhost:8192/ep1/");
+        ep1.setLocationURI("http://localhost:8193/ep1/");
         ep1.setValidateWsdl(true);
         http.setEndpoints(new HttpEndpointType[] {ep1});
         container.activateComponent(http, "http");
@@ -662,7 +709,7 @@
 
         WSDLFactory factory = WSDLFactory.newInstance();
         WSDLReader reader = factory.newWSDLReader();
-        Definition def = reader.readWSDL("http://localhost:8192/ep1/?wsdl");
+        Definition def = reader.readWSDL("http://localhost:8193/ep1/?wsdl");
         StringWriter writer = new StringWriter();
         factory.newWSDLWriter().writeWSDL(def, writer);
         log.info(writer.toString());
@@ -672,6 +719,9 @@
         ExtensibilityElement ee = (ExtensibilityElement) bop.getExtensibilityElements().iterator().next();
         assertTrue(ee instanceof SOAPOperation);
         assertEquals("", ((SOAPOperation) ee).getSoapActionURI());
+        
+        container.deactivateComponent("echo");
+        container.deactivateComponent("http");
     }
 
 }

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpBridgeServletTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpBridgeServletTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpBridgeServletTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpBridgeServletTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,212 @@
+package org.apache.servicemix.http;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.mortbay.jetty.Request;
+import org.mortbay.jetty.Response;
+
+import junit.framework.TestCase;
+
+public class HttpBridgeServletTest extends TestCase {
+
+	private HttpBridgeServlet httpBridgeServlet;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		httpBridgeServlet = new HttpBridgeServlet();
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		httpBridgeServlet = null;
+	}
+	
+	// Test init() when HttpProcessor is null.
+	public void testInitProcessorNull() throws Exception {
+		httpBridgeServlet.setProcessor(null);
+		TestServletConfig config = new TestServletConfig();
+		
+		try {
+			httpBridgeServlet.init(config);
+			fail("init() should fail when HttpProcessor is null");
+		} catch (ServletException se) {
+			String errorMsg = se.getMessage();
+			assertTrue("ServletException does not contain the expected error message", 
+					errorMsg.contains("No binding property available"));
+		}
+	}
+	
+	// Test service() method - check for exceptions, fail if any are thrown.
+	public void testService() throws Exception {
+		TestHttpProcessor processor = new TestHttpProcessor();
+		httpBridgeServlet.setProcessor(processor);
+		TestServletConfig config = new TestServletConfig();
+		
+		httpBridgeServlet.init(config);
+		
+		Request request = new Request();
+		Response response = null;
+		
+		try {
+			httpBridgeServlet.service(request, response);
+		} catch (Exception e) {
+			fail("service() should not throw an exception");
+		}
+		
+	}
+
+	// Dummy ServletConfig implementation for testing.  
+	public static class TestServletConfig implements ServletConfig {
+
+		public String getInitParameter(String name) {
+			return null;
+		}
+
+		public Enumeration<String> getInitParameterNames() {
+			return null;
+		}
+
+		public ServletContext getServletContext() {
+			return new TestServletContext();
+		}
+
+		public String getServletName() {
+			return null;
+		}
+		
+	}
+	
+	// Dummy ServletContext implementation for testing.
+	public static class TestServletContext implements ServletContext {
+
+		public Object getAttribute(String name) {
+			return null;
+		}
+
+		public Enumeration<Object> getAttributeNames() {
+			return null;
+		}
+
+		public ServletContext getContext(String uripath) {
+			return this;
+		}
+
+		public String getContextPath() {
+			return null;
+		}
+
+		public String getInitParameter(String name) {
+			return null;
+		}
+
+		public Enumeration<String> getInitParameterNames() {
+			return null;
+		}
+
+		public int getMajorVersion() {
+			return 0;
+		}
+
+		public String getMimeType(String file) {
+			return null;
+		}
+
+		public int getMinorVersion() {
+			return 0;
+		}
+
+		public RequestDispatcher getNamedDispatcher(String name) {
+			return null;
+		}
+
+		public String getRealPath(String path) {
+			return null;
+		}
+
+		public RequestDispatcher getRequestDispatcher(String path) {
+			return null;
+		}
+
+		public URL getResource(String path) throws MalformedURLException {
+			return null;
+		}
+
+		public InputStream getResourceAsStream(String path) {
+			return null;
+		}
+
+		public Set<String> getResourcePaths(String path) {
+			return null;
+		}
+
+		public String getServerInfo() {
+			return null;
+		}
+
+		public String getServletContextName() {
+			return null;
+		}
+
+		public void log(String message, Throwable throwable) {
+			
+		}
+
+		public void log(String msg) {
+			
+		}
+
+		public void removeAttribute(String name) {
+			
+		}
+
+		public void setAttribute(String name, Object object) {
+			
+		}
+
+		public Servlet getServlet(String name) throws ServletException {
+			return null;
+		}
+
+		public Enumeration<Servlet> getServletNames() {
+			return null;
+		}
+
+		public Enumeration<Servlet> getServlets() {
+			return null;
+		}
+
+		public void log(Exception exception, String msg) {
+			
+		}
+		
+	}
+	
+	// Dummy HttpProcessor implementation for testing.
+    public static class TestHttpProcessor implements HttpProcessor {
+    	
+        public SslParameters getSsl() {
+            return null;
+        }
+
+        public String getAuthMethod() {
+            return null;
+        }
+
+        public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+            
+        }
+
+    }
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpBridgeServletTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpConfigurationTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpConfigurationTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpConfigurationTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpConfigurationTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,77 @@
+package org.apache.servicemix.http;
+
+import java.io.File;
+
+import org.apache.servicemix.util.FileUtil;
+
+import junit.framework.TestCase;
+
+public class HttpConfigurationTest extends TestCase {
+
+	private HttpConfiguration httpConfig;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		httpConfig = new HttpConfiguration();
+	}
+	
+	protected void tearDown() throws Exception {
+		httpConfig = null;
+	}
+	
+	// Test load() when rootDir is not set.
+	public void testLoadNoRootDir() throws Exception {
+		boolean isLoaded = httpConfig.load();
+		assertTrue("HTTP Config should NOT be loaded with no root dir", !isLoaded);
+	}
+	
+	// Test load() when config file does not exist.
+	public void testLoadNoConfigFile() throws Exception {
+		httpConfig.setRootDir("src/test/resources");
+		assertTrue("HTTP Config should NOT be loaded with no config file", !httpConfig.load());
+	}
+	
+	// Test save() (to config file) and load() (from config file).
+	public void testSaveAndLoad() throws Exception {
+		File rootDir = new File("target/httpConfig-test");
+		if (!rootDir.exists())
+			rootDir.mkdirs();
+		
+		httpConfig.setRootDir(rootDir.getAbsolutePath());
+		
+		// Save the HTTP Config (mostly default values)
+		httpConfig.save();
+		
+		File configFile = new File(rootDir, HttpConfiguration.CONFIG_FILE);
+		assertTrue("HTTP Config file should exist", configFile.exists());
+		
+		boolean isLoaded = httpConfig.load();
+		
+		assertTrue("HTTP Config should be loaded", isLoaded);		
+		
+		// clean up
+		FileUtil.deleteFile(new File(httpConfig.getRootDir()));
+	}
+	
+	// Test setMapping when input string does not begin with "/"
+	public void testSetMappingBeginsNoSlash() throws Exception {
+		String strMap = "pathHasNoSlash";
+		httpConfig.setMapping(strMap);
+		
+		String actMap = httpConfig.getMapping();
+		
+		assertTrue("HTTP Config Mapping should begin with /", actMap.equals("/" + strMap));
+	}
+	
+	// Test setMapping when input string ends with "/"
+	public void testSetMappingEndsWithSlash() throws Exception {
+		String strMap1 = "/pathEndsWithSlash";
+		String strMap2 = "/";
+		httpConfig.setMapping(strMap1 + strMap2);
+		
+		String actMap = httpConfig.getMapping();
+		
+		assertTrue("HTTP Config Mapping should not end with /", actMap.equals(strMap1));
+	}
+	
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpConfigurationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpEndpointTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpEndpointTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpEndpointTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,75 @@
+package org.apache.servicemix.http;
+
+import javax.jbi.management.DeploymentException;
+
+import org.apache.servicemix.common.DefaultServiceUnit;
+
+import junit.framework.TestCase;
+
+public class HttpEndpointTest extends TestCase {
+
+	private HttpEndpoint httpEndpoint;
+	private MyServiceUnit httpSU;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		httpEndpoint = new HttpEndpoint();
+		httpSU = new MyServiceUnit();
+		httpEndpoint.setServiceUnit(httpSU);
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		httpEndpoint = null;
+	}
+	
+	// Test validate() when getRole() returns null.
+	public void testValidateRoleNull() throws Exception {
+		try {
+			httpEndpoint.validate();
+			fail("validate() should fail when Role is null");
+		} catch (DeploymentException de) {
+			String errorMsg = de.getMessage();
+			assertTrue("Exception should contain the correct error message string", 
+					errorMsg.contains("Endpoint must have a defined role"));
+		}
+	}
+	
+	// Test validate() when location URI is null.
+	public void testValidateLocationUriNull() throws Exception {
+		httpEndpoint.setRoleAsString("consumer");
+		
+		try {
+			httpEndpoint.validate();
+			fail("validate() should fail when Location URI is null");
+		} catch (DeploymentException de) {
+			String errorMsg = de.getMessage();
+			assertTrue("Exception should contain the correct error message string", 
+					errorMsg.contains("Endpoint must have a defined locationURI"));
+		}
+	}
+	
+	// Test validate() for non-SOAP endpoint when default MEP is not set.
+	public void testValidateNonSoapNoMep() throws Exception {
+		httpEndpoint.setRoleAsString("consumer");
+		httpEndpoint.setSoap(false);
+		httpEndpoint.setLocationURI("http://webhost:8080/someService");
+		httpEndpoint.setDefaultMep(null);
+		
+		try {
+			httpEndpoint.validate();
+			fail("validate() should fail for non-SOAP endpoint with no default MEP");
+		} catch (DeploymentException de) {
+			String errorMsg = de.getMessage();
+			assertTrue("Exception should contain the correct error message string", 
+					errorMsg.contains("Non soap endpoints must have a defined defaultMep"));
+		}
+	}
+
+	// Support class needed for HttpEndpoint tests.
+    public class MyServiceUnit extends DefaultServiceUnit {
+        public MyServiceUnit() {
+            super(new HttpComponent());
+        }
+    }
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ManagedContextManagerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ManagedContextManagerTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ManagedContextManagerTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ManagedContextManagerTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,102 @@
+package org.apache.servicemix.http;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.mortbay.jetty.HttpURI;
+import org.mortbay.jetty.Request;
+import org.mortbay.jetty.Response;
+
+import junit.framework.TestCase;
+
+public class ManagedContextManagerTest extends TestCase {
+
+	private static transient Log log = LogFactory.getLog(ManagedContextManagerTest.class);
+	private ManagedContextManager server;
+	private HttpConfiguration config;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		config = new HttpConfiguration();
+		server = new ManagedContextManager();
+		server.setConfiguration(config);
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		server.shutDown();
+		server = null;
+		config = null;
+	}
+	
+	// Test createContext with a path that does not begin with a / and
+	// does not end with a /.
+	public void testCreateContext() throws Exception {
+		server.init();
+		server.start();
+		
+		TestHttpProcessor httpProcessor = new TestHttpProcessor();
+		String strUrl = "path/to/some/resource";
+		
+		String returnedPath = (String)server.createContext(strUrl, httpProcessor);
+		
+		assertTrue("Context path should have / at end and at the beginning", 
+				returnedPath.equals("/" + strUrl + "/"));
+	}
+	
+	// Test getMainProcessor with an unmanaged config - should throw IllegalStateException
+	public void testGetMainProcessorUnmanagedConfig() throws Exception {
+		server.init();
+		server.start();
+		
+		try {
+			server.getMainProcessor();
+			fail("getMainProcessor() should fail for unmanaged config.");
+		} catch (IllegalStateException ise) {
+			// test succeeds
+			log.info("testGetMainProcessorUnmanagedConfig() threw the expected exception");
+		}
+	}
+/*	
+	public void testProcessorProcess() throws Exception {
+		server.init();
+		server.start();
+		
+		Request request = new Request();
+		request.setUri(new HttpURI("/"));
+		request.setMethod("GET");
+		request.setProtocol("http");
+		TestResponse response = new TestResponse();
+		
+		TestHttpProcessor httpProcessor = new TestHttpProcessor();
+		String strUrl = "/path/to/some/resource/";
+		
+		server.createContext(strUrl, httpProcessor);
+		
+		server.getConfiguration().setManaged(true);
+		
+		server.getMainProcessor().process(request, response);
+		
+		assertTrue("", response.getStatus() == HttpServletResponse.SC_NOT_FOUND);
+		
+	}
+*/	
+    public static class TestHttpProcessor implements HttpProcessor {
+        public SslParameters getSsl() {
+            return null;
+        }
+
+        public String getAuthMethod() {
+            return null;
+        }
+
+        public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+            log.info(request);
+        }
+
+    }
+    
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ManagedContextManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ProxyParametersTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ProxyParametersTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ProxyParametersTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ProxyParametersTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,47 @@
+package org.apache.servicemix.http;
+
+import org.apache.servicemix.expression.PropertyExpression;
+
+import junit.framework.TestCase;
+
+public class ProxyParametersTest extends TestCase {
+	
+	private PropertyExpression usernameProp;
+	private PropertyExpression passwordProp;
+	private ProxyParameters proxyParams;
+	private static final String userName = "username";
+	private static final String password = "password";
+	private static final String proxyHost = "hostname";
+	private static final int proxyPort = 80;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		usernameProp = new PropertyExpression(userName);
+		passwordProp = new PropertyExpression(password);
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		usernameProp = null;
+		passwordProp = null;
+		proxyParams = null;
+	}
+	
+	public void testProxyParams() throws Exception {
+		BasicAuthCredentials bac = new BasicAuthCredentials();
+		bac.setUsername(usernameProp);
+		bac.setPassword(passwordProp);
+
+		// Create the Proxy Parameters
+		proxyParams = new ProxyParameters();
+		proxyParams.setProxyCredentials(bac);
+		proxyParams.setProxyHost(proxyHost);
+		proxyParams.setProxyPort(proxyPort);
+		
+		assertTrue("Proxy Parameters should have non-null authentication credentials", 
+				proxyParams.getProxyCredentials() != null);
+		assertTrue("Proxy Host should be: " + proxyHost, proxyParams.getProxyHost().equals(proxyHost));
+		assertTrue("Proxy Port should be: " + proxyPort, proxyParams.getProxyPort() == proxyPort);		
+	}
+
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ProxyParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ServerManagerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ServerManagerTest.java?rev=781404&r1=781403&r2=781404&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ServerManagerTest.java (original)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/ServerManagerTest.java Wed Jun  3 14:26:30 2009
@@ -30,6 +30,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.components.http.InvalidStatusResponseException;
 import org.apache.servicemix.http.jetty.JettyContextManager;
+import org.mortbay.jetty.handler.ContextHandler;
 import org.mortbay.thread.QueuedThreadPool;
 
 public class ServerManagerTest extends TestCase {
@@ -105,6 +106,43 @@
             // ok
         }
     }
+    
+    // Test create context when an authorization method is set on the HTTP processor.
+    public void testContextWithAuth() throws Exception {
+    	server.init();
+    	server.start();
+    	
+    	Object contextObj = server.createContext("http://localhost:8192/Service1/test", new TestAltHttpProcessor());
+    	
+    	assertNotNull("Context should not be null", contextObj);    	
+    	assertTrue("Context should be started", ((ContextHandler)contextObj).isStarted());
+    }
+    
+    // Test when https protocol used but SSL params is null.
+    public void testHttpsNoSslParams() throws Exception {
+    	server.init();
+    	server.start();
+    	
+    	try {
+    		server.createContext("https://localhost:8143/Service/test", new TestHttpProcessor());
+    		fail("Context for https URL with no SSL Params should not be created");
+    	} catch (IllegalArgumentException iae) {
+    		// test passes
+    	}
+    }
+    
+    // Test invalid protocol
+    public void testContextWithInvalidProtocol() throws Exception {
+    	server.init();
+    	server.start();
+    	
+    	try {
+    		server.createContext("file://localhost:8192/Service/test", new TestHttpProcessor());
+    		fail("Context for invalid protocol should not be created.");
+    	} catch (UnsupportedOperationException uoe) {
+    		// test passes
+    	}
+    }
 
     public void testSetMaxThreads() throws Exception {
         int maxThreads = 512;
@@ -159,4 +197,18 @@
         }
 
     }
+    
+    public static class TestAltHttpProcessor implements HttpProcessor {
+    	public SslParameters getSsl() {
+            return null;
+        }
+
+        public String getAuthMethod() {
+            return "usernameToken";
+        }
+
+        public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+            log.info(request);
+        }
+    }
 }

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/SslParametersTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/SslParametersTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/SslParametersTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/SslParametersTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,50 @@
+package org.apache.servicemix.http;
+
+import junit.framework.TestCase;
+
+public class SslParametersTest extends TestCase {
+
+	private SslParameters sslParams;
+	
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		sslParams = null;
+	}
+	
+	// Test to verify that keyManagerFactoryAlgorithm and trustManagerFactoryAlgorithm
+	// are set up at object construction.
+	public void testSslParamsKeyAndTrustManagerAlgorithms() throws Exception {
+		sslParams = new SslParameters();
+		assertTrue("Ssl Parameters keyManagerFactoryAlgorithm should not be null", sslParams.getKeyManagerFactoryAlgorithm() != null);
+		assertTrue("Ssl Parameters trustManagerFactoryAlgorithm should not be null", sslParams.getTrustManagerFactoryAlgorithm() != null);
+	}
+	
+	// SSL Parameters equals test - same object
+	public void testSslParamsObjectsEqualSameObject() throws Exception {
+		sslParams = new SslParameters();
+		SslParameters sslParamsSame = sslParams;
+		assertTrue("SSL Parameters objects should be equal (same)", sslParams.equals(sslParamsSame));
+	}
+	
+	// Test SSL Parameters 2 separate objects equal
+	public void testSslParamsObjectsEquals() throws Exception {
+		sslParams = new SslParameters();
+		SslParameters sslParams2 = new SslParameters();
+		assertTrue("SSL Parameters objects should be equal", sslParams.equals(sslParams2));
+	}
+	
+	// Test SSL Parameters 2 objects not equal
+	public void testSslParamsObjectsNotEqual() throws Exception {
+		sslParams = new SslParameters();
+		SslParameters sslParams2 = new SslParameters();
+		sslParams2.setKeyPassword("bogus");
+		assertTrue("SSL Parameters objects should NOT be equal", !sslParams.equals(sslParams2));
+	}
+	
+	// Test SSL Parameters object not equal to another object type
+	public void testSslParamsObjectNotEqualOtherObjectType() throws Exception {
+		sslParams = new SslParameters();
+		String nonSslParamObj = "some string";
+		assertTrue("SSL Parameters object should NOT equal another object type", !sslParams.equals(nonSslParamObj));
+	}
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/SslParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshalerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshalerTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshalerTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshalerTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,155 @@
+package org.apache.servicemix.http.endpoints;
+
+import java.util.HashMap;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.expression.PropertyExpression;
+import org.apache.servicemix.http.jetty.SmxHttpExchange;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.mock.MockExchangeFactory;
+import org.mortbay.jetty.HttpMethods;
+
+import junit.framework.TestCase;
+
+public class DefaultHttpProviderMarshalerTest extends TestCase {
+
+	private DefaultHttpProviderMarshaler defHttpProviderMarshaler;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		defHttpProviderMarshaler = new DefaultHttpProviderMarshaler();
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		defHttpProviderMarshaler = null;
+	}
+	
+	// Test getLocationUri when URI on message exchange is null.
+	public void testGetLocationUriNull() throws Exception {
+		MockExchangeFactory mef = new MockExchangeFactory();
+        MessageExchange me = mef.createInOnlyExchange();
+        NormalizedMessage msg = me.createMessage();
+        msg.setContent(new StringSource("<input>input message</input>"));
+        
+        defHttpProviderMarshaler.setLocationURI(null);
+        
+        try {
+        	defHttpProviderMarshaler.getLocationUri(me, msg);
+        	fail("getLocationUri() should throw an exception for null URI");
+        } catch (IllegalStateException ise) {
+        	// test succeeds
+        }
+	}
+	
+	// Test getLocationUri when LocationURIExpression is set.
+	public void testGetLocationUriExpression() throws Exception {
+		MockExchangeFactory mef = new MockExchangeFactory();
+        MessageExchange me = mef.createInOnlyExchange();
+        me.setProperty("uri", "someOperation");
+        NormalizedMessage msg = me.createMessage();
+        msg.setContent(new StringSource("<input>input message</input>"));
+        
+        PropertyExpression uriExp = new PropertyExpression("uri");
+        
+        defHttpProviderMarshaler.setLocationURIExpression(uriExp);
+        
+        String uriReturned = defHttpProviderMarshaler.getLocationUri(me, msg);
+        
+        assertTrue("getLocationUri() should return the string value set on the exchange", 
+        		uriReturned.equals("someOperation"));
+	}
+
+	// Test getMethod when in msg has no content.  Method should be HTTP GET. 
+	public void testGetMethodInMsgContentNull() throws Exception {
+		MockExchangeFactory mef = new MockExchangeFactory();
+        MessageExchange me = mef.createInOnlyExchange();
+        NormalizedMessage msg = me.createMessage();
+        
+        String httpMethod = defHttpProviderMarshaler.getMethod(me, msg);
+        
+        assertTrue("getMethod() with null in msg contents should return GET", 
+        		httpMethod.equals(HttpMethods.GET));
+	}
+	
+	// Test getMethod when a methodExpression is set on the message exchange.
+	public void testGetMethodWithMethodExpression() throws Exception {
+		MockExchangeFactory mef = new MockExchangeFactory();
+        MessageExchange me = mef.createInOnlyExchange();
+        me.setProperty("method", "POST");
+        NormalizedMessage msg = me.createMessage();
+        msg.setContent(new StringSource("<input>input message</input>"));
+        
+        PropertyExpression methodExp = new PropertyExpression("method");
+        
+        defHttpProviderMarshaler.setMethodExpression(methodExp);
+        
+        String httpMethod = defHttpProviderMarshaler.getMethod(me, msg);
+        
+        assertTrue("getMethod() with method expression should return the value set on the exchange", 
+        		httpMethod.equals(HttpMethods.POST));
+	}
+	
+	// Test getContentType when content type is null.
+	public void testGetContentTypeNull() throws Exception {
+		MockExchangeFactory mef = new MockExchangeFactory();
+        MessageExchange me = mef.createInOnlyExchange();
+        NormalizedMessage msg = me.createMessage();
+
+        // Must explicitly set contentType to null.  It is set by default.
+        defHttpProviderMarshaler.setContentType(null);
+        
+        try {
+        	defHttpProviderMarshaler.getContentType(me, msg);
+        	fail("getContentType() should throw an exception when contentType is null");
+        } catch (IllegalStateException ise) {
+        	// test passes
+        }
+	}
+	
+	// Test getContentType when contentTypeExpression is set on the exchange.
+	public void testGetContentTypeExpression() throws Exception {
+		MockExchangeFactory mef = new MockExchangeFactory();
+        MessageExchange me = mef.createInOnlyExchange();
+        me.setProperty("contentType", "text/plain");
+        NormalizedMessage msg = me.createMessage();
+        msg.setContent(new StringSource("<input>input message</input>"));
+        
+        PropertyExpression contentTypeExp = new PropertyExpression("contentType");
+        
+        defHttpProviderMarshaler.setContentTypeExpression(contentTypeExp);
+        
+        String contentType = defHttpProviderMarshaler.getContentType(me, msg);
+        
+        assertTrue("getContentType() should return the value set on the exchange", 
+        		contentType.equals("text/plain"));
+        
+	}
+	
+	// Test createRequest when headers are set.
+	public void testCreateRequestWithHeaders() throws Exception {
+		MockExchangeFactory mef = new MockExchangeFactory();
+        MessageExchange me = mef.createInOnlyExchange();
+        me.setProperty("uri", "http://localhost:8192/Service1/someOperation");
+        NormalizedMessage msg = me.createMessage();
+        msg.setContent(new StringSource("<input>input message</input>"));
+        SmxHttpExchange httpExchange = new SmxHttpExchange();
+        
+        PropertyExpression uriExp = new PropertyExpression("uri");
+        
+        // Create a header to add to the exchange.
+        HashMap<String, String> headers = new HashMap<String, String>();
+        headers.put("Cache-Control", "no-cache");
+        
+        defHttpProviderMarshaler.setHeaders(headers);
+        defHttpProviderMarshaler.setLocationURIExpression(uriExp);
+        
+        defHttpProviderMarshaler.createRequest(me, msg, httpExchange);
+        
+        // Create request sets the request content on the httpExchange.
+        assertNotNull("createRequest() should set the http exchange's request content", 
+        		httpExchange.getRequestContent());
+	}
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshalerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerEndpointTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerEndpointTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerEndpointTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,88 @@
+package org.apache.servicemix.http.endpoints;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.jbi.component.ComponentContext;
+
+import org.apache.servicemix.common.DefaultServiceUnit;
+import org.apache.servicemix.http.HttpComponent;
+
+import junit.framework.TestCase;
+
+public class HttpSoapConsumerEndpointTest extends TestCase {
+
+	private HttpSoapConsumerEndpoint httpSoapConsEp;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		httpSoapConsEp = new HttpSoapConsumerEndpoint();
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		httpSoapConsEp = null;
+	}
+	
+	// Test activate() when target endpoint WSDL is null.
+	public void testActivateTargetEndpointWsdlNull() throws Exception {
+		
+		TestServiceUnit serviceUnit = new TestServiceUnit();
+		
+		httpSoapConsEp.setServiceUnit(serviceUnit);
+		try {
+			httpSoapConsEp.activate();
+			fail("activate() should fail if target endpoint WSDL is null");
+		} catch (JBIException jbie) {
+			// test passes
+		}
+	}
+	
+	// Test validate() when an invalid marshaler is set.
+	public void testValidateInvalidMarshaler() throws Exception {
+		httpSoapConsEp.setMarshaler(new TestHttpConsumerMarshaler());
+		
+		try {
+			httpSoapConsEp.validate();
+			fail("validate() should fail when marshaler is not an HttpSoapConsumerMarshaler");
+		} catch (DeploymentException de) {
+			// test succeeds
+		}
+		
+	}
+	
+    // TestServiceUnit needed to create a service unit associated with the HTTP component.
+	public static class TestServiceUnit extends DefaultServiceUnit {
+		public TestServiceUnit() {
+			super(new HttpComponent());
+		}
+	}	
+	
+	// TestHttpConsumerMarshaler needed for invalid marshaler test.
+	public static class TestHttpConsumerMarshaler implements HttpConsumerMarshaler {
+		public void sendOut(MessageExchange exchange, NormalizedMessage outMsg, HttpServletRequest request,
+		        HttpServletResponse response) {
+		}
+		
+		public void sendFault(MessageExchange exchange, Fault fault, HttpServletRequest request, 
+				HttpServletResponse response) {
+		}
+
+        public void sendError(MessageExchange exchange, Exception error, HttpServletRequest request, 
+    		HttpServletResponse response) {	
+        }
+
+        public void sendAccepted(MessageExchange exchange, HttpServletRequest request, 
+    		HttpServletResponse response) {	
+        }
+        
+        public MessageExchange createExchange(HttpServletRequest request, ComponentContext context) {
+        	return null;
+        }
+        
+	}
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpointTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpointTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpointTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,76 @@
+package org.apache.servicemix.http.endpoints;
+
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.http.jetty.SmxHttpExchange;
+import org.springframework.core.io.FileSystemResource;
+
+import junit.framework.TestCase;
+
+public class HttpSoapProviderEndpointTest extends TestCase {
+
+	private HttpSoapProviderEndpoint soapProviderEp;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		soapProviderEp = new HttpSoapProviderEndpoint();
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		soapProviderEp = null;
+	}
+	
+	// Test for validate() when WSDL is null.
+	public void testValidateWsdlNull() throws Exception {
+		try {
+			soapProviderEp.validate();
+			fail("validate() should fail when WSDL is null");
+		} catch (DeploymentException de) {
+			// test passes
+		}
+	}
+
+	public void testValidateInvalidMarshaler() throws Exception {
+		FileSystemResource wsdl = new FileSystemResource("provider/http.wsdl");
+		soapProviderEp.setWsdl(wsdl);
+		soapProviderEp.setMarshaler(new TestHttpProviderMarshaler());
+		
+		try {
+			soapProviderEp.validate();
+			fail("validate() should fail when an invalid marshaler is used");
+		} catch (DeploymentException de) {
+			// test passes
+		}
+	}
+	
+	public void testValidateNonexistentWsdl() throws Exception {
+		FileSystemResource wsdl = new FileSystemResource("provider/noexist.wsdl");
+		soapProviderEp.setWsdl(wsdl);
+		
+		try {
+			soapProviderEp.validate();
+			fail("validate() should fail for non-existent WSDL");
+		} catch (DeploymentException de) {
+			// test succeeds
+		}
+	}
+	
+	// Dummy implementation of a marshaler for the invalid marshaler test.
+	public static class TestHttpProviderMarshaler implements HttpProviderMarshaler {
+		public void createRequest(MessageExchange exchange,
+                NormalizedMessage inMsg,
+                SmxHttpExchange httpExchange) {
+		}
+
+        public void handleResponse(MessageExchange exchange,
+                 SmxHttpExchange httpExchange) {
+        }
+
+        public void handleException(MessageExchange exchange,
+                  SmxHttpExchange httpExchange, Throwable ex) {
+        }
+	}
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/jetty/SmxHttpExchangeTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/jetty/SmxHttpExchangeTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/jetty/SmxHttpExchangeTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/jetty/SmxHttpExchangeTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,130 @@
+package org.apache.servicemix.http.jetty;
+
+import java.io.InputStream;
+import java.io.Reader;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mortbay.io.ByteArrayBuffer;
+
+import junit.framework.TestCase;
+
+public class SmxHttpExchangeTest extends TestCase {
+
+	private static transient Log log = LogFactory.getLog(SmxHttpExchangeTest.class);
+	private SmxHttpExchange httpExchange;
+	private static final String strResponseContent = "valid response content";
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		httpExchange = new SmxHttpExchange();
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		httpExchange = null;
+	}
+
+	// Test getResponseStatus when it throws an IllegalStateException
+	public void testGetResponseStatusException() throws Exception {
+		// set the response status
+		httpExchange.onResponseStatus(null, 0, null);
+		
+		try {
+			httpExchange.getResponseStatus();
+			fail("getResponseStatus() should fail with IllegalStateException");
+		} catch (IllegalStateException ise) {
+			log.info("testGetResponseStatusException() got the expected exception");
+		}
+	}
+	
+	// Test getResponseFields when it throws an IllegalStateException
+	public void testGetResponseFieldsException() throws Exception {
+		
+		// set the response status
+		httpExchange.onResponseStatus(null, 0, null);
+		
+		try {
+			httpExchange.getResponseFields();
+			fail("getResponseFields() should fail with IllegalStateException");
+		} catch (IllegalStateException ise) {
+			log.info("testGetResponseFieldsException() got the expected exception");
+		}
+	}
+	
+	// Test getResponseContent when responseContent is null.
+	public void testGetResponseContentNull() throws Exception {
+		
+		assertNull("getResponseContent() should return null", httpExchange.getResponseContent());
+	}
+	
+	// Test getResponseContent when responseContent is returned as a string.
+	public void testGetResponseContentString() throws Exception {
+		
+		// set the response content
+		setResponseContent();
+		
+		String returnedContent = httpExchange.getResponseContent();
+		
+		assertTrue("", returnedContent.equalsIgnoreCase(strResponseContent));
+	}
+	
+	// Test getResponseReader when responseContent is null.
+	public void testGetResponseReaderNull() throws Exception {		
+		assertNull("getResponseReader() should return null", httpExchange.getResponseReader());
+	}
+	
+	// Test getResponseReader when responseContent is returned as a reader.
+	public void testGetResponseReader() throws Exception {
+
+		// set the response content
+		setResponseContent();
+		
+		Reader inReader = httpExchange.getResponseReader();
+		
+		assertNotNull("getResponseReader() should return a Reader", inReader);
+	}
+	
+	// Test getResponseStream when responseContent is null.
+	public void testGetResponseStreamNull() throws Exception {
+
+		assertNull("getResponseStream() should return null", httpExchange.getResponseStream());		
+	}
+	
+	// Test getResponseStream when responseContent is returned as an InputStream.
+	public void testGetResponseStream() throws Exception {
+		
+		// set the response content
+		setResponseContent();
+		
+		InputStream inStream = httpExchange.getResponseStream();
+		
+		assertNotNull("getResponseStream() should return an InputStream", inStream);
+	}
+	
+	// Test getResponseData when responseContent is null.
+	public void testGetResponseDataNull() throws Exception {
+
+		assertNull("getResponseData() should return null", httpExchange.getResponseData());
+	}
+	
+	// Test getResponseData when responseContent is returned as a byte array.
+	public void testGetResponseData() throws Exception {
+		
+		// set the response content
+		setResponseContent();
+		
+		byte[] byteArray = httpExchange.getResponseData();
+		
+		assertTrue("getResponseData() should return more than 0 bytes", byteArray.length > 0);
+	}
+	
+	// Method used for test setup to set the exchange's responseContent 
+	//for getResponse<type> tests.
+	private void setResponseContent() throws Exception {
+		ByteArrayBuffer contentBuffer = new ByteArrayBuffer(strResponseContent);
+		
+		// set the exchange's responseContent
+		httpExchange.onResponseContent(contentBuffer);
+	}
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/jetty/SmxHttpExchangeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/packaging/HttpServiceUnitAnalyzerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/packaging/HttpServiceUnitAnalyzerTest.java?rev=781404&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/packaging/HttpServiceUnitAnalyzerTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/packaging/HttpServiceUnitAnalyzerTest.java Wed Jun  3 14:26:30 2009
@@ -0,0 +1,150 @@
+package org.apache.servicemix.http.packaging;
+
+import java.util.List;
+
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchange.Role;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.common.DefaultServiceUnit;
+import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.http.HttpEndpoint;
+import org.w3c.dom.Document;
+
+import junit.framework.TestCase;
+
+public class HttpServiceUnitAnalyzerTest extends TestCase {
+
+	private HttpServiceUnitAnalyzer httpSuAnalyzer;
+	private DefaultServiceUnit su;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		httpSuAnalyzer = new HttpServiceUnitAnalyzer();
+		su = new DefaultServiceUnit();
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	    su = null;
+	    httpSuAnalyzer = null;
+	}
+	
+	// Test isValidEndpoint() for valid HttpEndpoint on ServiceUnit.
+	public void testIsValidEndpointTrue() throws Exception {
+		HttpEndpoint httpEp = new HttpEndpoint();	
+		httpEp.setService(new QName("urn:test", "service"));
+		httpEp.setEndpoint("http://localhost:8080/someService");
+		su.addEndpoint(httpEp);
+		
+		// Create the key that was used by the addEndpoint method.
+		String epKey = "{urn:test}service:http://localhost:8080/someService";
+		assertTrue("", httpSuAnalyzer.isValidEndpoint(su.getEndpoint(epKey)));
+	}
+	
+	// Test isValidEndpoint() for non-HttpEndpoint on Service Unit.
+	public void testIsValidEndpointFalse() throws Exception {
+		TestEndpoint testEp = new TestEndpoint();
+		su.addEndpoint(testEp);
+		
+		assertFalse("isValidEndpoint() should return false for non-HttpEndpoint", 
+				httpSuAnalyzer.isValidEndpoint(su.getEndpoint("test")));
+	}
+	
+	// Test getConsumes() when endpoint has proper target setup.
+	public void testGetConsumesUsingTargets() throws Exception {
+		HttpEndpoint httpEp = new HttpEndpoint();	
+		httpEp.setRoleAsString("consumer");
+		httpEp.setTargetService(new QName("urn:test", "service"));
+		httpEp.setTargetEndpoint("http://localhost:8080/someService");
+		httpEp.setTargetInterfaceName(new QName("urn:test", "portType"));
+		
+		List consumeList = httpSuAnalyzer.getConsumes(httpEp);
+		
+		assertNotNull("getConsumes() should not return null list", consumeList);
+	}
+	
+	// Test getConsumes() when endpoint does not have target setup.
+	public void testGetConsumesInvalidList() throws Exception {
+		HttpEndpoint httpEp = new HttpEndpoint();	
+		httpEp.setRoleAsString("consumer");
+		httpEp.setService(new QName("urn:test", "service"));
+		httpEp.setEndpoint("http://localhost:8080/someService");
+		httpEp.setInterfaceName(new QName("urn:test", "portType"));
+		
+		List consumeList = httpSuAnalyzer.getConsumes(httpEp);
+		
+		assertNotNull("getConsumes() should not return null list", consumeList);
+	}
+
+	// Dummy Endpoint implementation for testing.
+	public static class TestEndpoint implements Endpoint {
+
+		private String key;
+		
+		public TestEndpoint() {
+			key = "test";
+		}
+		
+		public void activate() throws Exception {
+		}
+
+		public void deactivate() throws Exception {
+		}
+
+		public Document getDescription() {
+			return null;
+		}
+
+		public String getEndpoint() {
+			return null;
+		}
+
+		public QName getInterfaceName() {
+			return null;
+		}
+
+		public String getKey() {
+			return key;
+		}
+
+		public Role getRole() {
+			return null;
+		}
+
+		public QName getService() {
+			return null;
+		}
+
+		public ServiceUnit getServiceUnit() {
+			return null;
+		}
+
+		public boolean isExchangeOkay(MessageExchange exchange) {
+			return false;
+		}
+
+		public void process(MessageExchange exchange) throws Exception {
+			
+		}
+
+		public void setServiceUnit(ServiceUnit serviceUnit) {
+			
+		}
+
+		public void start() throws Exception {
+			
+		}
+
+		public void stop() throws Exception {
+			
+		}
+
+		public void validate() throws DeploymentException {
+			
+		}
+		
+	}
+}

Propchange: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/packaging/HttpServiceUnitAnalyzerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native