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-37875: Junit Tests #1008

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
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 @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<PageResponseV2Dto<FtmDetailSummaryDto>> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -99,6 +105,9 @@ public class FTPChipDetailServiceTest {
@Mock
PartnerServiceRepository partnerRepository;

@Mock
FtmDetailsSummaryRepository ftmDetailsSummaryRepository;

@Mock
private Environment environment;

Expand Down Expand Up @@ -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<PageResponseV2Dto<FtmDetailSummaryDto>> responseWrapper = new ResponseWrapperV2<>();
Page<FtmDetailSummaryEntity> 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<PageResponseV2Dto<FtmDetailSummaryDto>> responseWrapper = new ResponseWrapperV2<>();
Page<FtmDetailSummaryEntity> page = null;
when(ftmDetailsSummaryRepository.getSummaryOfPartnersFtmDetails(anyString(), anyString(), anyString(), anyString(), anyString(), any())).thenReturn(page);
fTPChipDetailServiceImpl.getPartnersFtmChipDetails(sortFieldName, sortType, pageNo, pageSize, null);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class ClientManagementControllerTest {
@Autowired
ClientManagementController clientManagementController;

@Autowired
@Mock
private ClientManagementServiceImpl serviceImpl;

@Mock
Expand Down Expand Up @@ -167,4 +168,18 @@ public void getClients() throws Exception {
ResponseWrapperV2<List<OauthClientDto>> 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<PageResponseV2Dto<ClientSummaryDto>> responseWrapper = new ResponseWrapperV2<>();
PageResponseV2Dto<ClientSummaryDto> pageResponse = new PageResponseV2Dto<>();
responseWrapper.setResponse(pageResponse);
when(serviceImpl.getPartnersClients(sortFieldName, sortType, pageNo, pageSize, filterDto))
.thenReturn(responseWrapper);
ResponseWrapperV2<PageResponseV2Dto<ClientSummaryDto>> responseWrapperV2 = clientController.getPartnersClients(sortFieldName, sortType, pageNo, pageSize, "abc", "org", "group123", "123", "test", "ACTIVE");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand All @@ -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;
Expand Down Expand Up @@ -79,6 +82,9 @@ public class ClientManagementServiceImplTest {
@Mock
AuthPolicyRepository authPolicyRepository;

@Mock
ClientSummaryRepository clientSummaryRepository;

@Mock
PartnerPolicyRequestRepository partnerPolicyRequestRepository;

Expand Down Expand Up @@ -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<PageResponseV2Dto<ClientSummaryDto>> responseWrapper = new ResponseWrapperV2<>();
Page<ClientSummaryEntity> 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<PageResponseV2Dto<ClientSummaryDto>> responseWrapper = new ResponseWrapperV2<>();
Page<ClientSummaryEntity> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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