Search in sources :

Example 6 with RequestInfo

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ResponseInfoXPathSet(com.google.api.ads.common.lib.soap.ResponseInfoXPathSet) Transformer(javax.xml.transform.Transformer) Mock(org.mockito.Mock) SOAPException(javax.xml.soap.SOAPException) StreamResult(javax.xml.transform.stream.StreamResult) Supplier(com.google.common.base.Supplier) RunWith(org.junit.runner.RunWith) Node(javax.xml.soap.Node) AdsApiConfiguration(com.google.api.ads.common.lib.conf.AdsApiConfiguration) Streams(com.google.api.ads.common.lib.utils.Streams) HashSet(java.util.HashSet) SOAPElement(javax.xml.soap.SOAPElement) MockitoAnnotations(org.mockito.MockitoAnnotations) Answer(org.mockito.stubbing.Answer) NodeExtractor(com.google.api.ads.common.lib.utils.NodeExtractor) Charset(java.nio.charset.Charset) SOAPHeader(javax.xml.soap.SOAPHeader) SOAPBody(javax.xml.soap.SOAPBody) MessageContext(javax.xml.ws.handler.MessageContext) Before(org.junit.Before) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Mockito.verify(org.mockito.Mockito.verify) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) Mockito(org.mockito.Mockito) SOAPPart(javax.xml.soap.SOAPPart) UTF_8(org.apache.commons.lang.CharEncoding.UTF_8) RequestInfoXPathSet(com.google.api.ads.common.lib.soap.RequestInfoXPathSet) QName(javax.xml.namespace.QName) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) Assert.assertEquals(org.junit.Assert.assertEquals) StreamResult(javax.xml.transform.stream.StreamResult) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Test(org.junit.Test)

Example 7 with RequestInfo

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ResponseInfoXPathSet(com.google.api.ads.common.lib.soap.ResponseInfoXPathSet) Transformer(javax.xml.transform.Transformer) Mock(org.mockito.Mock) SOAPException(javax.xml.soap.SOAPException) StreamResult(javax.xml.transform.stream.StreamResult) Supplier(com.google.common.base.Supplier) RunWith(org.junit.runner.RunWith) Node(javax.xml.soap.Node) AdsApiConfiguration(com.google.api.ads.common.lib.conf.AdsApiConfiguration) Streams(com.google.api.ads.common.lib.utils.Streams) HashSet(java.util.HashSet) SOAPElement(javax.xml.soap.SOAPElement) MockitoAnnotations(org.mockito.MockitoAnnotations) Answer(org.mockito.stubbing.Answer) NodeExtractor(com.google.api.ads.common.lib.utils.NodeExtractor) Charset(java.nio.charset.Charset) SOAPHeader(javax.xml.soap.SOAPHeader) SOAPBody(javax.xml.soap.SOAPBody) MessageContext(javax.xml.ws.handler.MessageContext) Before(org.junit.Before) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Mockito.verify(org.mockito.Mockito.verify) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) Mockito(org.mockito.Mockito) SOAPPart(javax.xml.soap.SOAPPart) UTF_8(org.apache.commons.lang.CharEncoding.UTF_8) RequestInfoXPathSet(com.google.api.ads.common.lib.soap.RequestInfoXPathSet) QName(javax.xml.namespace.QName) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) Assert.assertEquals(org.junit.Assert.assertEquals) StreamResult(javax.xml.transform.stream.StreamResult) SOAPElement(javax.xml.soap.SOAPElement) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Test(org.junit.Test)

Example 8 with RequestInfo

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());
}
Also used : SOAPException(javax.xml.soap.SOAPException) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Test(org.junit.Test)

Example 9 with RequestInfo

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());
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn) Test(org.junit.Test)

Example 10 with RequestInfo

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);
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Test(org.junit.Test)

Aggregations

RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)16 ResponseInfo (com.google.api.ads.common.lib.client.ResponseInfo)11 Test (org.junit.Test)11 RemoteCallReturn (com.google.api.ads.common.lib.client.RemoteCallReturn)6 SOAPException (javax.xml.soap.SOAPException)3 SOAPHeader (javax.xml.soap.SOAPHeader)3 SOAPMessage (javax.xml.soap.SOAPMessage)3 SOAPPart (javax.xml.soap.SOAPPart)3 StreamResult (javax.xml.transform.stream.StreamResult)3 Before (org.junit.Before)3 AdsApiConfiguration (com.google.api.ads.common.lib.conf.AdsApiConfiguration)2 RequestInfoXPathSet (com.google.api.ads.common.lib.soap.RequestInfoXPathSet)2 ResponseInfoXPathSet (com.google.api.ads.common.lib.soap.ResponseInfoXPathSet)2 NodeExtractor (com.google.api.ads.common.lib.utils.NodeExtractor)2 Streams (com.google.api.ads.common.lib.utils.Streams)2 Supplier (com.google.common.base.Supplier)2 OutputStream (java.io.OutputStream)2 Charset (java.nio.charset.Charset)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2