Search in sources :

Example 41 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-source-record-storage by folio-org.

the class DataImportConsumersVerticleTest method shouldDeleteMarcAuthorityRecord.

@Test
public void shouldDeleteMarcAuthorityRecord() throws InterruptedException {
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(JOB_PROFILE).withContent(JsonObject.mapFrom(new JobProfile().withId(UUID.randomUUID().toString()).withDataType(JobProfile.DataType.MARC)).getMap()).withChildSnapshotWrappers(List.of(new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(ACTION_PROFILE).withOrder(0).withContent(JsonObject.mapFrom(new ActionProfile().withId(UUID.randomUUID().toString()).withAction(DELETE).withFolioRecord(ActionProfile.FolioRecord.MARC_AUTHORITY)).getMap())));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(PROFILE_SNAPSHOT_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(profileSnapshotWrapper))));
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put("MATCHED_MARC_AUTHORITY", Json.encode(record));
    payloadContext.put(PROFILE_SNAPSHOT_ID_KEY, profileSnapshotWrapper.getId());
    var eventPayload = new DataImportEventPayload().withContext(payloadContext).withOkapiUrl(mockServer.baseUrl()).withTenant(TENANT_ID).withToken(TOKEN).withJobExecutionId(snapshotId).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
    String topic = getTopicName(DI_MARC_FOR_DELETE_RECEIVED.value());
    KeyValue<String, String> kafkaRecord = buildKafkaRecord(eventPayload);
    kafkaRecord.addHeader(RECORD_ID_HEADER, record.getId(), UTF_8);
    kafkaRecord.addHeader(CHUNK_ID_HEADER, UUID.randomUUID().toString(), UTF_8);
    var request = SendKeyValues.to(topic, singletonList(kafkaRecord)).useDefaults();
    // when
    cluster.send(request);
    String observeTopic = getTopicName(DI_SRS_MARC_AUTHORITY_RECORD_DELETED.name());
    List<KeyValue<String, String>> observedRecords = cluster.observe(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
    Event obtainedEvent = Json.decodeValue(observedRecords.get(0).getValue(), Event.class);
    var resultPayload = Json.decodeValue(obtainedEvent.getEventPayload(), DataImportEventPayload.class);
    assertEquals(DI_SRS_MARC_AUTHORITY_RECORD_DELETED.value(), resultPayload.getEventType());
    assertEquals(record.getExternalIdsHolder().getAuthorityId(), resultPayload.getContext().get("AUTHORITY_RECORD_ID"));
    assertEquals(ACTION_PROFILE, resultPayload.getCurrentNode().getContentType());
}
Also used : KeyValue(net.mguenther.kafka.junit.KeyValue) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) HashMap(java.util.HashMap) JobProfile(org.folio.JobProfile) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.rest.jaxrs.model.DataImportEventPayload) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Event(org.folio.rest.jaxrs.model.Event) ActionProfile(org.folio.ActionProfile) Test(org.junit.Test) AbstractLBServiceTest(org.folio.services.AbstractLBServiceTest)

Example 42 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-source-record-storage by folio-org.

the class InstancePostProcessingEventHandlerTest method shouldUpdateField005WhenThisFiledIsProtected.

@Test
public void shouldUpdateField005WhenThisFiledIsProtected(TestContext context) throws IOException {
    Async async = context.async();
    MappingParameters mappingParameters = new MappingParameters().withMarcFieldProtectionSettings(List.of(new MarcFieldProtectionSetting().withField(TAG_005).withData("*")));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters))))));
    String recordId = UUID.randomUUID().toString();
    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(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
    Record defaultRecord = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
    String expectedInstanceId = UUID.randomUUID().toString();
    String expectedHrId = UUID.randomUUID().toString();
    JsonObject instance = createExternalEntity(expectedInstanceId, expectedHrId);
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(INSTANCE.value(), instance.encode());
    payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(defaultRecord));
    String expectedDate = AdditionalFieldsUtil.getValueFromControlledField(record, TAG_005);
    DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_INSTANCE_CREATED_READY_FOR_POST_PROCESSING);
    CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
    future.whenComplete((payload, throwable) -> {
        if (throwable != null) {
            context.fail(throwable);
        }
        recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
            if (getAr.failed()) {
                context.fail(getAr.cause());
            }
            context.assertTrue(getAr.result().isPresent());
            Record updatedRecord = getAr.result().get();
            String actualDate = AdditionalFieldsUtil.getValueFromControlledField(updatedRecord, TAG_005);
            Assert.assertEquals(expectedDate, actualDate);
            async.complete();
        });
    });
}
Also used : MarcFieldProtectionSetting(org.folio.rest.jaxrs.model.MarcFieldProtectionSetting) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) DataImportEventPayload(org.folio.DataImportEventPayload) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 43 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-source-record-storage by folio-org.

the class MarcAuthorityUpdateModifyEventHandlerTest method setUp.

@Before
public void setUp(TestContext context) {
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(new MappingParameters()))))));
    recordDao = new RecordDaoImpl(postgresClientFactory);
    recordService = new RecordServiceImpl(recordDao);
    modifyRecordEventHandler = new MarcAuthorityUpdateModifyEventHandler(recordService, new MappingParametersSnapshotCache(vertx), vertx);
    Snapshot snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
    snapshotForRecordUpdate = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withStatus(Snapshot.Status.PARSING_IN_PROGRESS);
    record = new Record().withId(recordId).withSnapshotId(snapshot.getJobExecutionId()).withGeneration(0).withMatchedId(recordId).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
    ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID);
    SnapshotDaoUtil.save(queryExecutor, snapshot).compose(v -> recordService.saveRecord(record, TENANT_ID)).compose(v -> SnapshotDaoUtil.save(queryExecutor, snapshotForRecordUpdate)).onComplete(context.asyncAssertSuccess());
}
Also used : TestContext(io.vertx.ext.unit.TestContext) JOB_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.JOB_PROFILE) RecordDaoImpl(org.folio.dao.RecordDaoImpl) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) UPDATE(org.folio.rest.jaxrs.model.MappingDetail.MarcMappingOption.UPDATE) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) After(org.junit.After) JsonObject(io.vertx.core.json.JsonObject) MarcBibUpdateModifyEventHandler(org.folio.services.handlers.actions.MarcBibUpdateModifyEventHandler) MappingProfile(org.folio.MappingProfile) DI_SRS_MARC_BIB_RECORD_MODIFIED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MODIFIED) RecordDao(org.folio.dao.RecordDao) DataImportEventPayload(org.folio.DataImportEventPayload) JobProfile(org.folio.JobProfile) MarcField(org.folio.rest.jaxrs.model.MarcField) UUID(java.util.UUID) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) Data(org.folio.rest.jaxrs.model.Data) MODIFY(org.folio.ActionProfile.Action.MODIFY) Slf4jNotifier(com.github.tomakehurst.wiremock.common.Slf4jNotifier) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MarcAuthorityUpdateModifyEventHandler(org.folio.services.handlers.actions.MarcAuthorityUpdateModifyEventHandler) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) MARC_AUTHORITY(org.folio.rest.jaxrs.model.EntityType.MARC_AUTHORITY) BeforeClass(org.junit.BeforeClass) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) MarcMappingDetail(org.folio.rest.jaxrs.model.MarcMappingDetail) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) WireMock(com.github.tomakehurst.wiremock.client.WireMock) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) TestUtil(org.folio.TestUtil) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) ActionProfile(org.folio.ActionProfile) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) MarcSubfield(org.folio.rest.jaxrs.model.MarcSubfield) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) MappingParametersSnapshotCache(org.folio.services.caches.MappingParametersSnapshotCache) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) DI_SRS_MARC_BIB_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED) DI_SRS_MARC_AUTHORITY_RECORD_UPDATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_UPDATED) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MARC_BIB(org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB) Rule(org.junit.Rule) Assert(org.junit.Assert) Collections(java.util.Collections) Snapshot(org.folio.rest.jaxrs.model.Snapshot) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) MarcAuthorityUpdateModifyEventHandler(org.folio.services.handlers.actions.MarcAuthorityUpdateModifyEventHandler) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) MappingParametersSnapshotCache(org.folio.services.caches.MappingParametersSnapshotCache) Date(java.util.Date) Snapshot(org.folio.rest.jaxrs.model.Snapshot) RecordDaoImpl(org.folio.dao.RecordDaoImpl) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Example 44 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-source-record-storage by folio-org.

the class SnapshotApiTest method setUp.

@Before
public void setUp(TestContext context) {
    WireMock.stubFor(WireMock.delete(new UrlPathPattern(new RegexPattern(INVENTORY_INSTANCES_PATH + "/.*"), true)).willReturn(WireMock.noContent()));
    Async async = context.async();
    SnapshotDaoUtil.deleteAll(PostgresClientFactory.getQueryExecutor(vertx, TENANT_ID)).onComplete(delete -> {
        if (delete.failed()) {
            context.fail(delete.cause());
        }
        async.complete();
    });
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) Before(org.junit.Before)

Example 45 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class AuthUrlStaticTest method namespaceIsProvisioned.

@Test
void namespaceIsProvisioned() {
    UrlPathPattern ssoUrl = urlPathMatching("/api/kafkas_mgmt/v1/sso_providers");
    UrlPathPattern cosUrl = urlPathMatching("/api/connector_mgmt/v1/agent/kafka_connector_clusters/.*/namespaces");
    given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
    untilAsserted(() -> {
        server.verify(exactly(1), getRequestedFor(cosUrl));
        server.verify(exactly(0), getRequestedFor(ssoUrl));
    });
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)112 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)84 Test (org.junit.Test)76 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)54 Async (io.vertx.ext.unit.Async)42 Before (org.junit.Before)33 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)28 Matchers.containsString (org.hamcrest.Matchers.containsString)26 JsonObject (io.vertx.core.json.JsonObject)22 TestContext (io.vertx.ext.unit.TestContext)20 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)19 IOException (java.io.IOException)19 RunWith (org.junit.runner.RunWith)19 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)16 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)15 URISyntaxException (java.net.URISyntaxException)15 STUB_TENANT (org.folio.test.util.TestUtil.STUB_TENANT)14 After (org.junit.After)14 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)13 HashMap (java.util.HashMap)13