Package com.google.api.client.http

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


   public void should_ReturnExpectedError_WhenSuccessfulPutMade_ToAdminPortalRoot() throws Exception {

      final String requestUrl = String.format("%s/", ADMIN_URL);
      final HttpRequest httpPutRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl);

      final HttpResponse httpResponse = httpPutRequest.execute();
      final String statusMessage = httpResponse.getStatusMessage().trim();
      final String responseMessage = httpResponse.parseAsString().trim();

      assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.METHOD_NOT_ALLOWED_405);
      assertThat(statusMessage).isEqualTo("Method Not Allowed");
      assertThat(responseMessage).isEqualTo("Method PUT is not allowed on URI /");
   }
View Full Code Here


   public void should_ReturnExpectedError_WhenSuccessfulEmptyPutMade_ToAdminPortalRootWithValidIndexURI() throws Exception {

      final String requestUrl = String.format("%s/1", ADMIN_URL);
      final HttpRequest httpPuttRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl);

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

      assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT_204);
      assertThat(statusMessage).isEqualTo("PUT request on URI /1 was empty");
   }
View Full Code Here

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

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

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

      assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT_204);
      assertThat(statusMessage).isEqualTo(expectedMessage);
   }
View Full Code Here

   @Test
   public void should_UpdateStubbedRequest_WhenSuccessfulPutMade_ToAdminPortalRootWithValidIndexURI() throws Exception {

      final String requestUrl = String.format("%s%s", ADMIN_URL, "/0");
      HttpRequest httpGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      HttpResponse httpGetResponse = httpGetRequest.execute();
      String getResponseContent = httpGetResponse.parseAsString().trim();

      assertThat(HttpStatus.OK_200).isEqualTo(httpGetResponse.getStatusCode());
      assertThat(getResponseContent).containsOnlyOnce("request");
      assertThat(getResponseContent).containsOnlyOnce("url: ^/resources/asn/");
      assertThat(getResponseContent).containsOnlyOnce("response");
      assertThat(getResponseContent).containsOnlyOnce("content-type: application/json");

      final String yamlToUpdate = new YamlBuilder()
         .newStubbedRequest()
         .withUrl("^/resources/something/new")
         .withMethodGet()
         .withQuery("someKey", "someValue")
         .newStubbedResponse()
         .withHeaderContentType("application/xml")
         .withLiteralBody("OK")
         .withStatus("201")
         .build();

      final HttpRequest httpPutRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl, yamlToUpdate);

      final HttpResponse httpPutResponse = httpPutRequest.execute();
      final String putResponseContent = httpPutResponse.parseAsString().trim();
      final String putResponseLocationHeader = httpPutResponse.getHeaders().getLocation();

      assertThat(HttpStatus.OK_200).isEqualTo(httpGetResponse.getStatusCode());
      assertThat(putResponseLocationHeader).isEqualTo("^/resources/something/new?someKey=someValue");
      assertThat(putResponseContent).isEqualTo("Stub request index#0 updated successfully");
View Full Code Here

   @Test
   public void should_UpdateStubbedRequest_WithJsonRequest_ToAdminPortalRootWithValidIndexURI() throws Exception {

      final String requestUrl = String.format("%s%s", ADMIN_URL, "/0");
      HttpRequest httpGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      HttpResponse httpGetResponse = httpGetRequest.execute();
      String getResponseContent = httpGetResponse.parseAsString().trim();

      assertThat(HttpStatus.OK_200).isEqualTo(httpGetResponse.getStatusCode());
      assertThat(getResponseContent).containsOnlyOnce("request");
      assertThat(getResponseContent).containsOnlyOnce("url: ^/resources/asn/");
      assertThat(getResponseContent).containsOnlyOnce("response");
      assertThat(getResponseContent).containsOnlyOnce("content-type: application/json");

      final URL url = AdminPortalTest.class.getResource("/json/update.request.without.escaped.slashes.json");
      final InputStream jsonInputStream = url.openStream();
      final String jsonToUpdate = StringUtils.inputStreamToString(jsonInputStream);

      final HttpRequest httpPutRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl, jsonToUpdate);

      final HttpResponse httpPutResponse = httpPutRequest.execute();
      final String putResponseContent = httpPutResponse.parseAsString().trim();
      final String putResponseLocationHeader = httpPutResponse.getHeaders().getLocation();

      assertThat(HttpStatus.OK_200).isEqualTo(httpGetResponse.getStatusCode());
      assertThat(putResponseLocationHeader).isEqualTo("^/resources/something/new?someKey=someValue");
      assertThat(putResponseContent).isEqualTo("Stub request index#0 updated successfully");
