forked from mosip/esignet-mock-services
-
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.
Signed-off-by: Venkata Saidurga Polamraju <[email protected]>
- Loading branch information
1 parent
439c7b6
commit 3640c04
Showing
3 changed files
with
109 additions
and
2 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 |
---|---|---|
|
@@ -31,8 +31,7 @@ | |
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class IdentityServiceTest { | ||
|
@@ -115,11 +114,25 @@ public void addIdentity_withValidDetails_thenPass() throws MockIdentityException | |
IdentityData identityData = new IdentityData(); | ||
identityData.setEmail("[email protected]"); | ||
identityData.setEncodedPhoto("encodedPhoto"); | ||
identityData.setPassword("password"); | ||
when(identityRepository.findById(identityData.getIndividualId())).thenReturn(Optional.empty()); | ||
identityService.addIdentity(identityData); | ||
verify(identityRepository).save(any(MockIdentity.class)); | ||
} | ||
|
||
@Test | ||
public void addIdentity_withDuplicateDetails_thenFail() throws MockIdentityException { | ||
IdentityData identityData = new IdentityData(); | ||
identityData.setEmail("[email protected]"); | ||
identityData.setEncodedPhoto("encodedPhoto"); | ||
when(identityRepository.findById(identityData.getIndividualId())).thenReturn(Optional.of(new MockIdentity())); | ||
try{ | ||
identityService.addIdentity(identityData); | ||
}catch (MockIdentityException e){ | ||
Assert.assertEquals(ErrorConstants.DUPLICATE_INDIVIDUAL_ID,e.getErrorCode()); | ||
} | ||
} | ||
|
||
@Test | ||
public void getIdentity_withValidDetails_thenPass() throws MockIdentityException, JsonProcessingException { | ||
IdentityData identityData = new IdentityData(); | ||
|
@@ -145,4 +158,30 @@ public void getIdentity_withInvalidId_thenFail() { | |
}); | ||
assertEquals(ErrorConstants.INVALID_INDIVIDUAL_ID, exception.getMessage()); | ||
} | ||
|
||
@Test | ||
public void updateIdentity_withExistingIndividualId_thenPass() { | ||
IdentityData identityData = new IdentityData(); | ||
identityData.setIndividualId("existing-id"); | ||
identityData.setPassword("new-password"); | ||
MockIdentity mockIdentity = new MockIdentity(); | ||
mockIdentity.setIndividualId("existing-id"); | ||
mockIdentity.setIdentityJson("{\"existingField\": \"value\"}"); | ||
when(identityRepository.findById("existing-id")).thenReturn(Optional.of(mockIdentity)); | ||
identityService.updateIdentity(identityData); | ||
verify(identityRepository, times(1)).save(mockIdentity); | ||
Assert.assertNotNull(mockIdentity.getIdentityJson()); | ||
} | ||
|
||
@Test | ||
public void updateIdentity_withNonExistingIndividualId_thenFail() { | ||
IdentityData identityData = new IdentityData(); | ||
identityData.setIndividualId("non-existing-id"); | ||
when(identityRepository.findById("non-existing-id")).thenReturn(Optional.empty()); | ||
MockIdentityException exception = assertThrows(MockIdentityException.class, () -> { | ||
identityService.updateIdentity(identityData); | ||
}); | ||
assertEquals(ErrorConstants.INVALID_INDIVIDUAL_ID, exception.getErrorCode()); | ||
} | ||
|
||
} |