当前位置: 首页>>代码示例>>Java>>正文


Java MockLowLevelHttpRequest类代码示例

本文整理汇总了Java中com.google.api.client.testing.http.MockLowLevelHttpRequest的典型用法代码示例。如果您正苦于以下问题:Java MockLowLevelHttpRequest类的具体用法?Java MockLowLevelHttpRequest怎么用?Java MockLowLevelHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MockLowLevelHttpRequest类属于com.google.api.client.testing.http包,在下文中一共展示了MockLowLevelHttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildRequest

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
    return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
            String rawPath = url;
            Map<String, String> params = new HashMap<>();

            int pathEndPos = url.indexOf('?');
            if (pathEndPos != -1) {
                rawPath = url.substring(0, pathEndPos);
                RestUtils.decodeQueryString(url, pathEndPos + 1, params);
            }

            Handler handler = handlers.retrieve(method + " " + rawPath, params);
            if (handler != null) {
                return handler.execute(rawPath, params, this);
            }
            return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "Unable to handle request [method=" + method + ", url=" + url + "]");
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:MockHttpTransport.java

示例2: configureMock

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
protected static HttpTransport configureMock() {
    return new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, final String url) throws IOException {
            return new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                    MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
                    response.setStatusCode(200);
                    response.setContentType(Json.MEDIA_TYPE);
                    if (url.startsWith(GCE_METADATA_URL)) {
                        logger.info("--> Simulate GCE Auth/Metadata response for [{}]", url);
                        response.setContent(readGoogleInternalJsonResponse(url));
                    } else {
                        logger.info("--> Simulate GCE API response for [{}]", url);
                        response.setContent(readGoogleApiJsonResponse(url));
                    }

                    return response;
                }
            };
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:GceMockUtils.java

示例3: buildRequest

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
  callCount ++;

  if (!HttpMethods.GET.equals(method) || !expectedUrl.equals(url)) {
    // Throw RuntimeException to fail the test.
    throw new RuntimeException();
  }

  return new MockLowLevelHttpRequest() {
    @Override
    public LowLevelHttpResponse execute() throws IOException {
      MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
      response.setStatusCode(HttpStatusCodes.STATUS_CODE_OK);
      response.setContentType(Json.MEDIA_TYPE);
      response.setContent(jsonResponse);
      return response;
    }
  };
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:21,代码来源:DefautKeyUriSupplierTest.java

示例4: buildRequest

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
  return new MockLowLevelHttpRequest() {
    @Override
    public LowLevelHttpResponse execute() throws IOException {
      if (ioException != null) {
        throw ioException;
      }
      MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
      response.setStatusCode(HttpStatus.SC_ACCEPTED);
      response.setContentType(Json.MEDIA_TYPE);
      response.setContent(content);
      return response;
    }
  };
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:17,代码来源:DefaultJwksSupplierTest.java

示例5: mockClient

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
/**
 * Return a Client that is mocked to return the given HTTP response.
 *
 * @param httpResponse The full HTTP response data
 * @return The Client instance
 */
public Client mockClient(final String httpResponse) {
  Client client = new Client();

  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          return mockResponse(response, httpResponse);
        }
      };
    }
  };

  client.setTransport(transport);

  return client;
}
 
开发者ID:dnsimple,项目名称:dnsimple-java,代码行数:27,代码来源:DnsimpleTestBase.java

示例6: constructHttpRequest

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
private HttpRequest constructHttpRequest(final String content) throws IOException {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
          result.setContentType("application/json");
          result.setContent(content);
          return result;
        }
      };
    }
  };
  return transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com"))
      .setParser(new JsonObjectParser(new JacksonFactory()));
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:19,代码来源:GoogleAuthTest.java

示例7: getContent

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Override
protected byte[] getContent(String method, String url, MockLowLevelHttpRequest request)
    throws IOException {
  if (url.equals("https://api.github.com/repos/google/example/issues/" + prNumber)) {
    return mockIssue(Integer.toString(prNumber), defaultPresentLabels).getBytes();
  } else if (url.startsWith(
      "https://api.github.com/repos/google/example/pulls/" + prNumber)) {
    return ("{\n"
        + "  \"id\": 1,\n"
        + "  \"number\": " + prNumber + ",\n"
        + "  \"state\": \"open\",\n"
        + "  \"title\": \"test summary\",\n"
        + "  \"body\": \"test summary\n\nMore text\",\n"
        + "  \"head\": {\n"
        + "    \"label\": \"googletestuser:example-branch\",\n"
        + "    \"ref\": \"example-branch\"\n"
        + "   },\n"
        + "  \"base\": {\n"
        + "    \"label\": \"google:master\",\n"
        + "    \"ref\": \"master\"\n"
        + "   }\n"
        + "}").getBytes(UTF_8);
  }
  fail(method + " " + url);
  throw new IllegalStateException();
}
 
开发者ID:google,项目名称:copybara,代码行数:27,代码来源:GithubPrOriginTest.java

示例8: setUp

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  // A mock transport that lets us mock the API responses.
  MockHttpTransport transport =
      new MockHttpTransport.Builder()
          .setLowLevelHttpRequest(
              new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                  return response;
                }
              })
          .build();

  // A sample BigQuery API client that uses default JsonFactory and RetryHttpInitializer.
  bigquery =
      new Bigquery.Builder(
              transport, Transport.getJsonFactory(), new RetryHttpRequestInitializer())
          .build();
}
 
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:BigQueryServicesImplTest.java

示例9: createMockTransport

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
private MockHttpTransport createMockTransport (final ByteSource iirdeaResponse) {
  return new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      mockRequest = new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          response.setContentType(PLAIN_TEXT_UTF_8.toString());
          response.setContent(iirdeaResponse.read());
          return response;
        }
      };
      mockRequest.setUrl(url);
      return mockRequest;
    }
  };
}
 
开发者ID:google,项目名称:nomulus,代码行数:20,代码来源:IcannHttpReporterTest.java

示例10: makeResponseException

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
/** Returns a valid GoogleJsonResponseException for the given status code and error message.  */
private GoogleJsonResponseException makeResponseException(
    final int statusCode,
    final String message) throws Exception {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(statusCode);
          response.setContentType(Json.MEDIA_TYPE);
          response.setContent(String.format(
              "{\"error\":{\"code\":%d,\"message\":\"%s\",\"domain\":\"global\","
              + "\"reason\":\"duplicate\"}}",
              statusCode,
              message));
          return response;
        }};
    }};
  HttpRequest request = transport.createRequestFactory()
      .buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL)
      .setThrowExceptionOnExecuteError(false);
  return GoogleJsonResponseException.from(new JacksonFactory(), request.execute());
}
 
开发者ID:google,项目名称:nomulus,代码行数:27,代码来源:DirectoryGroupsConnectionTest.java

示例11: sendFirebaseMessage_create

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void sendFirebaseMessage_create() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.sendFirebaseMessage("my_key", new Game());

  verify(mockHttpTransport, times(1)).buildRequest(
      "PATCH", FIREBASE_DB_URL + "/channels/my_key.json");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java

示例12: sendFirebaseMessage_delete

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void sendFirebaseMessage_delete() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.sendFirebaseMessage("my_key", null);

  verify(mockHttpTransport, times(1)).buildRequest(
      "DELETE", FIREBASE_DB_URL + "/channels/my_key.json");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java

示例13: firebasePut

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebasePut() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Game game = new Game();

  firebaseChannel.firebasePut(FIREBASE_DB_URL + "/my/path", game);

  verify(mockHttpTransport, times(1)).buildRequest("PUT", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java

示例14: firebasePatch

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebasePatch() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Game game = new Game();

  firebaseChannel.firebasePatch(FIREBASE_DB_URL + "/my/path", game);

  verify(mockHttpTransport, times(1)).buildRequest("PATCH", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java

示例15: firebasePost

import com.google.api.client.testing.http.MockLowLevelHttpRequest; //导入依赖的package包/类
@Test
public void firebasePost() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Game game = new Game();

  firebaseChannel.firebasePost(FIREBASE_DB_URL + "/my/path", game);

  verify(mockHttpTransport, times(1)).buildRequest("POST", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


注:本文中的com.google.api.client.testing.http.MockLowLevelHttpRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。