Author: bimargulies
Date: Sun Sep 6 12:34:08 2009
New Revision: 811823
URL: http://svn.apache.org/viewvc?rev=811823&view=rev
Log:
Add a quick interop test with the Jackson JSON provider.
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceJacksonSpringProviders.java
(with props)
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
(with props)
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
(with props)
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/web.xml
(with props)
Modified:
cxf/trunk/systests/jaxrs/pom.xml
Modified: cxf/trunk/systests/jaxrs/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/pom.xml?rev=811823&r1=811822&r2=811823&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/pom.xml (original)
+++ cxf/trunk/systests/jaxrs/pom.xml Sun Sep 6 12:34:08 2009
@@ -417,6 +417,16 @@
<artifactId>commons-httpclient</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-jaxrs</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-core-asl</artifactId>
+ <version>1.2.0</version>
+ </dependency>
</dependencies>
<properties>
<surefire.fork.mode>pertest</surefire.fork.mode>
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceJacksonSpringProviders.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceJacksonSpringProviders.java?rev=811823&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceJacksonSpringProviders.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceJacksonSpringProviders.java
Sun Sep 6 12:34:08 2009
@@ -0,0 +1,90 @@
+/**
+ * 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.cxf.systest.jaxrs;
+
+import java.net.URISyntaxException;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.handler.DefaultHandler;
+import org.mortbay.jetty.handler.HandlerCollection;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.webapp.WebAppContext;
+
+
+public class BookServerResourceJacksonSpringProviders extends
AbstractBusTestServerBase {
+
+ private org.mortbay.jetty.Server server;
+
+ protected void run() {
+ System.out.println("Starting Server");
+
+ server = new org.mortbay.jetty.Server();
+
+ SelectChannelConnector connector = new SelectChannelConnector();
+ connector.setPort(9080);
+ server.setConnectors(new Connector[] {connector});
+
+ WebAppContext webappcontext = new WebAppContext();
+ String contextPath = null;
+ try {
+ contextPath =
getClass().getResource("/jaxrs_jackson_provider").toURI().getPath();
+ } catch (URISyntaxException e1) {
+ e1.printStackTrace();
+ }
+ webappcontext.setContextPath("/webapp");
+
+ webappcontext.setWar(contextPath);
+
+ HandlerCollection handlers = new HandlerCollection();
+ handlers.setHandlers(new Handler[] {webappcontext, new
DefaultHandler()});
+
+ server.setHandler(handlers);
+ try {
+ server.start();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ if (server != null) {
+ server.stop();
+ server.destroy();
+ server = null;
+ }
+ }
+
+ public static void main(String args[]) {
+ try {
+ BookServerResourceJacksonSpringProviders s = new
BookServerResourceJacksonSpringProviders();
+ s.start();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(-1);
+ } finally {
+ System.out.println("done!");
+ }
+ }
+
+}
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceJacksonSpringProviders.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java?rev=811823&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
Sun Sep 6 12:34:08 2009
@@ -0,0 +1,181 @@
+/**
+ * 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.cxf.systest.jaxrs;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.Socket;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.List;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JAXRSClientServerResourceJacksonSpringProviderTest extends
AbstractBusClientServerTestBase {
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ assertTrue("server did not launch correctly",
+
launchServer(BookServerResourceJacksonSpringProviders.class));
+ }
+
+ @Test
+ public void testMultipleRootsWadl() throws Exception {
+ List<Element> resourceEls =
getWadlResourcesInfo("http://localhost:9080/webapp/",
+
"http://localhost:9080/webapp/", 2);
+ String path1 = resourceEls.get(0).getAttribute("path");
+ int bookStoreInd = path1.contains("/bookstore") ? 0 : 1;
+ int petStoreInd = bookStoreInd == 0 ? 1 : 0;
+ checkBookStoreInfo(resourceEls.get(bookStoreInd));
+ checkPetStoreInfo(resourceEls.get(petStoreInd));
+ }
+
+ @Test
+ public void testBookStoreWadl() throws Exception {
+ List<Element> resourceEls =
getWadlResourcesInfo("http://localhost:9080/webapp/",
+
"http://localhost:9080/webapp/bookstore", 1);
+ checkBookStoreInfo(resourceEls.get(0));
+ }
+
+ @Test
+ public void testPetStoreWadl() throws Exception {
+ List<Element> resourceEls =
getWadlResourcesInfo("http://localhost:9080/webapp/",
+
"http://localhost:9080/webapp/petstore", 1);
+ checkPetStoreInfo(resourceEls.get(0));
+ }
+
+ private void checkBookStoreInfo(Element resource) {
+ assertEquals("/bookstore", resource.getAttribute("path"));
+ }
+
+ private void checkPetStoreInfo(Element resource) {
+ assertEquals("/petstore/", resource.getAttribute("path"));
+ }
+
+ private List<Element> getWadlResourcesInfo(String baseURI, String
requestURI, int size) throws Exception {
+ WebClient client = WebClient.create(requestURI + "?_wadl&_type=xml");
+ Document doc = DOMUtils.readXml(new
InputStreamReader(client.get(InputStream.class), "UTF-8"));
+ Element root = doc.getDocumentElement();
+ assertEquals("http://research.sun.com/wadl/2006/10",
root.getNamespaceURI());
+ assertEquals("application", root.getLocalName());
+ List<Element> resourcesEls = DOMUtils.getChildrenWithName(root,
+
"http://research.sun.com/wadl/2006/10", "resources");
+ assertEquals(1, resourcesEls.size());
+ Element resourcesEl = resourcesEls.get(0);
+ assertEquals(baseURI, resourcesEl.getAttribute("base"));
+ List<Element> resourceEls =
+ DOMUtils.getChildrenWithName(resourcesEl,
+
"http://research.sun.com/wadl/2006/10", "resource");
+ assertEquals(size, resourceEls.size());
+ return resourceEls;
+ }
+
+ @Test
+ public void testGetBook123() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:9080/webapp/bookstore/books/123";
+ URL url = new URL(endpointAddress);
+ URLConnection connect = url.openConnection();
+ connect.addRequestProperty("Accept", "application/json");
+ InputStream in = connect.getInputStream();
+ assertNotNull(in);
+
+ assertEquals("Jackson output not correct",
+ "{\"name\":\"CXF in Action\",\"id\":123}",
+ getStringFromInputStream(in).trim());
+ }
+
+ @Test
+ public void testPostPetStatus() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:9080/webapp/petstore/pets";
+
+ URL url = new URL(endpointAddress);
+ HttpURLConnection httpUrlConnection =
(HttpURLConnection)url.openConnection();
+
+ httpUrlConnection.setUseCaches(false);
+ httpUrlConnection.setDefaultUseCaches(false);
+ httpUrlConnection.setDoOutput(true);
+ httpUrlConnection.setDoInput(true);
+ httpUrlConnection.setRequestMethod("POST");
+ httpUrlConnection.setRequestProperty("Accept", "text/xml");
+ httpUrlConnection.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
+ httpUrlConnection.setRequestProperty("Connection", "close");
+
+ OutputStream outputstream = httpUrlConnection.getOutputStream();
+ File inputFile = new
File(getClass().getResource("resources/singleValPostBody.txt").toURI());
+
+ byte[] tmp = new byte[4096];
+ int i = 0;
+ InputStream is = new FileInputStream(inputFile);
+ try {
+ while ((i = is.read(tmp)) >= 0) {
+ outputstream.write(tmp, 0, i);
+ }
+ } finally {
+ is.close();
+ }
+
+ outputstream.flush();
+
+ int responseCode = httpUrlConnection.getResponseCode();
+ assertEquals(200, responseCode);
+ assertEquals("Wrong status returned", "open",
getStringFromInputStream(httpUrlConnection
+ .getInputStream()));
+ httpUrlConnection.disconnect();
+ }
+
+ @Test
+ public void testPostPetStatus2() throws Exception {
+
+
+ Socket s = new Socket("localhost", 9080);
+
IOUtils.copyAndCloseInput(getClass().getResource("resources/formRequest.txt").openStream(),
+ s.getOutputStream());
+
+ s.getOutputStream().flush();
+ try {
+ assertTrue("Wrong status returned",
getStringFromInputStream(s.getInputStream())
+ .contains("open"));
+ } finally {
+ s.close();
+ }
+ }
+
+ private String getStringFromInputStream(InputStream in) throws Exception {
+ return IOUtils.toString(in);
+ }
+
+}
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml?rev=811823&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
(added)
+++
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
Sun Sep 6 12:34:08 2009
@@ -0,0 +1,41 @@
+<?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"
+ xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans
+http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxrs
+http://cxf.apache.org/schemas/jaxrs.xsd">
+
+ <jaxrs:server id="bookservice"
+ address="/">
+ <jaxrs:serviceBeans>
+ <ref bean="petstore"/>
+ <ref bean="bookstore"/>
+ </jaxrs:serviceBeans>
+ <jaxrs:providers>
+ <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
+ </jaxrs:providers>
+ </jaxrs:server>
+ <bean id="bookstore" scope="prototype"
class="org.apache.cxf.systest.jaxrs.BookStore"/>
+ <bean id="petstore" scope="prototype"
class="org.apache.cxf.systest.jaxrs.PetStore"/>
+</beans>
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/web.xml?rev=811823&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/web.xml
(added)
+++
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/web.xml
Sun Sep 6 12:34:08 2009
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<!--
+ 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.
+-->
+<!-- START SNIPPET: webxml -->
+<web-app>
+
+ <servlet>
+ <servlet-name>CXFServlet</servlet-name>
+ <display-name>CXF Servlet</display-name>
+ <servlet-class>
+ org.apache.cxf.transport.servlet.CXFServlet
+ </servlet-class>
+ <init-param>
+ <param-name>config-location</param-name>
+ <param-value>/WEB-INF/beans.xml</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>CXFServlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
+<!-- END SNIPPET: webxml -->
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml