Skip to content

Commit

Permalink
MOSIP-31715,MOSIP-31940,MOSIP-31570 (mosip#944)
Browse files Browse the repository at this point in the history
* MOSIP-31715

Signed-off-by: dhanendra06 <[email protected]>

* updated the code based on review comments

Signed-off-by: dhanendra06 <[email protected]>

* updated the code based on review comments

Signed-off-by: dhanendra06 <[email protected]>

* updated the code based on review comments

Signed-off-by: dhanendra06 <[email protected]>

---------

Signed-off-by: dhanendra06 <[email protected]>
Signed-off-by: Yash S <[email protected]>
  • Loading branch information
dhanendra06 authored and yashmsonkusare committed Apr 5, 2024
1 parent b07a8b7 commit 7fa9df1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public enum SchemaErrorCode {
SUB_TYPE_REQUIRED_EXCEPTION("KER-SCH-017", "SubType is required for field %s"),
BIO_ATTRIBUTES_REQUIRED_EXCEPTION("KER-SCH-018", "BioAttributes are required for field %s"),
BIO_ATTRIBUTES_DUPLICATED_EXCEPTION("KER-SCH-019", "Same BioAttributes used in field with same SubType : %s"),

PUBLISHED_SCHEMA_EXCEPTION("KER-SCH-022", "Published identity schema can't be deleted"),

DYNAMIC_FIELD_VALUE_JSON_INVALID("KER-DYN-001", "Dynamic field is invalid, must contain code and value keys");

private final String errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,16 @@ public IdSchemaResponseDto updateSchema(String id, IdentitySchemaDto dto) {
@Transactional
public String deleteSchema(String id) {
try {
int updatedRows = identitySchemaRepository.deleteIdentitySchema(id, MetaDataUtils.getCurrentDateTime(),
MetaDataUtils.getContextUser());

if (updatedRows < 1) {
IdentitySchema entity = identitySchemaRepository.findIdentitySchemaById(id);
if (entity == null) {
throw new RequestException(SchemaErrorCode.SCHEMA_NOT_FOUND_EXCEPTION.getErrorCode(),
SchemaErrorCode.SCHEMA_NOT_FOUND_EXCEPTION.getErrorMessage());
} else if (STATUS_PUBLISHED.equalsIgnoreCase(entity.getStatus())) {
throw new RequestException(SchemaErrorCode.PUBLISHED_SCHEMA_EXCEPTION.getErrorCode(),
SchemaErrorCode.PUBLISHED_SCHEMA_EXCEPTION.getErrorMessage());
}

identitySchemaRepository.deleteIdentitySchema(id, MetaDataUtils.getCurrentDateTime(),
MetaDataUtils.getContextUser());
} catch (DataAccessException | DataAccessLayerException e) {
LOGGER.error("Error while deleting identity schema : " , ExceptionUtils.neutralizeParam(id), e);
throw new MasterDataServiceException(SchemaErrorCode.SCHEMA_UPDATE_EXCEPTION.getErrorCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,33 @@ public void testPublishIdentitySchemaWithException() throws Exception {

@Test
@WithUserDetails("global-admin")
public void testDeleteIdentitySchema() throws Exception {
Mockito.when(identitySchemaRepository.deleteIdentitySchema(Mockito.anyString(), Mockito.any(LocalDateTime.class),
Mockito.anyString())).thenReturn(1);
identitySchemaService.deleteSchema("test-test");
public void deleteIdentitySchema_withValidId_recordDeleted() throws Exception {
String id="123456789";
Mockito.when(identitySchemaRepository.findIdentitySchemaById(id)).thenReturn(draftSchema);
assertEquals(id,identitySchemaService.deleteSchema(id));
}

@Test(expected = RequestException.class)
@WithUserDetails("global-admin")
public void testDeleteIdentitySchemaFailed() throws Exception {
public void deleteIdentitySchema_invalidId_failedToDelete() throws Exception {
Mockito.when(identitySchemaRepository.deleteIdentitySchema(Mockito.anyString(), Mockito.any(LocalDateTime.class),
Mockito.anyString())).thenReturn(0);
identitySchemaService.deleteSchema("test-test");
}

@Test(expected = MasterDataServiceException.class)
@WithUserDetails("global-admin")
public void testDeleteIdentitySchemaFailedUpdate() throws Exception {
Mockito.when(identitySchemaRepository.deleteIdentitySchema(Mockito.anyString(), Mockito.any(LocalDateTime.class),
Mockito.anyString())).thenThrow(DataAccessLayerException.class);
public void deleteIdentitySchema_withDbException_failedToDelete() throws Exception {
Mockito.when(identitySchemaRepository.findIdentitySchemaById(
Mockito.anyString())).thenThrow(DataAccessLayerException.class);
identitySchemaService.deleteSchema("test-test");
}

@Test(expected = RequestException.class)
@WithUserDetails("global-admin")
public void deleteIdentitySchema_publishedSchema_Failed() throws Exception {
Mockito.when(identitySchemaRepository.findIdentitySchemaById(
Mockito.anyString())).thenReturn(publishedSchema);
identitySchemaService.deleteSchema("test-test");
}

Expand Down

0 comments on commit 7fa9df1

Please sign in to comment.