Package com.google.api.client.http

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


   }

   @Test
   public void should_NotReturnExpectedRecordedResponse_FromValidUrl_WhenQueryValueNotCorrect() throws Exception {
      final String requestUrl = String.format("%s%s", STUBS_URL, "/feed/2?language=russian&greeting=nihao");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      final HttpHeaders requestHeaders = new HttpHeaders();
      requestHeaders.setContentType(HEADER_APPLICATION_JSON);
      request.setHeaders(requestHeaders);

      final HttpResponse response = request.execute();

      final HttpHeaders headers = response.getHeaders();
      assertThat(headers.getContentType().contains("application/xml")).isTrue();

      String responseContent = response.parseAsString().trim();
View Full Code Here


      final boolean NO_AUTO_FLUSH = false;
      final PrintStream oldPrintStream = System.out;
      System.setOut(new PrintStream(consoleCaptor, NO_AUTO_FLUSH, StringUtils.UTF_8));

      final String requestUrl = String.format("%s%s", STUBS_URL, "/feed/1?language=chinese&greeting=nihao");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      final HttpHeaders requestHeaders = new HttpHeaders();
      requestHeaders.setContentType(HEADER_APPLICATION_JSON);
      request.setHeaders(requestHeaders);

      final int LIMIT = 5;
      for (int idx = 1; idx <= LIMIT; idx++) {
         final HttpResponse actualResponse = request.execute();
         final String actualConsoleOutput = consoleCaptor.toString(StringUtils.UTF_8).trim();

         String firstCallResponseContent = actualResponse.parseAsString().trim();
         assertThat(firstCallResponseContent).contains("<payment><invoiceTypeLookupCode>STANDARD</invoiceTypeLookupCode></payment>");
         // Make sure we only hitting recordabe source once
View Full Code Here

         .withLiteralBody("OK")
         .withStatus("200")
         .build();

      final String adminRequestUrl = String.format("%s/", ADMIN_URL);
      final HttpRequest httpPuttRequest = HttpUtils.constructHttpRequest(HttpMethods.POST, adminRequestUrl, yamlToUpdate);

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

      assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.CREATED_201);
      assertThat(statusMessage).isEqualTo("Created");
      assertThat(responseMessage).contains("Configuration created successfully");

      final String stubsRequestUrl = String.format("%s%s", STUBS_URL, "/new/resource/account?someKey=someValue");
      final HttpRequest stubsGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, stubsRequestUrl);
      final HttpResponse stubsGetResponse = stubsGetRequest.execute();

      final String stubsGetResponseContentTypeHeader = stubsGetResponse.getContentType();
      final String stubsGetResponseContent = stubsGetResponse.parseAsString().trim();

      assertThat(stubsGetResponse.getStatusCode()).isEqualTo(HttpStatus.OK_200);
View Full Code Here

   @Test
   public void should_AdjustResourceIdHeaderAccordingly_WhenSuccessfulDeleteMade() throws Exception {

      final String stubsRequestUrl = String.format("%s%s", STUBS_URL, "/this/stub/should/always/be/second/in/this/file");
      final HttpRequest stubsGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, stubsRequestUrl);
      final HttpResponse preDeletionStubGetResponse = stubsGetRequest.execute();
      final HttpHeaders preDeletionResponseHeaders = preDeletionStubGetResponse.getHeaders();
      assertThat(preDeletionResponseHeaders.containsKey(StubResponse.STUBBY_RESOURCE_ID_HEADER)).isTrue();
      assertThat(preDeletionResponseHeaders.getFirstHeaderStringValue(StubResponse.STUBBY_RESOURCE_ID_HEADER)).isEqualTo("1");

      final HttpRequest httpDeleteRequest = HttpUtils.constructHttpRequest(HttpMethods.DELETE, String.format("%s%s", ADMIN_URL, "/0"));
      final HttpResponse httpDeleteResponse = httpDeleteRequest.execute();
      final String deleteResponseContent = httpDeleteResponse.parseAsString().trim();
      assertThat(HttpStatus.OK_200).isEqualTo(httpDeleteResponse.getStatusCode());
      assertThat(deleteResponseContent).isEqualTo("Stub request index#0 deleted successfully");

      final HttpRequest postDeletionStubGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, stubsRequestUrl);
      final HttpResponse postDeletionStubGetResponse = postDeletionStubGetRequest.execute();
      final HttpHeaders postDeletionResponseHeaders = postDeletionStubGetResponse.getHeaders();
      assertThat(postDeletionResponseHeaders.containsKey(StubResponse.STUBBY_RESOURCE_ID_HEADER)).isTrue();
      assertThat(postDeletionResponseHeaders.getFirstHeaderStringValue(StubResponse.STUBBY_RESOURCE_ID_HEADER)).isEqualTo("0");
   }
