/** * Captures the raw XML message behind a SOAP interaction. * * @param context the context of the SOAP message passing through this handler */ private void captureSoapXml(SOAPMessageContext context) { SOAPMessage message = context.getMessage(); if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) { // Outbound message (request). requestInfoXPathSet.parseMessage(lastRequestInfo, message); } else { // Inbound message (response). responseInfoXPathSet.parseMessage(lastResponseInfo, message); } }
@Test public void testGettersWithNullConfigXPaths() { apiConfig = Mockito.mock(AdsApiConfiguration.class); xPathSet = new ResponseInfoXPathSet(apiConfig, nodeExtractor); assertFalse( "getOperationsXPath should have returned an empty iterator", xPathSet.getOperationsCountXPath().iterator().hasNext()); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(apiConfig.getResponseOperationsCountXPath()).thenReturn("/foo/bar/operations"); xPathSet = new ResponseInfoXPathSet(apiConfig, nodeExtractor); }
@Test public void testToString() { String toString = xPathSet.toString(); assertThat( "Missing label for request ID XPath", toString, Matchers.containsString("requestIdXPath")); assertThat( "Missing label for response time XPath", toString, Matchers.containsString("responseTimeXPath")); assertThat( "Missing label for operations count XPath", toString, Matchers.containsString("operationsCountXPath")); assertThat( "toString should contain all of the operations XPath elements", toString, Matchers.stringContainsInOrder(Arrays.asList("foo", "bar", "operations"))); } }
/** * Captures the raw XML message behind a SOAP interaction. * * @param context the context of the SOAP message passing through this handler */ private void captureSoapXml(SOAPMessageContext context) { SOAPMessage message = context.getMessage(); if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) { // Outbound message (request). requestInfoXPathSet.parseMessage(lastRequestInfo, message); } else { // Inbound message (response). responseInfoXPathSet.parseMessage(lastResponseInfo, message); } }
@Test public void testParseWithNullMessage() { Builder builder = Mockito.mock(Builder.class); assertSame( "parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, (SOAPMessage) null)); // Message was null, so no methods should have been called on the builder. verifyZeroInteractions(builder); }
@Test public void testParseWithNullBuilder_fails() { thrown.expect(NullPointerException.class); xPathSet.parseMessage((Builder) null, Mockito.mock(SOAPMessage.class)); }
@Test public void testParseActualMessage() throws SOAPException, IOException { Builder builder = new Builder(); SOAPMessage message = Mockito.mock(SOAPMessage.class); SOAPHeader header = Mockito.mock(SOAPHeader.class); when(message.getSOAPHeader()).thenReturn(header); final String payload = "<foo><bar>MyBar</bar></foo>"; doAnswer( invocation -> { OutputStream outputStream = (OutputStream) invocation.getArguments()[0]; outputStream.write(payload.getBytes(StandardCharsets.UTF_8)); return null; }) .when(message) .writeTo(org.mockito.Matchers.any(OutputStream.class)); assertSame( "parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message)); ResponseInfo responseInfo = builder.build(); assertEquals("Payload doesn't match", payload, responseInfo.getPayload()); }
.build()); ResponseInfo.Builder responseInfoBuilder = new ResponseInfo.Builder(); responseInfoXPathSet.parseMessage(responseInfoBuilder, messageContext.getResponseMessage()); builder.withResponseInfo(responseInfoBuilder.build());
.build()); ResponseInfo.Builder responseInfoBuilder = new ResponseInfo.Builder(); responseInfoXPathSet.parseMessage(responseInfoBuilder, messageContext.getResponseMessage()); builder.withResponseInfo(responseInfoBuilder.build());