Search in sources :

Example 1 with BatchJobMutateResultInterface

use of com.google.api.ads.adwords.lib.utils.BatchJobMutateResultInterface in project googleads-java-lib by googleads.

the class BatchJobLoggerTest method testLogDownload.

/**
 * Confirms a download is logged as expected.
 */
@SuppressWarnings("unchecked")
@Test
public void testLogDownload() {
    BatchJobMutateResponseInterface<String, IllegalArgumentException, BatchJobMutateResultInterface<String, IllegalArgumentException>> response = Mockito.mock(BatchJobMutateResponseInterface.class);
    // Cannot specify generic args for mocks
    @SuppressWarnings("rawtypes") BatchJobMutateResultInterface[] mutateResults = new BatchJobMutateResultInterface[] { Mockito.mock(BatchJobMutateResultInterface.class), Mockito.mock(BatchJobMutateResultInterface.class) };
    when(response.getMutateResults()).thenReturn(mutateResults);
    batchJobLogger.logDownload(url, response, exception);
    ArgumentCaptor<RemoteCallReturn> returnCaptor = ArgumentCaptor.forClass(RemoteCallReturn.class);
    verify(loggerDelegate).logRequestSummary(returnCaptor.capture());
    RemoteCallReturn capturedReturn = returnCaptor.getValue();
    assertEquals(exception, capturedReturn.getException());
    RequestInfo requestInfo = capturedReturn.getRequestInfo();
    assertEquals(url, requestInfo.getUrl());
    assertEquals("clientCustomerId", requestInfo.getContextName());
    assertNull(requestInfo.getContextValue());
    assertNull(requestInfo.getPayload());
    assertThat(requestInfo.getServiceName(), containsString("download"));
    ResponseInfo responseInfo = capturedReturn.getResponseInfo();
    assertNull(responseInfo.getRequestId());
    assertEquals("Results count: 2", responseInfo.getPayload());
    verify(loggerDelegate).logRequestDetails(returnCaptor.capture());
    assertSame("The same RemoteCallReturn object was not passed to request details and request summary", capturedReturn, returnCaptor.getValue());
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) BatchJobMutateResultInterface(com.google.api.ads.adwords.lib.utils.BatchJobMutateResultInterface) Matchers.containsString(org.hamcrest.Matchers.containsString) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn) Test(org.junit.Test)

Aggregations

BatchJobMutateResultInterface (com.google.api.ads.adwords.lib.utils.BatchJobMutateResultInterface)1 RemoteCallReturn (com.google.api.ads.common.lib.client.RemoteCallReturn)1 RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)1 ResponseInfo (com.google.api.ads.common.lib.client.ResponseInfo)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1