Package com.google.api.client.http

Examples of com.google.api.client.http.HttpResponse


   @Test
   public void should_MakeSuccessfulRequest_WhenQueryParamsAreAnArrayWithEscapedQuotedElements() throws Exception {
      final String requestUrl = String.format("%s%s", STUBS_URL, "/entity.find?type_name=user&client_id=id&client_secret=secret&attributes=[%22id%22,%22uuid%22,%22created%22,%22lastUpdated%22,%22displayName%22,%22email%22,%22givenName%22,%22familyName%22]");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      final HttpResponse response = request.execute();
      final String responseContent = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat("{\"status\": \"hello world\"}").isEqualTo(responseContent);
   }
View Full Code Here


   @Test
   public void should_MakeSuccessfulRequest_WhenQueryParamsAreAnArray() throws Exception {
      final String requestUrl = String.format("%s%s", STUBS_URL, "/entity.find.again?type_name=user&client_id=id&client_secret=secret&attributes=[id,uuid,created,lastUpdated,displayName,email,givenName,familyName]");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      final HttpResponse response = request.execute();
      final String responseContent = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat("{\"status\": \"hello world\"}").isEqualTo(responseContent);
   }
View Full Code Here

   @Test
   public void should_ReactToPostRequest_WithoutPost_AndPostNotSupplied() throws Exception {
      final String requestUrl = String.format("%s%s", STUBS_URL, "/invoice/new/no/post");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.POST, requestUrl);

      final HttpResponse response = request.execute();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT_204);
   }
View Full Code Here

   public void should_ReactToPostRequest_WithoutPost_AndPostSupplied() throws Exception {
      final String requestUrl = String.format("%s%s", STUBS_URL, "/invoice/new/no/post");
      final String content = "{\"name\": \"chocolate\", \"description\": \"full\", \"department\": \"savoury\"}";
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.POST, requestUrl, content);

      final HttpResponse response = request.execute();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT_204);
   }
View Full Code Here

   @Test
   public void should_ReturnPDF_WhenGetRequestMade() throws Exception {

      final String requestUrl = String.format("%s%s", STUBS_URL, "/pdf/hello-world");
      final HttpResponse response = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl).execute();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(response.getHeaders()).containsKey("content-type");
      assertThat(response.getHeaders().getContentType()).contains("application/pdf;charset=UTF-8");
      assertThat(response.getHeaders()).containsKey("content-disposition");
   }
View Full Code Here

      final URL jsonContentUrl = StubsPortalTest.class.getResource("/json/response.json");
      assertThat(jsonContentUrl).isNotNull();
      final String expectedContent = StringUtils.inputStreamToString(jsonContentUrl.openStream());

      final String requestUrl = String.format("%s%s", STUBS_URL, "/invoice?status=active&type=full");
      final HttpResponse response = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl).execute();

      final String contentTypeHeader = response.getContentType();
      final String responseContent = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(expectedContent).isEqualTo(responseContent);
      assertThat(contentTypeHeader).contains(HEADER_APPLICATION_JSON);
   }
View Full Code Here

   @Test
   public void should_FailToReturnAllProducts_WhenGetRequestMadeWithoutRequiredQueryString() throws Exception {

      final String requestUrl = String.format("%s%s", STUBS_URL, "/invoice?status=active");
      final HttpResponse response = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl).execute();
      final String responseContentAsString = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
      assertThat(responseContentAsString).contains("(404) Nothing found for GET request at URI /invoice?status=active");
   }
View Full Code Here

      final URL jsonContentUrl = StubsPortalTest.class.getResource("/json/response.json");
      assertThat(jsonContentUrl).isNotNull();
      final String expectedContent = StringUtils.inputStreamToString(jsonContentUrl.openStream());

      final String requestUrl = String.format("%s%s", STUBS_SSL_URL, "/invoice?status=active&type=full");
      final HttpResponse response = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl).execute();

      final String contentTypeHeader = response.getContentType();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(expectedContent).isEqualTo(response.parseAsString().trim());
      assertThat(contentTypeHeader).contains(HEADER_APPLICATION_JSON);
   }
View Full Code Here

   @Test
   public void should_FailToReturnAllProducts_WhenGetRequestMadeWithoutRequiredQueryStringOverSsl() throws Exception {

      final String requestUrl = String.format("%s%s", STUBS_SSL_URL, "/invoice?status=active");
      final HttpResponse response = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl).execute();
      final String responseContentAsString = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
      assertThat(responseContentAsString).contains("(404) Nothing found for GET request at URI /invoice?status=active");

   }
View Full Code Here

      final HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.setContentType(HEADER_APPLICATION_JSON);

      request.setHeaders(httpHeaders);

      final HttpResponse response = request.execute();
      final String contentTypeHeader = response.getContentType();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat("{\"id\": \"123\", \"status\": \"updated\"}").isEqualTo(response.parseAsString().trim());
      assertThat(contentTypeHeader).contains(HEADER_APPLICATION_JSON);
   }
View Full Code Here

TOP

Related Classes of com.google.api.client.http.HttpResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.