-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODTLR-13 Handle request update event from data tenant to update ECS TLR
- Loading branch information
1 parent
48341eb
commit 8c672a7
Showing
3 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/test/java/org/folio/service/KafkaEventHandlerImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.folio.service; | ||
|
||
import org.folio.api.BaseIT; | ||
import org.folio.listener.kafka.KafkaEventListener; | ||
import org.folio.repository.EcsTlrRepository; | ||
import org.folio.service.impl.EcsTlrServiceImpl; | ||
import org.folio.service.impl.KafkaEventHandlerImpl; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import java.util.Optional; | ||
import static org.folio.support.MockDataUtils.getEcsTlrEntity; | ||
import static org.folio.support.MockDataUtils.getMockDataAsString; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class KafkaEventHandlerImplTest extends BaseIT { | ||
private static final String CHECK_IN_EVENT_SAMPLE = getMockDataAsString("mockdata/kafka/check_in.json"); | ||
|
||
@InjectMocks | ||
private KafkaEventHandlerImpl eventHandler; | ||
|
||
@InjectMocks | ||
private EcsTlrServiceImpl ecsTlrService; | ||
|
||
@MockBean | ||
private EcsTlrRepository ecsTlrRepository; | ||
|
||
@Autowired | ||
private KafkaEventListener eventListener; | ||
|
||
@Test | ||
void handleCheckInEventInPickupFromOpenToAwaitingPickupTest() { | ||
when(ecsTlrRepository.findByTlrId(any())).thenReturn(Optional.of(getEcsTlrEntity())); | ||
eventListener.handleRequestEvent(CHECK_IN_EVENT_SAMPLE); | ||
verify(ecsTlrRepository).save(any()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.folio.support; | ||
|
||
import lombok.SneakyThrows; | ||
import org.folio.EcsTlrApplication; | ||
import org.folio.domain.entity.EcsTlrEntity; | ||
import org.testcontainers.shaded.org.apache.commons.io.IOUtils; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
public class MockDataUtils { | ||
|
||
public static final UUID TLR_ID = UUID.fromString("100d10bf-2f06-4aa0-be15-0b95b2d9f9e3"); | ||
|
||
public static EcsTlrEntity getEcsTlrEntity() { | ||
return EcsTlrEntity.builder() | ||
.id(UUID.randomUUID()) | ||
.tlrId(TLR_ID) | ||
.build(); | ||
} | ||
|
||
@SneakyThrows | ||
public static String getMockDataAsString(String path) { | ||
try (InputStream resourceAsStream = EcsTlrApplication.class.getClassLoader().getResourceAsStream(path)) { | ||
if (resourceAsStream != null) { | ||
return IOUtils.toString(resourceAsStream, StandardCharsets.UTF_8); | ||
} else { | ||
StringBuilder sb = new StringBuilder(); | ||
try (Stream<String> lines = Files.lines(Paths.get(path))) { | ||
lines.forEach(sb::append); | ||
} | ||
return sb.toString(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
{ | ||
"id": "7034faf8-ef8c-47e4-b3bb-32dad1f7259b", | ||
"type": "UPDATED", | ||
"tenant": "diku", | ||
"timestamp": 1706684034764, | ||
"data": { | ||
"old": { | ||
"id": "398501a2-5c97-4ba6-9ee7-d1cd6433cb98", | ||
"requestLevel": "Title", | ||
"requestType": "Page", | ||
"requestDate": "2024-01-30T13:45:29.644+00:00", | ||
"requesterId": "2205005b-ca51-4a04-87fd-938eefa8f6de", | ||
"instanceId": "5bf370e0-8cca-4d9c-82e4-5170ab2a0a39", | ||
"holdingsRecordId": "e3ff6133-b9a2-4d4c-a1c9-dc1867d4df19", | ||
"itemId": "100d10bf-2f06-4aa0-be15-0b95b2d9f9e3", | ||
"status": "Open - In transit", | ||
"position": 1, | ||
"instance": { | ||
"title": "A semantic web primer", | ||
"identifiers": [ | ||
{ | ||
"value": "0262012103", | ||
"identifierTypeId": "8261054f-be78-422d-bd51-4ed9f33c3422" | ||
}, | ||
{ | ||
"value": "9780262012102", | ||
"identifierTypeId": "8261054f-be78-422d-bd51-4ed9f33c3422" | ||
}, | ||
{ | ||
"value": "2003065165", | ||
"identifierTypeId": "c858e4f2-2b6b-4385-842b-60732ee14abb" | ||
} | ||
] | ||
}, | ||
"item": { | ||
"barcode": "90000" | ||
}, | ||
"requester": { | ||
"firstName": "psych", | ||
"lastName": "rick", | ||
"barcode": "123" | ||
}, | ||
"fulfillmentPreference": "Hold Shelf", | ||
"pickupServicePointId": "c4c90014-c8c9-4ade-8f24-b5e313319f4b", | ||
"metadata": { | ||
"createdDate": "2024-01-30T13:46:14.597+00:00", | ||
"createdByUserId": "7187c6f3-41ec-5731-b551-7f0092abb4c6", | ||
"updatedDate": "2024-01-30T13:47:19.594+00:00", | ||
"updatedByUserId": "7187c6f3-41ec-5731-b551-7f0092abb4c6" | ||
}, | ||
"searchIndex": { | ||
"callNumberComponents": { | ||
"callNumber": "TK5105.88815 . A58 2004 FT MEADE" | ||
}, | ||
"shelvingOrder": "TK5105.88815 . A58 2004 FT MEADE", | ||
"pickupServicePointName": "Circ Desk 2" | ||
} | ||
}, | ||
"new": { | ||
"id": "398501a2-5c97-4ba6-9ee7-d1cd6433cb98", | ||
"requestLevel": "Title", | ||
"requestType": "Page", | ||
"requestDate": "2024-01-30T13:45:29.644+00:00", | ||
"requesterId": "2205005b-ca51-4a04-87fd-938eefa8f6de", | ||
"instanceId": "5bf370e0-8cca-4d9c-82e4-5170ab2a0a39", | ||
"holdingsRecordId": "e3ff6133-b9a2-4d4c-a1c9-dc1867d4df19", | ||
"itemId": "100d10bf-2f06-4aa0-be15-0b95b2d9f9e3", | ||
"status": "Open - In transit", | ||
"position": 1, | ||
"instance": { | ||
"title": "A semantic web primer", | ||
"identifiers": [ | ||
{ | ||
"value": "0262012103", | ||
"identifierTypeId": "8261054f-be78-422d-bd51-4ed9f33c3422" | ||
}, | ||
{ | ||
"value": "9780262012102", | ||
"identifierTypeId": "8261054f-be78-422d-bd51-4ed9f33c3422" | ||
}, | ||
{ | ||
"value": "2003065165", | ||
"identifierTypeId": "c858e4f2-2b6b-4385-842b-60732ee14abb" | ||
} | ||
] | ||
}, | ||
"item": { | ||
"barcode": "90000" | ||
}, | ||
"requester": { | ||
"firstName": "psych", | ||
"lastName": "rick", | ||
"barcode": "123" | ||
}, | ||
"fulfillmentPreference": "Hold Shelf", | ||
"pickupServicePointId": "c4c90014-c8c9-4ade-8f24-b5e313319f4b", | ||
"metadata": { | ||
"createdDate": "2024-01-30T13:46:14.597+00:00", | ||
"createdByUserId": "7187c6f3-41ec-5731-b551-7f0092abb4c6", | ||
"updatedDate": "2024-01-31T06:53:54.533+00:00", | ||
"updatedByUserId": "7187c6f3-41ec-5731-b551-7f0092abb4c6" | ||
}, | ||
"searchIndex": { | ||
"callNumberComponents": { | ||
"callNumber": "TK5105.88815 . A58 2004 FT MEADE" | ||
}, | ||
"shelvingOrder": "TK5105.88815 . A58 2004 FT MEADE", | ||
"pickupServicePointName": "Circ Desk 2" | ||
} | ||
} | ||
} | ||
} |