Skip to content

Commit

Permalink
MOSIP-32692: Junit tests for MultiPartnerServiceController (#679)
Browse files Browse the repository at this point in the history
Signed-off-by: SwethaKrish4 <[email protected]>
  • Loading branch information
SwethaKrish4 authored May 22, 2024
1 parent 49eb185 commit 622e405
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@RestController
@RequestMapping(value = "/partners")
@Api(tags = { "All Partner Service Controller" })
@Api(tags = { "Multi Partner Service Controller" })
public class MultiPartnerServiceController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public List<CertificateDto> getAllCertificateDetails() {
ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage());
}
} catch (PartnerServiceException ex) {
LOGGER.info("sessionId", "idType", "id", "In getAllCertificateDetails method of AllPartnerServiceImpl - " + ex.getMessage());
LOGGER.info("sessionId", "idType", "id", "In getAllCertificateDetails method of MultiPartnerServiceImpl - " + ex.getMessage());
throw ex;
} catch (Exception ex) {
LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace());
LOGGER.error("sessionId", "idType", "id",
"In getAllCertificateDetails method of AllPartnerServiceImpl - " + ex.getMessage());
"In getAllCertificateDetails method of MultiPartnerServiceImpl - " + ex.getMessage());
throw new PartnerServiceException(ErrorCode.PARTNER_CERTIFICATES_FETCH_ERROR.getErrorCode(),
ErrorCode.PARTNER_CERTIFICATES_FETCH_ERROR.getErrorMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.mosip.pms.test.partner.controller;

import io.mosip.pms.common.response.dto.ResponseWrapper;
import io.mosip.pms.partner.controller.MultiPartnerServiceController;
import io.mosip.pms.partner.dto.CertificateDto;
import io.mosip.pms.partner.dto.PolicyDto;
import io.mosip.pms.partner.service.MultiPartnerService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.WebApplicationContext;

import java.util.ArrayList;
import java.util.List;

@ContextConfiguration(classes = {TestContext.class, WebApplicationContext.class})
@RunWith(SpringRunner.class)
@WebMvcTest
public class MultiPartnerServiceControllerTest {

@InjectMocks
private MultiPartnerServiceController multiPartnerServiceController;

@Mock
private MultiPartnerService multiPartnerService;

@Test
@WithMockUser(roles = {"PARTNER"})
public void getAllCertificateDetails() throws Exception {
CertificateDto certificateDto = new CertificateDto();
certificateDto.setPartnerId("abc");
certificateDto.setPartnerType("Auth_Partner");
certificateDto.setIsCertificateAvailable(false);

List<CertificateDto> certificateDtoList = new ArrayList<>();
certificateDtoList.add(certificateDto);

Mockito.when(multiPartnerService.getAllCertificateDetails()).thenReturn(certificateDtoList);
ResponseWrapper<List<CertificateDto>> response = multiPartnerServiceController.getAllCertificateDetails();
}

@Test
@WithMockUser(roles = {"PARTNER"})
public void getAllPoliciesRequestList() throws Exception {
PolicyDto policyDto = new PolicyDto();
policyDto.setPartnerId("abc");
policyDto.setPartnerType("Auth_Partner");
policyDto.setPolicyGroup("123");
policyDto.setPolicyName("test");
List<PolicyDto> policyDtoList = new ArrayList<>();
policyDtoList.add(policyDto);
Mockito.when(multiPartnerService.getAllPolicies()).thenReturn(policyDtoList);
ResponseWrapper<List<PolicyDto>> response = multiPartnerServiceController.getAllPolicies();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import java.util.ArrayList;
import java.util.List;

import io.mosip.pms.partner.response.dto.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -76,10 +78,10 @@ public class PartnerServiceControllerTest {
@Autowired
private MockMvc mockMvc;

@MockBean
@Mock
private PartnerService partnerService;

@MockBean
@Mock
PartnerManagerService partnerManagerService;

@Autowired
Expand Down Expand Up @@ -164,13 +166,14 @@ public void getBiometricExtractorsTest() throws JsonProcessingException, Excepti
Mockito.when(partnerService.getBiometricExtractors("123456", "12345")).thenReturn(new ExtractorsDto());
mockMvc.perform(MockMvcRequestBuilders.get("/partners/123456/bioextractors/12345")).andExpect(status().isOk());
}

@Test
@WithMockUser(roles = {"PARTNER"})
public void retrievePartnerCertificateTest() throws Exception {
Mockito.when(partnerService.getPartnerCertificate(Mockito.any())).thenReturn(Mockito.any());
PartnerCertDownloadResponeDto partnerCertDownloadResponeDto = new PartnerCertDownloadResponeDto();
Mockito.when(partnerService.getPartnerCertificate(Mockito.any())).thenReturn(partnerCertDownloadResponeDto);
mockMvc.perform(MockMvcRequestBuilders.get("/partners/12345/certificate")).andExpect(MockMvcResultMatchers.status().isOk());
}
}


@Test
Expand Down

0 comments on commit 622e405

Please sign in to comment.