-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CCMSPUI-381 Added check for error transactions before attempting to f…
…ind actual client transactions. Updated tests to correlate with this. Signed-off-by: Jamie Briggs <jamie.briggs@digital.justice.gov.uk>
- Loading branch information
1 parent
978a965
commit b3af35d
Showing
8 changed files
with
190 additions
and
7 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
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
15 changes: 15 additions & 0 deletions
15
data-service/src/main/java/uk/gov/laa/ccms/data/service/ClientServiceException.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,15 @@ | ||
package uk.gov.laa.ccms.data.service; | ||
|
||
/** | ||
* Custom exception class used to handle errors specific to the ClientService. | ||
* | ||
* <p>This exception is thrown when a client-related operation encounters an error | ||
* such as a user function transaction error.</p> | ||
* | ||
* @author Jamie Briggs | ||
*/ | ||
public class ClientServiceException extends RuntimeException { | ||
public ClientServiceException(String message) { | ||
super(message); | ||
} | ||
} |
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
133 changes: 133 additions & 0 deletions
133
data-service/src/test/java/uk/gov/laa/ccms/data/service/ClientServiceTest.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,133 @@ | ||
package uk.gov.laa.ccms.data.service; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Optional; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import uk.gov.laa.ccms.data.mapper.TransactionStatusMapper; | ||
import uk.gov.laa.ccms.data.model.TransactionStatus; | ||
import uk.gov.laa.ccms.data.repository.TransactionStatusRepository; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@DisplayName("ClientServiceTest") | ||
class ClientServiceTest { | ||
|
||
@Mock | ||
TransactionStatusMapper transactionStatusMapper; | ||
@Mock | ||
TransactionStatusRepository transactionStatusRepository; | ||
|
||
ClientService clientService; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
clientService = | ||
new ClientService(transactionStatusMapper, transactionStatusRepository); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should return empty client transaction status") | ||
void shouldReturnEmptyClientTransactionStatus() { | ||
// Given | ||
String transactionId = "123"; | ||
// When | ||
Optional<TransactionStatus> transactionStatus = clientService.getTransactionStatus( | ||
transactionId); | ||
// Then | ||
assertTrue(transactionStatus.isEmpty()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should return client transaction status") | ||
void shouldReturnClientTransactionStatus() { | ||
// Given | ||
String transactionId = "123"; | ||
uk.gov.laa.ccms.data.entity.TransactionStatus entity = | ||
uk.gov.laa.ccms.data.entity.TransactionStatus.builder() | ||
.requestId(transactionId) | ||
.processName("CreateClient").status("Success").build(); | ||
when(transactionStatusRepository.findClientTransactionByTransactionId(transactionId)) | ||
.thenReturn(Optional.of(entity)); | ||
TransactionStatus result = new TransactionStatus().submissionStatus("Success") | ||
.referenceNumber("123"); | ||
when(transactionStatusMapper.toTransactionStatus(entity)).thenReturn( | ||
result); | ||
// When | ||
Optional<TransactionStatus> transactionStatus = clientService.getTransactionStatus( | ||
transactionId); | ||
// Then | ||
verify(transactionStatusRepository, times(1)).findAllUserFunctionTransactionsByTransactionId( | ||
transactionId); | ||
verify(transactionStatusRepository, times(1)).findClientTransactionByTransactionId( | ||
transactionId); | ||
assertTrue(transactionStatus.isPresent()); | ||
assertEquals(result, transactionStatus.get()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should return client transaction status even with success transaction") | ||
void shouldReturnClientTransactionStatusEvenWithSuccessTransactions() { | ||
// Given | ||
String transactionId = "123"; | ||
uk.gov.laa.ccms.data.entity.TransactionStatus successTransaction = | ||
uk.gov.laa.ccms.data.entity.TransactionStatus.builder() | ||
.requestId(transactionId) | ||
.processName("XXCCMS_COMMON_UTIL.USER_FUNC_AUTH").status("Success").build(); | ||
when(transactionStatusRepository.findAllUserFunctionTransactionsByTransactionId(transactionId)) | ||
.thenReturn(singletonList(successTransaction)); | ||
uk.gov.laa.ccms.data.entity.TransactionStatus entity = | ||
uk.gov.laa.ccms.data.entity.TransactionStatus.builder() | ||
.requestId(transactionId) | ||
.processName("CreateClient").status("Success").build(); | ||
when(transactionStatusRepository.findClientTransactionByTransactionId(transactionId)) | ||
.thenReturn(Optional.of(entity)); | ||
TransactionStatus result = new TransactionStatus().submissionStatus("Success") | ||
.referenceNumber("123"); | ||
when(transactionStatusMapper.toTransactionStatus(entity)).thenReturn( | ||
result); | ||
|
||
// When | ||
Optional<TransactionStatus> transactionStatus = clientService.getTransactionStatus( | ||
transactionId); | ||
|
||
// Then | ||
verify(transactionStatusRepository, times(1)).findAllUserFunctionTransactionsByTransactionId( | ||
transactionId); | ||
verify(transactionStatusRepository, times(1)).findClientTransactionByTransactionId( | ||
transactionId); | ||
assertTrue(transactionStatus.isPresent()); | ||
assertEquals(result, transactionStatus.get()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should throw exception when user function transaction is error") | ||
void shouldThrowExceptionWhenUserFunctionTransactionIsError() { | ||
// Given | ||
String transactionId = "123"; | ||
uk.gov.laa.ccms.data.entity.TransactionStatus successTransaction = | ||
uk.gov.laa.ccms.data.entity.TransactionStatus.builder() | ||
.requestId(transactionId) | ||
.processName("XXCCMS_COMMON_UTIL.USER_FUNC_AUTH").status("Error").build(); | ||
when(transactionStatusRepository.findAllUserFunctionTransactionsByTransactionId(transactionId)) | ||
.thenReturn(singletonList(successTransaction)); | ||
|
||
// When & Then | ||
assertThrows(ClientServiceException.class, () -> clientService.getTransactionStatus(transactionId)); | ||
verify(transactionStatusRepository, times(1)).findAllUserFunctionTransactionsByTransactionId( | ||
transactionId); | ||
verify(transactionStatusRepository, times(0)).findClientTransactionByTransactionId( | ||
transactionId); | ||
} | ||
|
||
} |