use of com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo in project sandbox by backpaper0.
the class HelloWireMockTest method test.
@Test
void test(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
WireMock wireMock = wireMockRuntimeInfo.getWireMock();
wireMock.register(get("/hello").willReturn(ok().withBody("Hello, world!")));
int port = wireMockRuntimeInfo.getHttpPort();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(HttpRequest.newBuilder(URI.create("http://localhost:" + port + "/hello")).build(), BodyHandlers.ofString());
assertEquals(200, response.statusCode());
assertEquals("Hello, world!", response.body());
}
use of com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo in project concord by walmartlabs.
the class SecretClientTest method testInvalidSecretType.
@Test
public void testInvalidSecretType(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
String orgName = "org_" + System.currentTimeMillis();
String secretName = "secret_" + System.currentTimeMillis();
stubFor(post(urlEqualTo("/api/v1/org/" + orgName + "/secret/" + secretName + "/data")).willReturn(aResponse().withStatus(200).withHeader(Constants.Headers.SECRET_TYPE, SecretEntry.TypeEnum.DATA.name()).withBody("Hello!")));
ApiClient apiClient = new ConcordApiClient("http://localhost:" + wmRuntimeInfo.getHttpPort());
SecretClient secretClient = new SecretClient(apiClient);
try {
secretClient.getData(orgName, secretName, null, SecretEntry.TypeEnum.KEY_PAIR);
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("Unexpected type of " + orgName + "/" + secretName));
}
}
use of com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo in project comet-java-sdk by comet-ml.
the class ConnectionTest method testDownloadAsync_onCometApiException.
@Test
public void testDownloadAsync_onCometApiException(@NonNull WireMockRuntimeInfo wmRuntimeInfo) throws IOException {
// create test error response
//
stubFor(get(urlPathEqualTo(SOME_ENDPOINT)).willReturn(aResponse().withStatus(404)));
// execute request and check results
//
File downloadFile = Files.createTempFile(null, null).toFile();
downloadFile.deleteOnExit();
Connection connection = new Connection(wmRuntimeInfo.getHttpBaseUrl(), TEST_API_KEY, MAX_AUTH_RETRIES_DEFAULT, logger);
ListenableFuture<Response> responseListenableFuture = connection.downloadAsync(downloadFile, SOME_ENDPOINT, SOME_PARAMS);
assertNotNull(responseListenableFuture, "future expected");
// wait for result
CompletableFuture<Response> completableFuture = responseListenableFuture.toCompletableFuture();
Exception exception = assertThrows(ExecutionException.class, () -> completableFuture.get(5, TimeUnit.SECONDS));
// check that inventory was fully processed
assertEquals(0, connection.getRequestsInventory().get(), "inventory must be empty");
// check that correct exception returned
assertTrue(exception.getCause() instanceof CometApiException, "wrong exception returned");
}
use of com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo in project comet-java-sdk by comet-ml.
the class ConnectionTest method testSendPostWithRetries_throwOnFailure_onCometWebException.
/**
* Tests that correct exception raised when Comet web error code received and max retry attempts exceeded
* with throwOnFailure set to false.
*/
@Test
public void testSendPostWithRetries_throwOnFailure_onCometWebException(@NonNull WireMockRuntimeInfo wmRuntimeInfo) {
// create test error response
//
stubFor(post(urlPathEqualTo(SOME_ENDPOINT)).willReturn(aResponse().withBody(JsonUtils.toJson(COMET_WEB_JAVA_SDK_EXCEPTION)).withStatus(BAD_REQUEST_ERROR_CODE).withHeader(CONTENT_TYPE.toString(), APPLICATION_JSON.toString())));
// execute request and check results
//
String baseUrl = wmRuntimeInfo.getHttpBaseUrl();
Connection connection = new Connection(baseUrl, TEST_API_KEY, MAX_AUTH_RETRIES_DEFAULT, logger);
CometApiException cometApiException = assertThrows(CometApiException.class, () -> connection.sendPostWithRetries(SOME_REQUEST_STRING, SOME_ENDPOINT, true));
// check that inventory was fully processed
assertEquals(0, connection.getRequestsInventory().get(), "inventory must be empty");
// check that correct exception returned
checkWebJavaSdkException(cometApiException);
}
use of com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo in project comet-java-sdk by comet-ml.
the class ConnectionTest method testSendPostAsync.
@Test
public void testSendPostAsync(@NonNull WireMockRuntimeInfo wmRuntimeInfo) {
// create test HTTP stub
//
stubFor(post(urlPathEqualTo(SOME_ENDPOINT)).willReturn(ok(SOME_JSON_RESPONSE).withHeader(CONTENT_TYPE.toString(), APPLICATION_JSON.toString())));
// execute request and check results
//
String baseUrl = wmRuntimeInfo.getHttpBaseUrl();
Connection connection = new Connection(baseUrl, TEST_API_KEY, MAX_AUTH_RETRIES_DEFAULT, logger);
ListenableFuture<Response> responseListenableFuture = connection.sendPostAsync(SOME_REQUEST_STRING, SOME_ENDPOINT);
assertNotNull(responseListenableFuture, "future expected");
// wait for result
CompletableFuture<Response> completableFuture = responseListenableFuture.toCompletableFuture();
assertDoesNotThrow(() -> {
Response response = completableFuture.exceptionally(throwable -> fail("response failed", throwable)).get(5, TimeUnit.SECONDS);
assertEquals(SOME_JSON_RESPONSE, response.getResponseBody(), "wrong response body");
});
// check that inventory was fully processed
assertEquals(0, connection.getRequestsInventory().get(), "inventory must be empty");
}
Aggregations