diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/HolidayServiceImpl.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/HolidayServiceImpl.java index 964b8ebb6e0..42310b8e06f 100644 --- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/HolidayServiceImpl.java +++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/HolidayServiceImpl.java @@ -1,22 +1,6 @@ package io.mosip.kernel.masterdata.service.impl; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.*; -import java.util.stream.Collectors; - -import io.mosip.kernel.masterdata.dto.response.*; -import io.mosip.kernel.masterdata.service.LocationService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataAccessException; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.data.domain.Sort.Direction; -import org.springframework.stereotype.Service; - import io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException; -import io.mosip.kernel.core.http.RequestWrapper; import io.mosip.kernel.core.util.EmptyCheckUtils; import io.mosip.kernel.masterdata.constant.HolidayErrorCode; import io.mosip.kernel.masterdata.constant.LocationErrorCode; @@ -36,6 +20,11 @@ import io.mosip.kernel.masterdata.dto.request.SearchDto; import io.mosip.kernel.masterdata.dto.request.SearchFilter; import io.mosip.kernel.masterdata.dto.request.SearchSort; +import io.mosip.kernel.masterdata.dto.response.HolidaySearchDto; +import io.mosip.kernel.masterdata.dto.response.PageResponseDto; +import io.mosip.kernel.masterdata.dto.response.FilterResponseCodeDto; +import io.mosip.kernel.masterdata.dto.response.ColumnCodeValue; +import io.mosip.kernel.masterdata.dto.response.FilterResult; import io.mosip.kernel.masterdata.entity.Holiday; import io.mosip.kernel.masterdata.entity.Location; import io.mosip.kernel.masterdata.exception.DataNotFoundException; @@ -44,6 +33,7 @@ import io.mosip.kernel.masterdata.repository.HolidayRepository; import io.mosip.kernel.masterdata.repository.LocationRepository; import io.mosip.kernel.masterdata.service.HolidayService; +import io.mosip.kernel.masterdata.service.LocationService; import io.mosip.kernel.masterdata.utils.AuditUtil; import io.mosip.kernel.masterdata.utils.ExceptionUtils; import io.mosip.kernel.masterdata.utils.MapperUtils; @@ -56,6 +46,26 @@ import io.mosip.kernel.masterdata.validator.FilterColumnValidator; import io.mosip.kernel.masterdata.validator.FilterTypeEnum; import io.mosip.kernel.masterdata.validator.FilterTypeValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Optional; +import java.util.Map; +import java.util.HashMap; +import java.util.Collections; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; /** * Service Impl class for Holiday Data @@ -236,7 +246,7 @@ else if(existingHoliday.isPresent()){ entity.setHolidayId(holidayRepository.findMaxHolidayId()+1); } - holiday = holidayRepository.create(entity); + holiday = holidayRepository.save(entity); /* * if (holiday.getIsActive() == true && * supportedLang.contains(holiday.getLangCode())) { Holiday diff --git a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/controller/HolidayControllerTest.java b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/controller/HolidayControllerTest.java index 69715749d67..48d770416d7 100644 --- a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/controller/HolidayControllerTest.java +++ b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/controller/HolidayControllerTest.java @@ -1,12 +1,23 @@ package io.mosip.kernel.masterdata.test.controller; -import static org.mockito.Mockito.doNothing; - -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; - +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import io.mosip.kernel.core.http.RequestWrapper; +import io.mosip.kernel.core.websub.model.EventModel; +import io.mosip.kernel.core.websub.spi.PublisherClient; +import io.mosip.kernel.masterdata.dto.HolidayDto; +import io.mosip.kernel.masterdata.dto.HolidayIdDeleteDto; +import io.mosip.kernel.masterdata.dto.HolidayUpdateDto; +import io.mosip.kernel.masterdata.dto.request.FilterDto; +import io.mosip.kernel.masterdata.dto.request.FilterValueDto; +import io.mosip.kernel.masterdata.dto.request.Pagination; +import io.mosip.kernel.masterdata.dto.request.SearchDto; +import io.mosip.kernel.masterdata.dto.request.SearchSort; +import io.mosip.kernel.masterdata.test.TestBootApplication; +import io.mosip.kernel.masterdata.test.utils.MasterDataTest; +import io.mosip.kernel.masterdata.utils.AuditUtil; +import io.mosip.kernel.masterdata.validator.FilterColumnEnum; +import io.mosip.kernel.masterdata.validator.FilterTypeEnum; import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Ignore; @@ -25,25 +36,12 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; -import io.mosip.kernel.core.http.RequestWrapper; -import io.mosip.kernel.core.websub.model.EventModel; -import io.mosip.kernel.core.websub.spi.PublisherClient; -import io.mosip.kernel.masterdata.dto.HolidayDto; -import io.mosip.kernel.masterdata.dto.HolidayIdDeleteDto; -import io.mosip.kernel.masterdata.dto.HolidayUpdateDto; -import io.mosip.kernel.masterdata.dto.request.FilterDto; -import io.mosip.kernel.masterdata.dto.request.FilterValueDto; -import io.mosip.kernel.masterdata.dto.request.Pagination; -import io.mosip.kernel.masterdata.dto.request.SearchDto; -import io.mosip.kernel.masterdata.dto.request.SearchSort; -import io.mosip.kernel.masterdata.test.TestBootApplication; -import io.mosip.kernel.masterdata.test.utils.MasterDataTest; -import io.mosip.kernel.masterdata.utils.AuditUtil; -import io.mosip.kernel.masterdata.validator.FilterColumnEnum; -import io.mosip.kernel.masterdata.validator.FilterTypeEnum; +import static org.mockito.Mockito.doNothing; @RunWith(SpringRunner.class) @SpringBootTest(classes = TestBootApplication.class) @@ -177,7 +175,7 @@ public void t001saveHolidayTest2() throws Exception { + " \"holidayName\": \"Eidi\",\n" + " \"langCode\": \"eng\",\n" + " \"holidayDesc\": \"National holiday\"\n" + " }\n" + "}")) - .andReturn(), "KER-MSD-729"); + .andReturn(), null); } @Ignore diff --git a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/integration/MasterdataIntegrationTest.java b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/integration/MasterdataIntegrationTest.java index 1d55e4b50a7..daf19a3854f 100644 --- a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/integration/MasterdataIntegrationTest.java +++ b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/integration/MasterdataIntegrationTest.java @@ -1,76 +1,11 @@ package io.mosip.kernel.masterdata.test.integration; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.isA; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import java.sql.Timestamp; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.Month; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.util.*; - -import io.mosip.kernel.masterdata.test.utils.MasterDataTest; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentMatchers; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrint; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.dao.DataRetrievalFailureException; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.data.domain.Sort.Direction; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.security.test.context.support.WithUserDetails; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.client.RestTemplate; - import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; - import io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException; import io.mosip.kernel.core.http.RequestWrapper; import io.mosip.kernel.core.http.ResponseWrapper; @@ -192,7 +127,6 @@ import io.mosip.kernel.masterdata.entity.id.RegistrationCenterMachineDeviceHistoryID; import io.mosip.kernel.masterdata.entity.id.RegistrationCenterMachineDeviceID; import io.mosip.kernel.masterdata.entity.id.RegistrationCenterMachineUserHistoryID; -import io.mosip.kernel.masterdata.exception.DataNotFoundException; import io.mosip.kernel.masterdata.exception.MasterDataServiceException; import io.mosip.kernel.masterdata.exception.RequestException; import io.mosip.kernel.masterdata.repository.ApplicantValidDocumentRepository; @@ -244,11 +178,82 @@ import io.mosip.kernel.masterdata.repository.ZoneUserHistoryRepository; import io.mosip.kernel.masterdata.repository.ZoneUserRepository; import io.mosip.kernel.masterdata.test.TestBootApplication; +import io.mosip.kernel.masterdata.test.utils.MasterDataTest; import io.mosip.kernel.masterdata.utils.AuditUtil; import io.mosip.kernel.masterdata.utils.MapperUtils; import io.mosip.kernel.masterdata.utils.MasterdataCreationUtil; import io.mosip.kernel.masterdata.utils.RegistrationCenterValidator; import io.mosip.kernel.masterdata.utils.ZoneUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrint; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.dao.DataRetrievalFailureException; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.security.test.context.support.WithUserDetails; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; + +import java.sql.Timestamp; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Month; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Set; +import java.util.HashSet; +import java.util.Collections; +import java.util.Map; +import java.util.HashMap; +import java.util.Optional; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.isA; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** * @@ -2009,9 +2014,10 @@ public void addHolidayTypeLanguageValidationTest() throws Exception { public void addHolidayTypeExceptionTest() throws Exception { String json = "{\n" + " \"id\": \"string\",\n" + " \"metadata\": {},\n" + " \"request\": {\n" - + " \"holidayDate\": \"2019-01-01\",\n" + " \"holidayDesc\": \"New Year\",\n" - + " \"holidayName\": \"New Year\",\n" - + " \"isActive\": true,\n" + " \"langCode\": \"eng\",\n" + " \"locationCode\": \"BLR\"\n" + + " \"holidayDate\": \"2019-01-01\",\n" + " \"holidayDay\": \"Sunday\",\n" + + " \"holidayDesc\": \"New Year\",\n" + " \"holidayMonth\": \"January\",\n" + + " \"holidayName\": \"New Year\",\n" + " \"holidayYear\": \"2019\",\n" + " \"id\": 1,\n" + + " \"isActive\": true,\n" + " \"langCode\": \"asd\",\n" + " \"locationCode\": \"BLR\"\n" + " },\n" + " \"requesttime\": \"2018-12-06T08:49:32.190Z\",\n" + " \"version\": \"string\"\n" + "}"; when(holidayRepository.create(Mockito.any())) .thenThrow(new DataAccessLayerException("", "cannot execute ", null)); @@ -2035,7 +2041,7 @@ public void addHolidayTypeExceptionTest() throws Exception { ResponseWrapper responseWrapper = objectMapper.readValue(result.getResponse().getContentAsString(), ResponseWrapper.class); - assertThat(responseWrapper.getErrors().get(0).getErrorCode(), is("KER-MSD-729")); + assertThat(responseWrapper.getErrors().get(0).getErrorCode(), is("KER-MSD-999")); } // -----------------------------IdTypeTest----------------------------------