use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method shouldMarkJobExecutionAsErrorAndDeleteAllAssociatedRecords.
@Test
public void shouldMarkJobExecutionAsErrorAndDeleteAllAssociatedRecords(TestContext testContext) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
WireMock.stubFor(WireMock.delete(new UrlPathPattern(new RegexPattern(SNAPSHOT_SERVICE_URL + "/.*"), true)).willReturn(WireMock.noContent()));
Async async = testContext.async();
RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(DEFAULT_JOB_PROFILE_ID).withDataType(JobProfileInfo.DataType.MARC)).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).body(rawRecordsDto.withId(UUID.randomUUID().toString())).when().post(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).when().delete(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(CANCELLED.value())).body("completedDate", notNullValue(Date.class));
async.complete();
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project neow3j by neow3j.
the class WireMockTestHelper method setUpWireMockForCall.
public static void setUpWireMockForCall(String call, String responseFile, String... params) throws IOException {
String responseBody = loadFile("/responses/" + responseFile);
StringBuilder regexPattern = new StringBuilder().append(".*\"method\":\"").append(call).append("\".*").append(".*\"params\":.*");
for (String param : params) {
regexPattern.append(".*").append(param).append(".*");
}
WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/")).withRequestBody(new RegexPattern(regexPattern.toString())).willReturn(WireMock.aResponse().withStatus(200).withBody(responseBody)));
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project neow3j by neow3j.
the class WireMockTestHelper method setUpWireMockForInvokeFunction.
public static void setUpWireMockForInvokeFunction(String contractFunction, String responseFile) throws IOException {
String responseBody = loadFile("/responses/" + responseFile);
WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/")).withRequestBody(new RegexPattern("" + ".*\"method\":\"invokefunction\"" + ".*\"params\":.*\"" + contractFunction + "\".*")).willReturn(WireMock.aResponse().withStatus(200).withBody(responseBody)));
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class LoadHoldingsStatusImplTest method shouldReturnStatusCompleted.
@Test
public void shouldReturnStatusCompleted(TestContext context) throws IOException, URISyntaxException {
setupDefaultLoadKBConfiguration();
mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), "responses/rmapi/holdings/status/get-status-completed-one-page.json");
stubFor(post(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)).willReturn(new ResponseDefinitionBuilder().withBody("").withStatus(202)));
mockGet(new RegexPattern(RMAPI_POST_HOLDINGS_URL), "responses/rmapi/holdings/holdings/get-holdings.json");
Async async = context.async();
handleStatusChange(COMPLETED, holdingsStatusRepository, o -> async.complete());
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
async.await(TIMEOUT);
final HoldingsLoadingStatus status = getWithOk(STUB_HOLDINGS_LOAD_STATUS_BY_ID_URL, STUB_TOKEN_HEADER).body().as(HoldingsLoadingStatus.class);
assertThat(status.getData().getType(), equalTo(LoadStatusData.Type.STATUS));
assertThat(status.getData().getAttributes().getTotalCount(), equalTo(2));
assertThat(status.getData().getAttributes().getStatus().getName(), equalTo(COMPLETED));
assertTrue(parse(status.getData().getAttributes().getStarted(), POSTGRES_TIMESTAMP_FORMATTER).isBefore(parse(status.getData().getAttributes().getFinished(), POSTGRES_TIMESTAMP_FORMATTER)));
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class UsersLookUpServiceTest method shouldReturn404WhenUserNotFound.
@Test
public void shouldReturn404WhenUserNotFound(TestContext context) {
final String stubUserId = "xyz";
final String stubUserIdEndpoint = GET_USER_ENDPOINT + stubUserId;
Async async = context.async();
OKAPI_HEADERS.put(XOkapiHeaders.TENANT, STUB_TENANT);
OKAPI_HEADERS.put(XOkapiHeaders.URL, getWiremockUrl());
OKAPI_HEADERS.put(XOkapiHeaders.USER_ID, stubUserId);
stubFor(get(new UrlPathPattern(new RegexPattern(stubUserIdEndpoint), true)).willReturn(new ResponseDefinitionBuilder().withStatus(404).withStatusMessage("User Not Found")));
CompletableFuture<User> info = usersLookUpService.lookUpUser(new OkapiParams(OKAPI_HEADERS));
info.thenCompose(result -> {
context.assertNull(result);
async.complete();
return null;
}).exceptionally(exception -> {
context.assertTrue(exception.getCause() instanceof NotFoundException);
async.complete();
return null;
});
}
Aggregations