Package com.google.api.client.testing.http

Examples of com.google.api.client.testing.http.MockLowLevelHttpRequest


    class MyTransport extends MockHttpTransport {
      boolean resetAccessToken;

      @Override
      public LowLevelHttpRequest buildRequest(String method, String url) {
        return new MockLowLevelHttpRequest(url) {
          @Override
          public LowLevelHttpResponse execute() {
            MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
            if (!checkAuth.checkAuth(this)) {
              response.setStatusCode(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
View Full Code Here


    class MyTransport extends MockHttpTransport {
      boolean resetAccessToken;

      @Override
      public LowLevelHttpRequest buildRequest(String method, String url) {
        return new MockLowLevelHttpRequest(url) {
          @Override
          public LowLevelHttpResponse execute() {
            MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
            if (!checkAuth.checkAuth(this)) {
              response.setStatusCode(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
View Full Code Here

    int calls = 0;

    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) {
      return new MockLowLevelHttpRequest(url) {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          calls++;
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setContentType(Json.MEDIA_TYPE);
View Full Code Here

    boolean error = false;

    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) {
      return new MockLowLevelHttpRequest(url) {
          @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setContentType("UTF-8");
          GenericData responseData;
View Full Code Here

    @Override
    public LowLevelHttpRequest buildRequest(String name, String url) {
      if (name.equals("POST")) {
        assertEquals(TEST_RESUMABLE_REQUEST_URL, url);

        return new MockLowLevelHttpRequest() {
            @Override
          public LowLevelHttpResponse execute() {
            // Assert that the required headers are set.
            if (!contentLengthNotSpecified) {
              assertEquals(
                  Integer.toString(contentLength), getFirstHeaderValue("x-upload-content-length"));
            }
            assertEquals(TEST_CONTENT_TYPE, getFirstHeaderValue("x-upload-content-type"));
            // This is the initiation call. Return 200 with the upload URI.
            MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
            response.setStatusCode(200);
            response.addHeader("Location", TEST_UPLOAD_URL);
            return response;
          }
        };
      }
      assertEquals(TEST_UPLOAD_URL, url);

      return new MockLowLevelHttpRequest() {
          @Override
        public LowLevelHttpResponse execute() {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();

          String bytesRange =
View Full Code Here

      return requestCount;
    }

    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) {
      MockLowLevelHttpRequest request = new MockLowLevelHttpRequest(url) {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          requestCount++;
          throw new IOException("MockRequestCountingTransport request failed.");
        }
View Full Code Here

          }
        } else {
          assertEquals(TEST_RESUMABLE_REQUEST_URL, url);
        }

        return new MockLowLevelHttpRequest() {
            @Override
          public LowLevelHttpResponse execute() {
            lowLevelExecCalls++;
            if (!directUploadEnabled) {
              // Assert that the required headers are set.
              if (!contentLengthNotSpecified) {
                assertEquals(Integer.toString(contentLength),
                    getFirstHeaderValue("x-upload-content-length"));
              }
              assertEquals(TEST_CONTENT_TYPE, getFirstHeaderValue("x-upload-content-type"));
            }
            if (assertTestHeaders) {
              assertEquals("test-header-value", getFirstHeaderValue("test-header-name"));
            }
            // This is the initiation call.
            MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
            assertFalse(directUploadEnabled && testIOException);
            if (directUploadEnabled && testServerError && lowLevelExecCalls == 1) {
              // send a server error in the 1st request of a direct upload
              response.setStatusCode(500);
            } else if (testAuthenticationError) {
              // Return 404.
              response.setStatusCode(404);
            } else {
              // Return 200 with the upload URI.
              response.setStatusCode(200);
              if (!directUploadEnabled) {
                response.addHeader("Location", TEST_UPLOAD_URL);
              }
            }
            return response;
          }
        };
      }
      assertEquals(TEST_UPLOAD_URL, url);
      assertEquals("PUT", name);
      return new MockLowLevelHttpRequest() {
          @Override
        public LowLevelHttpResponse execute() throws IOException {
          lowLevelExecCalls++;
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          String contentRangeHeader = getFirstHeaderValue("Content-Range");
View Full Code Here

    MockHttpTransport transport = new MockHttpTransport() {

      @Override
      public LowLevelHttpRequest buildRequest(String method, String url) {
        return new MockLowLevelHttpRequest(url) {

          @Override
          public LowLevelHttpResponse execute() throws IOException {
            assertEquals("multipart/mixed; boundary=__END_OF_PART__", getContentType());
            ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

    }

    @Override
    public LowLevelHttpRequest buildRequest(String name, String url) {
      actualCalls++;
      return new MockLowLevelHttpRequest() {
          @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          response.addHeader("Content-Type", "multipart/mixed; boundary=" + RESPONSE_BOUNDARY);
View Full Code Here

  static class PublicCertsMockHttpTransport extends MockHttpTransport {
    boolean useAgeHeader;

    @Override
    public LowLevelHttpRequest buildRequest(String name, String url) {
      return new MockLowLevelHttpRequest() {
          @Override
        public LowLevelHttpResponse execute() {
          MockLowLevelHttpResponse r = new MockLowLevelHttpResponse();
          r.setStatusCode(200);
          r.addHeader("Cache-Control", "max-age=" + MAX_AGE);
View Full Code Here

TOP

Related Classes of com.google.api.client.testing.http.MockLowLevelHttpRequest

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.