From d6394df607a7adc081ecc087a65c9867d9a17da3 Mon Sep 17 00:00:00 2001 From: Swetha K Date: Fri, 29 Nov 2024 13:20:08 +0530 Subject: [PATCH] MOSIP-37875: Junit Tests Signed-off-by: Swetha K --- .../FTPChipDetailControllerTest.java | 27 ++++++++++ .../impl/FTPChipDetailServiceTest.java | 49 +++++++++++++++++++ .../ClientManagementControllerTest.java | 17 ++++++- .../impl/ClientManagementServiceImplTest.java | 46 +++++++++++++++++ .../src/test/resources/application.properties | 10 +++- 5 files changed, 147 insertions(+), 2 deletions(-) diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/FTPChipDetailControllerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/FTPChipDetailControllerTest.java index ba95e1bdc2..dcfd5e928c 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/FTPChipDetailControllerTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/FTPChipDetailControllerTest.java @@ -14,6 +14,7 @@ import io.mosip.pms.common.request.dto.RequestWrapperV2; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.device.dto.FtmChipFilterDto; import io.mosip.pms.device.request.dto.*; import io.mosip.pms.device.response.dto.*; import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto; @@ -42,6 +43,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.mosip.pms.common.constant.Purpose; +import io.mosip.pms.common.dto.PageResponseV2Dto; import io.mosip.pms.common.dto.PageResponseDto; import io.mosip.pms.common.dto.Pagination; import io.mosip.pms.common.dto.SearchFilter; @@ -405,4 +407,29 @@ public void getOriginalFtmCertificateTest() throws Exception { Mockito.when(ftpChipDetaillService.getOriginalFtmCertificate(Mockito.any())).thenReturn(responseWrapper); mockMvc.perform(MockMvcRequestBuilders.get("/ftpchipdetail/1234/original-ftm-certificate")).andExpect(MockMvcResultMatchers.status().isOk()); } + + @Test + @WithMockUser(roles = {"PARTNER_ADMIN"}) + public void getPartnersFtmDetailsTest() throws Exception { + String sortFieldName = "createdDateTime"; + String sortType = "desc"; + int pageNo = 0; + int pageSize = 8; + FtmChipFilterDto filterDto = new FtmChipFilterDto(); + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + + Mockito.when(ftpChipDetailServiceImpl.getPartnersFtmChipDetails(sortFieldName, sortType, pageNo, pageSize, filterDto)) + .thenReturn(responseWrapper); + mockMvc.perform(MockMvcRequestBuilders.get("/ftpchipdetail/search/v2") + .param("sortFieldName", sortFieldName) + .param("sortType", sortType) + .param("pageNo", String.valueOf(pageNo)) + .param("pageSize", String.valueOf(pageSize)) + .param("partnerId", "123") + .param("orgName", "ABC") + .param("make", "test") + .param("model", "test") + .param("status", "approved")) + .andExpect(MockMvcResultMatchers.status().isOk()); + } } diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java index f9dba93446..44b3a56f55 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java @@ -20,7 +20,11 @@ import io.mosip.pms.common.request.dto.ErrorResponse; import io.mosip.pms.common.response.dto.ResponseWrapperV2; import io.mosip.pms.device.authdevice.entity.DeviceDetail; +import io.mosip.pms.device.authdevice.entity.FtmDetailSummaryEntity; import io.mosip.pms.device.authdevice.entity.SecureBiometricInterface; +import io.mosip.pms.device.authdevice.repository.FtmDetailsSummaryRepository; +import io.mosip.pms.device.dto.FtmChipFilterDto; +import io.mosip.pms.device.response.dto.FtmDetailSummaryDto; import io.mosip.pms.device.response.dto.FtpCertDownloadResponeDto; import io.mosip.pms.partner.dto.DataShareDto; import io.mosip.pms.partner.dto.DataShareResponseDto; @@ -39,6 +43,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.env.Environment; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.http.MediaType; import org.springframework.security.core.Authentication; @@ -52,6 +57,7 @@ import io.mosip.kernel.core.http.RequestWrapper; import io.mosip.pms.common.constant.Purpose; +import io.mosip.pms.common.dto.PageResponseV2Dto; import io.mosip.pms.common.dto.Pagination; import io.mosip.pms.common.dto.SearchFilter; import io.mosip.pms.common.dto.SearchSort; @@ -99,6 +105,9 @@ public class FTPChipDetailServiceTest { @Mock PartnerServiceRepository partnerRepository; + @Mock + FtmDetailsSummaryRepository ftmDetailsSummaryRepository; + @Mock private Environment environment; @@ -1175,4 +1184,44 @@ public void getOriginalFtmCertificate_Test2() throws Exception{ ftpChipDetailService.getOriginalFtmCertificate("23456"); } + + @Test + public void getPartnersFtmChipDetailsTest() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + String sortFieldName = "createdDateTime"; + String sortType = "desc"; + int pageNo = 0; + int pageSize = 8; + FtmChipFilterDto filterDto = new FtmChipFilterDto(); + filterDto.setPartnerId("abc"); + filterDto.setMake("make"); + filterDto.setOrgName("ABC"); + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + Page page = null; + when(ftmDetailsSummaryRepository.getSummaryOfPartnersFtmDetails(anyString(), anyString(), anyString(), anyString(), anyString(), any())).thenReturn(page); + fTPChipDetailServiceImpl.getPartnersFtmChipDetails(sortFieldName, sortType, pageNo, pageSize, filterDto); + } + + @Test + public void getPartnersFtmChipDetailsTestException() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + String sortFieldName = "createdDateTime"; + String sortType = "desc"; + int pageNo = 0; + int pageSize = 8; + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + Page page = null; + when(ftmDetailsSummaryRepository.getSummaryOfPartnersFtmDetails(anyString(), anyString(), anyString(), anyString(), anyString(), any())).thenReturn(page); + fTPChipDetailServiceImpl.getPartnersFtmChipDetails(sortFieldName, sortType, pageNo, pageSize, null); + } } diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/oauth/controller/ClientManagementControllerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/oauth/controller/ClientManagementControllerTest.java index 0b97ae251d..f8b811d58f 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/oauth/controller/ClientManagementControllerTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/oauth/controller/ClientManagementControllerTest.java @@ -1,6 +1,7 @@ package io.mosip.pms.test.oauth.controller; import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.pms.common.dto.PageResponseV2Dto; import io.mosip.pms.common.request.dto.RequestWrapper; import io.mosip.pms.common.response.dto.ResponseWrapper; import io.mosip.pms.common.response.dto.ResponseWrapperV2; @@ -36,7 +37,7 @@ public class ClientManagementControllerTest { @Autowired ClientManagementController clientManagementController; - @Autowired + @Mock private ClientManagementServiceImpl serviceImpl; @Mock @@ -167,4 +168,18 @@ public void getClients() throws Exception { ResponseWrapperV2> actualResponse = clientController.getClients(); } + @Test + public void getPartnersClientsTest() throws Exception { + String sortFieldName = "createdDateTime"; + String sortType = "desc"; + int pageNo = 0; + int pageSize = 8; + ClientFilterDto filterDto = new ClientFilterDto(); + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + PageResponseV2Dto pageResponse = new PageResponseV2Dto<>(); + responseWrapper.setResponse(pageResponse); + when(serviceImpl.getPartnersClients(sortFieldName, sortType, pageNo, pageSize, filterDto)) + .thenReturn(responseWrapper); + ResponseWrapperV2> responseWrapperV2 = clientController.getPartnersClients(sortFieldName, sortType, pageNo, pageSize, "abc", "org", "group123", "123", "test", "ACTIVE"); + } } \ No newline at end of file diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/oauth/service/impl/ClientManagementServiceImplTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/oauth/service/impl/ClientManagementServiceImplTest.java index 46a9853534..84a3c7a3bc 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/oauth/service/impl/ClientManagementServiceImplTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/oauth/service/impl/ClientManagementServiceImplTest.java @@ -14,6 +14,7 @@ import io.mosip.pms.common.entity.*; import io.mosip.pms.common.entity.ClientDetail; import io.mosip.pms.common.repository.*; +import io.mosip.pms.common.response.dto.ResponseWrapperV2; import io.mosip.pms.device.util.AuditUtil; import io.mosip.pms.oidc.client.contant.ClientServiceAuditEnum; import com.fasterxml.jackson.core.JsonProcessingException; @@ -22,6 +23,7 @@ import io.mosip.pms.common.dto.PartnerDataPublishDto; import io.mosip.pms.common.dto.PolicyPublishDto; import io.mosip.pms.common.dto.Type; +import io.mosip.pms.common.dto.PageResponseV2Dto; import io.mosip.pms.common.exception.ApiAccessibleException; import io.mosip.pms.common.util.MapperUtils; import io.mosip.pms.oauth.client.dto.*; @@ -40,6 +42,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.env.Environment; +import org.springframework.data.domain.Page; import org.springframework.http.MediaType; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext; @@ -79,6 +82,9 @@ public class ClientManagementServiceImplTest { @Mock AuthPolicyRepository authPolicyRepository; + @Mock + ClientSummaryRepository clientSummaryRepository; + @Mock PartnerPolicyRequestRepository partnerPolicyRequestRepository; @@ -1326,6 +1332,46 @@ public void getClients() throws Exception { serviceImpl.getClients(); } + @Test + public void getPartnersClientsTest() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + String sortFieldName = "createdDateTime"; + String sortType = "desc"; + int pageNo = 0; + int pageSize = 8; + ClientFilterDto filterDto = new ClientFilterDto(); + filterDto.setPartnerId("abc"); + filterDto.setStatus("ACTIVE"); + filterDto.setOrgName("ABC"); + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + Page page = null; + when(clientSummaryRepository.getSummaryOfAllPartnerClients(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), any())).thenReturn(page); + serviceImpl.getPartnersClients(sortFieldName, sortType, pageNo, pageSize, filterDto); + } + + @Test + public void getPartnersClientsTestException() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + String sortFieldName = "createdDateTime"; + String sortType = "desc"; + int pageNo = 0; + int pageSize = 8; + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + Page page = null; + when(clientSummaryRepository.getSummaryOfAllPartnerClients(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), any())).thenReturn(page); + serviceImpl.getPartnersClients(sortFieldName, sortType, pageNo, pageSize, null); + } + private io.mosip.kernel.openid.bridge.model.MosipUserDto getMosipUserDto() { io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = new io.mosip.kernel.openid.bridge.model.MosipUserDto(); mosipUserDto.setUserId("123"); diff --git a/partner/partner-management-service/src/test/resources/application.properties b/partner/partner-management-service/src/test/resources/application.properties index ec7eca6a4d..213d4fa668 100644 --- a/partner/partner-management-service/src/test/resources/application.properties +++ b/partner/partner-management-service/src/test/resources/application.properties @@ -324,6 +324,10 @@ mosip.role.pms.postdeactivateftm=FTM_PROVIDER,PARTNER_ADMIN mosip.role.pms.getoriginalftmcertificate=FTM_PROVIDER,PARTNER_ADMIN mosip.role.pms.getpartnerdetails=PARTNER_ADMIN mosip.role.pms.getallpartners=PARTNER_ADMIN +mosip.role.pms.getallpartnerpolicymappingrequests=PARTNER_ADMIN +mosip.role.pms.getoauthpartnersclients=PARTNER_ADMIN +mosip.role.pms.getpartnersapikeyrequests=PARTNER_ADMIN +mosip.role.pms.getpartnersftmchipdetails=PARTNER_ADMIN #id for the API mosip.pms.api.id.oauth.clients.get=mosip.pms.oauth.clients.get @@ -349,4 +353,8 @@ mosip.pms.api.id.approved.ftm.provider.ids.get=mosip.pms.approved.ftm.provider.i mosip.pms.api.id.deactivate.ftm.post=mosip.pms.deactivate.ftm.post mosip.pms.api.id.original.ftm.certificate.get=mosip.pms.original.ftm.certificate.get mosip.pms.api.id.partner.details.get=mosip.pms.partner.details.get -mosip.pms.api.id.all.partners.get=mosip.pms.all.partners.get \ No newline at end of file +mosip.pms.api.id.all.partners.get=mosip.pms.all.partners.get +mosip.pms.api.id.all.partner.policy.mapping.requests.get=mosip.pms.all.partner.policy.mapping.requests.get +mosip.pms.api.id.oauth.partners.clients.get=mosip.pms.oauth.partners.clients.get +mosip.pms.api.id.all.api.key.requests.get=mosip.pms.all.api.key.requests.get +mosip.pms.api.id.partners.ftm.chip.details.get=mosip.pms.partners.ftm.chip.details.get \ No newline at end of file