@Test public void testParseTransformException() throws TransformerException { Builder builder = Mockito.mock(Builder.class); SOAPMessage message = Mockito.mock(SOAPMessage.class); doThrow(TransformerException.class) .when(transformer).transform(any(Source.class), any(Result.class)); assertSame( "parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message) ); }
@Test public void testGettersWithNullConfigXPaths() { when(apiConfig.getRequestContextXPath()).thenReturn(null); xPathSet = new RequestInfoXPathSet(apiConfig, nodeExtractor, transformerSupplier, logger); assertNull( "getContextName should have returned null when no context XPath was supplied", xPathSet.getContextName()); assertFalse( "getContextXPath should have returned an empty iterator when no context XPath was supplied", xPathSet.getContextXPath().iterator().hasNext()); }
@Test public void testGettersWithConfigXPaths() { assertArrayEquals( new String[] {"foo", "bar"}, Iterables.toArray(xPathSet.getContextXPath(), String.class)); assertEquals( "getContextName should return the last element of the context XPath", "bar", xPathSet.getContextName()); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(apiConfig.getRequestContextXPath()).thenReturn("/foo/bar"); xPathSet = new RequestInfoXPathSet(apiConfig, nodeExtractor, transformerSupplier, logger); }
@Test public void testToString() { when(apiConfig.getRequestContextXPath()).thenReturn("/foo/bar"); String toString = xPathSet.toString(); assertThat( "Missing label for context XPath", toString, Matchers.containsString("contextXPath")); assertThat( "toString should contain all of the context XPath elements", toString, Matchers.stringContainsInOrder(Arrays.asList("foo", "bar"))); assertThat("Missing label for context name", toString, Matchers.containsString("contextName")); } }
/** * 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); } }
/** * 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 testParseWithNullTransformer() { Builder builder = Mockito.mock(Builder.class); when(transformerSupplier.get()).thenReturn(null); SOAPMessage message = Mockito.mock(SOAPMessage.class); when(message.getSOAPPart()).thenReturn(Mockito.mock(SOAPPart.class)); assertSame( "parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message)); // Transformer was null, so no methods should have been called on the builder. verifyZeroInteractions(builder); }
@Test public void testParseWithNullSoapPart() { Builder builder = Mockito.mock(Builder.class); SOAPMessage message = Mockito.mock(SOAPMessage.class); when(message.getSOAPPart()).thenReturn(null); assertSame( "parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message)); // SOAPPart was null, so no methods should have been called on the builder. verifyZeroInteractions(builder); }
@Test public void testParseWithNullMessage() { Builder builder = Mockito.mock(Builder.class); assertSame( "parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, 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, TransformerException { Builder builder = new Builder(); SOAPMessage message = Mockito.mock(SOAPMessage.class); SOAPHeader header = Mockito.mock(SOAPHeader.class); SOAPPart soapPart = Mockito.mock(SOAPPart.class); when(message.getSOAPHeader()).thenReturn(header); when(message.getSOAPPart()).thenReturn(soapPart); final String payload = "<foo><bar>MyBar</bar></foo>"; when(transformerSupplier.get()).thenReturn(transformer); doAnswer( invocation -> { StreamResult streamResult = (StreamResult) invocation.getArguments()[1]; streamResult.getOutputStream().write(payload.getBytes(StandardCharsets.UTF_8)); return null; }) .when(transformer) .transform(any(Source.class), any(StreamResult.class)); assertSame( "parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message)); RequestInfo requestInfo = builder.build(); assertEquals("Payload doesn't match", payload, requestInfo.getPayload()); assertEquals("Context name doesn't match", "bar", requestInfo.getContextName()); }
.withServiceName(stub._getService().getServiceName().getLocalPart()) .withUrl(stub._getCall().getTargetEndpointAddress()); requestInfoXPathSet.parseMessage(requestInfoBuilder, messageContext.getRequestMessage()); builder.withRequestInfo(requestInfoBuilder .build());
.withServiceName(stub._getService().getServiceName().getLocalPart()) .withUrl(stub._getCall().getTargetEndpointAddress()); requestInfoXPathSet.parseMessage(requestInfoBuilder, messageContext.getRequestMessage()); builder.withRequestInfo(requestInfoBuilder .build());