Search in sources :

Example 76 with Dispatcher

use of okhttp3.Dispatcher in project spring-security by spring-projects.

the class ClientRegistrationsTests method registrationOAuth2.

private ClientRegistration.Builder registrationOAuth2(String path, String body) throws Exception {
    this.issuer = createIssuerFromServer(path);
    this.response.put("issuer", this.issuer);
    this.issuer = this.server.url(path).toString();
    final String responseBody = (body != null) ? body : this.mapper.writeValueAsString(this.response);
    final Dispatcher dispatcher = new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) {
            switch(request.getPath()) {
                case "/.well-known/oauth-authorization-server/issuer1":
                case "/.well-known/oauth-authorization-server/":
                    return buildSuccessMockResponse(responseBody);
            }
            return new MockResponse().setResponseCode(404);
        }
    };
    this.server.setDispatcher(dispatcher);
    // @formatter:off
    return ClientRegistrations.fromIssuerLocation(this.issuer).clientId("client-id").clientSecret("client-secret");
// @formatter:on
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Dispatcher(okhttp3.mockwebserver.Dispatcher)

Example 77 with Dispatcher

use of okhttp3.Dispatcher in project spring-security by spring-projects.

the class ReactiveJwtDecodersTests method prepareConfigurationResponses.

private void prepareConfigurationResponses(Map<String, MockResponse> responses) {
    Dispatcher dispatcher = new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) {
            // @formatter:off
            return Optional.of(request).map(RecordedRequest::getRequestUrl).map(HttpUrl::toString).map(responses::get).orElse(new MockResponse().setResponseCode(404));
        // @formatter:on
        }
    };
    this.server.setDispatcher(dispatcher);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Dispatcher(okhttp3.mockwebserver.Dispatcher) HttpUrl(okhttp3.HttpUrl)

Example 78 with Dispatcher

use of okhttp3.Dispatcher in project spring-security by spring-projects.

the class JwtDecodersTests method prepareConfigurationResponses.

private void prepareConfigurationResponses(Map<String, MockResponse> responses) {
    Dispatcher dispatcher = new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) {
            // @formatter:off
            return Optional.of(request).map(RecordedRequest::getRequestUrl).map(HttpUrl::toString).map(responses::get).orElse(new MockResponse().setResponseCode(404));
        // @formatter:on
        }
    };
    this.server.setDispatcher(dispatcher);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Dispatcher(okhttp3.mockwebserver.Dispatcher) HttpUrl(okhttp3.HttpUrl)

Example 79 with Dispatcher

use of okhttp3.Dispatcher in project OpenRefine by OpenRefine.

the class WbExpressionTest method startServer.

@BeforeClass
public void startServer() throws IOException {
    server = new MockWebServer();
    String json = TestingData.jsonFromFile("langcode/wikidata-monolingualtext-langcode.json");
    server.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            return new MockResponse().addHeader("Content-Type", "application/json; charset=utf-8").setBody(json);
        }
    });
    server.start();
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) MockWebServer(okhttp3.mockwebserver.MockWebServer) Dispatcher(okhttp3.mockwebserver.Dispatcher) BeforeClass(org.testng.annotations.BeforeClass)

Example 80 with Dispatcher

use of okhttp3.Dispatcher in project OpenRefine by OpenRefine.

the class ExtendDataOperationTests method testFetchCounts.

/**
 * Test to fetch counts of values
 */
@Test
public void testFetchCounts() throws Exception {
    DataExtensionConfig extension = DataExtensionConfig.reconstruct("{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"count\":\"on\",\"rank\":\"any\"}}]}");
    mockHttpCall("{\"ids\":[\"Q863\",\"Q794\",\"Q17\",\"Q30\"],\"properties\":[{\"id\":\"P38\",\"settings\":{\"count\":\"on\",\"rank\":\"any\"}}]}", "{" + "\"rows\": {" + "    \"Q794\": {\"P38\": [{\"float\": 1}]}," + "    \"Q863\": {\"P38\": [{\"float\": 2}]}," + "    \"Q30\": {\"P38\": [{\"float\": 1}]}," + "    \"Q17\": {\"P38\": [{\"float\": 1}]}" + "}," + "\"meta\": [" + "    {\"settings\": {\"count\": \"on\", \"rank\": \"any\"}, \"name\": \"currency\", \"id\": \"P38\"}" + "]}");
    try (MockWebServer server = new MockWebServer()) {
        server.start();
        server.setDispatcher(dispatcher);
        EngineDependentOperation op = new ExtendDataOperation(engine_config, "country", server.url("/reconcile").url().toString(), RECON_IDENTIFIER_SPACE, RECON_SCHEMA_SPACE, extension, 1);
        LongRunningProcessStub process = new LongRunningProcessStub(op.createProcess(project, options));
        process.run();
        // Test to be updated as countries change currencies!
        Assert.assertTrue(Math.round((double) project.rows.get(2).getCellValue(1)) == 2, "Incorrect number of currencies returned for Tajikistan.");
        Assert.assertTrue(Math.round((double) project.rows.get(3).getCellValue(1)) == 1, "Incorrect number of currencies returned for United States.");
        // Make sure we did not create any recon stats for that column (no reconciled value)
        Assert.assertTrue(project.columnModel.getColumnByName("currency").getReconStats() == null);
    }
}
Also used : LongRunningProcessStub(com.google.refine.process.LongRunningProcessStub) EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) MockWebServer(okhttp3.mockwebserver.MockWebServer) DataExtensionConfig(com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Dispatcher (okhttp3.Dispatcher)40 OkHttpClient (okhttp3.OkHttpClient)34 MockResponse (okhttp3.mockwebserver.MockResponse)27 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)25 Dispatcher (okhttp3.mockwebserver.Dispatcher)24 IOException (java.io.IOException)17 Before (org.junit.Before)14 Test (org.junit.Test)13 Call (okhttp3.Call)11 MockWebServer (okhttp3.mockwebserver.MockWebServer)11 LruNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory)10 ArrayList (java.util.ArrayList)8 Request (okhttp3.Request)8 Response (okhttp3.Response)8 ResponseBody (okhttp3.ResponseBody)7 Gson (com.google.gson.Gson)5 Interceptor (okhttp3.Interceptor)5 CloudantClient (com.cloudant.client.api.CloudantClient)4 RefineTest (com.google.refine.RefineTest)4 DataExtensionConfig (com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig)4