svn commit: r702150 - in /activemq/camel/trunk/tests/camel-itest/src/test: java/org/apache/camel/itest/jetty/ resources/ resources/org/apache/camel/itest/jetty/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r702150 - in /activemq/camel/trunk/tests/camel-itest/src/test: java/org/apache/camel/itest/jetty/ resources/ resources/org/apache/camel/itest/jetty/

ningjiang
Author: ningjiang
Date: Mon Oct  6 07:06:55 2008
New Revision: 702150

URL: http://svn.apache.org/viewvc?rev=702150&view=rev
Log:
CAMEL-877 added an integrate test

Added:
    activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/HttpClient.java   (with props)
    activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyValidatorTest.java   (with props)
    activemq/camel/trunk/tests/camel-itest/src/test/resources/OptimizationRequest.xsd   (with props)
    activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/InvalidRequest.xml   (with props)
    activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/ValidRequest.xml   (with props)

Added: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/HttpClient.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/HttpClient.java?rev=702150&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/HttpClient.java (added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/HttpClient.java Mon Oct  6 07:06:55 2008
@@ -0,0 +1,81 @@
+/**
+ * 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.jetty;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/**
+ * An <code>HttpClient</code> is an example on how one would connect to an
+ * HTTP endpoint. To use this <code>HttpClient</code>, you must:
+ * <ol>
+ * <li> specify the URL of the location URI of the HTTP endpoint you wish to
+ * connect to, and </li>
+ * <li> specify the xml file name in your classpath that you wish to send to the
+ * endpoint</li>
+ * </ol>
+ */
+public class HttpClient {
+    private static String httpEndpoint = "http://localhost:8192/test";
+
+    public static String send(String content) throws Exception, IOException {
+        return send(new ByteArrayInputStream(content.getBytes()));
+    }
+
+    public static String send(InputStream inputStream) throws Exception, IOException {
+        HttpURLConnection connection = getHttpConnection();
+        connection.setDoOutput(true);
+        OutputStream sender = connection.getOutputStream();
+        byte[] inBuffer = new byte[256];
+        for (int numBytesRead = inputStream.read(inBuffer); numBytesRead != -1; numBytesRead = inputStream
+            .read(inBuffer)) {
+            sender.write(inBuffer, 0, numBytesRead);
+        }
+        sender.close();
+        inputStream.close();
+        /*System.out.println("HTTP response code is: "
+                 + connection.getResponseCode() + ". The status message is: "
+                 + connection.getResponseMessage());*/
+
+        // Read the response.
+        InputStreamReader responseInputStream = new InputStreamReader(connection.getInputStream());
+        BufferedReader receiver = new BufferedReader(responseInputStream);
+        String response = "";
+        String line;
+        while ((line = receiver.readLine()) != null) {
+            response += line;
+        }
+        response = response.replace("&lt;", "<");
+        receiver.close();
+        return response;
+    }
+
+    private static HttpURLConnection getHttpConnection() throws Exception {
+        HttpURLConnection connection = (HttpURLConnection)new URL(httpEndpoint).openConnection();
+        return connection;
+    }
+
+    public void setHttpEndpoint(String endpointURI) {
+        httpEndpoint = endpointURI;
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/HttpClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/HttpClient.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyValidatorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyValidatorTest.java?rev=702150&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyValidatorTest.java (added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyValidatorTest.java Mon Oct  6 07:06:55 2008
@@ -0,0 +1,64 @@
+/**
+ * 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.jetty;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.ValidationException;
+import org.apache.camel.builder.RouteBuilder;
+
+public class JettyValidatorTest extends ContextTestSupport {
+
+    public void testValideRequest() throws Exception {
+        InputStream inputStream = HttpClient.class.getResourceAsStream("ValidRequest.xml");
+        assertNotNull("the inputStream should not be null", inputStream);
+        String response = HttpClient.send(inputStream);
+        assertEquals("The response should be ok", response, "<ok/>");
+    }
+
+    public void testInvalideRequest() throws Exception {
+        InputStream inputStream = HttpClient.class.getResourceAsStream("InvalidRequest.xml");
+        assertNotNull("the inputStream should not be null", inputStream);
+        String response = HttpClient.send(inputStream);
+        assertEquals("The response should be error", response, "<error/>");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("jetty:http://localhost:8192/test")
+                    .setBody(body(String.class))
+                    .to("log:in")
+                    .tryBlock()
+                        .to("validator:OptimizationRequest.xsd")
+                        .setBody(constant("<ok/>"))
+                    .handle(ValidationException.class)
+                    .setBody(constant("<error/>"))
+                    .end()
+                    .to("log:out");
+            }
+        };
+    }
+
+}

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/tests/camel-itest/src/test/resources/OptimizationRequest.xsd
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/resources/OptimizationRequest.xsd?rev=702150&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/resources/OptimizationRequest.xsd (added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/resources/OptimizationRequest.xsd Mon Oct  6 07:06:55 2008
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema
+ targetNamespace="http://test"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:typens="http://test"
+ elementFormDefault="qualified">
+ <xsd:element name="OptimizationRequestGroup">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="OptimizationRequest" type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+</xsd:schema>
\ No newline at end of file

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/OptimizationRequest.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/OptimizationRequest.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/OptimizationRequest.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/InvalidRequest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/InvalidRequest.xml?rev=702150&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/InvalidRequest.xml (added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/InvalidRequest.xml Mon Oct  6 07:06:55 2008
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<typens:OptimizationRequestGroups xmlns:typens="http://test">
+  <typens:OptimizationRequest>XXX
+  </typens:OptimizationRequest>
+</typens:OptimizationRequestGroups>

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/InvalidRequest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/InvalidRequest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/InvalidRequest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/ValidRequest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/ValidRequest.xml?rev=702150&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/ValidRequest.xml (added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/ValidRequest.xml Mon Oct  6 07:06:55 2008
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<typens:OptimizationRequestGroup xmlns:typens="http://test">
+  <typens:OptimizationRequest>XXX
+  </typens:OptimizationRequest>
+</typens:OptimizationRequestGroup>

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/ValidRequest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/ValidRequest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/ValidRequest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml