use of org.folio.rest.jaxrs.model.Event in project mod-inventory by folio-org.
the class MarcBibInstanceHridSetKafkaHandlerTest method shouldReturnFailedFutureWhenPayloadCanNotBeMapped.
@Test
public void shouldReturnFailedFutureWhenPayloadCanNotBeMapped(TestContext context) {
// given
Async async = context.async();
Event event = new Event().withId("01").withEventPayload(null);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
// when
Future<String> future = marcBibInstanceHridSetKafkaHandler.handle(kafkaRecord);
// then
future.onComplete(ar -> {
context.assertTrue(ar.failed());
async.complete();
});
}
use of org.folio.rest.jaxrs.model.Event in project mod-inventory by folio-org.
the class MarcHoldingsRecordHridSetKafkaHandlerTest method shouldReturnFailedFutureWhenPayloadCanNotBeMapped.
@Test
public void shouldReturnFailedFutureWhenPayloadCanNotBeMapped(TestContext context) {
// given
Async async = context.async();
Event event = new Event().withId("01").withEventPayload(null);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
// when
Future<String> future = marcHoldingsRecordHridSetKafkaHandler.handle(kafkaRecord);
// then
future.onComplete(ar -> {
context.assertTrue(ar.failed());
async.complete();
});
}
use of org.folio.rest.jaxrs.model.Event in project mod-inventory by folio-org.
the class MarcHoldingsRecordHridSetKafkaHandlerTest method shouldReturnSucceededFutureWithObtainedRecordKey.
@Test
public void shouldReturnSucceededFutureWithObtainedRecordKey(TestContext context) {
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put(JOB_EXECUTION_ID_KEY, UUID.randomUUID().toString());
payload.put("MARC_HOLDINGS", Json.encode(record));
Event event = new Event().withId("01").withEventPayload(Json.encode(payload));
String expectedKafkaRecordKey = "test_key";
when(kafkaRecord.key()).thenReturn(expectedKafkaRecordKey);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
when(kafkaRecord.headers()).thenReturn(okapiHeaders);
// when
Future<String> future = marcHoldingsRecordHridSetKafkaHandler.handle(kafkaRecord);
// then
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertEquals(expectedKafkaRecordKey, ar.result());
async.complete();
});
}
use of org.folio.rest.jaxrs.model.Event in project mod-inventory by folio-org.
the class QuickMarcKafkaHandlerTest method shouldSendInstanceUpdatedEvent.
@Test
public void shouldSendInstanceUpdatedEvent(TestContext context) throws InterruptedException {
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put("RECORD_TYPE", "MARC_BIB");
payload.put("MARC_BIB", Json.encode(bibRecord));
payload.put("MAPPING_RULES", bibMappingRules.encode());
payload.put("MAPPING_PARAMS", new JsonObject().encode());
payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_BIB).withRelatedRecordVersion("1")));
Event event = new Event().withId("01").withEventPayload(Json.encode(payload));
String expectedKafkaRecordKey = "test_key";
when(kafkaRecord.key()).thenReturn(expectedKafkaRecordKey);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
// when
Future<String> future = handler.handle(kafkaRecord);
// then
String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_INVENTORY_INSTANCE_UPDATED.name());
cluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertEquals(expectedKafkaRecordKey, ar.result());
async.complete();
});
}
use of org.folio.rest.jaxrs.model.Event in project mod-inventory by folio-org.
the class QuickMarcKafkaHandlerTest method shouldSendHoldingsUpdatedEvent.
@Test
public void shouldSendHoldingsUpdatedEvent(TestContext context) throws InterruptedException {
List<HoldingsType> holdings = new ArrayList<>();
holdings.add(new HoldingsType().withName("testingnote$a"));
MappingParameters mappingParameters = new MappingParameters();
mappingParameters.withHoldingsTypes(holdings);
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put("RECORD_TYPE", "MARC_HOLDING");
payload.put("MARC_HOLDING", Json.encode(holdingsRecord));
payload.put("MAPPING_RULES", holdingsMappingRules.encode());
payload.put("MAPPING_PARAMS", Json.encode(mappingParameters));
payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_HOLDING).withRelatedRecordVersion("1")));
Event event = new Event().withId("01").withEventPayload(Json.encode(payload));
String expectedKafkaRecordKey = "test_key";
when(kafkaRecord.key()).thenReturn(expectedKafkaRecordKey);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
// when
Future<String> future = handler.handle(kafkaRecord);
// then
String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_INVENTORY_HOLDINGS_UPDATED.name());
cluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertEquals(expectedKafkaRecordKey, ar.result());
async.complete();
});
}
Aggregations