You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2008/09/30 17:55:56 UTC

svn commit: r700513 - in /activemq/camel/trunk/components/camel-rest: ./ src/main/java/org/apache/camel/rest/resources/ src/main/java/org/apache/camel/rest/util/ src/main/webapp/WEB-INF/ src/main/webapp/org/apache/camel/rest/model/Endpoints/ src/test/j...

Author: jstrachan
Date: Tue Sep 30 08:55:55 2008
New Revision: 700513

URL: http://svn.apache.org/viewvc?rev=700513&view=rev
Log:
added better tests for the REST support

Added:
    activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/CamelResourceConfig.java   (with props)
    activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsHtmlTest.java   (contents, props changed)
      - copied, changed from r700455, activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsTest.java
Removed:
    activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/CamelContextResourceTest.java
Modified:
    activemq/camel/trunk/components/camel-rest/pom.xml
    activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java
    activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/JAXBContextResolver.java
    activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml
    activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/model/Endpoints/index.jsp
    activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsTest.java
    activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/TestSupport.java

Modified: activemq/camel/trunk/components/camel-rest/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/pom.xml?rev=700513&r1=700512&r2=700513&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/pom.xml (original)
+++ activemq/camel/trunk/components/camel-rest/pom.xml Tue Sep 30 08:55:55 2008
@@ -160,6 +160,7 @@
           </includes>
           <excludes>
             <!-- TODO FIXME ASAP -->
+            <exclude>**/EndpointsHtmlTest.*</exclude>
             <exclude>**/RoutesTest.*</exclude>
           </excludes>
         </configuration>

Modified: activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java?rev=700513&r1=700512&r2=700513&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java (original)
+++ activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java Tue Sep 30 08:55:55 2008
@@ -64,7 +64,7 @@
      */
     @GET
     @Path("endpoints")
