use of org.folio.rest.jaxrs.model.Event in project mod-circulation-storage by folio-org.
the class RequestExpirationApiTest method assertPublishedEvents.
private void assertPublishedEvents(List<JsonObject> events) {
events.forEach(e -> {
Event event = e.mapTo(Event.class);
assertThat(event.getEventType(), is(LOG_RECORD.name()));
JsonObject payload = new JsonObject(event.getEventPayload()).getJsonObject(PAYLOAD.value());
Request original = payload.getJsonObject(REQUESTS.value()).getJsonObject(ORIGINAL.value()).mapTo(Request.class);
Request updated = payload.getJsonObject(REQUESTS.value()).getJsonObject(UPDATED.value()).mapTo(Request.class);
assertThat(original.getStatus(), not(equalTo(updated.getStatus())));
});
}
use of org.folio.rest.jaxrs.model.Event in project mod-inventory by folio-org.
the class QuickMarcKafkaHandler method handle.
@Override
public Future<String> handle(KafkaConsumerRecord<String, String> record) {
var params = new OkapiConnectionParams(kafkaHeadersToMap(record.headers()), vertx);
var context = constructContext(params.getTenantId(), params.getToken(), params.getOkapiUrl());
Event event = Json.decodeValue(record.value(), Event.class);
LOGGER.info("Quick marc event payload has been received with event type: {}", event.getEventType());
return getEventPayload(event).compose(eventPayload -> processPayload(eventPayload, context).compose(recordType -> sendEvent(eventPayload, getReplyEventType(recordType), params)).recover(throwable -> sendErrorEvent(params, eventPayload, throwable)).map(ar -> record.key()), th -> {
LOGGER.error("Update record state was failed while handle event, {}", th.getMessage());
return Future.failedFuture(th.getMessage());
});
}
use of org.folio.rest.jaxrs.model.Event in project mod-inventory by folio-org.
the class DataImportKafkaHandlerTest method shouldReturnSucceededFutureWhenProcessingCoreHandlerSucceeded.
@Test
public void shouldReturnSucceededFutureWhenProcessingCoreHandlerSucceeded(TestContext context) {
// given
Async async = context.async();
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withTenant(TENANT_ID).withOkapiUrl(mockServer.baseUrl()).withToken("test-token").withContext(new HashMap<>(Map.of("JOB_PROFILE_SNAPSHOT_ID", profileSnapshotWrapper.getId())));
Event event = new Event().withId("01").withEventPayload(Json.encode(dataImportEventPayload));
String expectedKafkaRecordKey = "test_key";
when(kafkaRecord.key()).thenReturn(expectedKafkaRecordKey);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
when(kafkaRecord.headers()).thenReturn(List.of(KafkaHeader.header(RECORD_ID_HEADER, UUID.randomUUID().toString()), KafkaHeader.header(CHUNK_ID_HEADER, UUID.randomUUID().toString())));
EventHandler mockedEventHandler = mock(EventHandler.class);
when(mockedEventHandler.isEligible(any(DataImportEventPayload.class))).thenReturn(true);
when(mockedEventHandler.handle(any(DataImportEventPayload.class))).thenReturn(CompletableFuture.completedFuture(new DataImportEventPayload()));
EventManager.registerEventHandler(mockedEventHandler);
// when
Future<String> future = dataImportKafkaHandler.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 MarcBibInstanceHridSetKafkaHandlerTest method shouldReturnFailedFutureWhenPayloadHasNoMarcRecord.
@Test
public void shouldReturnFailedFutureWhenPayloadHasNoMarcRecord(TestContext context) throws IOException {
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put(JOB_EXECUTION_ID_KEY, UUID.randomUUID().toString());
Event event = new Event().withId("01").withEventPayload(Json.encode(payload));
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 MarcBibInstanceHridSetKafkaHandlerTest method shouldReturnFailedIfOLErrorExist.
@Test
public void shouldReturnFailedIfOLErrorExist(TestContext context) {
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put("MARC_BIB", Json.encode(record));
payload.put(JOB_EXECUTION_ID_KEY, UUID.randomUUID().toString());
payload.put("CURRENT_RETRY_NUMBER", "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<Failure> failureHandler = invocationOnMock.getArgument(2);
failureHandler.accept(new Failure("Cannot update record 601a8dc4-dee7-48eb-b03f-d02fdf0debd0 because it has been changed (optimistic locking): Stored _version is 2, _version of request is 1", 409));
return null;
}).when(mockedInstanceCollection).update(any(), any(), any());
// when
Future<String> future = marcBibInstanceHridSetKafkaHandler.handle(kafkaRecord);
// then
future.onComplete(ar -> {
context.assertTrue(ar.failed());
async.complete();
});
}
Aggregations