use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest in project appengine-java-standard by GoogleCloudPlatform.
the class URLFetchServiceImplTest method testSync_DnsLookupFailedException.
@Test
public void testSync_DnsLookupFailedException() throws Exception {
URL url = new URL("http://dnsfailure.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.DNS_ERROR.getNumber(), errorDetails));
UnknownHostException ex = assertThrows(UnknownHostException.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_ResponseTooLarge.
@Test
public void testSync_ResponseTooLarge() throws Exception {
URL url = new URL("http://toomuchdata.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.RESPONSE_TOO_LARGE.getNumber(), errorDetails));
ResponseTooLargeException ex = assertThrows(ResponseTooLargeException.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_SimpleGET.
@Test
public void testSync_SimpleGET() throws Exception {
URL url = new URL("http://google.com/foo");
HTTPRequest request = new HTTPRequest(url);
String responseContent = "<p>This is the desired response.</p>";
URLFetchRequest requestProto = URLFetchRequest.newBuilder().setUrl(url.toString()).setMethod(RequestMethod.GET).setFollowRedirects(true).build();
URLFetchResponse responseProto = URLFetchResponse.newBuilder().setStatusCode(200).setContent(ByteString.copyFromUtf8(responseContent)).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(200);
assertThat(new String(response.getContent(), UTF_8)).isEqualTo(responseContent);
assertThat(response.getFinalUrl()).isNull();
}
use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest in project appengine-java-standard by GoogleCloudPlatform.
the class URLFetchServiceImplTest method testSync_ConnectionClosedException.
@Test
public void testSync_ConnectionClosedException() throws Exception {
URL url = new URL("http://connectionclosed.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.CLOSED.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_TooManyRedirectsException.
@Test
public void testSync_TooManyRedirectsException() throws Exception {
URL url = new URL("http://toomanyredirects.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.TOO_MANY_REDIRECTS.getNumber(), errorDetails));
IOException ex = assertThrows(IOException.class, () -> new URLFetchServiceImpl().fetch(request));
assertThat(ex).hasMessageThat().contains(url.toString());
}
Aggregations