-
Notifications
You must be signed in to change notification settings - Fork 6
Increasing test coverage of the GP2GP Requesting adaptor #1287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b7c39d7
increasing test coverage
ORybak5 88e3033
making copc with capital letters
ORybak5 e868282
checkstyle
ORybak5 54cdc99
checkstyle
ORybak5 4a4ac0b
refactoring
ORybak5 2e15d95
checkstyle
ORybak5 aebe788
adding more tests
ORybak5 2771856
fixing a failing test
ORybak5 d27396f
fixing a failing test
ORybak5 d80dabb
refactoring
ORybak5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
common/src/test/java/uk/nhs/adaptors/common/util/FileUtilTest.java
This file contains hidden or 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,23 @@ | ||
| package uk.nhs.adaptors.common.util; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import java.io.FileNotFoundException; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class FileUtilTest { | ||
|
|
||
| @Test | ||
| public void shouldReadTextResource() { | ||
| var content = FileUtil.readResourceAsString("/file-util/sample.txt"); | ||
|
|
||
| assertEquals("sample-content", content.trim()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldThrowWhenResourceDoesNotExist() { | ||
| assertThrows(FileNotFoundException.class, () -> FileUtil.readResourceAsString("/file-util/missing.txt")); | ||
| } | ||
| } |
This file contains hidden or 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,2 @@ | ||
| sample-content | ||
|
|
85 changes: 85 additions & 0 deletions
85
...or/src/test/java/uk/nhs/adaptors/connector/service/MessagePersistDurationServiceTest.java
This file contains hidden or 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,85 @@ | ||
| package uk.nhs.adaptors.connector.service; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| import uk.nhs.adaptors.connector.dao.MessagePersistDurationDao; | ||
| import uk.nhs.adaptors.connector.model.MessagePersistDuration; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| public class MessagePersistDurationServiceTest { | ||
|
|
||
| public static final int PERSIST_DURATION_SECONDS = 300; | ||
| public static final int MIGRATION_REQUEST_ID = 101010; | ||
| public static final int TWO_CALLS = 2; | ||
| public static final int NINETY_NINE = 99; | ||
| public static final int SEVEN = 7; | ||
| public static final long PERSIST_DURATION = 300L; | ||
| public static final int FIVE = 5; | ||
| public static final String COPC = "COPC"; | ||
| @Mock | ||
| private MessagePersistDurationDao messagePersistDurationDao; | ||
|
|
||
| @InjectMocks | ||
| private MessagePersistDurationService messagePersistDurationService; | ||
|
|
||
| @Test | ||
| public void shouldSaveAndReturnPersistDuration() { | ||
| var expected = MessagePersistDuration.builder() | ||
| .id(1) | ||
| .messageType("ehrExtract") | ||
| .persistDuration(Duration.ofSeconds(PERSIST_DURATION_SECONDS)) | ||
| .callsSinceUpdate(TWO_CALLS) | ||
| .migrationRequestId(MIGRATION_REQUEST_ID) | ||
| .build(); | ||
|
|
||
| when(messagePersistDurationDao.getMessagePersistDuration(MIGRATION_REQUEST_ID, "ehrExtract")).thenReturn(expected); | ||
|
|
||
| var actual = messagePersistDurationService.addMessagePersistDuration("ehrExtract", | ||
| Duration.ofMinutes(FIVE), | ||
| TWO_CALLS, | ||
| MIGRATION_REQUEST_ID); | ||
|
|
||
| verify(messagePersistDurationDao).saveMessagePersistDuration("ehrExtract", PERSIST_DURATION, TWO_CALLS, MIGRATION_REQUEST_ID); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReturnPersistDurationWhenMessageTypeExists() { | ||
| var expected = MessagePersistDuration.builder() | ||
| .messageType(COPC) | ||
| .migrationRequestId(NINETY_NINE) | ||
| .build(); | ||
|
|
||
| when(messagePersistDurationDao.messageTypeExists(NINETY_NINE, COPC)).thenReturn(true); | ||
| when(messagePersistDurationDao.getMessagePersistDuration(NINETY_NINE, COPC)).thenReturn(expected); | ||
|
|
||
| var actual = messagePersistDurationService.getMessagePersistDuration(NINETY_NINE, COPC); | ||
|
|
||
| assertTrue(actual.isPresent()); | ||
| assertEquals(expected, actual.get()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReturnEmptyWhenMessageTypeDoesNotExist() { | ||
| when(messagePersistDurationDao.messageTypeExists(SEVEN, "missing")).thenReturn(false); | ||
|
|
||
| var actual = messagePersistDurationService.getMessagePersistDuration(SEVEN, "missing"); | ||
|
|
||
| assertFalse(actual.isPresent()); | ||
| verify(messagePersistDurationDao, never()).getMessagePersistDuration(SEVEN, "missing"); | ||
| } | ||
| } | ||
|
|
||
56 changes: 56 additions & 0 deletions
56
...r/src/test/java/uk/nhs/adaptors/connector/service/PatientMigrationRequestServiceTest.java
This file contains hidden or 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,56 @@ | ||
| package uk.nhs.adaptors.connector.service; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| import uk.nhs.adaptors.common.enums.MigrationStatus; | ||
| import uk.nhs.adaptors.connector.dao.PatientMigrationRequestDao; | ||
| import uk.nhs.adaptors.connector.model.PatientMigrationRequest; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| public class PatientMigrationRequestServiceTest { | ||
|
|
||
| private static final int MIGRATION_REQUEST_ID = 11111111; | ||
| @Mock | ||
| private PatientMigrationRequestDao patientMigrationRequestDao; | ||
|
|
||
| @InjectMocks | ||
| private PatientMigrationRequestService patientMigrationRequestService; | ||
|
|
||
| @Test | ||
| public void shouldReturnRequestsByMigrationStatus() { | ||
| var statuses = List.of(MigrationStatus.REQUEST_RECEIVED); | ||
| var request = PatientMigrationRequest.builder() | ||
| .id(MIGRATION_REQUEST_ID) | ||
| .conversationId("conversation-id-123") | ||
| .build(); | ||
|
|
||
| when(patientMigrationRequestDao.getMigrationRequestsByLatestMigrationStatusIn(statuses)).thenReturn(List.of(request)); | ||
|
|
||
| var actual = patientMigrationRequestService.getMigrationRequestsByMigrationStatusIn(statuses); | ||
|
|
||
| assertEquals(1, actual.size()); | ||
| assertEquals("conversation-id-123", actual.get(0).getConversationId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReturnTrueWhenMigrationRequestExists() { | ||
| when(patientMigrationRequestDao.existsByConversationId("conversation-id-123")).thenReturn(true); | ||
|
|
||
| var exists = patientMigrationRequestService.hasMigrationRequest("conversation-id-123"); | ||
|
|
||
| assertTrue(exists); | ||
| verify(patientMigrationRequestDao).existsByConversationId("conversation-id-123"); | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.