camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r917465 - in /camel/trunk/tests/camel-itest: ./ src/test/java/org/apache/camel/itest/http/ src/test/resources/org/apache/camel/itest/http/
Date Mon, 01 Mar 2010 10:54:57 GMT
Author: davsclaus
Date: Mon Mar  1 10:54:57 2010
New Revision: 917465

URL: http://svn.apache.org/viewvc?rev=917465&view=rev
Log:
Added http integration tests back. Thanks to Christian Mueller for providing the patch.

Added:
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java
  (with props)
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java
  (with props)
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
  (with props)
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
  (with props)
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest-context.xml
  (with props)
Modified:
    camel/trunk/tests/camel-itest/pom.xml

Modified: camel/trunk/tests/camel-itest/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/pom.xml?rev=917465&r1=917464&r2=917465&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/pom.xml (original)
+++ camel/trunk/tests/camel-itest/pom.xml Mon Mar  1 10:54:57 2010
@@ -225,6 +225,15 @@
             <artifactId>spring-test</artifactId>
             <scope>test</scope>
         </dependency>
+        
+        <!-- for http component tests -->
+    	<dependency>
+    		<groupId>org.apache.httpcomponents</groupId>
+    		<artifactId>httpclient</artifactId>
+    		<version>${httpclient4-version}</version>
+    		<classifier>tests</classifier>
+    		<scope>test</scope>
+    	</dependency>
     </dependencies>
 
     <build>

Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java?rev=917465&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java
(added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java
Mon Mar  1 10:54:57 2010
@@ -0,0 +1,82 @@
+/**
+ * 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.camel.itest.http;
+
+import java.io.IOException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpRequestHandler;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+@ContextConfiguration
+public class HttpEndpointTest extends AbstractJUnit4SpringContextTests {
+
+    @Autowired
+    protected CamelContext camelContext;
+
+    @EndpointInject(uri = "direct:start")
+    protected ProducerTemplate producer;
+
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint mock;
+
+    protected HttpTestServer localServer;
+
+    @Before
+    public void setUp() throws Exception {
+        localServer = new HttpTestServer(null, null);
+        localServer.register("/", new HttpRequestHandler() {
+            public void handle(HttpRequest request, HttpResponse response,
+                    HttpContext context) throws HttpException, IOException {
+                response.setStatusCode(HttpStatus.SC_OK);
+                response.setEntity(new StringEntity("OK", HTTP.ISO_8859_1));
+            }
+        });
+        localServer.start();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (localServer != null) {
+            localServer.stop();
+        }
+    }
+
+    @Test
+    public void testMocksIsValid() throws Exception {
+        mock.expectedMessageCount(1);
+
+        producer.sendBody(null);
+
+        mock.assertIsSatisfied();
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java?rev=917465&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java
(added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java
Mon Mar  1 10:54:57 2010
@@ -0,0 +1,83 @@
+/**
+ * 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.camel.itest.http;
+
+import java.io.IOException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpRequestHandler;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+@ContextConfiguration
+public class HttpMaxConnectionPerHostTest extends
+        AbstractJUnit4SpringContextTests {
+
+    @Autowired
+    protected CamelContext camelContext;
+
+    @EndpointInject(uri = "direct:start")
+    protected ProducerTemplate producer;
+
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint mock;
+
+    protected HttpTestServer localServer;
+
+    @Before
+    public void setUp() throws Exception {
+        localServer = new HttpTestServer(null, null);
+        localServer.register("/", new HttpRequestHandler() {
+            public void handle(HttpRequest request, HttpResponse response,
+                    HttpContext context) throws HttpException, IOException {
+                response.setStatusCode(HttpStatus.SC_OK);
+                response.setEntity(new StringEntity("OK", HTTP.ISO_8859_1));
+            }
+        });
+        localServer.start();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (localServer != null) {
+            localServer.stop();
+        }
+    }
+
+    @Test
+    public void testMocksIsValid() throws Exception {
+        mock.expectedMessageCount(1);
+
+        producer.sendBody(null);
+
+        mock.assertIsSatisfied();
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java?rev=917465&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
(added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
Mon Mar  1 10:54:57 2010
@@ -0,0 +1,65 @@
+/**
+ * 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.camel.itest.http;
+
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+
+import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpProcessor;
+
+/**
+ * Subclass the org.apache.http.localserver.LocalTestServer to choose a specific
+ * port.
+ * 
+ * @author muellerc
+ */
+public class HttpTestServer extends LocalTestServer {
+
+    /**
+     * The local address to bind to. The host is an IP number rather than
+     * "localhost" to avoid surprises on hosts that map "localhost" to an IPv6
+     * address or something else. The port is 18080 by default.
+     */
+    public static final InetSocketAddress TEST_SERVER_ADDR = new InetSocketAddress(
+            "127.0.0.1", 18080);
+
+    public HttpTestServer(BasicHttpProcessor proc, HttpParams params) {
+        super(proc, params);
+    }
+
+    /**
+     * Starts this test server. Use {@link #getServicePort getServicePort} to
+     * obtain the port number afterwards.
+     */
+    @Override
+    public void start() throws Exception {
+        if (servicedSocket != null) {
+            throw new IllegalStateException(this.toString() + " already running");
+        }
+
+        ServerSocket ssock = new ServerSocket();
+        ssock.setReuseAddress(true); // probably pointless for port '0'
+        ssock.bind(TEST_SERVER_ADDR);
+        servicedSocket = ssock;
+
+        listenerThread = new Thread(new RequestListener());
+        listenerThread.setDaemon(false);
+        listenerThread.start();
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml?rev=917465&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
(added)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
Mon Mar  1 10:54:57 2010
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <!-- START SNIPPET: e1 -->
+    <bean id="httpEndpoint" class="org.apache.camel.component.http.HttpEndpoint">
+        <property name="httpUri" value="http://127.0.0.1:18080/"/>
+        <property name="clientParams" ref="clientParams"/>
+        <property name="clientConnectionManager" ref="clientConnectionManager"/>
+    </bean>
+
+    <bean id="clientParams" class="org.apache.http.params.BasicHttpParams" />
+    
+    <bean id="clientConnectionManager" class="org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager">
+        <constructor-arg ref="clientParams"/>
+        <constructor-arg ref="schemeRegistry"/>
+    </bean>
+    
+    <bean id="plainSocketFactory" class="org.apache.http.conn.scheme.PlainSocketFactory"
factory-method="getSocketFactory" />
+    
+    <bean id="http" class="org.apache.http.conn.scheme.Scheme">
+    	<constructor-arg value="http" />
+    	<constructor-arg>
+    		<bean class="org.apache.http.conn.scheme.PlainSocketFactory" factory-method="getSocketFactory"
/>
+    	</constructor-arg>
+    	<constructor-arg value="80" />
+    </bean>
+    
+    <bean id="schemeRegistry" class="org.apache.http.conn.scheme.SchemeRegistry" />
+    
+    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    	<property name="targetObject" ref="schemeRegistry"/>
+		<property name="targetMethod" value="register"/>
+    	<property name="arguments">
+    		<list>
+    			<ref bean="http"/>
+    		</list>
+    	</property>
+    </bean>
+    <!-- END SNIPPET: e1 -->
+
+    <!-- START SNIPPET: e2 -->
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" trace="true">
+        <route>
+            <from uri="direct:start"/>
+            <to uri="httpEndpoint"/>
+            <to uri="mock:result"/>
+        </route>
+    </camelContext>
+    <!-- END SNIPPET: e2 -->
+
+</beans>
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest-context.xml?rev=917465&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest-context.xml
(added)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest-context.xml
Mon Mar  1 10:54:57 2010
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <!-- START SNIPPET: e1 -->
+    <bean id="httpComponent" class="org.apache.camel.component.http.HttpComponent">
+        <property name="camelContext" ref="camel"/>
+        <property name="clientConnectionManager" ref="clientConnectionManager"/>
+        <property name="connectionsPerRoute" value="5" />
+    </bean>
+
+    <bean id="clientConnectionManager" class="org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager">
+        <constructor-arg ref="clientParams"/>
+        <constructor-arg ref="schemeRegistry"/>
+    </bean>
+
+    <bean id="clientParams" class="org.apache.http.params.BasicHttpParams" />
+    
+    <bean id="plainSocketFactory" class="org.apache.http.conn.scheme.PlainSocketFactory"
factory-method="getSocketFactory" />
+    
+    <bean id="http" class="org.apache.http.conn.scheme.Scheme">
+    	<constructor-arg value="http" />
+    	<constructor-arg>
+    		<bean class="org.apache.http.conn.scheme.PlainSocketFactory" factory-method="getSocketFactory"
/>
+    	</constructor-arg>
+    	<constructor-arg value="80" />
+    </bean>
+    
+    <bean id="schemeRegistry" class="org.apache.http.conn.scheme.SchemeRegistry" />
+    
+    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    	<property name="targetObject" ref="schemeRegistry"/>
+		<property name="targetMethod" value="register"/>
+    	<property name="arguments">
+    		<list>
+    			<ref bean="http"/>
+    		</list>
+    	</property>
+    </bean>
+
+    <!-- END SNIPPET: e1 -->
+
+    <!-- START SNIPPET: e2 -->
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" trace="true">
+        <route>
+            <from uri="direct:start"/>
+            <to uri="http://127.0.0.1:18080/"/>
+            <to uri="mock:result"/>
+        </route>
+    </camelContext>
+    <!-- END SNIPPET: e2 -->
+</beans>
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message