Search in sources :

Example 1 with RemoteCallReturn

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

the class BatchJobLoggerTest method testLogUpload.

/**
 * Confirms an upload is logged as expected.
 */
@Test
public void testLogUpload() throws IOException {
    String contentsString = "some contents";
    InputStream responseContent = CharSource.wrap(contentsString).asByteSource(UTF_8).openStream();
    BatchJobUploadResponse response = new BatchJobUploadResponse(responseContent, statusCode, statusMessage, contentsString.length(), URI.create(url));
    ArgumentCaptor<RemoteCallReturn> returnCaptor = ArgumentCaptor.forClass(RemoteCallReturn.class);
    batchJobLogger.logUpload(contentsString, URI.create(url), response, exception);
    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());
    assertThat(requestInfo.getPayload(), containsString(contentsString));
    assertThat(requestInfo.getServiceName(), containsString("upload"));
    ResponseInfo responseInfo = capturedReturn.getResponseInfo();
    assertNull(responseInfo.getRequestId());
    assertThat(responseInfo.getPayload(), startsWith(String.valueOf(response.getHttpStatus())));
    assertThat(responseInfo.getPayload(), containsString(response.getHttpResponseMessage()));
    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) BatchJobUploadResponse(com.google.api.ads.adwords.lib.utils.BatchJobUploadResponse) InputStream(java.io.InputStream) 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)

Example 2 with RemoteCallReturn

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

the class BatchJobLoggerTest method testLogUpload_nullablesNull.

/**
 * Confirms that passing {@code null} to {@code logUpload} for parameters marked {@code Nullable}
 * does not result in any exceptions.
 */
@Test
public void testLogUpload_nullablesNull() {
    String contentsString = "success contents";
    ArgumentCaptor<RemoteCallReturn> returnCaptor = ArgumentCaptor.forClass(RemoteCallReturn.class);
    batchJobLogger.logUpload(contentsString, URI.create(url), null, null);
    verify(loggerDelegate).logRequestSummary(returnCaptor.capture());
    RemoteCallReturn capturedReturn = returnCaptor.getValue();
    assertNull(capturedReturn.getException());
    verify(loggerDelegate).logRequestDetails(returnCaptor.capture());
    assertSame("The same RemoteCallReturn object was not passed to request details and request summary", capturedReturn, returnCaptor.getValue());
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn) Test(org.junit.Test)

Example 3 with RemoteCallReturn

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

Example 4 with RemoteCallReturn

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

the class BatchJobLoggerTest method testLogDownload_nullablesNull.

/**
 * Confirms that passing {@code null} to {@code logUpload} for parameters marked {@code Nullable}
 * does not result in any exceptions.
 */
@Test
public void testLogDownload_nullablesNull() {
    batchJobLogger.logDownload(url, null, null);
    ArgumentCaptor<RemoteCallReturn> returnCaptor = ArgumentCaptor.forClass(RemoteCallReturn.class);
    verify(loggerDelegate).logRequestSummary(returnCaptor.capture());
    RemoteCallReturn capturedReturn = returnCaptor.getValue();
    assertNull(capturedReturn.getException());
    ResponseInfo responseInfo = capturedReturn.getResponseInfo();
    assertEquals("Results count: 0", 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) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn) Test(org.junit.Test)

Example 5 with RemoteCallReturn

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

the class SoapServiceClient method invoke.

/**
 * Wraps the underlying SOAP RPC such that first the method, by its name,
 * is applied to the runtime class. If no such method exists, it is assumed
 * that the call is meant for the SOAP client. In this case, the SOAP client
 * handler will invoke the SOAP client method with provided arguments.
 *
 * @param proxy the proxy class that invoke was called on
 * @param method the method to apply to the proxy class or the underlying SOAP
 *     client
 * @param args the method arguments
 * @return the return from the {@code SoapServiceClient} or a
 *     {@link RemoteCallReturn} object containing the result from the SOAP call
 * @see InvocationHandler#invoke(Object, Method, Object[])
 * @throws Throwable thrown if the SOAP call passed into this method results
 *     in an exception. The exception thrown will be not be wrapped - it will
 *     adhere to the "throws" clause of the passed in {@code Method}.
 */
@Override
public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable {
    try {
        return getClass().getMethod(method.getName(), method.getParameterTypes()).invoke(this, args);
    } catch (NoSuchMethodException e) {
    // Ignore and let the SOAP client handler take over.
    }
    setHeaders();
    RemoteCallReturn remoteCallReturn = callSoapClient(createSoapCall(soapClientHandler.getSoapClientMethod(soapClient, method), args));
    logSoapCall(remoteCallReturn);
    return unwrapRemoteCallReturn(remoteCallReturn);
}
Also used : RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn)

Aggregations

RemoteCallReturn (com.google.api.ads.common.lib.client.RemoteCallReturn)17 Test (org.junit.Test)11 ResponseInfo (com.google.api.ads.common.lib.client.ResponseInfo)8 RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)7 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ServiceException (com.google.api.ads.common.lib.exception.ServiceException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 SOAPException (javax.xml.soap.SOAPException)2 BindingProvider (javax.xml.ws.BindingProvider)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 SoapCall (com.google.api.ads.common.lib.soap.SoapCall)1 CampaignServiceInterface (com.google.api.ads.common.lib.soap.jaxws.testing.mocks.CampaignServiceInterface)1 CampaignServiceInterfaceImpl (com.google.api.ads.common.lib.soap.jaxws.testing.mocks.CampaignServiceInterfaceImpl)1 InputStream (java.io.InputStream)1 MessageContext (org.apache.axis.MessageContext)1 Stub (org.apache.axis.client.Stub)1