use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadHoldingsImplTest method shouldRetryLoadingHoldingsFromStartWhenPageFailsToLoad.
@Test
public void shouldRetryLoadingHoldingsFromStartWhenPageFailsToLoad(TestContext context) throws IOException, URISyntaxException {
setupDefaultLoadKBConfiguration();
mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), RMAPI_RESPONSE_HOLDINGS_STATUS_COMPLETED);
stubFor(post(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)).willReturn(new ResponseDefinitionBuilder().withBody("").withStatus(202)));
ResponseDefinitionBuilder successfulResponse = new ResponseDefinitionBuilder().withBody(readFile(RMAPI_RESPONSE_HOLDINGS)).withStatus(200);
ResponseDefinitionBuilder failedResponse = new ResponseDefinitionBuilder().withStatus(500);
mockResponseList(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false), successfulResponse, failedResponse, failedResponse, successfulResponse);
int firstTryPages = 1;
int secondTryPages = 2;
Async async = context.async(firstTryPages + secondTryPages);
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SAVE_HOLDINGS_ACTION, message -> async.countDown());
vertx.eventBus().addOutboundInterceptor(interceptor);
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
async.await(TIMEOUT);
assertTrue(async.isSucceeded());
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadHoldingsImplTest method shouldStopRetryingAfterMultipleFailures.
@Test
public void shouldStopRetryingAfterMultipleFailures(TestContext context) throws IOException, URISyntaxException {
setupDefaultLoadKBConfiguration();
mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), RMAPI_RESPONSE_HOLDINGS_STATUS_COMPLETED);
UrlPathPattern urlPattern = new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false);
stubFor(post(urlPattern).willReturn(new ResponseDefinitionBuilder().withStatus(500)));
Async async = context.async(TEST_SNAPSHOT_RETRY_COUNT);
interceptor = interceptAndContinue(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_FAILED_ACTION, o -> async.countDown());
vertx.eventBus().addOutboundInterceptor(interceptor);
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
async.await(TIMEOUT);
Async retryStatusAsync = context.async();
retryStatusRepository.findByCredentialsId(UUID.fromString(STUB_CREDENTIALS_ID), STUB_TENANT).thenAccept(status -> {
boolean timerExists = vertx.cancelTimer(status.getTimerId());
context.assertEquals(0, status.getRetryAttemptsLeft());
context.assertFalse(timerExists);
retryStatusAsync.complete();
});
retryStatusAsync.await(TIMEOUT);
verify(TEST_SNAPSHOT_RETRY_COUNT, RequestPatternBuilder.newRequestPattern(RequestMethod.POST, urlPattern));
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadServiceFacadeTest method shouldNotCreateSnapshotIfItWasRecentlyCreated.
@Test
public void shouldNotCreateSnapshotIfItWasRecentlyCreated(TestContext context) throws IOException, URISyntaxException {
Async async = context.async();
String now = HOLDINGS_STATUS_TIME_FORMATTER.format(LocalDateTime.now(ZoneOffset.UTC));
HoldingsLoadStatus status = readJsonFile("responses/rmapi/holdings/status/get-status-completed.json", HoldingsLoadStatus.class).toBuilder().created(now).build();
mockGetWithBody(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), Json.encode(status));
mockPostHoldings();
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> async.complete());
vertx.eventBus().addOutboundInterceptor(interceptor);
loadServiceFacade.createSnapshot(new ConfigurationMessage(configuration, STUB_CREDENTIALS_ID, STUB_TENANT));
async.await(TIMEOUT);
WireMock.verify(0, postRequestedFor(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)));
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class UsersLookUpServiceTest method shouldReturn200WhenUserIdIsValid.
@Test
public void shouldReturn200WhenUserIdIsValid(TestContext context) throws IOException, URISyntaxException {
final String stubUserId = "88888888-8888-4888-8888-888888888888";
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().withBody(TestUtil.readFile(USER_INFO_STUB_FILE))));
CompletableFuture<User> info = usersLookUpService.lookUpUser(new OkapiParams(OKAPI_HEADERS));
info.thenCompose(userInfo -> {
context.assertNotNull(userInfo);
context.assertEquals("cedrick", userInfo.getUserName());
context.assertEquals("firstname_test", userInfo.getFirstName());
context.assertNull(userInfo.getMiddleName());
context.assertEquals("lastname_test", userInfo.getLastName());
async.complete();
return null;
}).exceptionally(throwable -> {
context.fail(throwable);
async.complete();
return null;
});
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-source-record-storage by folio-org.
the class DataImportConsumersVerticleTest method setUp.
@Before
public void setUp(TestContext context) throws IOException {
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(new MappingParameters()))))));
RawRecord rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
ParsedRecord parsedRecord = new ParsedRecord().withId(recordId).withContent(PARSED_CONTENT);
Snapshot snapshot = new Snapshot().withJobExecutionId(snapshotId).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
record = new Record().withId(recordId).withSnapshotId(snapshot.getJobExecutionId()).withGeneration(0).withMatchedId(recordId).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord).withExternalIdsHolder(new ExternalIdsHolder().withAuthorityId(UUID.randomUUID().toString()));
ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID);
RecordDaoImpl recordDao = new RecordDaoImpl(postgresClientFactory);
SnapshotDaoUtil.save(queryExecutor, snapshot).compose(v -> recordDao.saveRecord(record, TENANT_ID)).onComplete(context.asyncAssertSuccess());
}
Aggregations