use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-source-record-manager by folio-org.
the class ChangeManagerParsedRecordsAPITest method shouldReturnNotFoundIfThereIsNoSourceRecord.
@Test
public void shouldReturnNotFoundIfThereIsNoSourceRecord(TestContext testContext) {
Async async = testContext.async();
String externalId = UUID.randomUUID().toString();
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(SOURCE_RECORDS_URL + ".*"), true)).willReturn(notFound()));
RestAssured.given().spec(spec).queryParam(EXTERNAL_ID_QUERY_PARAM, externalId).when().get(PARSED_RECORDS_URL).then().statusCode(HttpStatus.SC_NOT_FOUND);
async.complete();
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-source-record-manager by folio-org.
the class ChangeManagerParsedRecordsAPITest method shouldReturnErrorIfExceptionWasThrown.
@Test
public void shouldReturnErrorIfExceptionWasThrown(TestContext testContext) {
Async async = testContext.async();
String externalId = UUID.randomUUID().toString();
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(SOURCE_RECORDS_URL + ".*"), true)).willReturn(ok().withBody("{\"leader\":\"01240cas a2200397 4500\",\"fields\":[]}")));
RestAssured.given().spec(spec).queryParam(EXTERNAL_ID_QUERY_PARAM, externalId).when().get(PARSED_RECORDS_URL).then().statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
async.complete();
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-source-record-manager by folio-org.
the class ChangeManagerParsedRecordsAPITest method shouldReturnParsedRecordDtoIfSourceRecordExists.
@Test
public void shouldReturnParsedRecordDtoIfSourceRecordExists(TestContext testContext) {
Async async = testContext.async();
String externalId = UUID.randomUUID().toString();
SourceRecord sourceRecord = new SourceRecord().withRecordId(UUID.randomUUID().toString()).withParsedRecord(new ParsedRecord().withId(UUID.randomUUID().toString()).withContent("{\"leader\":\"01240cas a2200397 4500\",\"fields\":[]}")).withRecordType(SourceRecord.RecordType.MARC_BIB).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(externalId));
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(SOURCE_RECORDS_URL + ".*"), true)).willReturn(ok().withBody(JsonObject.mapFrom(sourceRecord).encode())));
RestAssured.given().spec(spec).queryParam(EXTERNAL_ID_QUERY_PARAM, externalId).when().get(PARSED_RECORDS_URL).then().statusCode(HttpStatus.SC_OK).body("id", is(sourceRecord.getRecordId())).body("parsedRecord.id", is(sourceRecord.getParsedRecord().getId())).body("recordType", is(sourceRecord.getRecordType().value())).body("externalIdsHolder.instanceId", is(externalId));
async.complete();
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-source-record-manager by folio-org.
the class RecordProcessedEventHandlingServiceImplTest method shouldMarkJobExecutionAsErrorOnHandleDIErrorEventWhenAllRecordsProcessed.
@Test
public void shouldMarkJobExecutionAsErrorOnHandleDIErrorEventWhenAllRecordsProcessed(TestContext context) {
// given
Async async = context.async();
RawRecordsDto rawRecordsDto = new RawRecordsDto().withInitialRecords(Collections.singletonList(new InitialRecord().withRecord(CORRECT_RAW_RECORD))).withRecordsMetadata(new RecordsMetadata().withLast(true).withCounter(2).withTotal(2).withContentType(RecordsMetadata.ContentType.MARC_RAW));
HashMap<String, String> payloadContext = new HashMap<>();
DataImportEventPayload datImpErrorEventPayload = new DataImportEventPayload().withEventType(DataImportEventTypes.DI_ERROR.value()).withContext(payloadContext);
DataImportEventPayload datImpCompletedEventPayload = new DataImportEventPayload().withEventType(DataImportEventTypes.DI_COMPLETED.value()).withContext(payloadContext);
Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).map(jobExecution -> {
datImpErrorEventPayload.withJobExecutionId(jobExecution.getId());
return datImpCompletedEventPayload.withJobExecutionId(jobExecution.getId());
}).compose(ar -> chunkProcessingService.processChunk(rawRecordsDto, datImpErrorEventPayload.getJobExecutionId(), params));
// when
Future<Optional<JobExecution>> jobFuture = future.compose(ar -> recordProcessedEventHandlingService.handle(Json.encode(datImpErrorEventPayload), params)).compose(ar -> recordProcessedEventHandlingService.handle(Json.encode(datImpCompletedEventPayload), params)).compose(ar -> jobExecutionService.getJobExecutionById(datImpCompletedEventPayload.getJobExecutionId(), TENANT_ID));
// then
jobFuture.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertTrue(ar.result().isPresent());
JobExecution jobExecution = ar.result().get();
context.assertEquals(ERROR, jobExecution.getStatus());
context.assertEquals(JobExecution.UiStatus.ERROR, jobExecution.getUiStatus());
context.assertEquals(rawRecordsDto.getRecordsMetadata().getTotal(), jobExecution.getProgress().getTotal());
context.assertNotNull(jobExecution.getStartedDate());
context.assertNotNull(jobExecution.getCompletedDate());
verify(2, putRequestedFor(new UrlPathPattern(new RegexPattern(SNAPSHOT_SERVICE_URL + "/.*"), true)));
async.complete();
});
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-source-record-manager by folio-org.
the class EventDrivenChunkProcessingServiceImplTest method setUp.
@Before
public void setUp() throws IOException {
String rules = TestUtil.readFileFromPath(RULES_PATH);
this.mocks = MockitoAnnotations.openMocks(this);
String[] hostAndPort = kafkaCluster.getBrokerList().split(":");
kafkaConfig = KafkaConfig.builder().kafkaHost(hostAndPort[0]).kafkaPort(hostAndPort[1]).envId(KAFKA_ENV_ID).build();
mappingRuleDao = when(mock(MappingRuleDaoImpl.class).get(any(Record.RecordType.class), anyString())).thenReturn(Future.succeededFuture(Optional.of(new JsonObject(rules)))).getMock();
marcRecordAnalyzer = new MarcRecordAnalyzer();
mappingRuleCache = new MappingRuleCache(mappingRuleDao, vertx);
mappingRuleService = new MappingRuleServiceImpl(mappingRuleDao, mappingRuleCache);
mappingParametersProvider = when(mock(MappingParametersProvider.class).get(anyString(), any(OkapiConnectionParams.class))).thenReturn(Future.succeededFuture(new MappingParameters())).getMock();
mappingMetadataService = new MappingMetadataServiceImpl(mappingParametersProvider, mappingRuleService, mappingRulesSnapshotDao, mappingParamsSnapshotDao);
changeEngineService = new ChangeEngineServiceImpl(jobExecutionSourceChunkDao, jobExecutionService, marcRecordAnalyzer, hrIdFieldService, recordsPublishingService, mappingMetadataService, kafkaConfig);
ReflectionTestUtils.setField(changeEngineService, "maxDistributionNum", 10);
ReflectionTestUtils.setField(changeEngineService, "batchSize", 100);
chunkProcessingService = new EventDrivenChunkProcessingServiceImpl(jobExecutionSourceChunkDao, jobExecutionService, changeEngineService, jobExecutionProgressService);
HashMap<String, String> headers = new HashMap<>();
headers.put(OKAPI_URL_HEADER, "http://localhost:" + snapshotMockServer.port());
headers.put(OKAPI_TENANT_HEADER, TENANT_ID);
headers.put(OKAPI_TOKEN_HEADER, "token");
params = new OkapiConnectionParams(headers, vertx);
WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern("/data-import-profiles/jobProfiles/" + ".*"), true)).willReturn(ok().withBody(JsonObject.mapFrom(jobProfile).encode())));
}
Aggregations