Author: sergeyb
Date: Fri Oct 17 06:34:11 2008
New Revision: 705614

URL: http://svn.apache.org/viewvc?rev=705614&view=rev
Log:
JAX-RS : starting with a jaxrs-jaxws system testing

Added:
    
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerRestSoap.java
   (with props)
    
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSoapService.java
   (with props)
    
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
   (with props)
    
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
   (with props)
    
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
   (with props)
    cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/
    cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/
    cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml   
(with props)
    cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml   
(with props)

Added: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerRestSoap.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerRestSoap.java?rev=705614&view=auto
==============================================================================
--- 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerRestSoap.java
 (added)
+++ 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerRestSoap.java
 Fri Oct 17 06:34:11 2008
@@ -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 BookServerRestSoap 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(9092);
+        server.setConnectors(new Connector[] {connector});
+
+        WebAppContext webappcontext = new WebAppContext();
+        String contextPath = null;
+        try {
+            contextPath = 
getClass().getResource("/jaxrs_soap_rest").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 void tearDown() throws Exception {
+        super.tearDown();
+        if (server != null) {
+            server.stop();
+            server.destroy();
+            server = null;
+        }
+    }    
+    
+    public static void main(String args[]) {
+        try {
+            BookServerRestSoap s = new BookServerRestSoap();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+
+}

Propchange: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerRestSoap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerRestSoap.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSoapService.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSoapService.java?rev=705614&view=auto
==============================================================================
--- 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSoapService.java
 (added)
+++ 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSoapService.java
 Fri Oct 17 06:34:11 2008
@@ -0,0 +1,48 @@
+/**
+ * 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.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebEndpoint;
+import javax.xml.ws.WebServiceClient;
+
+/**
+ * 
+ */
+
[EMAIL PROTECTED](name = "BookService", 
+                  targetNamespace = "http://books.com";)
+public class BookSoapService extends Service {
+    static final QName SERVICE = new QName("http://books.com";, "BookService");
+    static final QName BOOK_PORT = 
+        new QName("http://books.com";, "BookPort");
+    public BookSoapService(URL wsdlLocation, QName serviceName) {
+        super(wsdlLocation, serviceName);
+    }
+
+    @WebEndpoint(name = "BookPort")
+    public BookStoreJaxrsJaxws getBookPort() {
+        return (BookStoreJaxrsJaxws)super.getPort(BOOK_PORT, 
+                                                  BookStoreJaxrsJaxws.class);
+    }
+
+}

Propchange: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSoapService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSoapService.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java?rev=705614&view=auto
==============================================================================
--- 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
 (added)
+++ 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
 Fri Oct 17 06:34:11 2008
@@ -0,0 +1,38 @@
+/**
+ * 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 javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED]("/bookstore")
+public interface BookStoreJaxrsJaxws {
+    
+    @WebMethod
+    @GET
+    @Path("/{id}")
+    Book getBook(@PathParam("id") @WebParam(name = "id") Long id);
+
+}

Propchange: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java?rev=705614&view=auto
==============================================================================
--- 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
 (added)
+++ 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
 Fri Oct 17 06:34:11 2008
@@ -0,0 +1,46 @@
+/**
+ * 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.util.HashMap;
+import java.util.Map;
+
+import javax.jws.WebService;
+
[EMAIL PROTECTED]
+public class BookStoreSoapRestImpl implements BookStoreJaxrsJaxws {
+
+    private Map<Long, Book> books = new HashMap<Long, Book>();
+    
+    public BookStoreSoapRestImpl() {
+        init();
+    }
+    
+    public Book getBook(Long id) {
+        return books.get(id);
+    }
+
+    private void init() {
+        Book book = new Book();
+        book.setId(new Long(123));
+        book.setName("CXF in Action");
+        books.put(book.getId(), book);
+    }
+}

Propchange: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java?rev=705614&view=auto
==============================================================================
--- 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
 (added)
+++ 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
 Fri Oct 17 06:34:11 2008
@@ -0,0 +1,79 @@
+/**
+ * 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 java.net.URLConnection;
+
+import javax.xml.namespace.QName;
+
+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 JaxRsJaxWsBookTest extends AbstractBusClientServerTestBase {
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", 
+                   launchServer(BookServerRestSoap.class));
+    }
+    
+    @Test
+    public void testGetBook123() throws Exception {
+        String endpointAddress =
+            "http://localhost:9092/rest/bookstore/123";; 
+        URL url = new URL(endpointAddress);
+        URLConnection connect = url.openConnection();
+        connect.addRequestProperty("Accept", "application/xml");
+        InputStream in = connect.getInputStream();           
+
+        InputStream expected = getClass()
+            .getResourceAsStream("resources/expected_get_book123.txt");
+
+        assertEquals(getStringFromInputStream(expected), 
getStringFromInputStream(in));
+    }
+    
+    @Test
+    public void testGetBookSoap() throws Exception {
+        String wsdlAddress =
+            "http://localhost:9092/soap/bookservice?wsdl";; 
+        URL wsdlUrl = new URL(wsdlAddress);
+        BookSoapService service = 
+            new BookSoapService(wsdlUrl,
+                                new QName("http://books.com";, "BookService"));
+        BookStoreJaxrsJaxws store = service.getBookPort();
+        Book book = store.getBook(new Long(123));
+        assertEquals("id is wrong", book.getId(), 123);
+    }
+
+    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: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml?rev=705614&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml 
(added)
+++ cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml Fri 
Oct 17 06:34:11 2008
@@ -0,0 +1,49 @@
+<?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:jaxrs="http://cxf.apache.org/jaxrs";
+  xmlns:jaxws="http://cxf.apache.org/jaxws";
+  xsi:schemaLocation="http://www.springframework.org/schema/beans 
+http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxws
+http://cxf.apache.org/schemas/jaxws.xsd
+http://cxf.apache.org/jaxrs
+http://cxf.apache.org/schemas/jaxrs.xsd";>
+
+   <jaxws:endpoint xmlns:s="http://books.com";
+      serviceName="s:BookService"
+      endpointName="s:BookPort"
+      id="soapservice"
+      implementor="#bookstore"
+      address="http://localhost:9092/soap/bookservice"; />
+  
+  <jaxrs:server id="restservice"
+                       address="http://localhost:9092/rest";>
+    <jaxrs:serviceBeans>
+      <ref bean="bookstore"/>
+    </jaxrs:serviceBeans>                 
+  </jaxrs:server>
+  <bean id="bookstore" 
class="org.apache.cxf.systest.jaxrs.BookStoreSoapRestImpl">
+  </bean>
+
+</beans>
+<!-- END SNIPPET: beans -->

Propchange: 
cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml?rev=705614&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml 
(added)
+++ cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml Fri 
Oct 17 06:34:11 2008
@@ -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: 
cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
cxf/trunk/systests/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to