Package com.google.api.client.http

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


   public void should_MakeSuccessfulRequest_AndReturnMultipleSequencedResponses_FromFile_WithBadUrls() throws Exception {

      final String requestUrl = String.format("%s%s", STUBS_URL, "/uri/with/sequenced/responses/infile/withbadurls");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      HttpResponse firstSequenceResponse = request.execute();
      String firstResponseContent = firstSequenceResponse.parseAsString().trim();

      assertThat(HttpStatus.CREATED_201).isEqualTo(firstSequenceResponse.getStatusCode());
      assertThat(firstResponseContent).isEmpty();

      final HttpResponse secondSequenceResponse = request.execute();
      final String secondResponseContent = secondSequenceResponse.parseAsString().trim();

      assertThat(HttpStatus.CREATED_201).isEqualTo(secondSequenceResponse.getStatusCode());
      assertThat(secondResponseContent).isEqualTo("Still going strong!");

      final HttpResponse thirdSequenceResponse = request.execute();
      final String thirdResponseContent = thirdSequenceResponse.parseAsString().trim();

      assertThat(HttpStatus.INTERNAL_SERVER_ERROR_500).isEqualTo(thirdSequenceResponse.getStatusCode());
      assertThat(thirdResponseContent).isEmpty();

      firstSequenceResponse = request.execute();
      firstResponseContent = firstSequenceResponse.parseAsString().trim();
View Full Code Here


            "Who was busy with three boys of his own." + BR +
            "They were four men, living all together," + BR +
            "Yet they were all alone.";
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.POST, requestUrl, content);

      final HttpResponse response = request.execute();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(response.parseAsString().trim()).isEqualTo("OK");
   }
View Full Code Here

   public void should_ReturnExpectedResourceIdHeader_WhenSuccessfulRequestMade() throws Exception {

      final String requestUrl = String.format("%s%s", STUBS_URL, "/this/stub/should/always/be/second/in/this/file");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      final HttpResponse response = request.execute();

      final HttpHeaders headers = response.getHeaders();
      assertThat(headers.getContentType().contains("application/json")).isTrue();
      assertThat(headers.containsKey(StubResponse.STUBBY_RESOURCE_ID_HEADER)).isTrue();
      final List<String> headerValues = (List<String>) headers.get(StubResponse.STUBBY_RESOURCE_ID_HEADER);
      assertThat(headerValues.get(0)).isEqualTo("1");
   }
View Full Code Here

   @Test
   public void should_ReturnReplacedTokenizedResponse_WhenCapturingGroupsEqualToNumberOfTokens() throws Exception {
      String requestUrl = String.format("%s%s", STUBS_URL, "/resources/invoices/12345/category/milk");
      HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      HttpResponse response = request.execute();
      String responseContent = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(responseContent).isEqualTo("Returned invoice number# 12345 in category 'milk'");


      requestUrl = String.format("%s%s", STUBS_URL, "/resources/invoices/88888/category/army");
      request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      response = request.execute();
      responseContent = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(responseContent).isEqualTo("Returned invoice number# 88888 in category 'army'");
   }
View Full Code Here

   @Test
   public void should_ReturnReplacedTokenizedResponse_WhenUsingExternalFile() throws Exception {
      String requestUrl = String.format("%s%s", STUBS_URL, "/account/12345/category/milk?date=Saturday");
      HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      HttpResponse response = request.execute();
      String responseContent = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(responseContent).isEqualTo("Returned invoice number# 12345 in category 'milk' on the date 'Saturday'");


      requestUrl = String.format("%s%s", STUBS_URL, "/account/88888/category/army?date=NOW");
      request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      response = request.execute();
      responseContent = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(responseContent).isEqualTo("Returned invoice number# 88888 in category 'army' on the date 'NOW'");
   }
View Full Code Here

   @Test
   public void should_ReturnReplacedTokenizedResponse_WhenCapturingGroupsNotEqualsToNumberOfTokens() throws Exception {
      final String requestUrl = String.format("%s%s", STUBS_URL, "/resources/invoices/22222");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      final HttpResponse response = request.execute();

      String responseContent = response.parseAsString().trim();
      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(responseContent).isEqualTo("Returned invoice number# 22222 in category '<%url.2%>'");
   }
View Full Code Here

      final HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.set("custom-header", "XYZ");
      request.setHeaders(httpHeaders);

      final HttpResponse response = request.execute();

      String responseContent = response.parseAsString().trim();
      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(responseContent).isEqualTo("Returned content with URL /no/explicit/groups/22222, query param ABC and custom-header XYZ");
   }
View Full Code Here

   @Test
   public void should_ReturnReplacedTokenizedResponse_WhenCapturingGroupHasSubgroups() throws Exception {
      final String requestUrl = String.format("%s%s", STUBS_URL, "/groups/with/sub/groups/abc-123");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      final HttpResponse response = request.execute();

      String responseContent = response.parseAsString().trim();
      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(responseContent).isEqualTo("Returned content with URL /groups/with/sub/groups/abc-123, parent group abc-123 and two sub-groups abc & 123");
   }
View Full Code Here

   @Test
   public void should_MakeSuccessfulRequest_WhenGetRequestMadeWithNoEqualSignInQueryStringParam() throws Exception {

      final String requestUrl = String.format("%s%s", STUBS_URL, "/empty.param?type_name&client_secret=secret");
      final HttpResponse response = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl).execute();
      final String responseContentAsString = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(responseContentAsString).contains("EMPTY WORKS");
   }
View Full Code Here

      final int invalidIndex = 88888888;
      final String requestUrl = String.format("%s/%s", ADMIN_URL, invalidIndex);
      final HttpRequest httpGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      final HttpResponse httpResponse = httpGetRequest.execute();
      final String statusMessage = httpResponse.getStatusMessage().trim();

      final String expectedMessage = String.format("Stub request index#%s does not exist, cannot display", invalidIndex);

      assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT_204);
      assertThat(statusMessage).isEqualTo(expectedMessage);
   }
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.