use of org.mockserver.integration.ClientAndServer in project hadoop by apache.
the class TestRefreshTokenTimeBasedTokenRefresher method refreshUrlIsCorrect.
@Test
public void refreshUrlIsCorrect() throws IOException {
final int PORT = 7552;
final String REFRESH_ADDRESS = "http://localhost:" + PORT + "/refresh";
long tokenExpires = 0;
Configuration conf = buildConf("refresh token key", Long.toString(tokenExpires), "joebob", REFRESH_ADDRESS);
Timer mockTimer = mock(Timer.class);
when(mockTimer.now()).thenReturn(tokenExpires + 1000l);
AccessTokenProvider tokenProvider = new ConfRefreshTokenBasedAccessTokenProvider(mockTimer);
tokenProvider.setConf(conf);
// Build mock server to receive refresh request
ClientAndServer mockServer = startClientAndServer(PORT);
HttpRequest expectedRequest = request().withMethod("POST").withPath("/refresh").withBody(ParameterBody.params(Parameter.param(CLIENT_ID, "joebob"), Parameter.param(GRANT_TYPE, REFRESH_TOKEN), Parameter.param(REFRESH_TOKEN, "refresh token key")));
MockServerClient mockServerClient = new MockServerClient("localhost", PORT);
// https://tools.ietf.org/html/rfc6749#section-5.1
Map<String, Object> map = new TreeMap<>();
map.put(EXPIRES_IN, "0987654321");
map.put(TOKEN_TYPE, BEARER);
map.put(ACCESS_TOKEN, "new access token");
ObjectMapper mapper = new ObjectMapper();
HttpResponse resp = response().withStatusCode(HttpStatus.SC_OK).withHeaders(CONTENT_TYPE_APPLICATION_JSON).withBody(mapper.writeValueAsString(map));
mockServerClient.when(expectedRequest, exactly(1)).respond(resp);
assertEquals("new access token", tokenProvider.getAccessToken());
mockServerClient.verify(expectedRequest);
mockServerClient.clear(expectedRequest);
mockServer.stop();
}
use of org.mockserver.integration.ClientAndServer in project POL-POM-5 by PhoenicisOrg.
the class DownloaderTest method setUp.
@BeforeClass
public static void setUp() throws MalformedURLException {
mockServer = new ClientAndServer(MOCKSERVER_PORT);
mockServerURL = new URL("http://localhost:" + MOCKSERVER_PORT + "/test.txt");
mockServerURLFile2 = new URL("http://localhost:" + MOCKSERVER_PORT + "/test2.txt");
}
use of org.mockserver.integration.ClientAndServer in project phoenicis by PhoenicisOrg.
the class DownloaderTest method setUp.
@BeforeClass
public static void setUp() throws MalformedURLException {
mockServer = new ClientAndServer(MOCKSERVER_PORT);
mockServerURL = new URL("http://localhost:" + MOCKSERVER_PORT + "/test.txt");
mockServerURLFile2 = new URL("http://localhost:" + MOCKSERVER_PORT + "/test2.txt");
}
use of org.mockserver.integration.ClientAndServer in project wildfly by wildfly.
the class TestingOcspServer method start.
public void start() throws Exception {
Assert.assertNull("OCSP server already started", ocspServer);
ocspServer = new OcspServer();
ocspServer.setConfFile(TestingOcspServer.class.getResource("ocsp-responder.xml").getFile());
securityFactory.setSignerFactoryRegister(new SignerFactoryRegisterImpl());
ocspServer.setSecurityFactory(securityFactory);
ocspServer.init();
HttpOcspServlet servlet = new HttpOcspServlet();
servlet.setServer(ocspServer);
server = new ClientAndServer(port);
server.when(request().withMethod("POST").withPath("/ocsp"), Times.unlimited()).respond(request -> getHttpResponse(request, servlet));
server.when(request().withMethod("GET").withPath("/ocsp/.*"), Times.unlimited()).respond(request -> getHttpResponse(request, servlet));
}
use of org.mockserver.integration.ClientAndServer in project POL-POM-5 by PlayOnLinux.
the class DownloaderTest method setUp.
@BeforeClass
public static void setUp() throws MalformedURLException {
mockServer = new ClientAndServer(MOCKSERVER_PORT);
mockServerURL = new URL("http://localhost:" + MOCKSERVER_PORT + "/test.txt");
mockServerURLFile2 = new URL("http://localhost:" + MOCKSERVER_PORT + "/test2.txt");
}
Aggregations