You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/12/02 17:50:25 UTC

svn commit: r1547102 - in /cxf/trunk/systests/jaxrs/src/test: java/org/apache/cxf/systest/jaxrs/validation/spring/ resources/jaxrs_spring_validation/WEB-INF/

Author: sergeyb
Date: Mon Dec  2 16:50:25 2013
New Revision: 1547102

URL: http://svn.apache.org/r1547102
Log:
[CXF-5308] Adding a basic test showing the same bean validated on RS & WS paths

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorld.java   (with props)
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorldImpl.java   (with props)
Modified:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorld.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorld.java?rev=1547102&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorld.java (added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorld.java Mon Dec  2 16:50:25 2013
@@ -0,0 +1,40 @@
+/**
+ * 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.validation.spring;
+
+import javax.jws.WebService;
+import javax.validation.Valid;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.apache.cxf.systest.jaxrs.validation.BookWithValidation;
+
+@WebService(targetNamespace = "http://bookworld.com")
+@Path("/")
+public interface BookWorld {
+
+    @POST
+    @Produces("text/xml")
+    @Consumes("text/xml")
+    @Valid
+    BookWithValidation echoBook(@Valid BookWithValidation book);
+
+}

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

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

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorldImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorldImpl.java?rev=1547102&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorldImpl.java (added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookWorldImpl.java Mon Dec  2 16:50:25 2013
@@ -0,0 +1,35 @@
+/**
+ * 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: service
+package org.apache.cxf.systest.jaxrs.validation.spring;
+
+import javax.jws.WebService;
+
+import org.apache.cxf.systest.jaxrs.validation.BookWithValidation;
+
+@WebService(endpointInterface = "org.apache.cxf.systest.jaxrs.validation.spring.BookWorld",
+            serviceName = "BookWorld")
+public class BookWorldImpl implements BookWorld {
+
+    @Override
+    public BookWithValidation echoBook(BookWithValidation book) {
+        return book;
+    }
+}
+

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

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

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java?rev=1547102&r1=1547101&r2=1547102&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java Mon Dec  2 16:50:25 2013
@@ -18,13 +18,20 @@
  */
 package org.apache.cxf.systest.jaxrs.validation.spring;
 
+import javax.ws.rs.BadRequestException;
 import javax.ws.rs.core.Form;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.soap.SOAPFaultException;
 
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
 import org.apache.cxf.systest.jaxrs.AbstractSpringServer;
 import org.apache.cxf.systest.jaxrs.validation.AbstractJAXRSValidationTest;
+import org.apache.cxf.systest.jaxrs.validation.BookWithValidation;
 
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -61,15 +68,52 @@ public class JAXRSClientServerValidation
     
     @Test
     public void testProgrammaticValidationFailsIfNameIsNull()  {
-        final Response r = createWebClient("/bookstore/books").post(new Form().param("id", "1"));
+        final Response r = createWebClient("/jaxrs/bookstore/books").post(new Form().param("id", "1"));
         assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
     }
 
     @Test
     public void testProgrammaticValidationPassesButParameterValidationFailesIfIdIsNull()  {
-        final Response r = createWebClient("/bookstore/books").post(new Form().param("name", "aa"));
+        final Response r = createWebClient("/jaxrs/bookstore/books").post(new Form().param("name", "aa"));
         assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
     }
+    
+    @Test
+    public void testHelloRestValidationFailsIfNameIsNull() throws Exception {
+        String address = "http://localhost:" + PORT + "/bwrest";
+        
+        BookWorld service = JAXRSClientFactory.create(address, BookWorld.class);
+        
+        BookWithValidation bw = service.echoBook(new BookWithValidation("RS", "123"));
+        assertEquals("123", bw.getId());
+        
+        try {
+            service.echoBook(new BookWithValidation(null, "123"));
+            fail("Validation failure expected");
+        } catch (BadRequestException ex) {
+            // complete
+        }
+        
+    }
+    @Test
+    public void testHelloSoapValidationFailsIfNameIsNull() throws Exception {
+        final QName serviceName = new QName("http://bookworld.com", "BookWorld");
+        final QName portName = new QName("http://bookworld.com", "BookWorldPort");
+        final String address = "http://localhost:" + PORT + "/bwsoap";
+        
+        Service service = Service.create(serviceName);
+        service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
+    
+        BookWorld bwService = service.getPort(BookWorld.class); 
+        BookWithValidation bw = bwService.echoBook(new BookWithValidation("WS", "123"));
+        assertEquals("123", bw.getId());
+        try {
+            bwService.echoBook(new BookWithValidation(null, "123"));
+            fail("Validation failure expected");
+        } catch (SOAPFaultException ex) {
+            // complete
+        }
+    }
 
     @Override
     protected String getPort() {

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml?rev=1547102&r1=1547101&r2=1547102&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml Mon Dec  2 16:50:25 2013
@@ -20,20 +20,23 @@
 <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">
 	<import resource="classpath:/META-INF/cxf/cxf.xml"/>
 	<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
 
-    <jaxrs:server address="/">
+    <jaxrs:server address="/jaxrs">
         <jaxrs:inInterceptors>
-            <ref bean="validationInInterceptor" />
+            <ref bean="jaxrsValidationInInterceptor" />
         </jaxrs:inInterceptors>
         <jaxrs:outInterceptors>
-            <ref bean="validationOutInterceptor" />
+            <ref bean="jaxrsValidationOutInterceptor" />
         </jaxrs:outInterceptors>
         <jaxrs:serviceBeans>
             <ref bean="bookStoreWithValidation"/>
@@ -53,10 +56,36 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
     <bean id="bookStoreWithValidation" class="org.apache.cxf.systest.jaxrs.validation.spring.BookStoreWithValidation">
        <property name="provider" ref="validationProvider" />
     </bean>       
-    <bean id="validationInInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor">
+    <bean id="jaxrsValidationInInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor">
         <property name="provider" ref="validationProvider" />
     </bean>
-    <bean id="validationOutInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor">
+    <bean id="jaxrsValidationOutInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor">
         <property name="provider" ref="validationProvider" />
-    </bean>    
+    </bean>
+    
+    <jaxrs:server address="/bwrest">
+        <jaxrs:serviceBeans>
+            <ref bean="bookWorldValidation"/>
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref bean="exceptionMapper"/>
+        </jaxrs:providers>
+        <jaxrs:features>
+            <ref bean="commonValidationFeature" />
+        </jaxrs:features>
+    </jaxrs:server>
+    
+    <jaxws:endpoint xmlns:s="http://bookworld.com" 
+                    serviceName="s:BookWorld" 
+                    endpointName="s:BookWorldPort" 
+                    implementor="#bookWorldValidation" 
+                    address="/bwsoap">
+        <jaxws:features>
+            <ref bean="commonValidationFeature" />
+        </jaxws:features>
+    </jaxws:endpoint>                
+    
+    <bean id="bookWorldValidation" class="org.apache.cxf.systest.jaxrs.validation.spring.BookWorldImpl"/>
+    <bean id="commonValidationFeature" class="org.apache.cxf.validation.BeanValidationFeature"/>
+    
 </beans>