Skip to content

Commit

Permalink
[MODORDSTOR-416] Fix item handler unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Sep 26, 2024
1 parent 91e0d1e commit 25a014a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.apache.logging.log4j.Logger;
import org.folio.event.dto.InventoryFields;
import org.folio.event.dto.ResourceEvent;
import org.folio.okapi.common.GenericCompositeFuture;
import org.folio.rest.jaxrs.model.Location;
import org.folio.rest.jaxrs.model.Piece;
Expand Down Expand Up @@ -38,7 +39,8 @@ public HoldingCreateAsyncRecordHandler(Context context, Vertx vertx) {
}

@Override
protected Future<Void> processInventoryCreationEvent(JsonObject holdingObject, String tenantId) {
protected Future<Void> processInventoryCreationEvent(ResourceEvent resourceEvent, String tenantId) {
var holdingObject = JsonObject.mapFrom(resourceEvent.getNewValue());
var holdingId = holdingObject.getString(InventoryFields.ID.getValue());
var dbClient = new DBClient(getVertx(), tenantId);
var tenantIdUpdates = List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public Future<String> handle(KafkaConsumerRecord<String, String> kafkaConsumerRe
return Future.succeededFuture();
}

var inventoryObject = JsonObject.mapFrom(resourceEvent.getNewValue());
var tenantId = extractTenantFromHeaders(kafkaConsumerRecord.headers());
return processInventoryCreationEvent(inventoryObject, tenantId)
return processInventoryCreationEvent(resourceEvent, tenantId)
.onSuccess(v -> getLogger().info("handle:: '{}' event for '{}' processed successfully", eventType, inventoryEventType.getTopicName()))
.onFailure(t -> getLogger().error("Failed to process event: {}", kafkaConsumerRecord.value(), t))
.map(kafkaConsumerRecord.key());
Expand All @@ -62,7 +61,7 @@ public Future<String> handle(KafkaConsumerRecord<String, String> kafkaConsumerRe
}
}

protected abstract Future<Void> processInventoryCreationEvent(JsonObject inventoryObject, String tenantId);
protected abstract Future<Void> processInventoryCreationEvent(ResourceEvent resourceEvent, String tenantId);

protected abstract Logger getLogger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.commons.lang.ObjectUtils;
import org.apache.logging.log4j.Logger;
import org.folio.event.dto.InventoryFields;
import org.folio.event.dto.ResourceEvent;
import org.folio.rest.jaxrs.model.Piece;
import org.folio.rest.persist.DBClient;
import org.folio.services.piece.PieceService;
Expand All @@ -31,7 +32,8 @@ public ItemCreateAsyncRecordHandler(Context context, Vertx vertx) {
}

@Override
protected Future<Void> processInventoryCreationEvent(JsonObject itemObject, String tenantId) {
protected Future<Void> processInventoryCreationEvent(ResourceEvent resourceEvent, String tenantId) {
var itemObject = JsonObject.mapFrom(resourceEvent.getNewValue());
var itemId = itemObject.getString(InventoryFields.ID.getValue());
var dbClient = new DBClient(getVertx(), tenantId);
return pieceService.getPiecesByItemId(itemId, dbClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ void positive_shouldProcessItemCreateEvent()
createPiece(pieceId3, itemId).withHoldingId(holdingId).withReceivingTenantId(tenantId)
);

doReturn(Future.succeededFuture(pieces))
.when(pieceService).getPiecesByItemId(eq(itemId), any(DBClient.class));
doReturn(Future.succeededFuture(pieces)).when(pieceService).getPiecesByItemId(eq(itemId), any(DBClient.class));
doReturn(Future.succeededFuture()).when(pieceService).updatePieces(eq(expectedPieces), any(DBClient.class));
doReturn(pgClient).when(dbClient).getPgClient();
doReturn(tenantId).when(dbClient).getTenantId();
Expand All @@ -118,10 +117,10 @@ void positive_shouldProcessItemCreateEvent()
}).when(pgClient).withConn(any());

Method processItemCreateMethod = ItemCreateAsyncRecordHandler.class
.getDeclaredMethod("processItemCreationEvent", ResourceEvent.class, DBClient.class);
.getDeclaredMethod("processInventoryCreationEvent", ResourceEvent.class, String.class);
processItemCreateMethod.setAccessible(true);

processItemCreateMethod.invoke(handler, resourceEvent, dbClient);
processItemCreateMethod.invoke(handler, resourceEvent, tenantId);

verify(pieceService).getPiecesByItemId(eq(itemId), any(DBClient.class));
verify(pieceService).updatePieces(eq(expectedPieces), any(DBClient.class));
Expand Down

0 comments on commit 25a014a

Please sign in to comment.