Author: jliu
Date: Mon Nov 5 00:37:39 2007
New Revision: 591911
URL: http://svn.apache.org/viewvc?rev=591911&view=rev
Log:
CXF-1004: Added a system test that creates resource instances by Spring, then
pass the instance to JAX-RS runtime.
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedOutside.java
- copied, changed from r591869,
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedSpring.java
(with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java
- copied, changed from r591869,
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
(with props)
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/beans.xml
(with props)
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/web.xml
(with props)
Removed:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Copied:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedOutside.java
(from r591869,
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java)
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedOutside.java?p2=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedOutside.java&p1=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java&r1=591869&r2=591911&rev=591911&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedOutside.java
Mon Nov 5 00:37:39 2007
@@ -22,7 +22,7 @@
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
-public class BookServerFromResourceInstance extends AbstractBusTestServerBase {
+public class BookServerResourceCreatedOutside extends
AbstractBusTestServerBase {
protected void run() {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedSpring.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedSpring.java?rev=591911&view=auto
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedSpring.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedSpring.java
Mon Nov 5 00:37:39 2007
@@ -0,0 +1,89 @@
+/**
+ * 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 BookServerResourceCreatedSpring 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_spring").toURI().getPath();
+ } catch (URISyntaxException e1) {
+ e1.printStackTrace();
+ }
+ webappcontext.setContextPath("/");
+
+ 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 boolean stopInProcess() throws Exception {
+ boolean ret = super.stopInProcess();
+ if (server != null) {
+ server.stop();
+ }
+ return ret;
+ }
+
+ public static void main(String args[]) {
+ try {
+ BookServerResourceCreatedSpring s = new
BookServerResourceCreatedSpring();
+ s.start();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(-1);
+ } finally {
+ System.out.println("done!");
+ }
+ }
+
+}
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedSpring.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerResourceCreatedSpring.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=591911&r1=591910&r2=591911&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Mon Nov 5 00:37:39 2007
@@ -53,7 +53,7 @@
return books;
} */
-
+
@HttpMethod("GET")
@UriTemplate("/books/{bookId}/")
public Book getBook(@UriParam("bookId") String id) throws
BookNotFoundFault {
Copied:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java
(from r591869,
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java)
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java?p2=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java&p1=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java&r1=591869&r2=591911&rev=591911&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java
Mon Nov 5 00:37:39 2007
@@ -31,11 +31,11 @@
import org.junit.BeforeClass;
import org.junit.Test;
-public class JAXRSClientServerFromResourceInstanceBookTest extends
AbstractBusClientServerTestBase {
+public class JAXRSClientServerResourceCreatedOutsideBookTest extends
AbstractBusClientServerTestBase {
@BeforeClass
public static void startServers() throws Exception {
- assertTrue("server did not launch correctly",
launchServer(BookServerFromResourceInstance.class));
+ assertTrue("server did not launch correctly",
launchServer(BookServerResourceCreatedOutside.class));
}
@Test
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java?rev=591911&view=auto
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
Mon Nov 5 00:37:39 2007
@@ -0,0 +1,62 @@
+/**
+ * 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.InputStream;
+import java.net.URL;
+
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JAXRSClientServerResourceCreatedSpringBookTest extends
AbstractBusClientServerTestBase {
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ assertTrue("server did not launch correctly",
launchServer(BookServerResourceCreatedOutside.class));
+ }
+
+ @Test
+ public void testGetBook123() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:9080/bookstore/books/123";
+ URL url = new URL(endpointAddress);
+ InputStream in = url.openStream();
+ assertNotNull(in);
+
+ InputStream expected = getClass()
+ .getResourceAsStream("resources/expected_get_book123.txt");
+
+ assertEquals(getStringFromInputStream(expected),
getStringFromInputStream(in));
+ }
+
+ private String getStringFromInputStream(InputStream in) throws Exception {
+ CachedOutputStream bos = new CachedOutputStream();
+ IOUtils.copy(in, bos);
+ in.close();
+ bos.close();
+ //System.out.println(bos.getOut().toString());
+ return bos.getOut().toString();
+ }
+
+}
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/beans.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/beans.xml?rev=591911&view=auto
==============================================================================
---
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/beans.xml
(added)
+++
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/beans.xml
Mon Nov 5 00:37:39 2007
@@ -0,0 +1,50 @@
+<?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.
+-->
+<!-- START SNIPPET: beans -->
+<!--beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:simple="http://cxf.apache.org/simple"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd"-->
+<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">
+
+ <import resource="classpath:META-INF/cxf/cxf.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
+
+ <jaxrs:server id="bookservice"
+ address="/">
+ <jaxrs:serviceBeans>
+ <ref bean="bookstore"/>
+ </jaxrs:serviceBeans>
+ </jaxrs:server>
+ <bean id="bookstore" scope="prototype"
class="org.apache.cxf.systest.jaxrs.BookStore">
+ </bean>
+
+</beans>
+<!-- END SNIPPET: beans -->
Propchange:
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/web.xml?rev=591911&view=auto
==============================================================================
---
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/web.xml
(added)
+++
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/web.xml
Mon Nov 5 00:37:39 2007
@@ -0,0 +1,52 @@
+<?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>
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>WEB-INF/beans.xml</param-value>
+ </context-param>
+
+ <listener>
+ <listener-class>
+ org.springframework.web.context.ContextLoaderListener
+ </listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>CXFServlet</servlet-name>
+ <display-name>CXF Servlet</display-name>
+ <servlet-class>
+ org.apache.cxf.transport.servlet.CXFServlet
+ </servlet-class>
+ <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:
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
incubator/cxf/trunk/systests/src/test/resources/jaxrs_spring/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml