org.springframework.xml.transform.StringSource Java Examples

The following examples show how to use org.springframework.xml.transform.StringSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TicketAgentClientTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testListFlights() {
  Source requestPayload =
      new StringSource("<ns3:listFlightsRequest xmlns:ns3=\"http://example.org/TicketAgent.xsd\">"
          + "</ns3:listFlightsRequest>");

  Source responsePayload =
      new StringSource("<v1:listFlightsResponse xmlns:v1=\"http://example.org/TicketAgent.xsd\">"
          + "<flightNumber>101</flightNumber>" + "</v1:listFlightsResponse>");

  // check if the SOAP Header is present using the soapHeader matcher
  mockWebServiceServer
      .expect(
          soapHeader(new QName("http://example.org/TicketAgent.xsd", "listFlightsSoapHeaders")))
      .andExpect(payload(requestPayload)).andRespond(withPayload(responsePayload));

  List<BigInteger> flights = ticketAgentClient.listFlights();
  assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101));

  mockWebServiceServer.verify();
}
 
Example #2
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void parseTpicHeaderFromRequestToTraceeBackend() throws Exception {
	final Map<String, String> context = new HashMap<>();
	context.put("our key", "is our value");
	final StringResult result = new StringResult();
	new SoapHeaderTransport().renderSoapHeader(context, result);
	final Source source = new StringSource(result.toString());

	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getRequest()).getSoapHeader()).thenReturn(soapHeader);
	final SoapHeaderElement element = mock(SoapHeaderElement.class);
	when(element.getSource()).thenReturn(source);
	when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(singletonList(element).iterator());

	unit.handleRequest(messageContext, new Object());
	assertThat(backend.size(), is(2));
	assertThat(backend.copyToMap(), hasKey(INVOCATION_ID_KEY));
	assertThat(backend.copyToMap(), hasEntry("our key", "is our value"));
}
 
Example #3
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void parseTpicHeaderFromFaultResponseToBackend() throws Exception {
	final Map<String, String> context = new HashMap<>();
	context.put("our key", "is our value");
	final StringResult result = new StringResult();
	new SoapHeaderTransport().renderSoapHeader(context, result);
	final Source source = new StringSource(result.toString());

	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(soapHeader);
	final SoapHeaderElement element = mock(SoapHeaderElement.class);
	when(element.getSource()).thenReturn(source);
	when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(Collections.singletonList(element).iterator());

	unit.handleFault(messageContext);
	assertThat(backend.size(), is(1));
	assertThat(backend.copyToMap(), hasEntry("our key", "is our value"));
}
 
Example #4
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void parseTpicHeaderFromResponseToBackend() throws Exception {
	final Map<String, String> context = new HashMap<>();
	context.put("our key", "is our value");
	final StringResult result = new StringResult();
	new SoapHeaderTransport().renderSoapHeader(context, result);
	final Source source = new StringSource(result.toString());

	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(soapHeader);
	final SoapHeaderElement element = mock(SoapHeaderElement.class);
	when(element.getSource()).thenReturn(source);
	when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(Collections.singletonList(element).iterator());

	unit.handleResponse(messageContext);
	assertThat(backend.size(), is(1));
	assertThat(backend.copyToMap(), hasEntry("our key", "is our value"));
}
 
Example #5
Source File: SOAPUtil.java    From j-road with Apache License 2.0 6 votes vote down vote up
/**
 * Substitutes all occurences of some given string inside the given {@link WebServiceMessage} with another value.
 *
 * @param message message to substitute in
 * @param from the value to substitute
 * @param to the value to substitute with
 * @throws TransformerException
 */
public static void substitute(WebServiceMessage message, String from, String to) throws TransformerException {
  SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
  SOAPPart soapPart = saajSoapMessage.getSaajMessage().getSOAPPart();

  Source source = new DOMSource(soapPart);
  StringResult stringResult = new StringResult();

  TransformerFactory.newInstance().newTransformer().transform(source, stringResult);

  String content = stringResult.toString().replaceAll(from, to);

  try {
    soapPart.setContent(new StringSource(content));
  } catch (SOAPException e) {
    throw new TransformerException(e);
  }
}
 
Example #6
Source File: KirXTeeServiceImpl.java    From j-road with Apache License 2.0 6 votes vote down vote up
private void formatDate(SaajSoapMessage saajMsg, Date date) throws TransformerException {
    if (date == null) {
        return;
    }
    SOAPPart soapPart = saajMsg.getSaajMessage().getSOAPPart();
    Source source = new DOMSource(soapPart);
    StringResult stringResult = new StringResult();
    TransformerFactory.newInstance().newTransformer().transform(source, stringResult);
    try {
        String from = dateWithTimezone.format(date);
        String to = dateWithoutTimezone.format(date);
        String content = StringUtils.replace(stringResult.toString(), from, to);
        soapPart.setContent(new StringSource(content));
    } catch (Exception e) {
        throw new TransformerException(e);
    }
}
 
Example #7
Source File: SoapMessageHelper.java    From citrus-simulator with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new SOAP message representation from given payload resource. Constructs a SOAP envelope
 * with empty header and payload as body.
 *
 * @param message
 * @return
 * @throws IOException
 */
public Message createSoapMessage(Message message) {
    try {
        String payload = message.getPayload().toString();

        LOG.info("Creating SOAP message from payload: " + payload);

        WebServiceMessage soapMessage = soapMessageFactory.createWebServiceMessage();
        transformerFactory.newTransformer().transform(
                new StringSource(payload), soapMessage.getPayloadResult());

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        soapMessage.writeTo(bos);

        return new SoapMessage(new String(bos.toByteArray()), message.getHeaders());
    } catch (Exception e) {
        throw new CitrusRuntimeException("Failed to create SOAP message from payload resource", e);
    }
}
 
Example #8
Source File: TicketAgentClientTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testListFlights() {
  Source requestPayload =
      new StringSource("<ns3:listFlightsRequest xmlns:ns3=\"http://example.org/TicketAgent.xsd\">"
          + "</ns3:listFlightsRequest>");

  Source responsePayload =
      new StringSource("<v1:listFlightsResponse xmlns:v1=\"http://example.org/TicketAgent.xsd\">"
          + "<flightNumber>101</flightNumber>" + "</v1:listFlightsResponse>");

  // check if the SOAPAction is present using the custom matcher
  mockWebServiceServer.expect(new SoapActionMatcher("http://example.com/TicketAgent/listFlights"))
      .andExpect(payload(requestPayload)).andRespond(withPayload(responsePayload));

  List<BigInteger> flights = ticketAgentClient.listFlights();
  assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101));

  mockWebServiceServer.verify();
}
 
Example #9
Source File: CreateOrderEndpointMockTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testCreateOrder() throws XPathExpressionException {
    Source requestPayload = new StringSource(
            "<ns2:order xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:customer><ns2:firstName>John</ns2:firstName>"
                    + "<ns2:lastName>Doe</ns2:lastName>"
                    + "</ns2:customer><ns2:lineItems><ns2:lineItem>"
                    + "<ns2:product>" + "<ns2:id>2</ns2:id>"
                    + "<ns2:name>batman action figure</ns2:name>"
                    + "</ns2:product>"
                    + "<ns2:quantity>1</ns2:quantity>"
                    + "</ns2:lineItem>" + "</ns2:lineItems>"
                    + "</ns2:order>");

    Map<String, String> namespaces = Collections.singletonMap("ns1",
            "http://codenotfound.com/types/order");

    mockClient.sendRequest(withPayload(requestPayload))
            .andExpect(ResponseMatchers
                    .xpath("/ns1:orderConfirmation/ns1:confirmationId",
                            namespaces)
                    .exists());
}
 
