integration and unit tests
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 4 Jun 2015 22:29:27 +0000 (00:29 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 4 Jun 2015 22:29:27 +0000 (00:29 +0200)
13 files changed:
README.md
web-services-spring-server/pom.xml
web-services-spring-server/src/main/java/de/spring/webservices/business/CustomBindingBusinessExample.java [deleted file]
web-services-spring-server/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java
web-services-spring-server/src/main/java/de/spring/webservices/services/ExampleService.java [new file with mode: 0644]
web-services-spring-server/src/main/java/de/spring/webservices/services/impl/CustomBindingExampleServiceImpl.java [new file with mode: 0644]
web-services-spring-server/src/main/java/de/spring/webservices/services/impl/ExampleServiceImpl.java [new file with mode: 0644]
web-services-spring-server/src/main/resources/spring-configuration/ws/soap-ws.xml
web-services-spring-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointIntegrationTest.java
web-services-spring-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointTest.java [new file with mode: 0644]
web-services-spring-server/src/test/java/de/spring/webservices/services/ExampleServiceTest.java [new file with mode: 0644]
web-services-spring-server/src/test/java/de/spring/webservices/services/impl/CustomBindingExampleServiceTest.java [new file with mode: 0644]
web-services-spring/pom.xml

index 235ed8a..9fe3e8b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -10,6 +10,8 @@ mvn jetty:run
 mvn clean install -Dmaven.test.skip=true
 
 
+TODO: maven-jaxb2-plugin in order to reuse generated Java code from other projects (cxf-xjc-plugin doesn't implement such feature
+without generating episodes by myself)
 TODO: custom bindings when creating Java code from wsdl.
 TODO: using Jetty instead of Tomcat
 TODO: logging Spring information
index 4909a82..f7ee949 100644 (file)
       <artifactId>spring-ws-test</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/web-services-spring-server/src/main/java/de/spring/webservices/business/CustomBindingBusinessExample.java b/web-services-spring-server/src/main/java/de/spring/webservices/business/CustomBindingBusinessExample.java
deleted file mode 100644 (file)
index 3d5646e..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-package de.spring.webservices.business;
-
-import org.springframework.stereotype.Service;
-
-import de.spring.webservices.auto.CustomBindingExampleRequest;
-import de.spring.webservices.auto.CustomBindingExampleResponse;
-import de.spring.webservices.operations.Operations;
-
-
-@Service("customBindingBusinessExample")
-public class CustomBindingBusinessExample implements
-       Operations.RequestResponse<CustomBindingExampleResponse, CustomBindingExampleRequest> {
-
-       
-       @Override
-    public CustomBindingExampleResponse requestResponse(
-               final CustomBindingExampleRequest request) {
-        final CustomBindingExampleResponse response = new CustomBindingExampleResponse();
-
-        response.setData("CUSTOM BINDING SNAKE EYES AND " + request.getData());
-
-        return response;
-    }
-
-}
index 6a91779..8fb4e40 100644 (file)
@@ -14,6 +14,7 @@ import de.spring.webservices.auto.ExampleRequest;
 import de.spring.webservices.auto.ExampleResponse;
 import de.spring.webservices.operations.Operations;
 import de.spring.webservices.operations.Operations.RequestResponse;
+import de.spring.webservices.services.ExampleService;
 
 
 @Endpoint
@@ -21,36 +22,36 @@ public class ExampleEndPoint {
     private static final String NAMESPACE_URI = "http://gumartinm.name/spring-ws/example";
     
     private final Operations.RequestResponse
-       <CustomBindingExampleResponse, CustomBindingExampleRequest> customBindingExample;  
+       <CustomBindingExampleResponse, CustomBindingExampleRequest> customBindingExampleService;  
+    
+    private final ExampleService exampleService;
     
     @Autowired
        public ExampleEndPoint(
-            RequestResponse<CustomBindingExampleResponse, CustomBindingExampleRequest> customBindingExample) {
-           this.customBindingExample = customBindingExample;
+            RequestResponse<CustomBindingExampleResponse, CustomBindingExampleRequest> customBindingExampleService,
+            ExampleService exampleService) {
+           this.customBindingExampleService = customBindingExampleService;
+           this.exampleService = exampleService;
     }
        
     @PayloadRoot(localPart = "ExampleRequest", namespace = NAMESPACE_URI)
     @ResponsePayload
-    public ExampleResponse order(
-            @RequestPayload final ExampleRequest requestObject,
+    public ExampleResponse exampleResponse(
+            @RequestPayload final ExampleRequest request,
             @RequestPayload final Element element,
             final MessageContext messageContext) {
 
-       final ExampleResponse response = new ExampleResponse();
-
-        response.setData("SNAKE EYES AND " + requestObject.getData());
-
-        return response;
+        return this.exampleService.doResponse(request);
     }
     
     @PayloadRoot(localPart = "CustomBindingExampleRequest", namespace = NAMESPACE_URI)
     @ResponsePayload
-    public CustomBindingExampleResponse order(
+    public CustomBindingExampleResponse cuntomBindingExampleResponse(
             @RequestPayload final CustomBindingExampleRequest requestObject,
             @RequestPayload final Element element,
             final MessageContext messageContext) {
 
-        return this.customBindingExample.requestResponse(requestObject);
+        return this.customBindingExampleService.requestResponse(requestObject);
     }
 }
 
diff --git a/web-services-spring-server/src/main/java/de/spring/webservices/services/ExampleService.java b/web-services-spring-server/src/main/java/de/spring/webservices/services/ExampleService.java
new file mode 100644 (file)
index 0000000..9d7eb79
--- /dev/null
@@ -0,0 +1,11 @@
+package de.spring.webservices.services;
+
+import de.spring.webservices.auto.ExampleRequest;
+import de.spring.webservices.auto.ExampleResponse;
+
+
+public interface ExampleService {
+       
+       public ExampleResponse doResponse(ExampleRequest request);
+
+}
diff --git a/web-services-spring-server/src/main/java/de/spring/webservices/services/impl/CustomBindingExampleServiceImpl.java b/web-services-spring-server/src/main/java/de/spring/webservices/services/impl/CustomBindingExampleServiceImpl.java
new file mode 100644 (file)
index 0000000..caa7e41
--- /dev/null
@@ -0,0 +1,27 @@
+package de.spring.webservices.services.impl;
+
+import org.springframework.stereotype.Service;
+
+import de.spring.webservices.auto.CustomBindingExampleRequest;
+import de.spring.webservices.auto.CustomBindingExampleResponse;
+import de.spring.webservices.auto.ParentEnumType;
+import de.spring.webservices.operations.Operations;
+
+
+@Service("customBindingExampleService")
+public class CustomBindingExampleServiceImpl implements
+       Operations.RequestResponse<CustomBindingExampleResponse, CustomBindingExampleRequest> {
+
+       
+       @Override
+    public CustomBindingExampleResponse requestResponse(final CustomBindingExampleRequest request) {
+               
+        CustomBindingExampleResponse response = new CustomBindingExampleResponse();
+
+        response.setData("CUSTOM BINDING SNAKE EYES AND " + request.getData());
+        response.setParentEnum(ParentEnumType.FIRST);
+
+        return response;
+    }
+
+}
diff --git a/web-services-spring-server/src/main/java/de/spring/webservices/services/impl/ExampleServiceImpl.java b/web-services-spring-server/src/main/java/de/spring/webservices/services/impl/ExampleServiceImpl.java
new file mode 100644 (file)
index 0000000..5f2d50b
--- /dev/null
@@ -0,0 +1,23 @@
+package de.spring.webservices.services.impl;
+
+import org.springframework.stereotype.Service;
+
+import de.spring.webservices.auto.ExampleRequest;
+import de.spring.webservices.auto.ExampleResponse;
+import de.spring.webservices.services.ExampleService;
+
+
+@Service("exampleServiceImpl")
+public class ExampleServiceImpl implements ExampleService {
+       
+       @Override
+    public ExampleResponse doResponse(final ExampleRequest request) {
+               
+               ExampleResponse response = new ExampleResponse();
+
+        response.setData("SNAKE EYES AND " + request.getData());
+
+        return response;
+    }
+
+}
index d77e7ab..378780d 100644 (file)
@@ -45,7 +45,7 @@
     </sws:dynamic-wsdl>
 
 
-    <bean id="ParentTypes" class="org.springframework.xml.xsd.SimpleXsdSchema">
+    <bean id="parent" class="org.springframework.xml.xsd.SimpleXsdSchema">
         <property name="xsd" value="classpath:parent.xsd"/>
     </bean>
 
index 2b3a19a..f0204cb 100644 (file)
@@ -17,7 +17,7 @@ import org.springframework.xml.transform.StringSource;
 
 
 @RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration("/spring-configuration/ws/soap-ws.xml")
+@ContextConfiguration(locations = { "classpath*:spring-configuration/ws/soap-ws.xml" } )
 public class ExampleEndPointIntegrationTest {
 
     @Autowired
@@ -42,6 +42,21 @@ public class ExampleEndPointIntegrationTest {
                 "</ns2:ExampleResponse>");
         mockClient.sendRequest(withPayload(requestPayload)).andExpect(
                 payload(responsePayload));
+        
+
+        final Source customRequestPayload = new StringSource(
+                "<CustomBindingExampleRequest xmlns='http://gumartinm.name/spring-ws/example'>" +
+                        "<data>SCARLETT</data>" +
+                               "<exampleDate>2015-06-03T10:20:30Z</exampleDate>" +
+                        "<parentEnum>FIRST</parentEnum>" +
+                "</CustomBindingExampleRequest>");
+        final Source customResponsePayload = new StringSource(
+                "<ns2:CustomBindingExampleResponse xmlns:ns2='http://gumartinm.name/spring-ws/example'>" +
+                        "<ns2:data>CUSTOM BINDING SNAKE EYES AND SCARLETT</ns2:data>" +
+                        "<ns2:parentEnum>FIRST</ns2:parentEnum>" +
+                "</ns2:CustomBindingExampleResponse>");
+        mockClient.sendRequest(withPayload(customRequestPayload)).andExpect(
+                payload(customResponsePayload));
     }
 }
 
diff --git a/web-services-spring-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointTest.java b/web-services-spring-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointTest.java
new file mode 100644 (file)
index 0000000..5b04c2f
--- /dev/null
@@ -0,0 +1,52 @@
+package de.spring.webservices.endpoints;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import de.spring.webservices.auto.CustomBindingExampleRequest;
+import de.spring.webservices.auto.CustomBindingExampleResponse;
+import de.spring.webservices.auto.ExampleRequest;
+import de.spring.webservices.operations.Operations;
+import de.spring.webservices.services.ExampleService;
+
+
+public class ExampleEndPointTest {
+       
+       private ExampleService exampleService;
+       
+       private Operations.RequestResponse
+       <CustomBindingExampleResponse, CustomBindingExampleRequest> customBindingExampleService;
+       
+       private ExampleEndPoint exampleEndPoint;
+
+       @Before
+    public void init() {
+               exampleService = mock(ExampleService.class);
+               customBindingExampleService = mock(Operations.RequestResponse.class);
+               exampleEndPoint = new ExampleEndPoint(customBindingExampleService, exampleService);
+       }
+       
+       @Test
+       public void givenExampleRequestThenInvokeExampleService() {
+               ExampleRequest request = new ExampleRequest();
+               request.setData("SCARLETT");
+        
+               exampleEndPoint.exampleResponse(request, null, null);
+               
+               verify(exampleService).doResponse(request);
+       }
+       
+       @Test
+       public void givenCustomBindingExampleRequestThenInvokeCustomBindingExampleService() {
+               CustomBindingExampleRequest request = new CustomBindingExampleRequest();
+               request.setData("SCARLETT");
+        
+               exampleEndPoint.cuntomBindingExampleResponse(request, null, null);
+               
+               verify(customBindingExampleService).requestResponse(request);
+       }
+
+}
diff --git a/web-services-spring-server/src/test/java/de/spring/webservices/services/ExampleServiceTest.java b/web-services-spring-server/src/test/java/de/spring/webservices/services/ExampleServiceTest.java
new file mode 100644 (file)
index 0000000..493c76d
--- /dev/null
@@ -0,0 +1,32 @@
+package de.spring.webservices.services;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import de.spring.webservices.auto.ExampleRequest;
+import de.spring.webservices.auto.ExampleResponse;
+import de.spring.webservices.services.impl.ExampleServiceImpl;
+
+public class ExampleServiceTest {
+
+    private ExampleService exampleService;
+       
+       @Before
+    public void init() {
+               exampleService = new ExampleServiceImpl();
+       }
+
+       @Test
+       public void givenExampleRequestThenReturnExampleResponse() {
+               ExampleRequest request = new ExampleRequest();
+               request.setData("SCARLETT");
+               ExampleResponse expected = new ExampleResponse();
+               expected.setData("SNAKE EYES AND " + request.getData());
+               
+        ExampleResponse actual = exampleService.doResponse(request);
+        
+               Assert.assertEquals(expected.getData(), actual.getData());
+       }
+
+}
diff --git a/web-services-spring-server/src/test/java/de/spring/webservices/services/impl/CustomBindingExampleServiceTest.java b/web-services-spring-server/src/test/java/de/spring/webservices/services/impl/CustomBindingExampleServiceTest.java
new file mode 100644 (file)
index 0000000..45c019a
--- /dev/null
@@ -0,0 +1,33 @@
+package de.spring.webservices.services.impl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import de.spring.webservices.auto.CustomBindingExampleRequest;
+import de.spring.webservices.auto.CustomBindingExampleResponse;
+import de.spring.webservices.operations.Operations;
+
+
+public class CustomBindingExampleServiceTest {
+
+       private Operations.RequestResponse
+       <CustomBindingExampleResponse, CustomBindingExampleRequest>  customBindingExampleService;
+       
+       @Before
+    public void init() {
+               customBindingExampleService = new CustomBindingExampleServiceImpl();
+       }
+       
+       @Test
+       public void givenCustomBindingExampleRequestThenReturnCustomBindingExampleResponse() {
+               CustomBindingExampleRequest request = new CustomBindingExampleRequest();
+               request.setData("SCARLETT");
+               CustomBindingExampleResponse expected = new CustomBindingExampleResponse();
+               expected.setData("CUSTOM BINDING SNAKE EYES AND " + request.getData());
+               
+               CustomBindingExampleResponse actual = customBindingExampleService.requestResponse(request);
+        
+               Assert.assertEquals(expected.getData(), actual.getData());
+       }
+}
index c1085dd..3158e24 100644 (file)
         <version>${spring.ws.version}</version>
         <scope>test</scope>
       </dependency>
+      <dependency>
+        <groupId>org.mockito</groupId>
+        <artifactId>mockito-core</artifactId>
+        <version>2.0.11-beta</version>
+        <scope>test</scope>
+      </dependency>
    </dependencies>
   </dependencyManagement>
   <build>