Let me start with Spring context for test case (which is 99% the copy-paste from previous post).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <!--xml version="1.0" encoding="UTF-8"?--> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:context = "http://www.springframework.org/schema/context" xmlns:ws = "http://www.springframework.org/schema/web-services" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation=" < ws:annotation-driven ></ ws:annotation-driven > < bean class = "org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" ></ bean > < bean id = "jaxbPayloadMethodProcessor" class = "org.springframework.ws.server.endpoint.adapter.method.jaxb.JaxbElementPayloadMethodProcessor" ></ bean > < bean id = "defaultMethodEndpointAdapter" class = "org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter" > < property name = "methodArgumentResolvers" > < list > < ref bean = "jaxbPayloadMethodProcessor" ></ ref > </ list > </ property > < property name = "methodReturnValueHandlers" > < list > < ref bean = "jaxbPayloadMethodProcessor" ></ ref > </ list > </ property > </ bean > < bean id = "messageFactory" class = "org.springframework.ws.soap.saaj.SaajSoapMessageFactory" ></ bean > < bean id = "schema" class = "org.springframework.core.io.ClassPathResource" > < constructor-arg index = "0" value = "UserProfileSchema.xsd" > </ constructor-arg ></ bean > </ beans > |
- element <ws:static-wsdl/> has been removed
- element <bean id="schema" ... /> has been added
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | package org.example; import static org.springframework.ws.test.server.ResponseMatchers.validPayload; import static org.example.SoapActionRequestCreator.withPayload; import java.io.IOException; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.core.io.Resource; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.ws.test.server.MockWebServiceClient; @RunWith ( SpringJUnit4ClassRunner. class ) @ContextConfiguration ( locations = "/META-INF/spring-context.xml" ) public class UserProfileEndpointTestCase { @Autowired private ApplicationContext applicationContext; @Autowired private Resource schema; private MockWebServiceClient client; @Before public void setUp() { client = MockWebServiceClient.createClient( applicationContext ); } @Test public void testServiceCall() throws IOException { final Resource payload = applicationContext.getResource( "Request.xml" ); client.sendRequest( withPayload( "UserProfile" , request ) ). andExpect( validPayload( schema ) ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | package org.example; import java.io.IOException; import org.springframework.core.io.Resource; import org.springframework.util.Assert; import org.springframework.ws.WebServiceMessage; import org.springframework.ws.WebServiceMessageFactory; import org.springframework.ws.soap.SoapMessage; import org.springframework.ws.test.server.RequestCreator; import org.springframework.ws.test.support.creator.PayloadMessageCreator; import org.springframework.ws.test.support.creator.WebServiceMessageCreator; import org.springframework.xml.transform.ResourceSource; public class SoapActionRequestCreator implements RequestCreator { private final WebServiceMessageCreator adaptee; private final String action; private SoapActionRequestCreator ( final String action, final WebServiceMessageCreator adaptee ) { this .action = action; this .adaptee = adaptee; } public static RequestCreator withPayload( final String action, final Resource payload ) throws IOException { Assert.notNull(payload, "'payload' must not be null" ); return new SoapActionRequestCreator( action, new PayloadMessageCreator( new ResourceSource( payload ) ) ); } @Override public WebServiceMessage createRequest( final WebServiceMessageFactory messageFactory ) throws IOException { final WebServiceMessage message = adaptee.createMessage( messageFactory ); Assert.isInstanceOf( SoapMessage. class , message ); if ( message instanceof SoapMessage ) { ( ( SoapMessage )message ).setSoapAction( action ); } return message; } } |