use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-inventory by folio-org.
the class QuickMarcKafkaHandlerTest method shouldSendAuthorityUpdatedEvent.
@Test
public void shouldSendAuthorityUpdatedEvent(TestContext context) throws InterruptedException {
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put("RECORD_TYPE", "MARC_AUTHORITY");
payload.put("MARC_AUTHORITY", Json.encode(authorityRecord));
payload.put("MAPPING_RULES", authorityMappingRules.encode());
payload.put("MAPPING_PARAMS", new JsonObject().encode());
payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_AUTHORITY).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));
doAnswer(invocationOnMock -> {
Consumer<Success<Authority>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingAuthority));
return null;
}).when(mockedAuthorityRecordCollection).findById(anyString(), any(), any());
// when
Future<String> future = handler.handle(kafkaRecord);
// then
String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_INVENTORY_AUTHORITY_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