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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations