From 8257312fddd6b2c754f527143a18a403b61d5d23 Mon Sep 17 00:00:00 2001 From: Antony_Hruschev Date: Thu, 12 Dec 2024 13:56:28 +0400 Subject: [PATCH] UXPROD-5001 Add unit test --- .../resources/RequestNoticeSenderTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/test/java/org/folio/circulation/resources/RequestNoticeSenderTest.java diff --git a/src/test/java/org/folio/circulation/resources/RequestNoticeSenderTest.java b/src/test/java/org/folio/circulation/resources/RequestNoticeSenderTest.java new file mode 100644 index 0000000000..c8ea254f8d --- /dev/null +++ b/src/test/java/org/folio/circulation/resources/RequestNoticeSenderTest.java @@ -0,0 +1,62 @@ +package org.folio.circulation.resources; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; + +import java.util.UUID; +import java.util.stream.Stream; + +import org.apache.commons.lang3.StringUtils; +import org.folio.circulation.domain.Request; +import org.folio.circulation.domain.RequestAndRelatedRecords; +import org.folio.circulation.domain.notice.ImmediatePatronNoticeService; +import org.folio.circulation.domain.notice.PatronNoticeEvent; +import org.folio.circulation.support.StringUtil; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.testcontainers.shaded.org.bouncycastle.cert.ocsp.Req; + +import api.support.builders.RequestBuilder; +import io.vertx.core.json.JsonObject; + +@ExtendWith(MockitoExtension.class) +public class RequestNoticeSenderTest { + + @Mock + private ImmediatePatronNoticeService immediatePatronNoticeService; + @InjectMocks + private RequestNoticeSender requestNoticeSender; + + @ParameterizedTest + @MethodSource("requestAndRelatedRecords") + void shouldNotSendNotificationWhenIsDcbCancellationTrue(RequestAndRelatedRecords records, + int invocationTimes) { + + requestNoticeSender.sendNoticeOnRequestCancelled(records); + Mockito.verify(immediatePatronNoticeService, times(invocationTimes)).acceptNoticeEvent(any( + PatronNoticeEvent.class)); + } + + static Stream requestAndRelatedRecords() { + return Stream.of( + Arguments.of(getRequest(true, null), 0) +// Arguments.of(getRequest(false, null), 1), +// Arguments.of(getRequest(false, UUID.randomUUID()), 1) + ); + } + + private static RequestAndRelatedRecords getRequest(boolean isDcbReRequestCancellation, UUID itemId) { + JsonObject representation = new RequestBuilder() + .withItemId(itemId) + .create(); + representation.put("isDcbReRequestCancellation", isDcbReRequestCancellation); + return new RequestAndRelatedRecords(Request.from(representation)); + } +}