Author: davsclaus
Date: Tue Oct 20 10:40:10 2009
New Revision: 827027
URL: http://svn.apache.org/viewvc?rev=827027&view=rev
Log:
MR-194: Added more unit tests.
Added:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java
(with props)
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java
(with props)
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
(with props)
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java?rev=827027&r1=827026&r2=827027&view=diff
==============================================================================
---
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
(original)
+++
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
Tue Oct 20 10:40:10 2009
@@ -18,7 +18,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.nio.ByteBuffer;
import org.apache.camel.Converter;
import org.apache.camel.Exchange;
@@ -34,11 +33,6 @@
public class RequestEntityConverter {
@Converter
- public RequestEntity toRequestEntity(ByteBuffer buffer, Exchange exchange)
throws Exception {
- return asRequestEntity(buffer.array(), exchange);
- }
-
- @Converter
public RequestEntity toRequestEntity(byte[] data, Exchange exchange)
throws Exception {
return asRequestEntity(data, exchange);
}
Added:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java?rev=827027&view=auto
==============================================================================
---
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java
(added)
+++
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java
Tue Oct 20 10:40:10 2009
@@ -0,0 +1,45 @@
+/**
+ * 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.jetty;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpProducerByteTest extends CamelTestSupport {
+
+ @Test
+ public void testHttpProducerByteTest() throws Exception {
+ byte[] data = "Hello World".getBytes();
+ String out = template.requestBody("http://localhost:9080/test", data,
String.class);
+ assertEquals("Bye World", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from("jetty://http://localhost:9080/test").transform(constant("Bye World"));
+ }
+ };
+ }
+
+}
Propchange:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java?rev=827027&view=auto
==============================================================================
---
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java
(added)
+++
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java
Tue Oct 20 10:40:10 2009
@@ -0,0 +1,60 @@
+/**
+ * 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.jetty;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpOperationFailedException;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpRedirectNoLocationTest extends CamelTestSupport {
+
+ @Test
+ public void testHttpRedirectNoLocation() throws Exception {
+ try {
+ template.requestBody("http://localhost:9080/test", "Hello World",
String.class);
+ fail("Should have thrown an exception");
+ } catch (RuntimeCamelException e) {
+ HttpOperationFailedException cause =
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
+ assertEquals(302, cause.getStatusCode());
+ assertEquals(true, cause.isRedirectError());
+ assertEquals(false, cause.hasRedirectLocation());
+ assertEquals(null, cause.getRedirectLocation());
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("jetty://http://localhost:9080/test")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302);
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java?rev=827027&view=auto
==============================================================================
---
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
(added)
+++
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
Tue Oct 20 10:40:10 2009
@@ -0,0 +1,61 @@
+/**
+ * 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.jetty;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpOperationFailedException;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpRedirectTest extends CamelTestSupport {
+
+ @Test
+ public void testHttpRedirect() throws Exception {
+ try {
+ template.requestBody("http://localhost:9080/test", "Hello World",
String.class);
+ fail("Should have thrown an exception");
+ } catch (RuntimeCamelException e) {
+ HttpOperationFailedException cause =
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
+ assertEquals(301, cause.getStatusCode());
+ assertEquals(true, cause.isRedirectError());
+ assertEquals(true, cause.hasRedirectLocation());
+ assertEquals("http://localhost:9080/newtest",
cause.getRedirectLocation());
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("jetty://http://localhost:9080/test")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 301);
+ exchange.getOut().setHeader("location",
"http://localhost:9080/newtest");
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date