Example #10
Source File: TicketAgentEndpointTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testListFlights() {
  Source requestEnvelope = new StringSource(
      "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
          + "<SOAP-ENV:Header>"
          + "<ns3:listFlightsSoapHeaders xmlns:ns3=\"http://example.org/TicketAgent.xsd\">"
          + "<isGoldClubMember>true</isGoldClubMember>" + "<clientId>abc123</clientId>"
          + "</ns3:listFlightsSoapHeaders>" + "</SOAP-ENV:Header>" + "<SOAP-ENV:Body>"
          + "<ns3:listFlightsRequest xmlns:ns3=\"http://example.org/TicketAgent.xsd\">"
          + "</ns3:listFlightsRequest>" + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>");

  Source responsePayload =
      new StringSource("<v1:listFlightsResponse xmlns:v1=\"http://example.org/TicketAgent.xsd\">"
          + "<flightNumber>101</flightNumber>" + "<flightNumber>202</flightNumber>"
          + "</v1:listFlightsResponse>");

  mockClient.sendRequest(withSoapEnvelope(requestEnvelope)).andExpect(payload(responsePayload));
}
 
Example #11
Source File: OrderHistoryClientTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testGetOrderHistory() throws IOException {
  Source requestPayload = new StringSource(
      "<ns1:getOrderHistoryRequest xmlns:ns1=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns1:userId>abc123</ns1:userId>" + "</ns1:getOrderHistoryRequest>");

  Source responsePayload = new StringSource(
      "<ns1:getOrderHistoryResponse xmlns:ns1=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns1:orderHistory>" + "<ns1:orderList>"
          + "<ns1:order><ns1:orderId>order1</ns1:orderId></ns1:order>"
          + "<ns1:order><ns1:orderId>order2</ns1:orderId></ns1:order>"
          + "<ns1:order><ns1:orderId>order3</ns1:orderId></ns1:order>" + "</ns1:orderList>"
          + "</ns1:orderHistory>" + "</ns1:getOrderHistoryResponse>");

  mockWebServiceServer.expect(payload(requestPayload)).andRespond(withPayload(responsePayload));

  OrderHistory orderHistory = orderHistoryClient.getOrderHistory("abc123");
  assertThat(orderHistory.getOrders().get(2).getOrderId()).isEqualTo("order3");

  mockWebServiceServer.verify();
}
 
Example #12
Source File: CreateOrderEndpointMockTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testCreateOrder() throws XPathExpressionException {
    Source requestPayload = new StringSource(
            "<ns2:order xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:customer><ns2:firstName>John</ns2:firstName>"
                    + "<ns2:lastName>Doe</ns2:lastName>"
                    + "</ns2:customer><ns2:lineItems><ns2:lineItem>"
                    + "<ns2:product>" + "<ns2:id>2</ns2:id>"
                    + "<ns2:name>batman action figure</ns2:name>"
                    + "</ns2:product>"
                    + "<ns2:quantity>1</ns2:quantity>"
                    + "</ns2:lineItem>" + "</ns2:lineItems>"
                    + "</ns2:order>");

    Map<String, String> namespaces = Collections.singletonMap("ns1",
            "http://codenotfound.com/types/order");

    mockClient.sendRequest(withPayload(requestPayload))
            .andExpect(ResponseMatchers
                    .xpath("/ns1:orderConfirmation/ns1:confirmationId",
                            namespaces)
                    .exists());
}
 
Example #13
Source File: CreateOrderEndpointMockTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testCreateOrder() throws XPathExpressionException {
    Source requestPayload = new StringSource(
            "<ns2:order xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:customer><ns2:firstName>John</ns2:firstName>"
                    + "<ns2:lastName>Doe</ns2:lastName>"
                    + "</ns2:customer><ns2:lineItems><ns2:lineItem>"
                    + "<ns2:product>" + "<ns2:id>2</ns2:id>"
                    + "<ns2:name>batman action figure</ns2:name>"
                    + "</ns2:product>"
                    + "<ns2:quantity>1</ns2:quantity>"
                    + "</ns2:lineItem>" + "</ns2:lineItems>"
                    + "</ns2:order>");

    Map<String, String> namespaces = Collections.singletonMap("ns1",
            "http://codenotfound.com/types/order");

    mockClient.sendRequest(withPayload(requestPayload))
            .andExpect(ResponseMatchers
                    .xpath("/ns1:orderConfirmation/ns1:confirmationId",
                            namespaces)
                    .exists());
}
 
Example #14
Source File: CreateOrderEndpointMockTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testCreateOrder() throws XPathExpressionException {
    Source requestPayload = new StringSource(
            "<ns2:order xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:customer><ns2:firstName>John</ns2:firstName>"
                    + "<ns2:lastName>Doe</ns2:lastName>"
                    + "</ns2:customer><ns2:lineItems><ns2:lineItem>"
                    + "<ns2:product>" + "<ns2:id>2</ns2:id>"
                    + "<ns2:name>batman action figure</ns2:name>"
                    + "</ns2:product>"
                    + "<ns2:quantity>1</ns2:quantity>"
                    + "</ns2:lineItem>" + "</ns2:lineItems>"
                    + "</ns2:order>");

    Map<String, String> namespaces = Collections.singletonMap("ns1",
            "http://codenotfound.com/types/order");

    mockClient.sendRequest(withPayload(requestPayload))
            .andExpect(ResponseMatchers
                    .xpath("/ns1:orderConfirmation/ns1:confirmationId",
                            namespaces)
                    .exists());
}
 
Example #15
Source File: TicketAgentEndpointTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testGetOrderHistoryMinimumAssumptions() {
  Source requestPayload = new StringSource(
      "<ns1:getOrderHistoryRequest xmlns:ns1=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns1:oldWrapper>" + "<ns1:userId>pqr123</ns1:userId>" + "</ns1:oldWrapper>"
          + "</ns1:getOrderHistoryRequest>");

  Source responsePayload = new StringSource(
      "<ns2:getOrderHistoryResponse xmlns:ns2=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns2:orderHistory>" + "<ns2:orderList>"
          + "<ns2:order><ns2:orderId>order0</ns2:orderId></ns2:order>"
          + "<ns2:order><ns2:orderId>order1</ns2:orderId></ns2:order>"
          + "<ns2:order><ns2:orderId>order2</ns2:orderId></ns2:order>" + "</ns2:orderList>"
          + "</ns2:orderHistory>" + "</ns2:getOrderHistoryResponse>");

  mockClient.sendRequest(withPayload(requestPayload)).andExpect(payload(responsePayload));
}
 
Example #16
Source File: TicketAgentEndpointTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testGetOrderHistoryOnlyNeededElements() {
  Source requestPayload = new StringSource(
      "<ns1:getOrderHistoryRequest xmlns:ns1=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns1:userId>mno123</ns1:userId>" + "<ns1:userName>user-name</ns1:userName>"
          + "</ns1:getOrderHistoryRequest>");

  Source responsePayload = new StringSource(
      "<ns2:getOrderHistoryResponse xmlns:ns2=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns2:orderHistory>" + "<ns2:orderList>"
          + "<ns2:order><ns2:orderId>order0</ns2:orderId></ns2:order>"
          + "<ns2:order><ns2:orderId>order1</ns2:orderId></ns2:order>"
          + "<ns2:order><ns2:orderId>order2</ns2:orderId></ns2:order>" + "</ns2:orderList>"
          + "</ns2:orderHistory>" + "</ns2:getOrderHistoryResponse>");

  mockClient.sendRequest(withPayload(requestPayload)).andExpect(payload(responsePayload));
}
 
Example #17
Source File: TicketAgentEndpointTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testGetOrderHistory() {
  Source requestPayload = new StringSource(
      "<ns1:getOrderHistoryRequest xmlns:ns1=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns1:userId>jkl123</ns1:userId>" + "</ns1:getOrderHistoryRequest>");

  Source responsePayload = new StringSource(
      "<ns2:getOrderHistoryResponse xmlns:ns2=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns2:orderHistory>" + "<ns2:orderList>"
          + "<ns2:order><ns2:orderId>order0</ns2:orderId></ns2:order>"
          + "<ns2:order><ns2:orderId>order1</ns2:orderId></ns2:order>"
          + "<ns2:order><ns2:orderId>order2</ns2:orderId></ns2:order>" + "</ns2:orderList>"
          + "</ns2:orderHistory>" + "</ns2:getOrderHistoryResponse>");

  mockClient.sendRequest(withPayload(requestPayload)).andExpect(payload(responsePayload));
}
 
Example #18
Source File: OrderHistoryClientTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testGetOrderHistoryMinimumAssumptions() throws IOException {
  Source requestPayload = new StringSource(
      "<ns1:getOrderHistoryRequest xmlns:ns1=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns1:userId>ghi789</ns1:userId>" + "</ns1:getOrderHistoryRequest>");

  Source responsePayload = new StringSource(
      "<ns1:getOrderHistoryResponse xmlns:ns1=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns1:newWrapper>" + "<ns1:orderHistory>" + "<ns1:orderList>"
          + "<ns1:order><ns1:orderId>order7</ns1:orderId></ns1:order>"
          + "<ns1:order><ns1:orderId>order8</ns1:orderId></ns1:order>"
          + "<ns1:order><ns1:orderId>order9</ns1:orderId></ns1:order>" + "</ns1:orderList>"
          + "</ns1:orderHistory>" + "</ns1:newWrapper>" + "</ns1:getOrderHistoryResponse>");

  mockWebServiceServer.expect(payload(requestPayload)).andRespond(withPayload(responsePayload));

  OrderHistory orderHistory = orderHistoryClient.getOrderHistory("ghi789");
  assertThat(orderHistory.getOrders().get(2).getOrderId()).isEqualTo("order9");

  mockWebServiceServer.verify();
}
 
Example #19
Source File: OrderHistoryClientTest.java    From spring-ws with MIT License 6 votes vote down vote up
@Test
public void testGetOrderHistoryOnlyNeededElements() throws IOException {
  Source requestPayload = new StringSource(
      "<ns1:getOrderHistoryRequest xmlns:ns1=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns1:userId>def456</ns1:userId>" + "</ns1:getOrderHistoryRequest>");

  Source responsePayload = new StringSource(
      "<ns1:getOrderHistoryResponse xmlns:ns1=\"http://codenotfound.com/types/orderhistory\">"
          + "<ns1:orderHistory>" + "<ns1:orderList>"
          + "<ns1:order><ns1:orderId>order4</ns1:orderId><ns1:orderName>order-name-1</ns1:orderName></ns1:order>"
          + "<ns1:order><ns1:orderId>order5</ns1:orderId><ns1:orderName>order-name-2</ns1:orderName></ns1:order>"
          + "<ns1:order><ns1:orderId>order6</ns1:orderId><ns1:orderName>order-name-3</ns1:orderName></ns1:order>"
          + "</ns1:orderList>" + "</ns1:orderHistory>" + "</ns1:getOrderHistoryResponse>");

  mockWebServiceServer.expect(payload(requestPayload)).andRespond(withPayload(responsePayload));

  OrderHistory orderHistory = orderHistoryClient.getOrderHistory("def456");
  assertThat(orderHistory.getOrders().get(2).getOrderId()).isEqualTo("order6");

  mockWebServiceServer.verify();
}
 
Example #20
Source File: CreateOrderClientMockTest.java    From spring-ws with MIT License 5 votes vote down vote up
@Test
public void testCreateOrder() {
    Source requestPayload = new StringSource(
            "<ns2:order xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:customer><ns2:firstName>Jane</ns2:firstName>"
                    + "<ns2:lastName>Doe</ns2:lastName>"
                    + "</ns2:customer><ns2:lineItems><ns2:lineItem>"
                    + "<ns2:product>" + "<ns2:id>2</ns2:id>"
                    + "<ns2:name>superman action figure</ns2:name>"
                    + "</ns2:product>"
                    + "<ns2:quantity>1</ns2:quantity>"
                    + "</ns2:lineItem>" + "</ns2:lineItems>"
                    + "</ns2:order>");

    Source responsePayload = new StringSource(
            "<ns2:orderConfirmation xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:confirmationId>5678</ns2:confirmationId>"
                    + "</ns2:orderConfirmation>");

    mockWebServiceServer.expect(payload(requestPayload))
            .andRespond(withPayload(responsePayload));

    assertThat(createOrderClient.createOrder(customer, lineItems)
            .getConfirmationId()).isEqualTo("5678");

    mockWebServiceServer.verify();
}
 
Example #21
Source File: CreateOrderClientMockTest.java    From spring-ws with MIT License 5 votes vote down vote up
@Test
public void testCreateOrder() {
    Source requestPayload = new StringSource(
            "<ns2:order xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:customer><ns2:firstName>Jane</ns2:firstName>"
                    + "<ns2:lastName>Doe</ns2:lastName>"
                    + "</ns2:customer><ns2:lineItems><ns2:lineItem>"
                    + "<ns2:product>" + "<ns2:id>2</ns2:id>"
                    + "<ns2:name>superman action figure</ns2:name>"
                    + "</ns2:product>"
                    + "<ns2:quantity>1</ns2:quantity>"
                    + "</ns2:lineItem>" + "</ns2:lineItems>"
                    + "</ns2:order>");

    Source responsePayload = new StringSource(
            "<ns2:orderConfirmation xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:confirmationId>5678</ns2:confirmationId>"
                    + "</ns2:orderConfirmation>");

    mockWebServiceServer.expect(payload(requestPayload))
            .andRespond(withPayload(responsePayload));

    assertThat(createOrderClient.createOrder(customer, lineItems)
            .getConfirmationId()).isEqualTo("5678");

    mockWebServiceServer.verify();
}
 
Example #22
Source File: CreateOrderClientMockTest.java    From spring-ws with MIT License 5 votes vote down vote up
@Test
public void testCreateOrder() {
    Source requestPayload = new StringSource(
            "<ns2:order xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:customer><ns2:firstName>Jane</ns2:firstName>"
                    + "<ns2:lastName>Doe</ns2:lastName>"
                    + "</ns2:customer><ns2:lineItems><ns2:lineItem>"
                    + "<ns2:product>" + "<ns2:id>2</ns2:id>"
                    + "<ns2:name>superman action figure</ns2:name>"
                    + "</ns2:product>"
                    + "<ns2:quantity>1</ns2:quantity>"
                    + "</ns2:lineItem>" + "</ns2:lineItems>"
                    + "</ns2:order>");

    Source responsePayload = new StringSource(
            "<ns2:orderConfirmation xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:confirmationId>5678</ns2:confirmationId>"
                    + "</ns2:orderConfirmation>");

    mockWebServiceServer.expect(payload(requestPayload))
            .andRespond(withPayload(responsePayload));

    assertThat(createOrderClient.createOrder(customer, lineItems)
            .getConfirmationId()).isEqualTo("5678");

    mockWebServiceServer.verify();
}
 
Example #23
Source File: TicketAgentEndpointTest.java    From spring-ws with MIT License 5 votes vote down vote up
@Test
public void testListFlights() {
  Source requestPayload =
      new StringSource("<ns3:listFlightsRequest xmlns:ns3=\"http://example.org/TicketAgent.xsd\">"
          + "</ns3:listFlightsRequest>");

  Source responsePayload =
      new StringSource("<v1:listFlightsResponse xmlns:v1=\"http://example.org/TicketAgent.xsd\">"
          + "<flightNumber>101</flightNumber>" + "</v1:listFlightsResponse>");

  mockClient
      .sendRequest(
          new SoapActionCreator(requestPayload, "http://example.com/TicketAgent/listFlights"))
      .andExpect(payload(responsePayload));
}
 
Example #24
Source File: TestCaseService.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
/**
 * Get test case model from XML source code.
 * @param test
 * @return
 */
private TestcaseModel getXmlTestModel(Project project, Test test) {
    String xmlSource = getSourceCode(project, test.getSourceFiles()
                                                    .stream()
                                                    .filter(file -> file.endsWith(".xml"))
                                                    .findAny()
                                                    .orElse(""));

    if (!StringUtils.hasText(xmlSource)) {
        throw new ApplicationRuntimeException("Failed to get XML source code for test: " + test.getPackageName() + "." + test.getName());
    }

    return ((SpringBeans) new TestCaseMarshaller().unmarshal(new StringSource(xmlSource))).getTestcase();
}
 
Example #25
Source File: CreateOrderClientMockTest.java    From spring-ws with MIT License 5 votes vote down vote up
@Test
public void testCreateOrder() {
    Source requestPayload = new StringSource(
            "<ns2:order xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:customer><ns2:firstName>Jane</ns2:firstName>"
                    + "<ns2:lastName>Doe</ns2:lastName>"
                    + "</ns2:customer><ns2:lineItems><ns2:lineItem>"
                    + "<ns2:product>" + "<ns2:id>2</ns2:id>"
                    + "<ns2:name>superman action figure</ns2:name>"
                    + "</ns2:product>"
                    + "<ns2:quantity>1</ns2:quantity>"
                    + "</ns2:lineItem>" + "</ns2:lineItems>"
                    + "</ns2:order>");

    Source responsePayload = new StringSource(
            "<ns2:orderConfirmation xmlns:ns2=\"http://codenotfound.com/types/order\">"
                    + "<ns2:confirmationId>5678</ns2:confirmationId>"
                    + "</ns2:orderConfirmation>");

    mockWebServiceServer.expect(payload(requestPayload))
            .andRespond(withPayload(responsePayload));

    assertThat(createOrderClient.createOrder(customer, lineItems)
            .getConfirmationId()).isEqualTo("5678");

    mockWebServiceServer.verify();
}