Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. @Test
  2. public void testValidateSimpleRequestAndSendResponse() throws Exception {
  3.     //add the mock responses with request path, expected request and response
  4.     //expected request is compared with the actual one using xmlunit
  5.     httpTestServer.addResponseForRequest("/test",
  6.         new ClassPathResource("mock-request/validSearchByID12345.xml"),
  7.         new ClassPathResource("mock-response/validSearchByID12345.xml"),
  8.         null);
  9.  
  10.     //load and send request to OSB
  11.     final ClassPathResource resource =
  12.         new ClassPathResource("/request/validSearchByIDRequest.xml");
  13.     final ContentExchange contentExchange =
  14.         httpTestClient.postToUrl(osbEndpoint, resource.getInputStream());
  15.  
  16.     //assert that a 200 status is retrieved
  17.     assertThat("error: " + contentExchange.getResponseContent(),
  18.         contentExchange.getResponseStatus(), is(200));
  19.     //other assert to the payload
  20.     ...
  21. }
  22.  
  23. @Test
  24. public void testValidateBadRequest() throws Exception {
  25.     //no responses are put in the mock server
  26.     //load and send request to OSB
  27.     final ClassPathResource resource =
  28.         new ClassPathResource("/request/invalidRequest.xml");
  29.     final ContentExchange contentExchange =
  30.         httpTestClient.postToUrl(osbEndpoint, resource.getInputStream());
  31.  
  32.     //assert that a 500 status is retrieved
  33.     assertThat(contentExchange.getResponseStatus(), is(500));
  34.     //other assert to the format of the SOAP fault
  35.     ...
  36. }