You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/04/10 12:49:35 UTC
svn commit: r932690 [3/3] - in /camel/trunk/components/camel-http: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/camel/ src/main/java/org/apache/camel/component/
src/main/java/org/apache/camel/co...
Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,183 @@
+/**
+ * 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.component.http;
+
+import java.io.IOException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.httpclient.HttpMethod;
+import org.junit.Test;
+
+import static org.apache.camel.component.http.HttpMethods.GET;
+import static org.apache.camel.component.http.HttpMethods.POST;
+
+/**
+ * Unit test to verify the algorithm for selecting either GET or POST.
+ */
+public class HttpProducerSelectMethodTest extends CamelTestSupport {
+
+ @Test
+ public void testNoDataDefaultIsGet() throws Exception {
+ HttpComponent component = new HttpComponent();
+ component.setCamelContext(context);
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
+ MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", null);
+
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody(null);
+ try {
+ producer.process(exchange);
+ fail("Should have thrown HttpOperationFailedException");
+ } catch (HttpOperationFailedException e) {
+ assertEquals(500, e.getStatusCode());
+ }
+ producer.stop();
+ }
+
+ @Test
+ public void testDataDefaultIsPost() throws Exception {
+ HttpComponent component = new HttpComponent();
+ component.setCamelContext(context);
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
+ MyHttpProducer producer = new MyHttpProducer(endpoiont, "POST", null);
+
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody("This is some data to post");
+ try {
+ producer.process(exchange);
+ fail("Should have thrown HttpOperationFailedException");
+ } catch (HttpOperationFailedException e) {
+ assertEquals(500, e.getStatusCode());
+ }
+ producer.stop();
+ }
+
+ @Test
+ public void testWithMethodPostInHeader() throws Exception {
+ HttpComponent component = new HttpComponent();
+ component.setCamelContext(context);
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
+ MyHttpProducer producer = new MyHttpProducer(endpoiont, "POST", null);
+
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody("");
+ exchange.getIn().setHeader(Exchange.HTTP_METHOD, POST);
+ try {
+ producer.process(exchange);
+ fail("Should have thrown HttpOperationFailedException");
+ } catch (HttpOperationFailedException e) {
+ assertEquals(500, e.getStatusCode());
+ }
+ producer.stop();
+ }
+
+ @Test
+ public void testWithMethodGetInHeader() throws Exception {
+ HttpComponent component = new HttpComponent();
+ component.setCamelContext(context);
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
+ MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", null);
+
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody("");
+ exchange.getIn().setHeader(Exchange.HTTP_METHOD, GET);
+ try {
+ producer.process(exchange);
+ fail("Should have thrown HttpOperationFailedException");
+ } catch (HttpOperationFailedException e) {
+ assertEquals(500, e.getStatusCode());
+ }
+ producer.stop();
+ }
+
+ @Test
+ public void testWithEndpointQuery() throws Exception {
+ HttpComponent component = new HttpComponent();
+ component.setCamelContext(context);
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com?q=Camel");
+ MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", "q=Camel");
+
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody("");
+ try {
+ producer.process(exchange);
+ fail("Should have thrown HttpOperationFailedException");
+ } catch (HttpOperationFailedException e) {
+ assertEquals(500, e.getStatusCode());
+ }
+ producer.stop();
+ }
+
+ @Test
+ public void testWithQueryInHeader() throws Exception {
+ HttpComponent component = new HttpComponent();
+ component.setCamelContext(context);
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
+ MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", "q=Camel");
+
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody("");
+ exchange.getIn().setHeader(Exchange.HTTP_QUERY, "q=Camel");
+ try {
+ producer.process(exchange);
+ fail("Should have thrown HttpOperationFailedException");
+ } catch (HttpOperationFailedException e) {
+ assertEquals(500, e.getStatusCode());
+ }
+ producer.stop();
+ }
+
+ @Test
+ public void testWithQueryInHeaderOverrideEndpoint() throws Exception {
+ HttpComponent component = new HttpComponent();
+ component.setCamelContext(context);
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com?q=Donkey");
+ MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", "q=Camel");
+
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody("");
+ exchange.getIn().setHeader(Exchange.HTTP_QUERY, "q=Camel");
+ try {
+ producer.process(exchange);
+ fail("Should have thrown HttpOperationFailedException");
+ } catch (HttpOperationFailedException e) {
+ assertEquals(500, e.getStatusCode());
+ }
+ producer.stop();
+ }
+
+ private static class MyHttpProducer extends HttpProducer {
+ private String name;
+ private String queryString;
+
+ public MyHttpProducer(HttpEndpoint endpoint, String name, String queryString) {
+ super(endpoint);
+ this.name = name;
+ this.queryString = queryString;
+ }
+
+ @Override
+ protected int executeMethod(HttpMethod method) throws IOException {
+ // do the assertion what to expected either GET or POST
+ assertEquals(name, method.getName());
+ assertEquals(queryString, method.getQueryString());
+ // return 500 to not extract response as we dont have any
+ return 500;
+ }
+ }
+}
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,75 @@
+/**
+ * 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.component.http;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.httpclient.HttpClient;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpProxyTest extends CamelTestSupport {
+
+ @Test
+ @Ignore("ignore online tests, will be improved in Camel 2.3")
+ public void testNoHttpProxyConfigured() throws Exception {
+ HttpEndpoint http = context.getEndpoint("http://www.google.com", HttpEndpoint.class);
+
+ HttpClient client = http.createHttpClient();
+ assertNull("No proxy configured yet", client.getHostConfiguration().getProxyHost());
+ assertEquals("No proxy configured yet", -1, client.getHostConfiguration().getProxyPort());
+ }
+
+ @Test
+ @Ignore("ignore online tests, will be improved in Camel 2.3")
+ public void testHttpProxyConfigured() throws Exception {
+ HttpEndpoint http = context.getEndpoint("http://www.google.com", HttpEndpoint.class);
+
+ context.getProperties().put("http.proxyHost", "myproxy");
+ context.getProperties().put("http.proxyPort", "1234");
+
+ try {
+ HttpClient client = http.createHttpClient();
+ assertEquals("myproxy", client.getHostConfiguration().getProxyHost());
+ assertEquals(1234, client.getHostConfiguration().getProxyPort());
+ } finally {
+ context.getProperties().remove("http.proxyHost");
+ context.getProperties().remove("http.proxyPort");
+ }
+ }
+
+ @Test
+ @Ignore("ignore online tests, will be improved in Camel 2.3")
+ public void testHttpProxyEndpointConfigured() throws Exception {
+ HttpEndpoint http = context.getEndpoint("http://www.google.com?proxyHost=myotherproxy&proxyPort=2345", HttpEndpoint.class);
+
+ context.getProperties().put("http.proxyHost", "myproxy");
+ context.getProperties().put("http.proxyPort", "1234");
+
+ try {
+ HttpClient client = http.createHttpClient();
+ assertEquals("myotherproxy", client.getHostConfiguration().getProxyHost());
+ assertEquals(2345, client.getHostConfiguration().getProxyPort());
+ } finally {
+ context.getProperties().remove("http.proxyHost");
+ context.getProperties().remove("http.proxyPort");
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,41 @@
+/**
+ * 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.component.http;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+/**
+ * Unit test to query Google using GET with endpoint having the query parameters.
+ */
+public class HttpQueryGoogleTest extends CamelTestSupport {
+
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ @Ignore("ignore online tests, will be improved in Camel 2.3")
+ public void testQueryGoogle() throws Exception {
+ Object out = template.requestBody("http://www.google.com/search?q=Camel", "");
+ assertNotNull(out);
+ String data = context.getTypeConverter().convertTo(String.class, out);
+ assertTrue("Camel should be in search result from Google", data.indexOf("Camel") > -1);
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpReferenceParameterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpReferenceParameterTest.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpReferenceParameterTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpReferenceParameterTest.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,88 @@
+/**
+ * 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.component.http;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.httpclient.HttpClient;
+import org.junit.Test;
+
+/**
+ * Unit test for resolving reference parameters.
+ */
+public class HttpReferenceParameterTest extends CamelTestSupport {
+
+ private static final String TEST_URI_1 = "http://localhost:8080?httpBindingRef=#customBinding&httpClientConfigurerRef=#customConfigurer";
+ private static final String TEST_URI_2 = "http://localhost:8081?httpBindingRef=customBinding&httpClientConfigurerRef=customConfigurer";
+
+ private HttpEndpoint endpoint1;
+ private HttpEndpoint endpoint2;
+
+ private TestHttpBinding testBinding;
+ private TestClientConfigurer testConfigurer;
+
+ @Override
+ public void setUp() throws Exception {
+ this.testBinding = new TestHttpBinding();
+ this.testConfigurer = new TestClientConfigurer();
+ super.setUp();
+ this.endpoint1 = (HttpEndpoint)context.getEndpoint(TEST_URI_1);
+ this.endpoint2 = (HttpEndpoint)context.getEndpoint(TEST_URI_2);
+ }
+
+ @Test
+ public void testHttpBindingRef() {
+ assertSame(testBinding, endpoint1.getBinding());
+ assertSame(testBinding, endpoint2.getBinding());
+ }
+
+ @Test
+ public void testHttpClientConfigurerRef() {
+ assertSame(testConfigurer, endpoint1.getHttpClientConfigurer());
+ assertSame(testConfigurer, endpoint2.getHttpClientConfigurer());
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("customBinding", testBinding);
+ registry.bind("customConfigurer", testConfigurer);
+ return registry;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start1").to(TEST_URI_1);
+ from("direct:start2").to(TEST_URI_2);
+ }
+ };
+ }
+
+ private static class TestHttpBinding extends DefaultHttpBinding {
+ }
+
+ private static class TestClientConfigurer implements HttpClientConfigurer {
+
+ public void configureHttpClient(HttpClient client) {
+ }
+
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpReferenceParameterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpReferenceParameterTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsGetTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsGetTest.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsGetTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsGetTest.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,40 @@
+/**
+ * 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.component.http;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Before;
+
+public class HttpsGetTest extends HttpGetTest {
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ expectedText = "https://mail.google.com/mail/";
+ super.setUp();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .to("https://mail.google.com/mail/").to("mock:results");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsGetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsGetTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/GZIPHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/GZIPHelperTest.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/GZIPHelperTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/GZIPHelperTest.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,79 @@
+/**
+ * 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.component.http.helper;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.Message;
+import org.apache.camel.converter.IOConverter;
+import org.apache.camel.impl.DefaultMessage;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class GZIPHelperTest {
+
+ private static byte[] sampleBytes = new byte[]{1, 2, 3, 1, 2, 3};
+
+ @Test
+ public void toGZIPInputStreamShouldReturnTheSameInputStream() throws IOException {
+ InputStream inputStream = GZIPHelper.toGZIPInputStream("text", new ByteArrayInputStream(sampleBytes));
+ byte[] bytes = new byte[6];
+ inputStream.read(bytes);
+
+ assertEquals(-1, inputStream.read());
+ assertArrayEquals(sampleBytes, bytes);
+ }
+
+ @Test
+ public void toGZIPInputStreamShouldReturnAByteArrayInputStream() throws IOException {
+ InputStream inputStream = GZIPHelper.toGZIPInputStream("text", sampleBytes);
+
+ byte[] bytes = IOConverter.toBytes(inputStream);
+ assertArrayEquals(sampleBytes, bytes);
+ }
+
+ @Test
+ public void testIsGzipMessage() {
+ assertTrue(GZIPHelper.isGzip(createMessageWithContentEncodingHeader("gzip")));
+ assertTrue(GZIPHelper.isGzip(createMessageWithContentEncodingHeader("GZip")));
+
+ assertFalse(GZIPHelper.isGzip(createMessageWithContentEncodingHeader(null)));
+ assertFalse(GZIPHelper.isGzip(createMessageWithContentEncodingHeader("zip")));
+ }
+
+ @Test
+ public void isGzipString() {
+ assertTrue(GZIPHelper.isGzip("gzip"));
+ assertTrue(GZIPHelper.isGzip("GZip"));
+
+ assertFalse(GZIPHelper.isGzip((String) null));
+ assertFalse(GZIPHelper.isGzip("zip"));
+ }
+
+ private Message createMessageWithContentEncodingHeader(String contentEncoding) {
+ Message msg = new DefaultMessage();
+ msg.setHeader("Content-Encoding", contentEncoding);
+
+ return msg;
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/GZIPHelperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/GZIPHelperTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpProducerHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpProducerHelperTest.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpProducerHelperTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpProducerHelperTest.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,167 @@
+/**
+ * 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.component.http.helper;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.http.HttpEndpoint;
+import org.apache.camel.component.http.HttpMethods;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class HttpProducerHelperTest {
+
+ @Test
+ public void createURLShouldReturnTheHeaderURIIfNotBridgeEndpoint() throws URISyntaxException {
+ String url = HttpProducerHelper.createURL(
+ createExchangeWithOptionalCamelHttpUriHeader("http://apache.org", null),
+ createHttpEndpoint(false, "http://camel.apache.org"));
+
+ assertEquals("http://apache.org", url);
+ }
+
+ @Test
+ public void createURLShouldReturnTheEndpointURIIfBridgeEndpoint() throws URISyntaxException {
+ String url = HttpProducerHelper.createURL(
+ createExchangeWithOptionalCamelHttpUriHeader("http://apache.org", null),
+ createHttpEndpoint(true, "http://camel.apache.org"));
+
+ assertEquals("http://camel.apache.org", url);
+ }
+
+ @Test
+ public void createURLShouldReturnTheEndpointURIIfNotBridgeEndpoint() throws URISyntaxException {
+ String url = HttpProducerHelper.createURL(
+ createExchangeWithOptionalCamelHttpUriHeader(null, null),
+ createHttpEndpoint(false, "http://camel.apache.org"));
+
+ assertEquals("http://camel.apache.org", url);
+ }
+
+ @Test
+ public void createURLShouldReturnTheEndpointURIWithHeaderHttpPathAndAddOneSlash() throws URISyntaxException {
+ String url = HttpProducerHelper.createURL(
+ createExchangeWithOptionalCamelHttpUriHeader(null, "search"),
+ createHttpEndpoint(true, "http://www.google.com"));
+
+ assertEquals("http://www.google.com/search", url);
+ }
+
+ @Test
+ public void createURLShouldReturnTheEndpointURIWithHeaderHttpPathAndRemoveOneSlash() throws URISyntaxException {
+ String url = HttpProducerHelper.createURL(
+ createExchangeWithOptionalCamelHttpUriHeader(null, "/search"),
+ createHttpEndpoint(true, "http://www.google.com/"));
+
+ assertEquals("http://www.google.com/search", url);
+ }
+
+ @Test
+ public void createMethodAlwaysUseUserChoosenMethod() throws URISyntaxException {
+ HttpMethods method = HttpProducerHelper.createMethod(
+ createExchangeWithOptionalHttpQueryAndHttpMethodHeader("q=camel", HttpMethods.POST),
+ createHttpEndpoint(true, "http://www.google.com/search"),
+ false);
+
+ assertEquals(HttpMethods.POST, method);
+ }
+
+ @Test
+ public void createMethodUseGETIfQueryIsProvidedInHeader() throws URISyntaxException {
+ HttpMethods method = HttpProducerHelper.createMethod(
+ createExchangeWithOptionalHttpQueryAndHttpMethodHeader("q=camel", null),
+ createHttpEndpoint(true, "http://www.google.com/search"),
+ false);
+
+ assertEquals(HttpMethods.GET, method);
+ }
+
+ @Test
+ public void createMethodUseGETIfQueryIsProvidedInEndpointURI() throws URISyntaxException {
+ HttpMethods method = HttpProducerHelper.createMethod(
+ createExchangeWithOptionalHttpQueryAndHttpMethodHeader(null, null),
+ createHttpEndpoint(true, "http://www.google.com/search?q=test"),
+ false);
+
+ assertEquals(HttpMethods.GET, method);
+ }
+
+ @Test
+ public void createMethodUseGETIfNoneQueryOrPayloadIsProvided() throws URISyntaxException {
+ HttpMethods method = HttpProducerHelper.createMethod(
+ createExchangeWithOptionalHttpQueryAndHttpMethodHeader(null, null),
+ createHttpEndpoint(true, "http://www.google.com/search"),
+ false);
+
+ assertEquals(HttpMethods.GET, method);
+ }
+
+ @Test
+ public void createMethodUsePOSTIfNoneQueryButPayloadIsProvided() throws URISyntaxException {
+ HttpMethods method = HttpProducerHelper.createMethod(
+ createExchangeWithOptionalHttpQueryAndHttpMethodHeader(null, null),
+ createHttpEndpoint(true, "http://www.google.com/search"),
+ true);
+
+ assertEquals(HttpMethods.POST, method);
+ }
+
+ private Exchange createExchangeWithOptionalHttpQueryAndHttpMethodHeader(String httpQuery, HttpMethods httpMethod) {
+ CamelContext context = new DefaultCamelContext();
+ Exchange exchange = new DefaultExchange(context);
+ Message inMsg = exchange.getIn();
+ if (httpQuery != null) {
+ inMsg.setHeader("CamelHttpQuery", httpQuery);
+ }
+ if (httpMethod != null) {
+ inMsg.setHeader("CamelHttpMethod", httpMethod);
+ }
+
+ return exchange;
+ }
+
+ private Exchange createExchangeWithOptionalCamelHttpUriHeader(String endpointURI, String httpPath) {
+ CamelContext context = new DefaultCamelContext();
+ Exchange exchange = new DefaultExchange(context);
+ Message inMsg = exchange.getIn();
+ if (endpointURI != null) {
+ inMsg.setHeader("CamelHttpUri", endpointURI);
+ }
+ if (httpPath != null) {
+ inMsg.setHeader("CamelHttpPath", httpPath);
+ }
+
+ return exchange;
+ }
+
+ private HttpEndpoint createHttpEndpoint(boolean bridgeEndpoint, String endpointURI) throws URISyntaxException {
+ HttpEndpoint endpoint = new HttpEndpoint();
+ endpoint.setBridgeEndpoint(bridgeEndpoint);
+ if (endpointURI != null) {
+ endpoint.setHttpUri(new URI(endpointURI));
+ }
+
+ return endpoint;
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpProducerHelperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpProducerHelperTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStreamTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStreamTest.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStreamTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStreamTest.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,79 @@
+/**
+ * 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.component.http.helper;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+public class LoadingByteArrayOutputStreamTest {
+
+ private LoadingByteArrayOutputStream out;
+ private byte[] bytes = new byte[]{1, 2, 3, 4, 5};
+
+ @Before
+ public void setUp() throws Exception {
+ out = new LoadingByteArrayOutputStream(4);
+ out.write(bytes);
+ }
+
+ @Test
+ public void defaultConstructor() {
+ out = new LoadingByteArrayOutputStream() {
+ public byte[] toByteArray() {
+ return buf;
+ }
+ };
+
+ assertEquals(1024, out.toByteArray().length);
+ }
+
+ @Test
+ public void toByteArrayShouldReturnTheSameArray() {
+ byte[] byteArray1 = out.toByteArray();
+ byte[] byteArray2 = out.toByteArray();
+
+ assertEquals(5, byteArray1.length);
+ assertSame(byteArray1, byteArray2);
+ }
+
+ @Test
+ public void toByteArrayShouldReturnANewArray() throws IOException {
+ byte[] byteArray1 = out.toByteArray();
+ out.write(bytes);
+ byteArray1 = out.toByteArray();
+
+ assertEquals(10, byteArray1.length);
+ }
+
+ @Test
+ public void createInputStream() {
+ ByteArrayInputStream in = out.createInputStream();
+
+ assertEquals(1, in.read());
+ assertEquals(2, in.read());
+ assertEquals(3, in.read());
+ assertEquals(4, in.read());
+ assertEquals(5, in.read());
+ assertEquals(-1, in.read());
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStreamTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/resources/log4j.properties?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/resources/log4j.properties (added)
+++ camel/trunk/components/camel-http/src/test/resources/log4j.properties Sat Apr 10 10:49:33 2010
@@ -0,0 +1,36 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used for testing.
+#
+log4j.rootLogger=INFO, file
+
+# uncomment the following to enable camel debugging
+log4j.logger.org.apache.camel.component.http=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+log4j.appender.file.file=target/camel-http-test.log
\ No newline at end of file
Propchange: camel/trunk/components/camel-http/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-http/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain