-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* CIV-11363 add trigger event
- Loading branch information
Showing
4 changed files
with
93 additions
and
27 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
1693404277952499 | ||
1694435036274857 |
86 changes: 86 additions & 0 deletions
86
src/test/java/uk/gov/hmcts/reform/civil/handler/RetriggerCasesEventHandlerTest.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,86 @@ | ||
package uk.gov.hmcts.reform.civil.handler; | ||
|
||
import feign.FeignException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import uk.gov.hmcts.reform.civil.callback.CaseEvent; | ||
import uk.gov.hmcts.reform.civil.service.CoreCaseDataService; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
class RetriggerCasesEventHandlerTest { | ||
|
||
@Mock | ||
private CoreCaseDataService coreCaseDataService; | ||
|
||
@InjectMocks | ||
private RetriggerCasesEventHandler retriggerCasesEventHandler; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
void testUpdateCaseByEvent() { | ||
List<String> caseIdList = Arrays.asList("1", "2", "3"); | ||
|
||
retriggerCasesEventHandler.updateCaseByEvent(caseIdList, CaseEvent.RETRIGGER_CASES); | ||
|
||
// Assertions | ||
verify(coreCaseDataService, times(caseIdList.size())).triggerEvent(anyLong(), eq(CaseEvent.RETRIGGER_CASES)); | ||
} | ||
|
||
@Test | ||
void testUpdateCaseByEventWithFeignException() { | ||
List<String> caseIdList = Arrays.asList("1", "2", "3"); | ||
|
||
// Simulate FeignException | ||
doThrow(FeignException.class).when(coreCaseDataService).triggerEvent(anyLong(), eq(CaseEvent.RETRIGGER_CASES)); | ||
|
||
// Assertions | ||
FeignException exception = assertThrows(FeignException.class, () -> | ||
retriggerCasesEventHandler.updateCaseByEvent(caseIdList, CaseEvent.RETRIGGER_CASES) | ||
); | ||
} | ||
|
||
@Test | ||
void testUpdateCaseByEventWithGenericException() { | ||
List<String> caseIdList = Arrays.asList("1", "2", "3"); | ||
|
||
doThrow(new RuntimeException("Simulated RuntimeException")).when(coreCaseDataService) | ||
.triggerEvent(anyLong(), eq(CaseEvent.RETRIGGER_CASES)); | ||
|
||
RuntimeException exception = assertThrows(RuntimeException.class, () -> | ||
retriggerCasesEventHandler.updateCaseByEvent(caseIdList, CaseEvent.RETRIGGER_CASES) | ||
); | ||
|
||
assertEquals("Simulated RuntimeException", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
void testUpdateCaseByEventWithEmptyList() { | ||
List<String> emptyCaseIdList = Collections.emptyList(); | ||
|
||
retriggerCasesEventHandler.updateCaseByEvent(emptyCaseIdList, CaseEvent.RETRIGGER_CASES); | ||
|
||
// Assertions | ||
verify(coreCaseDataService, never()).triggerEvent(anyLong(), eq(CaseEvent.RETRIGGER_CASES)); | ||
} | ||
} | ||
|
||
|