use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchResponse 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.URLFetchResponse in project appengine-java-standard by GoogleCloudPlatform.
the class URLFetchServiceImplTest method testSync_SimplePOST.
@Test
public void testSync_SimplePOST() throws Exception {
String requestContent = "this=is&post=content";
String responseContent = "<p>This is the desired response.</p>";
URL url = new URL("http://google.com/foo");
HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST);
request.setPayload(requestContent.getBytes(UTF_8));
URLFetchRequest requestProto = URLFetchRequest.newBuilder().setUrl(url.toString()).setMethod(RequestMethod.POST).setPayload(ByteString.copyFromUtf8(requestContent)).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);
}
use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchResponse in project appengine-java-standard by GoogleCloudPlatform.
the class LocalURLFetchCertValidationTest method testCertNotVerifiedWithoutAsking.
@Test
public void testCertNotVerifiedWithoutAsking() throws Exception {
LocalRpcService.Status status = new LocalRpcService.Status();
URLFetchRequest request = URLFetchRequest.newBuilder().setMethod(RequestMethod.GET).setUrl(urlWithInvalidCert).setMustValidateServerCertificate(false).setFollowRedirects(false).build();
URLFetchResponse response = fetchService.fetch(status, request);
assertThat(status.getErrorCode()).isEqualTo(ErrorCode.OK.getNumber());
assertThat(response.getStatusCode()).isEqualTo(302);
}
use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchResponse in project appengine-java-standard by GoogleCloudPlatform.
the class URLFetchServiceImplTest method testSync_SimpleDELETE.
@Test
public void testSync_SimpleDELETE() throws Exception {
String responseContent = "<p>This is the desired response.</p>";
URL url = new URL("http://google.com/foo");
HTTPRequest request = new HTTPRequest(url, HTTPMethod.DELETE);
URLFetchRequest requestProto = URLFetchRequest.newBuilder().setUrl(url.toString()).setMethod(RequestMethod.DELETE).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);
}
use of com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchResponse 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();
}
Aggregations