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());
}
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();
});
});
}
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());
}
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();
});
}
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));
});
}
Aggregations