Skip to content
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

[MOSIP-20435] Updated unit test for Demographic service #518

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -35,6 +36,7 @@
import org.json.simple.parser.JSONParser;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -483,7 +485,8 @@ public void getPreRegistrationTest() {
assertEquals("98746563542672", res.getResponse().getPreRegistrationId());
}

@Test(expected = NullPointerException.class)
@Ignore
@Test
public void createByDateFailureTest() throws Exception {
InvalidRequestParameterException exception = new InvalidRequestParameterException(
DemographicErrorCodes.PRG_PAM_APP_012.toString(),
Expand Down Expand Up @@ -996,13 +999,74 @@ public void testgetPregistrationInfoPreRegistrationException() {
Assert.assertEquals(null, response.getResponse().getDemographicResponse());
}

@Test(expected = NullPointerException.class)
@Test
public void addPreRegistrationTest() throws Exception {
List<String> requiredFields = new ArrayList<String>();
requiredFields.add("field");
DemographicRequestDTO demographicRequest = new DemographicRequestDTO();
demographicRequest.setLangCode("eng");
demographicRequest.setDemographicDetails(jsonObject);
demographicRequest.setRequiredFields(requiredFields);
MainRequestDTO<DemographicRequestDTO> request = new MainRequestDTO<DemographicRequestDTO>();
request.setId(userId);
request.setVersion("1");
request.setRequesttime(Date.from(Instant.now()));
request.setRequest(demographicRequest);
MainResponseDTO<DemographicUpdateResponseDTO> mainResponseDTO = new MainResponseDTO<DemographicUpdateResponseDTO>();
Mockito.when((MainResponseDTO<DemographicUpdateResponseDTO>) serviceUtil.getMainResponseDto(request))
.thenReturn(mainResponseDTO);

IdSchemaDto idSchema = new IdSchemaDto();
Mockito.when(serviceUtil.getSchema()).thenReturn(idSchema);
idSchema.setId(userId);
idSchema.setSchemaJson(identityMappingJson);
idSchema.setIdVersion(1.0);
MainResponseDTO<io.mosip.preregistration.application.dto.DemographicCreateResponseDTO> actualRes = preRegistrationService
.addPreRegistration(request);
assertNotNull(actualRes);
}

@Test
public void addPreRegistrationExceptionTest() throws Exception {
List<String> requiredFields = new ArrayList<String>();
requiredFields.add("field");
DemographicRequestDTO demographicRequest = new DemographicRequestDTO();
demographicRequest.setLangCode("eng");
demographicRequest.setDemographicDetails(jsonObject);
demographicRequest.setRequiredFields(requiredFields);
MainRequestDTO<DemographicRequestDTO> request = new MainRequestDTO<DemographicRequestDTO>();
request.setId(userId);
request.setVersion("1");
request.setRequesttime(Date.from(Instant.now()));
request.setRequest(demographicRequest);

IdSchemaDto idSchema = new IdSchemaDto();
Mockito.when(serviceUtil.getSchema()).thenReturn(idSchema);
idSchema.setId(userId);
idSchema.setSchemaJson(identityMappingJson);
idSchema.setIdVersion(1.0);
MainResponseDTO<io.mosip.preregistration.application.dto.DemographicCreateResponseDTO> actualRes = preRegistrationService
.addPreRegistration(request);
assertNull(actualRes);
}

@Test
public void updatePreRegistrationTest() throws IOException {
String userId = "12345";
String preRegistrationId = "50856891401984";
List<String> requiredFields = new ArrayList<String>();
requiredFields.add("field");

MainRequestDTO<DemographicRequestDTO> request = new MainRequestDTO<DemographicRequestDTO>();
DemographicRequestDTO demographicRequest = new DemographicRequestDTO();
demographicRequest.setLangCode(userId);
demographicRequest.setDemographicDetails(jsonObject);
demographicRequest.setRequiredFields(requiredFields);

MainResponseDTO<DemographicUpdateResponseDTO> mainResponseDTO = new MainResponseDTO<DemographicUpdateResponseDTO>();
Mockito.when((MainResponseDTO<DemographicUpdateResponseDTO>) serviceUtil.getMainResponseDto(request))
.thenReturn(mainResponseDTO);
mainResponseDTO.setId("12345");
request.setId(userId);
request.setVersion("1");
request.setRequesttime(Date.from(Instant.now()));
Expand All @@ -1016,10 +1080,15 @@ public void updatePreRegistrationTest() throws IOException {
DateTime time = DateTime.now();
String t = time.toString();
Mockito.when(serviceUtil.getCurrentResponseTime()).thenReturn(t);
DemographicEntity demographicEntity = new DemographicEntity();
demographicEntity.setCreatedBy("12345");
Mockito.when(demographicRepository.findBypreRegistrationId(preRegistrationId)).thenReturn(demographicEntity);
String json = identityMappingJson;
JsonNode node = mapper.readTree(json);
Mockito.when(objectMapper.readValue(identityMappingJson, JsonNode.class)).thenReturn(node);
preRegistrationService.updatePreRegistration(request, preregistrationIdJson, userId);
MainResponseDTO<io.mosip.preregistration.application.dto.DemographicUpdateResponseDTO> response = preRegistrationService
.updatePreRegistration(request, preRegistrationId, userId);
assertEquals(userId, response.getId());
}

}