use of com.google.api.ads.common.lib.client.RequestInfo in project googleads-java-lib by googleads.
the class JaxWsSoapContextHandlerTest method testHandleMessage_outboundNoHeaders.
@Test
public void testHandleMessage_outboundNoHeaders() throws Exception {
final String mockSoapXml = "<Hi>Hello world!</Hi>";
Answer<Object> transform = (invocation) -> {
StreamResult stream = (StreamResult) invocation.getArguments()[1];
Streams.write(mockSoapXml, stream.getOutputStream(), Charset.forName(UTF_8));
return null;
};
when(mockSoapMessageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).thenReturn(Boolean.TRUE);
when(mockSoapMessageContext.getMessage()).thenReturn(mockMessage);
when(mockMessage.getSOAPPart()).thenReturn(mockSoapPart);
when(mockSoapPart.getEnvelope()).thenReturn(mockEnvelope);
when(mockEnvelope.addHeader()).thenReturn(mockHeader);
// captureServiceAndOperationNames
when(mockSoapMessageContext.get(MessageContext.WSDL_SERVICE)).thenReturn(wsdlService);
when(mockSoapMessageContext.getMessage()).thenReturn(mockMessage);
when(mockMessage.getSOAPBody()).thenReturn(mockSoapBody);
when(mockMessage.getSOAPPart()).thenReturn(mockSoapPart);
when(mockSoapBody.getFirstChild()).thenReturn(firstChild);
when(firstChild.getLocalName()).thenReturn(OPERATION_LOCAL_NAME);
// captureSoapXml
when(mockSoapMessageContext.getMessage()).thenReturn(mockMessage);
when(mockTransformerSupplier.get()).thenReturn(mockTransformer);
Mockito.doAnswer(transform).when(mockTransformer).transform(any(), any());
assertTrue(jaxWsSoapContextHandler.handleMessage(mockSoapMessageContext));
RequestInfo requestInfo = jaxWsSoapContextHandler.getLastRequestInfoBuilder().build();
assertEquals(mockSoapXml, requestInfo.getPayload());
assertEquals(wsdlService.getLocalPart(), requestInfo.getServiceName());
assertEquals(OPERATION_LOCAL_NAME, requestInfo.getMethodName());
}
use of com.google.api.ads.common.lib.client.RequestInfo in project googleads-java-lib by googleads.
the class JaxWsSoapContextHandlerTest method testHandleMessage_outboundWithHeaders.
@Test
public void testHandleMessage_outboundWithHeaders() throws Exception {
final String mockSoapXml = "<Hi>Hello world!</Hi>";
Answer<Object> transform = (invocation) -> {
StreamResult stream = (StreamResult) invocation.getArguments()[1];
Streams.write(mockSoapXml, stream.getOutputStream(), Charset.forName(UTF_8));
return null;
};
SOAPElement mockHeader1 = Mockito.mock(SOAPElement.class);
SOAPElement mockHeader2 = Mockito.mock(SOAPElement.class);
SOAPElement mockHeader3 = Mockito.mock(SOAPElement.class);
jaxWsSoapContextHandler.addHeader(null, null, mockHeader1);
jaxWsSoapContextHandler.addHeader(null, null, mockHeader2);
jaxWsSoapContextHandler.addHeader(null, null, mockHeader3);
when(mockSoapMessageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).thenReturn(Boolean.TRUE);
when(mockSoapMessageContext.getMessage()).thenReturn(mockMessage);
when(mockMessage.getSOAPHeader()).thenReturn(mockHeader);
// captureServiceAndOperationNames
when(mockSoapMessageContext.get(MessageContext.WSDL_SERVICE)).thenReturn(wsdlService);
when(mockSoapMessageContext.getMessage()).thenReturn(mockMessage);
when(mockMessage.getSOAPBody()).thenReturn(mockSoapBody);
when(mockMessage.getSOAPPart()).thenReturn(mockSoapPart);
when(mockSoapBody.getFirstChild()).thenReturn(firstChild);
when(firstChild.getLocalName()).thenReturn(OPERATION_LOCAL_NAME);
// captureSoapXml
when(mockSoapMessageContext.getMessage()).thenReturn(mockMessage);
when(mockTransformerSupplier.get()).thenReturn(mockTransformer);
Mockito.doAnswer(transform).when(mockTransformer).transform(any(), any());
assertTrue(jaxWsSoapContextHandler.handleMessage(mockSoapMessageContext));
RequestInfo requestInfo = jaxWsSoapContextHandler.getLastRequestInfoBuilder().build();
assertEquals(mockSoapXml, requestInfo.getPayload());
assertEquals(wsdlService.getLocalPart(), requestInfo.getServiceName());
assertEquals(OPERATION_LOCAL_NAME, requestInfo.getMethodName());
verify(mockHeader).addChildElement(mockHeader1);
verify(mockHeader).addChildElement(mockHeader2);
verify(mockHeader).addChildElement(mockHeader3);
}
use of com.google.api.ads.common.lib.client.RequestInfo in project googleads-java-lib by googleads.
the class JaxWsSoapContextHandlerTest method testCaptureServiceAndOperationNames_soapException.
@Test
public void testCaptureServiceAndOperationNames_soapException() throws Exception {
when(mockSoapMessageContext.get(MessageContext.WSDL_SERVICE)).thenReturn(wsdlService);
when(mockSoapMessageContext.getMessage()).thenReturn(mockMessage);
when(mockMessage.getSOAPBody()).thenThrow(new SOAPException());
jaxWsSoapContextHandler.captureServiceAndOperationNames(mockSoapMessageContext);
RequestInfo requestInfo = jaxWsSoapContextHandler.getLastRequestInfoBuilder().build();
assertEquals(wsdlService.getLocalPart(), requestInfo.getServiceName());
assertEquals("", requestInfo.getMethodName());
}
use of com.google.api.ads.common.lib.client.RequestInfo in project googleads-java-lib by googleads.
the class RemoteCallLoggerDelegateTest method testLogRequestSummary_failure.
@Test
public void testLogRequestSummary_failure() {
Throwable returnedException = new Throwable();
remoteCallReturn = new RemoteCallReturn.Builder().withRequestInfo(remoteCallReturn.getRequestInfo()).withResponseInfo(remoteCallReturn.getResponseInfo()).withException(returnedException).build();
when(requestInfoLogger.isWarnEnabled()).thenReturn(true);
loggerDelegate.logRequestSummary(remoteCallReturn);
RequestInfo requestInfo = remoteCallReturn.getRequestInfo();
ResponseInfo responseInfo = remoteCallReturn.getResponseInfo();
verify(requestInfoLogger).warn(RemoteCallLoggerDelegate.SUMMARY_TEMPLATE, requestInfo.getServiceName(), requestInfo.getMethodName(), requestInfo.getContextName(), requestInfo.getContextValue(), requestInfo.getUrl(), responseInfo.getRequestId(), responseInfo.getResponseTime(), responseInfo.getOperationsCount(), true, returnedException.toString());
}
use of com.google.api.ads.common.lib.client.RequestInfo in project googleads-java-lib by googleads.
the class RemoteCallLoggerDelegateTest method testLogRequestSummary_success.
@Test
public void testLogRequestSummary_success() {
// Set up the request info mock.
when(requestInfoLogger.isInfoEnabled()).thenReturn(true);
loggerDelegate.logRequestSummary(remoteCallReturn);
RequestInfo requestInfo = remoteCallReturn.getRequestInfo();
ResponseInfo responseInfo = remoteCallReturn.getResponseInfo();
verify(requestInfoLogger).info(RemoteCallLoggerDelegate.SUMMARY_TEMPLATE, requestInfo.getServiceName(), requestInfo.getMethodName(), requestInfo.getContextName(), requestInfo.getContextValue(), requestInfo.getUrl(), responseInfo.getRequestId(), responseInfo.getResponseTime(), responseInfo.getOperationsCount(), false, null);
}
Aggregations