View Full Code Here

   @Test
   public void should_UpdateStubbedRequest_WithEnquotedForwardSlashesEscapedJsonRequest_ToAdminPortalRootWithValidIndexURI() throws Exception {

      final String requestUrl = String.format("%s%s", ADMIN_URL, "/0");
      HttpRequest httpGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      HttpResponse httpGetResponse = httpGetRequest.execute();
      String getResponseContent = httpGetResponse.parseAsString().trim();

      assertThat(HttpStatus.OK_200).isEqualTo(httpGetResponse.getStatusCode());
      assertThat(getResponseContent).containsOnlyOnce("request");
      assertThat(getResponseContent).containsOnlyOnce("url: ^/resources/asn/");
      assertThat(getResponseContent).containsOnlyOnce("response");
      assertThat(getResponseContent).containsOnlyOnce("content-type: application/json");

      final URL url = AdminPortalTest.class.getResource("/json/update.request.with.enquoted.escaped.forward.slashes.json");
      final InputStream jsonInputStream = url.openStream();
      final String escapedJsonToUpdate = StringUtils.inputStreamToString(jsonInputStream);

      final HttpRequest httpPutRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl, escapedJsonToUpdate);

      final HttpResponse httpPutResponse = httpPutRequest.execute();
      final String putResponseContent = httpPutResponse.parseAsString().trim();
      final String putResponseLocationHeader = httpPutResponse.getHeaders().getLocation();

      assertThat(HttpStatus.OK_200).isEqualTo(httpGetResponse.getStatusCode());
      assertThat(putResponseLocationHeader).isEqualTo("^/resources/something/new?someKey=someValue");
      assertThat(putResponseContent).isEqualTo("Stub request index#0 updated successfully");
View Full Code Here

   @Test
   public void should_UpdateStubbedRequest_WithForwardSlashesEscapedJsonRequest_ToAdminPortalRootWithValidIndexURI() throws Exception {

      final String requestUrl = String.format("%s%s", ADMIN_URL, "/0");
      HttpRequest httpGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      HttpResponse httpGetResponse = httpGetRequest.execute();
      String getResponseContent = httpGetResponse.parseAsString().trim();

      assertThat(HttpStatus.OK_200).isEqualTo(httpGetResponse.getStatusCode());
      assertThat(getResponseContent).containsOnlyOnce("request");
      assertThat(getResponseContent).containsOnlyOnce("url: ^/resources/asn/");
      assertThat(getResponseContent).containsOnlyOnce("response");
      assertThat(getResponseContent).containsOnlyOnce("content-type: application/json");

      final URL url = AdminPortalTest.class.getResource("/json/update.request.with.escaped.forward.slashes.json");
      final InputStream jsonInputStream = url.openStream();
      final String escapedJsonToUpdate = StringUtils.inputStreamToString(jsonInputStream);

      final HttpRequest httpPutRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl, escapedJsonToUpdate);

      final HttpResponse httpPutResponse = httpPutRequest.execute();
      final String putResponseContent = httpPutResponse.parseAsString().trim();
      final String putResponseLocationHeader = httpPutResponse.getHeaders().getLocation();

      assertThat(HttpStatus.OK_200).isEqualTo(httpGetResponse.getStatusCode());
      assertThat(putResponseLocationHeader).isEqualTo("^/resources/something/new?someKey=someValue");
      assertThat(putResponseContent).isEqualTo("Stub request index#0 updated successfully");
View Full Code Here

   public void should_ReturnExpectedError_WhenSuccessfulDeleteMade_ToAdminPortalRoot() throws Exception {

      final String requestUrl = String.format("%s/", ADMIN_URL);
      final HttpRequest httpPutRequest = HttpUtils.constructHttpRequest(HttpMethods.DELETE, requestUrl);

      final HttpResponse httpResponse = httpPutRequest.execute();
      final String statusMessage = httpResponse.getStatusMessage().trim();
      final String responseMessage = httpResponse.parseAsString().trim();

      assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.METHOD_NOT_ALLOWED_405);
      assertThat(statusMessage).isEqualTo("Method Not Allowed");
      assertThat(responseMessage).isEqualTo("Method DELETE is not allowed on URI /");
   }
View Full Code Here

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

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

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

      assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT_204);
      assertThat(statusMessage).isEqualTo(expectedMessage);
   }
View Full Code Here

   @Test
   public void should_DeleteStubbedRequest_WhenSuccessfulDeleteMade_ToAdminPortalRootWithValidIndexURI() throws Exception {

      final String requestUrl = String.format("%s%s", ADMIN_URL, "/2");
      HttpRequest httpGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      HttpResponse httpGetResponse = httpGetRequest.execute();
      String getResponseContent = httpGetResponse.parseAsString().trim();

      assertThat(HttpStatus.OK_200).isEqualTo(httpGetResponse.getStatusCode());
      assertThat(getResponseContent).containsOnlyOnce("request");
      assertThat(getResponseContent).containsOnlyOnce("url: ^/[a-z]{3}-[a-z]{3}/[0-9]{2}/[A-Z]{2}/[a-z0-9]+\\?paramOne=[a-zA-Z]{3,8}&paramTwo=[a-zA-Z]{3,8}");
      assertThat(getResponseContent).containsOnlyOnce("response");
      assertThat(getResponseContent).containsOnlyOnce("content-type: application/json");


      final HttpRequest httpDeleteRequest = HttpUtils.constructHttpRequest(HttpMethods.DELETE, requestUrl);

      final HttpResponse httpDeleteResponse = httpDeleteRequest.execute();
      final String deleteResponseContent = httpDeleteResponse.parseAsString().trim();

      assertThat(HttpStatus.OK_200).isEqualTo(httpDeleteResponse.getStatusCode());
      assertThat(deleteResponseContent).isEqualTo("Stub request index#2 deleted successfully");

      httpGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
      httpGetResponse = httpGetRequest.execute();
      getResponseContent = httpGetResponse.parseAsString().trim();
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.