Search in sources :

Example 6 with ResponseInfo

use of com.google.api.ads.common.lib.client.ResponseInfo 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 7 with ResponseInfo

use of com.google.api.ads.common.lib.client.ResponseInfo 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)

Example 8 with ResponseInfo

use of com.google.api.ads.common.lib.client.ResponseInfo in project googleads-java-lib by googleads.

the class ReportServiceLoggerTest method testBuildInfos_failure.

@Test
public void testBuildInfos_failure() {
    RequestInfo requestInfo = reportServiceLogger.buildRequestInfo(httpRequest);
    checkRequestInfoAttributes(requestInfo, true);
    ResponseInfo responseInfo = reportServiceLogger.buildResponseInfo(httpRequest, HttpStatusCodes.STATUS_CODE_BAD_GATEWAY, "Bad gateway");
    checkResponseInfoAttributes(responseInfo, HttpStatusCodes.STATUS_CODE_BAD_GATEWAY, "Bad gateway");
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Test(org.junit.Test)

Example 9 with ResponseInfo

use of com.google.api.ads.common.lib.client.ResponseInfo in project googleads-java-lib by googleads.

the class ReportServiceLoggerTest method testBuildInfos_success.

@Test
public void testBuildInfos_success() {
    RequestInfo requestInfo = reportServiceLogger.buildRequestInfo(httpRequest);
    checkRequestInfoAttributes(requestInfo, true);
    ResponseInfo responseInfo = reportServiceLogger.buildResponseInfo(httpRequest, HttpStatusCodes.STATUS_CODE_OK, null);
    checkResponseInfoAttributes(responseInfo, HttpStatusCodes.STATUS_CODE_OK, 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)

Example 10 with ResponseInfo

use of com.google.api.ads.common.lib.client.ResponseInfo in project googleads-java-lib by googleads.

the class ResponseInfoXPathSetTest method testParseActualMessage.

@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.ArgumentMatchers.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());
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) Builder(com.google.api.ads.common.lib.client.ResponseInfo.Builder) OutputStream(java.io.OutputStream) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) Test(org.junit.Test)

Aggregations

ResponseInfo (com.google.api.ads.common.lib.client.ResponseInfo)12 RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)10 Test (org.junit.Test)8 RemoteCallReturn (com.google.api.ads.common.lib.client.RemoteCallReturn)6 Matchers.containsString (org.hamcrest.Matchers.containsString)2 BatchJobMutateResultInterface (com.google.api.ads.adwords.lib.utils.BatchJobMutateResultInterface)1 BatchJobUploadResponse (com.google.api.ads.adwords.lib.utils.BatchJobUploadResponse)1 ReportException (com.google.api.ads.adwords.lib.utils.ReportException)1 Builder (com.google.api.ads.common.lib.client.ResponseInfo.Builder)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 SOAPHeader (javax.xml.soap.SOAPHeader)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 Before (org.junit.Before)1