Search in sources :

Example 71 with RegexPattern

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();
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 72 with RegexPattern

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();
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 73 with RegexPattern

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();
}
Also used : ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 74 with RegexPattern

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();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) JournalServiceImpl(org.folio.services.journal.JournalServiceImpl) MockitoAnnotations(org.mockito.MockitoAnnotations) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) ERROR(org.folio.rest.jaxrs.model.JobExecution.Status.ERROR) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) MappingRulesSnapshotDaoImpl(org.folio.dao.MappingRulesSnapshotDaoImpl) DataImportEventPayload(org.folio.DataImportEventPayload) UUID(java.util.UUID) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) MarcImportEventsHandler(org.folio.verticle.consumers.util.MarcImportEventsHandler) Optional(java.util.Optional) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) JobExecutionSourceChunkDaoImpl(org.folio.dao.JobExecutionSourceChunkDaoImpl) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RunWith(org.junit.runner.RunWith) PARSING_IN_PROGRESS(org.folio.rest.jaxrs.model.JobExecution.Status.PARSING_IN_PROGRESS) HashMap(java.util.HashMap) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) JobExecutionProgressServiceImpl(org.folio.services.progress.JobExecutionProgressServiceImpl) WireMock.ok(com.github.tomakehurst.wiremock.client.WireMock.ok) WireMock(com.github.tomakehurst.wiremock.client.WireMock) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) DataType(org.folio.rest.jaxrs.model.JobProfileInfo.DataType) TestUtil(org.folio.TestUtil) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) InjectMocks(org.mockito.InjectMocks) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) JobExecutionProgressDaoImpl(org.folio.dao.JobExecutionProgressDaoImpl) RUNNING_COMPLETE(org.folio.rest.jaxrs.model.JobExecution.UiStatus.RUNNING_COMPLETE) Vertx(io.vertx.core.Vertx) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) IOException(java.io.IOException) Test(org.junit.Test) COMMITTED(org.folio.rest.jaxrs.model.JobExecution.Status.COMMITTED) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MappingParamsSnapshotDaoImpl(org.folio.dao.MappingParamsSnapshotDaoImpl) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.putRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) JsonArray(io.vertx.core.json.JsonArray) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) Rule(org.junit.Rule) WireMock.created(com.github.tomakehurst.wiremock.client.WireMock.created) File(org.folio.rest.jaxrs.model.File) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) DataImportEventTypes(org.folio.rest.jaxrs.model.DataImportEventTypes) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) Collections(java.util.Collections) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) KafkaConfig(org.folio.kafka.KafkaConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) Optional(java.util.Optional) HashMap(java.util.HashMap) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataImportEventPayload(org.folio.DataImportEventPayload) JobExecution(org.folio.rest.jaxrs.model.JobExecution) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Async(io.vertx.ext.unit.Async) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 75 with RegexPattern

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())));
}
Also used : HashMap(java.util.HashMap) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) Before(org.junit.Before)

Aggregations

RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)148 Test (org.junit.Test)119 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)79 Matchers.containsString (org.hamcrest.Matchers.containsString)46 Async (io.vertx.ext.unit.Async)33 JsonapiError (org.folio.rest.jaxrs.model.JsonapiError)31 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)26 Before (org.junit.Before)22 JsonObject (io.vertx.core.json.JsonObject)18 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)16 HashMap (java.util.HashMap)13 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)12 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 TestContext (io.vertx.ext.unit.TestContext)10 WireMockConfiguration (com.github.tomakehurst.wiremock.core.WireMockConfiguration)9 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)9 IOException (java.io.IOException)9 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)9 RunWith (org.junit.runner.RunWith)9