-    public Endpoints getEndpoints() {
+    public Endpoints getEndpoint() {
         return new Endpoints(camelContext);
     }
 
@@ -72,7 +72,7 @@
      * Looks up an individual endpoint
      */
     @GET
-    @Path("endpoints/{id}")
+    @Path("endpoint/{id}")
     public EndpointResource getEndpoint(@PathParam("id") String id) {
         // TODO lets assume the ID is the endpoint
         Endpoint endpoint = getCamelContext().getEndpoint(id);

Added: activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/CamelResourceConfig.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/CamelResourceConfig.java?rev=700513&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/CamelResourceConfig.java (added)
+++ activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/CamelResourceConfig.java Tue Sep 30 08:55:55 2008
@@ -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.rest.util;
+
+import com.sun.jersey.api.core.PackagesResourceConfig;
+
+import javax.ws.rs.core.MediaType;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class CamelResourceConfig extends PackagesResourceConfig {
+    public CamelResourceConfig() {
+        super("org.apache.camel.rest");
+    }
+
+    public Map<String, MediaType> getMediaTypeMappings() {
+        Map<String, MediaType> m = new HashMap<String, MediaType>();
+        m.put("html", MediaType.TEXT_HTML_TYPE);
+        m.put("xml", MediaType.APPLICATION_XML_TYPE);
+        m.put("json", MediaType.APPLICATION_JSON_TYPE);
+        return m;
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/CamelResourceConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/JAXBContextResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/JAXBContextResolver.java?rev=700513&r1=700512&r2=700513&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/JAXBContextResolver.java (original)
+++ activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/util/JAXBContextResolver.java Tue Sep 30 08:55:55 2008
@@ -42,7 +42,7 @@
 
     public JAXBContextResolver() throws Exception {
         Map<String, Object> props = new HashMap<String, Object>();
-        props.put(JSONJAXBContext.JSON_NOTATION, "MAPPED");
+        //props.put(JSONJAXBContext.JSON_NOTATION, "MAPPED");
         props.put(JSONJAXBContext.JSON_ROOT_UNWRAPPING, Boolean.TRUE);
         props.put(JSONJAXBContext.JSON_NON_STRINGS, "[\"number\"]");
 

Modified: activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml?rev=700513&r1=700512&r2=700513&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml (original)
+++ activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml Tue Sep 30 08:55:55 2008
@@ -60,8 +60,14 @@
     <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
     <init-param>
       <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
+      <param-value>org.apache.camel.rest.util.CamelResourceConfig</param-value>
+    </init-param>
+<!--
+    <init-param>
+      <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
       <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
     </init-param>
+-->
     <init-param>
       <param-name>com.sun.jersey.config.property.packages</param-name>
       <param-value>org.apache.camel.rest</param-value>

Modified: activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/model/Endpoints/index.jsp
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/model/Endpoints/index.jsp?rev=700513&r1=700512&r2=700513&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/model/Endpoints/index.jsp (original)
+++ activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/model/Endpoints/index.jsp Tue Sep 30 08:55:55 2008
@@ -2,7 +2,6 @@
 <%@page pageEncoding="UTF-8" %>
 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
 <html>
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

Copied: activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsHtmlTest.java (from r700455, activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsHtmlTest.java?p2=activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsHtmlTest.java&p1=activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsTest.java&r1=700455&r2=700513&rev=700513&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsTest.java (original)
+++ activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsHtmlTest.java Tue Sep 30 08:55:55 2008
@@ -20,19 +20,17 @@
 
 import org.apache.camel.rest.model.EndpointLink;
 import org.apache.camel.rest.model.Endpoints;
+import com.sun.jersey.api.client.WebResource;
 
 /**
  * @version $Revision$
  */
-public class EndpointsTest extends TestSupport {
+public class EndpointsHtmlTest extends TestSupport {
 
-    public void testEndpoints() throws Exception {
-        Endpoints endpoints = resource.path("endpoints").accept("application/xml").get(Endpoints.class);
-        assertNotNull("Should have found endpoints", endpoints);
+    public void testEndpointsAsHtml() throws Exception {
+        String response = resource("endpoints").accept("text/html").get(String.class);
 
-        System.out.println("Found: " + endpoints.getEndpoints());
-
-        List<EndpointLink> list = endpoints.getEndpoints();
-        assertTrue("Should have received some endpoints!", !list.isEmpty());
+        assertTrue("Should contain <html> but was: " + response, response.contains("<html>"));
     }
+
 }
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsHtmlTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsHtmlTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsHtmlTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsTest.java?rev=700513&r1=700512&r2=700513&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsTest.java (original)
+++ activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/EndpointsTest.java Tue Sep 30 08:55:55 2008
@@ -20,14 +20,24 @@
 
 import org.apache.camel.rest.model.EndpointLink;
 import org.apache.camel.rest.model.Endpoints;
+import com.sun.jersey.api.client.WebResource;
 
 /**
  * @version $Revision$
  */
 public class EndpointsTest extends TestSupport {
 
-    public void testEndpoints() throws Exception {
-        Endpoints endpoints = resource.path("endpoints").accept("application/xml").get(Endpoints.class);
+    public void testEndpointsAsXml() throws Exception {
+        Endpoints endpoints = resource("endpoints").accept("application/xml").get(Endpoints.class);
+        assertValidEndpoints(endpoints);
+
+        endpoints = resource("endpoints.xml").get(Endpoints.class);
+        assertValidEndpoints(endpoints);
+    }
+
+    // TODO test as JSON
+    
+    protected void assertValidEndpoints(Endpoints endpoints) {
         assertNotNull("Should have found endpoints", endpoints);
 
         System.out.println("Found: " + endpoints.getEndpoints());

Modified: activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/TestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/TestSupport.java?rev=700513&r1=700512&r2=700513&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/TestSupport.java (original)
+++ activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/TestSupport.java Tue Sep 30 08:55:55 2008
@@ -16,14 +16,13 @@
  */
 package org.apache.camel.rest.resources;
 
-import junit.framework.TestCase;
-
 import com.sun.jersey.api.client.Client;
 import com.sun.jersey.api.client.WebResource;
 import com.sun.jersey.api.client.config.ClientConfig;
 import com.sun.jersey.api.client.config.DefaultClientConfig;
-
+import junit.framework.TestCase;
 import org.apache.camel.rest.Main;
+
 /**
  * @version $Revision$
  */
@@ -45,6 +44,11 @@
         resource = client.resource("http://localhost:" + port + Main.WEBAPP_CTX);
     }
 
+    protected WebResource resource(String uri) {
+        System.out.println("About to test URI: " + uri);
+        return resource.path(uri);
+    }
+
     @Override
     protected void tearDown() throws Exception {
         super.tearDown();