View Full Code Here

   @Test
   public void should_ReturnAjaxRequestContent_WhenSuccessfulRequestMade() throws Exception {

      final String requestUrl = String.format("%s%s", STUBS_URL, "/invoice/new");
      final String postContent = "{\"name\": \"chocolate\", \"description\": \"full\", \"department\": \"savoury\"}";
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.POST, requestUrl, postContent);

      final HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.setContentType("application/json");

      request.setHeaders(httpHeaders);

      final HttpResponse response = request.execute();
      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED_201);

      final String resourceID = response.getHeaders().getFirstHeaderStringValue(StubResponse.STUBBY_RESOURCE_ID_HEADER);
      final String ajaxRequestUrl = String.format("%s%s%s%s", ADMIN_URL, "/ajax/resource/", resourceID, "/request/post");
      final HttpRequest ajaxRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, ajaxRequestUrl);

      final HttpResponse ajaxResponse = ajaxRequest.execute();
      assertThat(ajaxResponse.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(ajaxResponse.parseAsString().trim()).contains(postContent);
   }
View Full Code Here

   @Test
   public void should_ReturnAjaxResponseContent_WhenSuccessfulRequestMade() throws Exception {

      final String requestUrl = String.format("%s%s", STUBS_URL, "/invoice/new");
      final String postContent = "{\"name\": \"chocolate\", \"description\": \"full\", \"department\": \"savoury\"}";
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.POST, requestUrl, postContent);

      final HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.setContentType("application/json");

      request.setHeaders(httpHeaders);

      final HttpResponse response = request.execute();
      final String responseContent = response.parseAsString().trim();
      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED_201);

      final String resourceID = response.getHeaders().getFirstHeaderStringValue(StubResponse.STUBBY_RESOURCE_ID_HEADER);
      final String ajaxRequestUrl = String.format("%s%s%s%s", ADMIN_URL, "/ajax/resource/", resourceID, "/response/body");
      final HttpRequest ajaxRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, ajaxRequestUrl);

      final HttpResponse ajaxResponse = ajaxRequest.execute();
      assertThat(ajaxResponse.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(ajaxResponse.parseAsString().trim()).contains(responseContent);
   }
View Full Code Here

   @Test
   public void should_ReturnAjaxSequencedResponseContent_WhenSuccessfulRequestMade() throws Exception {

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

      final HttpResponse response = request.execute();
      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED_201);

      final String resourceID = response.getHeaders().getFirstHeaderStringValue(StubResponse.STUBBY_RESOURCE_ID_HEADER);
      final String ajaxRequestUrl = String.format("%s%s%s%s", ADMIN_URL, "/ajax/resource/", resourceID, "/response/1/file");
      final HttpRequest ajaxRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, ajaxRequestUrl);

      final HttpResponse ajaxResponse = ajaxRequest.execute();
      assertThat(ajaxResponse.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(ajaxResponse.parseAsString().trim()).contains("Still going strong!");
   }
View Full Code Here

   @Test
   public void should_ReturnAjaxResponseContentYaml_WhenSuccessfulRequestMade() throws Exception {

      final String requestUrl = String.format("%s%s", STUBS_URL, "/invoice/new");
      final String postContent = "{\"name\": \"chocolate\", \"description\": \"full\", \"department\": \"savoury\"}";
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.POST, requestUrl, postContent);

      final HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.setContentType("application/json");

      request.setHeaders(httpHeaders);

      final HttpResponse response = request.execute();
      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED_201);

      final String resourceID = response.getHeaders().getFirstHeaderStringValue(StubResponse.STUBBY_RESOURCE_ID_HEADER);
      final String ajaxRequestUrl = String.format("%s%s%s%s", ADMIN_URL, "/ajax/resource/", resourceID, "/httplifecycle/httpLifeCycleAsYaml");
      final HttpRequest ajaxRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, ajaxRequestUrl);

      final HttpResponse ajaxResponse = ajaxRequest.execute();
      assertThat(ajaxResponse.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat(ajaxResponse.parseAsString().trim()).contains(
         "- request:" + BR +
         "    method: POST" + BR +
         "    url: /invoice/new" + BR +
View Full Code Here

   @Test
   public void should_ReturnMethodNotImplemented_WhenSuccessfulOptionsMade_ToAdminPortalRoot() throws Exception {

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

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

      assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NOT_IMPLEMENTED_501);
      assertThat(statusMessage).isEqualTo("Not Implemented");
View Full Code Here

   @Test
   public void should_ReturnMethodNotImplemented_WhenSuccessfulHeadMade_ToAdminPortalRoot() throws Exception {

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

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

      assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NOT_IMPLEMENTED_501);
      assertThat(statusMessage).isEqualTo("Not Implemented");
View Full Code Here

TOP

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

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.