Skip to content

Commit

Permalink
MODSOURMAN-1084: Test case for creating two journal records when inve…
Browse files Browse the repository at this point in the history
…ntory instance update event received
  • Loading branch information
Maksat-Galymzhan committed Feb 2, 2024
1 parent d15657c commit 13f0b1d
Showing 1 changed file with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_HOLDINGS;
import static org.folio.rest.jaxrs.model.JournalRecord.EntityType.PO_LINE;
import static org.folio.services.journal.JournalUtil.ERROR_KEY;
import static org.folio.services.journal.JournalUtil.MARC_BIB_RECORD_CREATED;

@RunWith(VertxUnitRunner.class)
public class JournalUtilTest {
Expand Down Expand Up @@ -1044,4 +1045,99 @@ public void shouldBuildJournalRecordForNonMatchWithErrorAndMatchedNumberNotAvail
Assert.assertEquals(expectedErrorMessage, journalRecord.getError());
Assert.assertNotNull(journalRecord.getActionDate());
}

@Test
public void shouldReturnUpdatedInstanceAndCreatedMarcBibJournalRecordInMarcBibStatusTrue() throws JournalRecordMapperException {
String instanceId = UUID.randomUUID().toString();
String instanceHrid = UUID.randomUUID().toString();

JsonObject instanceJson = new JsonObject()
.put("id", instanceId)
.put("hrid", instanceHrid);

String recordId = UUID.randomUUID().toString();
String snapshotId = UUID.randomUUID().toString();

JsonObject recordJson = new JsonObject()
.put("id", recordId)
.put("snapshotId", snapshotId)
.put("order", 1);

HashMap<String, String> context = new HashMap<>();
context.put(INSTANCE.value(), instanceJson.encode());
context.put(MARC_BIBLIOGRAPHIC.value(), recordJson.encode());
context.put(MARC_BIB_RECORD_CREATED, Boolean.TRUE.toString());
context.put(CURRENT_EVENT_TYPE, "DI_INVENTORY_INSTANCE_UPDATED");

DataImportEventPayload eventPayload = new DataImportEventPayload()
.withEventType("DI_COMPLETED")
.withContext(context);

List<JournalRecord> journalRecord = JournalUtil.buildJournalRecordsByEvent(eventPayload,
UPDATE, INSTANCE, COMPLETED);

Assert.assertNotNull(journalRecord);
Assert.assertEquals(2, journalRecord.size());
Assert.assertEquals(snapshotId, journalRecord.get(0).getJobExecutionId());
Assert.assertEquals(recordId, journalRecord.get(0).getSourceId());
Assert.assertEquals(1, journalRecord.get(0).getSourceRecordOrder().intValue());
Assert.assertEquals(INSTANCE, journalRecord.get(0).getEntityType());
Assert.assertEquals(instanceId, journalRecord.get(0).getEntityId());
Assert.assertEquals(instanceHrid, journalRecord.get(0).getEntityHrId());
Assert.assertEquals(UPDATE, journalRecord.get(0).getActionType());
Assert.assertEquals(COMPLETED, journalRecord.get(0).getActionStatus());
Assert.assertNotNull(journalRecord.get(0).getActionDate());
Assert.assertEquals(CREATE, journalRecord.get(1).getActionType());
Assert.assertEquals(COMPLETED, journalRecord.get(1).getActionStatus());
Assert.assertEquals(MARC_BIBLIOGRAPHIC, journalRecord.get(1).getEntityType());
}

@Test
public void shouldReturnUpdatedInstanceAndCreatedMarcBibJournalRecordInMarcBibStatusFalse() throws JournalRecordMapperException {
String instanceId = UUID.randomUUID().toString();
String instanceHrid = UUID.randomUUID().toString();

JsonObject instanceJson = new JsonObject()
.put("id", instanceId)
.put("hrid", instanceHrid);

String recordId = UUID.randomUUID().toString();
String snapshotId = UUID.randomUUID().toString();

JsonObject recordJson = new JsonObject()
.put("id", recordId)
.put("snapshotId", snapshotId)
.put("order", 1);

HashMap<String, String> context = new HashMap<>();
context.put(INSTANCE.value(), instanceJson.encode());
context.put(MARC_BIBLIOGRAPHIC.value(), recordJson.encode());
context.put(MARC_BIB_RECORD_CREATED, Boolean.FALSE.toString());
context.put(CURRENT_EVENT_TYPE, "DI_INVENTORY_INSTANCE_UPDATED");

DataImportEventPayload eventPayload = new DataImportEventPayload()
.withEventType("DI_COMPLETED")
.withContext(context);

List<JournalRecord> journalRecord = JournalUtil.buildJournalRecordsByEvent(eventPayload,
UPDATE, INSTANCE, COMPLETED);

Assert.assertNotNull(journalRecord);
Assert.assertEquals(2, journalRecord.size());

Assert.assertEquals(snapshotId, journalRecord.get(0).getJobExecutionId());
Assert.assertEquals(recordId, journalRecord.get(0).getSourceId());
Assert.assertEquals(1, journalRecord.get(0).getSourceRecordOrder().intValue());
Assert.assertEquals(INSTANCE, journalRecord.get(0).getEntityType());
Assert.assertEquals(instanceId, journalRecord.get(0).getEntityId());
Assert.assertEquals(instanceHrid, journalRecord.get(0).getEntityHrId());
Assert.assertEquals(UPDATE, journalRecord.get(0).getActionType());
Assert.assertEquals(COMPLETED, journalRecord.get(0).getActionStatus());
Assert.assertNotNull(journalRecord.get(0).getActionDate());

Assert.assertEquals(UPDATE, journalRecord.get(1).getActionType());
Assert.assertEquals(COMPLETED, journalRecord.get(1).getActionStatus());
Assert.assertEquals(MARC_BIBLIOGRAPHIC, journalRecord.get(1).getEntityType());
}

}

0 comments on commit 13f0b1d

Please sign in to comment.