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
<artifactId>spring-ws-test</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
+++ /dev/null
-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;
- }
-
-}
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
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);
}
}
--- /dev/null
+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);
+
+}
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+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;
+ }
+
+}
</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>
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration("/spring-configuration/ws/soap-ws.xml")
+@ContextConfiguration(locations = { "classpath*:spring-configuration/ws/soap-ws.xml" } )
public class ExampleEndPointIntegrationTest {
@Autowired
"</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));
}
}
--- /dev/null
+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);
+ }
+
+}
--- /dev/null
+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());
+ }
+
+}
--- /dev/null
+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());
+ }
+}
<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>