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
}
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);
}
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);
}
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();
}
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);
}
}
Aggregations