My endpoint has the following signature:
@Endpoint public class GetMemberDetailsEndpoint { @Resource private MemberManager memberManager; @PayloadRoot(namespace = "http://bk.org/memberservice/", localPart = "MemberDetailsRequest") @ResponsePayload public MemberDetailsResponse getMemberDetails(@RequestPayload MemberDetailsRequest request) throws Exception { MemberDetail memberDetail = memberManager.findByMemberId(request.getId()); ...... }
I have a memberManager bean dependency in my endpoint, I mock this up using easymock first:
<bean name="memberManager" class="org.easymock.EasyMock" factory-method="createMock"> <constructor-arg value="org.bk.memberservice.service.MemberManager"/> </bean>
this way Spring will wire it to the endpoint when starting up the bean factory. Record the easymock with appropriate expectations:
MemberDetail memberDetail = new MemberDetail("john doe", "111-111-1111", "City", "State"); memberDetail.setId(1L); expect(memberManager.findByMemberId(1L)).andReturn(memberDetail); replay(memberManager);
Initialize MockWebserviceClient, set up the test:
mockClient = MockWebServiceClient.createClient(applicationContext); Source requestPayload = new StringSource( "<mem:MemberDetailsRequest xmlns:mem=\"http://bk.org/memberservice/\">" + "<mem:id>1</mem:id>" + "</mem:MemberDetailsRequest>"); Source responsePayload = new StringSource( "<ns3:MemberDetailsResponse xmlns:ns3=\"http://bk.org/memberservice/\">" + "<memberDetail>" + "<id>1</id>" + "<name>john doe</name>" + "<phone>111-111-1111</phone>" + "<city>City</city>" + "<state>State</state>" + "</memberDetail>" + "</ns3:MemberDetailsResponse>"); mockClient.sendRequest(withPayload(requestPayload)).andExpect(payload(responsePayload)); verify(this.memberManager);This completes the test, MockWebserviceClient would take care of packaging up the raw xml request, dispatching it the appropriate WS endpoint, getting the response and validating it. Updated codesample with integration test available at: git://github.com/bijukunjummen/memberservice-contractfirst.git
No comments:
Post a Comment