Skip to content

Commit

Permalink
MODTLR-98 Fix RequestServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrVidinieiev committed Dec 9, 2024
1 parent 565b4d9 commit e8b1913
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 103 deletions.
11 changes: 10 additions & 1 deletion src/main/java/org/folio/service/impl/RequestServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,16 @@ public RequestWrapper createIntermediateRequest(Request intermediateRequest,
throw new RequestCreatingException(errorMessage);
}

private CirculationItem createCirculationItem(Request request, String inventoryTenantId) {
public CirculationItem createCirculationItem(Request request, String inventoryTenantId) {
if (request == null) {
log.warn("createCirculationItem:: request is null, skipping");
return null;
}
if (inventoryTenantId == null) {
log.warn("createCirculationItem:: inventory tenant ID is null, skipping");
return null;
}

String itemId = request.getItemId();
String instanceId = request.getInstanceId();
String pickupLocation = request.getPickupServicePointId();
Expand Down
7 changes: 2 additions & 5 deletions src/test/java/org/folio/listener/KafkaEventListenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Map;

import org.folio.listener.kafka.KafkaEventListener;
import org.folio.service.impl.LoanEventHandler;
import org.folio.service.impl.RequestBatchUpdateEventHandler;
import org.folio.service.impl.RequestEventHandler;
import org.folio.service.impl.UserEventHandler;
Expand All @@ -25,8 +24,6 @@ class KafkaEventListenerTest {
@Mock
RequestEventHandler requestEventHandler;
@Mock
LoanEventHandler loanEventHandler;
@Mock
RequestBatchUpdateEventHandler requestBatchEventHandler;
@Mock
SystemUserScopedExecutionService systemUserScopedExecutionService;
Expand All @@ -40,8 +37,8 @@ void shouldHandleExceptionInEventHandler() {
doThrow(new NullPointerException("NPE")).when(systemUserScopedExecutionService)
.executeAsyncSystemUserScoped(any(), any());
KafkaEventListener kafkaEventListener = new KafkaEventListener(requestEventHandler,
loanEventHandler, requestBatchEventHandler, systemUserScopedExecutionService,
userGroupEventHandler, userEventHandler);
requestBatchEventHandler, systemUserScopedExecutionService, userGroupEventHandler,
userEventHandler);
kafkaEventListener.handleRequestEvent("{}",
new MessageHeaders(Map.of(TENANT, "default".getBytes())));

Expand Down
144 changes: 47 additions & 97 deletions src/test/java/org/folio/service/RequestServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,107 +55,57 @@ void setUp() {
any(Runnable.class));
}

// @Test
// void shouldReturnNullIfEcsTlrOrSecondaryRequestIsNull() {
// assertNull(requestService.createCirculationItem(null, secondaryRequest, BORROWER_ID, LENDER_ID));
// assertNull(requestService.createCirculationItem(ecsTlrEntity, null, BORROWER_ID, LENDER_ID));
// }
//
// @Test
// void shouldReturnNullIfItemIdOrInstanceIdIsNull() {
// secondaryRequest.setItemId(null);
// assertNull(requestService.createCirculationItem(ecsTlrEntity, secondaryRequest, BORROWER_ID, LENDER_ID));
//
// secondaryRequest.setItemId(ITEM_ID);
// secondaryRequest.setInstanceId(null);
// assertNull(requestService.createCirculationItem(ecsTlrEntity, secondaryRequest, BORROWER_ID, LENDER_ID));
// }
//
// @Test
// void shouldReturnExistingCirculationItemIfFound() {
// CirculationItem existingItem = new CirculationItem();
// when(circulationItemClient.getCirculationItem(any())).thenReturn(existingItem);
//
// assertEquals(existingItem, requestService.createCirculationItem(ecsTlrEntity, secondaryRequest, BORROWER_ID, LENDER_ID));
// }
@Test
void shouldReturnNullIfRequestIsNull() {
assertNull(requestService.createCirculationItem(null, LENDER_ID));
}

@Test
void shouldReturnNullIfItemIdOrInstanceIdIsNull() {
secondaryRequest.setItemId(null);
assertNull(requestService.createCirculationItem(secondaryRequest, LENDER_ID));

secondaryRequest.setItemId(ITEM_ID);
secondaryRequest.setInstanceId(null);
assertNull(requestService.createCirculationItem(secondaryRequest, LENDER_ID));
}

@Test
void shouldReturnExistingCirculationItemIfFound() {
CirculationItem existingItem = new CirculationItem();
when(circulationItemClient.getCirculationItem(any())).thenReturn(existingItem);

// @Test
// void shouldCreateCirculationItem() {
// when(circulationItemClient.getCirculationItem(any())).thenReturn(null);
// when(circulationItemClient.createCirculationItem(any(), any())).thenReturn(new CirculationItem());
//
// InventoryItem item = new InventoryItem();
// item.setStatus(new InventoryItemStatus((InventoryItemStatus.NameEnum.PAGED)));
// when(requestService.getItemFromStorage(eq(ITEM_ID), anyString())).thenReturn(item);
//
// String instanceTitle = "Title";
// InventoryInstance instance = new InventoryInstance();
// instance.setTitle(instanceTitle);
// when(requestService.getInstanceFromStorage(eq(INSTANCE_ID), anyString())).thenReturn(instance);
//
// CirculationItem expectedCirculationItem = new CirculationItem()
// .status(new CirculationItemStatus()
// .name(CirculationItemStatus.NameEnum.AVAILABLE))
// .id(UUID.fromString(ITEM_ID))
// .holdingsRecordId(UUID.fromString(HOLDINGS_RECORD_ID))
// .dcbItem(true)
// .instanceTitle(instanceTitle)
// .lendingLibraryCode(LENDING_LIBRARY_CODE);
// requestService.createCirculationItem(ecsTlrEntity, secondaryRequest, BORROWER_ID, LENDER_ID);
// verify(circulationItemClient).createCirculationItem(ITEM_ID, expectedCirculationItem);
// }
assertEquals(existingItem, requestService.createCirculationItem(secondaryRequest, LENDER_ID));
}

@Test
void shouldCreateCirculationItem() {
when(circulationItemClient.getCirculationItem(any())).thenReturn(null);
when(circulationItemClient.createCirculationItem(any(), any())).thenReturn(new CirculationItem());

InventoryItem item = new InventoryItem();
item.setStatus(new InventoryItemStatus((InventoryItemStatus.NameEnum.PAGED)));
when(requestService.getItemFromStorage(eq(ITEM_ID), anyString())).thenReturn(item);

String instanceTitle = "Title";
InventoryInstance instance = new InventoryInstance();
instance.setTitle(instanceTitle);
when(requestService.getInstanceFromStorage(eq(INSTANCE_ID), anyString())).thenReturn(instance);

CirculationItem expectedCirculationItem = new CirculationItem()
.status(new CirculationItemStatus()
.name(CirculationItemStatus.NameEnum.AVAILABLE))
.id(UUID.fromString(ITEM_ID))
.holdingsRecordId(UUID.fromString(HOLDINGS_RECORD_ID))
.dcbItem(true)
.instanceTitle(instanceTitle)
.lendingLibraryCode(LENDING_LIBRARY_CODE);
requestService.createCirculationItem(secondaryRequest, LENDER_ID);
verify(circulationItemClient).createCirculationItem(ITEM_ID, expectedCirculationItem);
}

@Test
void circulationItemUpdateShouldBeSkippedWhenNull() {
assertNull(requestService.updateCirculationItemOnRequestCreation(null, null));
}
// @Test
// void shouldReturnNullIfEcsTlrOrSecondaryRequestIsNull() {
// assertNull(requestService.createCirculationItem(null, secondaryRequest, BORROWER_ID, LENDER_ID));
// assertNull(requestService.createCirculationItem(ecsTlrEntity, null, BORROWER_ID, LENDER_ID));
// }
//
// @Test
// void shouldReturnNullIfItemIdOrInstanceIdIsNull() {
// secondaryRequest.setItemId(null);
// assertNull(requestService.createCirculationItem(ecsTlrEntity, secondaryRequest, BORROWER_ID, LENDER_ID));
//
// secondaryRequest.setItemId(ITEM_ID);
// secondaryRequest.setInstanceId(null);
// assertNull(requestService.createCirculationItem(ecsTlrEntity, secondaryRequest, BORROWER_ID, LENDER_ID));
// }
//
// @Test
// void shouldReturnExistingCirculationItemIfFound() {
// CirculationItem existingItem = new CirculationItem();
// when(circulationItemClient.getCirculationItem(any())).thenReturn(existingItem);
//
// assertEquals(existingItem, requestService.createCirculationItem(ecsTlrEntity, secondaryRequest, BORROWER_ID, LENDER_ID));
// }
//
// @Test
// void shouldCreateCirculationItem() {
// when(circulationItemClient.getCirculationItem(any())).thenReturn(null);
// when(circulationItemClient.createCirculationItem(any(), any())).thenReturn(new CirculationItem());
//
// InventoryItem item = new InventoryItem();
// item.setStatus(new InventoryItemStatus((InventoryItemStatus.NameEnum.PAGED)));
// when(requestService.getItemFromStorage(eq(ITEM_ID), anyString())).thenReturn(item);
//
// String instanceTitle = "Title";
// InventoryInstance instance = new InventoryInstance();
// instance.setTitle(instanceTitle);
// when(requestService.getInstanceFromStorage(eq(INSTANCE_ID), anyString())).thenReturn(instance);
//
// CirculationItem expectedCirculationItem = new CirculationItem()
// .status(new CirculationItemStatus()
// .name(CirculationItemStatus.NameEnum.AVAILABLE))
// .id(UUID.fromString(ITEM_ID))
// .holdingsRecordId(UUID.fromString(HOLDINGS_RECORD_ID))
// .dcbItem(true)
// .instanceTitle(instanceTitle)
// .lendingLibraryCode(LENDING_LIBRARY_CODE);
// requestService.createCirculationItem(ecsTlrEntity, secondaryRequest, BORROWER_ID, LENDER_ID);
// verify(circulationItemClient).createCirculationItem(ITEM_ID, expectedCirculationItem);
// }
}

0 comments on commit e8b1913

Please sign in to comment.