use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest in project appengine-java-standard by GoogleCloudPlatform.
the class URLFetchServiceImplTest method testSync_CannotConnect.
@Test
public void testSync_CannotConnect() throws Exception {
URL url = new URL("http://non-existent-domain.com/foo");
HTTPRequest request = new HTTPRequest(url);
URLFetchRequest requestProto = URLFetchRequest.newBuilder().setUrl(url.toString()).setMethod(RequestMethod.GET).setFollowRedirects(true).build();
String errorDetails = "details";
when(delegate.makeSyncCall(same(ApiProxy.getCurrentEnvironment()), eq(URLFetchServiceImpl.PACKAGE), eq("Fetch"), eq(requestProto.toByteArray()))).thenThrow(new ApiProxy.ApplicationException(ErrorCode.FETCH_ERROR.getNumber(), errorDetails));
IOException ex = assertThrows(IOException.class, () -> new URLFetchServiceImpl().fetch(request));
assertThat(ex).hasMessageThat().isEqualTo("Could not fetch URL: http://non-existent-domain.com/foo, error: " + errorDetails);
}
use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest in project appengine-java-standard by GoogleCloudPlatform.
the class URLFetchServiceImplTest method testSync_InternalTransientError.
@Test
public void testSync_InternalTransientError() throws Exception {
URL url = new URL("http://internaltransienterror.com/foo");
HTTPRequest request = new HTTPRequest(url);
URLFetchRequest requestProto = URLFetchRequest.newBuilder().setUrl(url.toString()).setMethod(RequestMethod.GET).setFollowRedirects(true).build();
String errorDetails = "details";
when(delegate.makeSyncCall(same(ApiProxy.getCurrentEnvironment()), eq(URLFetchServiceImpl.PACKAGE), eq("Fetch"), eq(requestProto.toByteArray()))).thenThrow(new ApiProxy.ApplicationException(ErrorCode.INTERNAL_TRANSIENT_ERROR.getNumber(), errorDetails));
InternalTransientException ex = assertThrows(InternalTransientException.class, () -> new URLFetchServiceImpl().fetch(request));
assertThat(ex).hasMessageThat().contains(url.toString());
}
use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest in project appengine-java-standard by GoogleCloudPlatform.
the class URLFetchServiceImplTest method testSync_MalformedReplyException.
@Test
public void testSync_MalformedReplyException() throws Exception {
URL url = new URL("http://badhttpreply.com/foo");
HTTPRequest request = new HTTPRequest(url);
URLFetchRequest requestProto = URLFetchRequest.newBuilder().setUrl(url.toString()).setMethod(RequestMethod.GET).setFollowRedirects(true).build();
String errorDetails = "details";
when(delegate.makeSyncCall(same(ApiProxy.getCurrentEnvironment()), eq(URLFetchServiceImpl.PACKAGE), eq("Fetch"), eq(requestProto.toByteArray()))).thenThrow(new ApiProxy.ApplicationException(ErrorCode.MALFORMED_REPLY.getNumber(), errorDetails));
IOException ex = assertThrows(IOException.class, () -> new URLFetchServiceImpl().fetch(request));
assertThat(ex).hasMessageThat().contains(url.toString());
}
use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest in project appengine-java-standard by GoogleCloudPlatform.
the class URLFetchServiceImplTest method testSync_Redirects_doNotFollowRedirects.
@Test
public void testSync_Redirects_doNotFollowRedirects() throws Exception {
URL url = new URL("http://non-existent-domain.com/foo");
HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET, doNotFollowRedirects());
URLFetchRequest requestProto = URLFetchRequest.newBuilder().setUrl(url.toString()).setMethod(RequestMethod.GET).setFollowRedirects(false).build();
URLFetchResponse responseProto = URLFetchResponse.newBuilder().setStatusCode(302).build();
when(delegate.makeSyncCall(same(ApiProxy.getCurrentEnvironment()), eq(URLFetchServiceImpl.PACKAGE), eq("Fetch"), eq(requestProto.toByteArray()))).thenReturn(responseProto.toByteArray());
HTTPResponse response = new URLFetchServiceImpl().fetch(request);
assertThat(response.getResponseCode()).isEqualTo(302);
verify(delegate).makeSyncCall(any(), any(), any(), any());
}
use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest in project appengine-java-standard by GoogleCloudPlatform.
the class URLFetchServiceImplTest method testAsync_Timeout2.
@Test
public void testAsync_Timeout2() throws Exception {
URL url = new URL("http://slow-domain.com/foo");
HTTPRequest request = new HTTPRequest(url);
URLFetchRequest requestProto = URLFetchRequest.newBuilder().setUrl(url.toString()).setMethod(RequestMethod.GET).setFollowRedirects(true).build();
when(delegate.makeAsyncCall(same(ApiProxy.getCurrentEnvironment()), eq(URLFetchServiceImpl.PACKAGE), eq("Fetch"), eq(requestProto.toByteArray()), any())).thenReturn(Futures.immediateFailedFuture(new ApiProxy.ApiDeadlineExceededException("urlfetch", "fetch")));
Future<HTTPResponse> response = new URLFetchServiceImpl().fetchAsync(request);
ExecutionException ex = assertThrows(ExecutionException.class, response::get);
assertThat(ex).hasCauseThat().isInstanceOf(SocketTimeoutException.class);
assertThat(ex).hasCauseThat().hasMessageThat().isEqualTo("Timeout while fetching URL: http://slow-domain.com/foo");
}
Aggregations