com.google.api.client.testing.http.MockLowLevelHttpRequest Java Examples
The following examples show how to use
com.google.api.client.testing.http.MockLowLevelHttpRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FirebaseChannelTest.java From java-docs-samples with Apache License 2.0 | 6 votes |
@Test public void firebaseDelete() 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().httpTransport = mockHttpTransport; firebaseChannel.firebaseDelete(FIREBASE_DB_URL + "/my/path"); verify(mockHttpTransport, times(1)).buildRequest("DELETE", FIREBASE_DB_URL + "/my/path"); }
Example #2
Source File: HttpResponseTest.java From google-http-java-client with Apache License 2.0 | 6 votes |
public void testGetContent_gzipEncoding_ReturnRawStream() throws IOException { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(String method, final String url) throws IOException { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() throws IOException { MockLowLevelHttpResponse result = new MockLowLevelHttpResponse(); result.setContent(""); result.setContentEncoding("gzip"); result.setContentType("text/plain"); return result; } }; } }; HttpRequest request = transport.createRequestFactory().buildHeadRequest(HttpTesting.SIMPLE_GENERIC_URL); request.setResponseReturnRawInputStream(true); assertFalse( "it should not decompress stream", request.execute().getContent() instanceof GZIPInputStream); }
Example #3
Source File: FakeWebServer.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 6 votes |
@Override public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { MockLowLevelHttpRequest request = new MockLowLevelHttpRequest(url) { @Override public LowLevelHttpResponse execute() throws IOException { MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); if (responses.isEmpty()) { throw new IOException( "Unexpected call to execute(), no injected responses left to return."); } return responses.remove(); } }; requests.add(new Request(method, request)); return request; }
Example #4
Source File: MockHttpTransportHelper.java From hadoop-connectors with Apache License 2.0 | 6 votes |
public static HttpResponse fakeResponse(Map<String, Object> headers, InputStream content) throws IOException { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(String method, String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); headers.forEach((h, hv) -> response.addHeader(h, String.valueOf(hv))); return response.setContent(content); } }; } }; HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); return request.execute(); }
Example #5
Source File: HttpResponseTest.java From google-http-java-client with Apache License 2.0 | 6 votes |
public void testParseAsString_validContentTypeWithParams() 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 result = new MockLowLevelHttpResponse(); result.setContent(SAMPLE2); result.setContentType(VALID_CONTENT_TYPE_WITH_PARAMS); return result; } }; } }; HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); HttpResponse response = request.execute(); assertEquals(SAMPLE2, response.parseAsString()); assertEquals(VALID_CONTENT_TYPE_WITH_PARAMS, response.getContentType()); assertNotNull(response.getMediaType()); }
Example #6
Source File: HttpResponseTest.java From google-http-java-client with Apache License 2.0 | 6 votes |
private void subtestStatusCode_negative(boolean throwExceptionOnExecuteError) throws Exception { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { return new MockLowLevelHttpRequest() .setResponse(new MockLowLevelHttpResponse().setStatusCode(-1)); } }; HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); request.setThrowExceptionOnExecuteError(throwExceptionOnExecuteError); try { // HttpResponse converts a negative status code to zero HttpResponse response = request.execute(); assertEquals(0, response.getStatusCode()); assertFalse(throwExceptionOnExecuteError); } catch (HttpResponseException e) { // exception should be thrown only if throwExceptionOnExecuteError is true assertTrue(throwExceptionOnExecuteError); assertEquals(0, e.getStatusCode()); } }
Example #7
Source File: MockHttpTransportHelper.java From hadoop-connectors with Apache License 2.0 | 6 votes |
public static MockHttpTransport mockTransport(LowLevelHttpResponse... responsesIn) { return new MockHttpTransport() { int responsesIndex = 0; final LowLevelHttpResponse[] responses = responsesIn; @Override public LowLevelHttpRequest buildRequest(String method, String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { return responses[responsesIndex++]; } }; } }; }
Example #8
Source File: HttpResponseTest.java From google-http-java-client with Apache License 2.0 | 6 votes |
public void testParseAsString_validContentType() 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 result = new MockLowLevelHttpResponse(); result.setContent(SAMPLE2); result.setContentType(VALID_CONTENT_TYPE); return result; } }; } }; HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); HttpResponse response = request.execute(); assertEquals(SAMPLE2, response.parseAsString()); assertEquals(VALID_CONTENT_TYPE, response.getContentType()); assertNotNull(response.getMediaType()); }
Example #9
Source File: BaseApiServiceTest.java From connector-sdk with Apache License 2.0 | 6 votes |
@Test public void testApiServiceWithPrebuiltClient() throws Exception { MockLowLevelHttpRequest request = buildRequest(200, new GenericJson()); HttpTransport transport = new TestingHttpTransport(ImmutableList.of(request)); TestApi apiClient = (TestApi) new TestApi.Builder(transport, JSON_FACTORY, null) .setApplicationName("bring your own client") .build(); TestApiService apiService = new TestApiService.Builder() .setService(apiClient) .setTransport(transport) .setCredentialFactory(scopes -> new MockGoogleCredential.Builder().build()) .build(); validateEmptyItem(apiService.get()); assertThat( request.getHeaderValues("user-agent").get(0), containsString("bring your own client")); }
Example #10
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 6 votes |
@Override public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() throws IOException { String firstHeader = getFirstHeaderValue(expectedHeader); assertTrue( String.format( "Expected header value to match %s, instead got %s.", expectedHeaderValue, firstHeader ), firstHeader.matches(expectedHeaderValue) ); return new MockLowLevelHttpResponse(); } }; }
Example #11
Source File: GitTestUtil.java From copybara with Apache License 2.0 | 6 votes |
public static LowLevelHttpRequest mockResponseWithStatus( String responseContent, int status, MockRequestAssertion requestValidator) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() throws IOException { assertWithMessage( String.format( "Request <%s> did not match predicate: '%s'", this.getContentAsString(), requestValidator)) .that(requestValidator.test(this.getContentAsString())) .isTrue(); // Responses contain a IntputStream for content. Cannot be reused between for two // consecutive calls. We create new ones per call here. return new MockLowLevelHttpResponse() .setContentType(Json.MEDIA_TYPE) .setContent(responseContent) .setStatusCode(status); } }; }
Example #12
Source File: BatchJobUploaderTest.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Tests that IOExceptions from executing an upload request are propagated properly. */ @SuppressWarnings("rawtypes") @Test public void testUploadBatchJobOperations_ioException_fails() throws Exception { final IOException ioException = new IOException("mock IO exception"); MockLowLevelHttpRequest lowLevelHttpRequest = new MockLowLevelHttpRequest(){ @Override public LowLevelHttpResponse execute() throws IOException { throw ioException; } }; when(uploadBodyProvider.getHttpContent(request, true, true)) .thenReturn(new ByteArrayContent(null, "foo".getBytes(UTF_8))); MockHttpTransport transport = new MockHttpTransport.Builder() .setLowLevelHttpRequest(lowLevelHttpRequest).build(); uploader = new BatchJobUploader(adWordsSession, transport, batchJobLogger); BatchJobUploadStatus uploadStatus = new BatchJobUploadStatus(0, URI.create("http://www.example.com")); thrown.expect(BatchJobException.class); thrown.expectCause(Matchers.sameInstance(ioException)); uploader.uploadIncrementalBatchJobOperations(request, true, uploadStatus); }
Example #13
Source File: GooglePublicKeysManagerTest.java From google-api-java-client with Apache License 2.0 | 6 votes |
@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); if (useAgeHeader) { r.addHeader("Age", String.valueOf(AGE)); } r.setContentType(Json.MEDIA_TYPE); r.setContent(TEST_CERTIFICATES); return r; } }; }
Example #14
Source File: GithubArchiveTest.java From copybara with Apache License 2.0 | 6 votes |
@Test public void repoExceptionOnDownloadFailure() throws Exception { httpTransport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(String method, String url) { MockLowLevelHttpRequest request = new MockLowLevelHttpRequest() { public LowLevelHttpResponse execute() throws IOException { throw new IOException("OH NOES!"); } }; return request; } }; RemoteFileOptions options = new RemoteFileOptions(); options.transport = () -> new GclientHttpStreamFactory(httpTransport, Duration.ofSeconds(20)); Console console = new TestingConsole(); OptionsBuilder optionsBuilder = new OptionsBuilder().setConsole(console); optionsBuilder.remoteFile = options; skylark = new SkylarkTestExecutor(optionsBuilder); ValidationException e = assertThrows(ValidationException.class, () -> skylark.eval("sha256", "sha256 = remotefiles.github_archive(" + "project = 'google/copybara'," + "revision='674ac754f91e64a0efb8087e59a176484bd534d1').sha256()")); assertThat(e).hasCauseThat().hasCauseThat().hasCauseThat().isInstanceOf(RepoException.class); }
Example #15
Source File: HttpResponseExceptionTest.java From google-http-java-client with Apache License 2.0 | 6 votes |
public void testConstructorWithStatusMessage() 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 result = new MockLowLevelHttpResponse(); result.setReasonPhrase("OK"); return result; } }; } }; HttpRequest request = transport.createRequestFactory().buildGetRequest(SIMPLE_GENERIC_URL); HttpResponse response = request.execute(); HttpResponseException responseException = new HttpResponseException(response); assertEquals("OK", responseException.getStatusMessage()); }
Example #16
Source File: OAuth2CredentialsTest.java From rides-java-sdk with MIT License | 6 votes |
@Override public LowLevelHttpRequest buildRequest(String method, final String url) throws IOException { return new MockLowLevelHttpRequest() { @Override public String getUrl() { return url; } @Override public LowLevelHttpResponse execute() throws IOException { lastRequestUrl = getUrl(); lastRequestContent = getContentAsString(); MockLowLevelHttpResponse mock = new MockLowLevelHttpResponse(); mock.setStatusCode(httpStatusCode); mock.setContent(httpResponseContent); return mock; } }; }
Example #17
Source File: BigQueryServicesImplTest.java From beam with Apache License 2.0 | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); // Set up the MockHttpRequest for future inspection request = new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() throws IOException { return response; } }; // A mock transport that lets us mock the API responses. MockHttpTransport transport = new MockHttpTransport.Builder().setLowLevelHttpRequest(request).build(); // A sample BigQuery API client that uses default JsonFactory and RetryHttpInitializer. bigquery = new Bigquery.Builder( transport, Transport.getJsonFactory(), new RetryHttpRequestInitializer()) .build(); }
Example #18
Source File: CustomTokenRequestTest.java From google-oauth-java-client with Apache License 2.0 | 6 votes |
@Override public LowLevelHttpRequest buildRequest(String method, String url) { return new MockLowLevelHttpRequest(url) { @Override public LowLevelHttpResponse execute() throws IOException { MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); response.setContentType(Json.MEDIA_TYPE); IdTokenResponse json = new IdTokenResponse(); json.setAccessToken("abc"); json.setRefreshToken("def"); json.setExpiresInSeconds(3600L); json.setIdToken(JWT_ENCODED_CONTENT); response.setContent(JSON_FACTORY.toString(json)); return response; } }; }
Example #19
Source File: IcannHttpReporterTest.java From nomulus with Apache License 2.0 | 6 votes |
private MockHttpTransport createMockTransport (final ByteSource iirdeaResponse) { return new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(String method, String url) { 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; } }; }
Example #20
Source File: DirectoryGroupsConnectionTest.java From nomulus with Apache License 2.0 | 6 votes |
/** 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) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { 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()); }
Example #21
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 6 votes |
public void testExecuteUsingHead() throws Exception { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(final String method, final String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { assertEquals("HEAD", method); assertEquals("https://www.googleapis.com/test/path/v1/tests/foo", url); return new MockLowLevelHttpResponse(); } }; } }; MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName( "Test Application").build(); MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>( client, HttpMethods.GET, URI_TEMPLATE, null, String.class); request.put("testId", "foo"); request.executeUsingHead(); }
Example #22
Source File: UpdateRegistrarRdapBaseUrlsActionTest.java From nomulus with Apache License 2.0 | 6 votes |
private void assertCorrectRequestsSent() { // Doing assertThat on the "getUrl()" of the elements to get better error message if we have the // wrong number of requests. // This way we'll see which URLs were hit on failure. assertThat(httpTransport.getRequestsSent().stream().map(request -> request.getUrl())) .hasSize(3); MockLowLevelHttpRequest loginRequest = httpTransport.getRequestsSent().get(0); MockLowLevelHttpRequest listRequest = httpTransport.getRequestsSent().get(1); MockLowLevelHttpRequest logoutRequest = httpTransport.getRequestsSent().get(2); assertThat(loginRequest.getUrl()).isEqualTo("https://mosapi.icann.org/mosapi/v1/tld/login"); // base64.b64encode("tld_ry:myPassword") gives "dGxkX3J5Om15UGFzc3dvcmQ=" assertThat(loginRequest.getHeaders()) .containsEntry("authorization", ImmutableList.of("Basic dGxkX3J5Om15UGFzc3dvcmQ=")); assertThat(listRequest.getUrl()) .isEqualTo("https://mosapi.icann.org/mosapi/v1/tld/registrarRdapBaseUrl/list"); assertThat(listRequest.getHeaders()) .containsEntry("cookie", ImmutableList.of("id=myAuthenticationId")); assertThat(logoutRequest.getUrl()).isEqualTo("https://mosapi.icann.org/mosapi/v1/tld/logout"); assertThat(logoutRequest.getHeaders()) .containsEntry("cookie", ImmutableList.of("id=myAuthenticationId")); }
Example #23
Source File: HttpResponseTest.java From google-http-java-client with Apache License 2.0 | 6 votes |
public void testDownload() 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 result = new MockLowLevelHttpResponse(); result.setContentType(Json.MEDIA_TYPE); result.setContent(SAMPLE); return result; } }; } }; HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); HttpResponse response = request.execute(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); response.download(outputStream); assertEquals(SAMPLE, outputStream.toString("UTF-8")); }
Example #24
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 6 votes |
public void testReturnRawInputStream_True() throws Exception { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(final String method, final String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { return new MockLowLevelHttpResponse().setContentEncoding("gzip").setContent(new ByteArrayInputStream( BaseEncoding.base64() .decode("H4sIAAAAAAAAAPNIzcnJV3DPz0/PSVVwzskvTVEILskvSkxPVQQA/LySchsAAAA="))); } }; } }; MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName( "Test Application").build(); MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>( client, HttpMethods.GET, URI_TEMPLATE, null, String.class); request.setReturnRawInputStream(true); InputStream inputStream = request.executeAsInputStream(); // The response will not be wrapped due to setReturnRawInputStream(true) assertTrue(inputStream instanceof ByteArrayInputStream); }
Example #25
Source File: HttpRequestTest.java From google-http-java-client with Apache License 2.0 | 6 votes |
@Override public LowLevelHttpRequest buildRequest(String method, String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() throws IOException { lowLevelExecCalls++; userAgentHeader = getHeaderValues("User-Agent"); if (lowLevelExecCalls <= callsBeforeSuccess) { throw new IOException(); } // Return success when count is more than callsBeforeSuccess MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); response.setStatusCode(200); return response; } }; }
Example #26
Source File: FirebaseChannelTest.java From java-docs-samples with Apache License 2.0 | 6 votes |
@Test public void firebaseGet() 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().httpTransport = mockHttpTransport; firebaseChannel.firebaseGet(FIREBASE_DB_URL + "/my/path"); verify(mockHttpTransport, times(1)).buildRequest("GET", FIREBASE_DB_URL + "/my/path"); }
Example #27
Source File: GoogleAuthTest.java From endpoints-java with Apache License 2.0 | 6 votes |
private HttpRequest constructHttpRequest(final String content, final int statusCode) 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); result.setStatusCode(statusCode); return result; } }; } }; HttpRequest httpRequest = transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com")).setParser(new JsonObjectParser(new JacksonFactory())); GoogleAuth.configureErrorHandling(httpRequest); return httpRequest; }
Example #28
Source File: HttpRequestTest.java From google-http-java-client with Apache License 2.0 | 5 votes |
public void testExecute_redirects() throws Exception { class MyTransport extends MockHttpTransport { int count = 1; @Override public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { // expect that it redirected to new URL every time using the count assertEquals(HttpTesting.SIMPLE_URL + "_" + count, url); count++; return new MockLowLevelHttpRequest() .setResponse( new MockLowLevelHttpResponse() .setStatusCode(HttpStatusCodes.STATUS_CODE_MOVED_PERMANENTLY) .setHeaderNames(Arrays.asList("Location")) .setHeaderValues(Arrays.asList(HttpTesting.SIMPLE_URL + "_" + count))); } } MyTransport transport = new MyTransport(); HttpRequest request = transport .createRequestFactory() .buildGetRequest(new GenericUrl(HttpTesting.SIMPLE_URL + "_" + transport.count)); try { request.execute(); fail("expected " + HttpResponseException.class); } catch (HttpResponseException e) { assertEquals(HttpStatusCodes.STATUS_CODE_MOVED_PERMANENTLY, e.getStatusCode()); } }
Example #29
Source File: UpdateRegistrarRdapBaseUrlsActionTest.java From nomulus with Apache License 2.0 | 5 votes |
@Override public LowLevelHttpRequest buildRequest(String method, String url) { assertThat(method).isEqualTo("GET"); MockLowLevelHttpRequest httpRequest = new MockLowLevelHttpRequest(url); httpRequest.setResponse(simulatedResponses.get(requestsSent.size())); requestsSent.add(httpRequest); return httpRequest; }
Example #30
Source File: IndexingServiceTransport.java From connector-sdk with Apache License 2.0 | 5 votes |
@Override public MockLowLevelHttpRequest buildRequest(final String method, final String url) throws IOException { List<String> requestKey = ImmutableList.of(method, url); boolean hasError = !requestMap.containsKey(requestKey) || requestMap.get(requestKey).isEmpty(); if (hasError) { logger.log(Level.INFO, " error for key {0}", requestKey); transportError.set(true); throw new UnsupportedOperationException("Unexpected call for key " + requestKey); } return requestMap.get(requestKey).poll(); }