Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop-pmp-revamp' into devel…
Browse files Browse the repository at this point in the history
…op-pmp-revamp
  • Loading branch information
mohanachandran-s committed Oct 7, 2024
2 parents 96ca082 + 88643bb commit 6e914b0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public ResponseWrapperV2<Boolean> inactiveMappingDeviceToSbi(SbiAndDeviceMapping
String partnerId = requestDto.getPartnerId();
String sbiId = requestDto.getSbiId();
String deviceDetailId = requestDto.getDeviceDetailId();
if (Objects.isNull(partnerId) || Objects.isNull(sbiId) || Objects.isNull(deviceDetailId) ){
if (Objects.isNull(partnerId) || partnerId.equals(BLANK_STRING) || Objects.isNull(sbiId) || sbiId.equals(BLANK_STRING) || Objects.isNull(deviceDetailId) || deviceDetailId.equals(BLANK_STRING)){
LOGGER.info("sessionId", "idType", "id", "User id does not exist.");
throw new PartnerServiceException(ErrorCode.INVALID_REQUEST_PARAM.getErrorCode(),
ErrorCode.INVALID_REQUEST_PARAM.getErrorMessage());
Expand Down Expand Up @@ -492,8 +492,16 @@ public static void validatePartnerId(Partner partner, String userId) {

private void deleteDeviceDetail(String deviceDetailId) {
try {
deviceDetailRepository.deleteById(deviceDetailId);
LOGGER.info("sessionId", "idType", "id", "Device detail with id " + deviceDetailId + " deleted successfully.");
if (!deviceDetailId.equals(BLANK_STRING) && Objects.nonNull(deviceDetailId)) {
Optional<DeviceDetail> deviceDetail = deviceDetailRepository.findById(deviceDetailId);
if (deviceDetail.isPresent()) {
List<DeviceDetailSBI> deviceDetailSBIList = deviceDetailSbiRepository.findByDeviceDetailId(deviceDetailId);
if (deviceDetailSBIList.isEmpty()) {
deviceDetailRepository.deleteById(deviceDetailId);
LOGGER.info("sessionId", "idType", "id", "Device detail with id " + deviceDetailId + " deleted successfully.");
}
}
}
} catch (Exception e) {
LOGGER.error("sessionId", "idType", "id", "Error while deleting device detail with id " + deviceDetailId + ": " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public enum ErrorCode {
DEVICE_NOT_EXISTS("PMS_DEVICE_ERROR_006", "Device do not exists."),
DEVICE_NOT_ASSOCIATED_WITH_PARTNER_ID("PMS_DEVICE_ERROR_007", "Device is not associated with partner Id."),
ADD_INACTIVE_DEVICE_MAPPING_WITH_SBI_ERROR("PMS_DEVICE_ERROR_008", "Error while adding inactive device mapping for sbi."),
SBI_NOT_APPROVED_OR_INACTIVE("PMS_DEVICE_ERROR_009","SBI for which device is being added is either not approved or deactivated."),
SBI_NOT_APPROVED_OR_INACTIVE("PMS_DEVICE_ERROR_009","Given SBI is either deactivated or not approved yet."),
DEVICE_NOT_PENDING_FOR_APPROVAL("PMS_DEVICE_ERROR_010","Given device details are not in pending for approval status."),
APPROVE_OR_REJECT_DEVICE_WITH_SBI_MAPPING_ERROR("PMS_DEVICE_ERROR_011", "Error while approving or rejecting device for Sbi Mapping."),
SBI_DEVICE_MAPPING_NOT_EXISTS("PMS_DEVICE_ERROR_012","SBI and Device mapping does not exists."),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.mosip.pms.test.partner.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.mosip.pms.common.request.dto.RequestWrapperV2;
import io.mosip.pms.common.response.dto.ResponseWrapperV2;
import io.mosip.pms.partner.controller.MultiPartnerAdminServiceController;
Expand All @@ -8,51 +9,96 @@
import io.mosip.pms.partner.util.RequestValidator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
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 org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.time.LocalDateTime;

@ContextConfiguration(classes = {TestContext.class, WebApplicationContext.class})
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MultiPartnerAdminServiceController.class})
@SpringBootTest
@AutoConfigureMockMvc
@EnableWebMvc
public class MultiPartnerAdminServiceContollerTest {

public static final String VERSION = "1.0";

@MockBean
@InjectMocks
MultiPartnerAdminServiceController multiPartnerAdminServiceController;

@MockBean
@Mock
MultiPartnerAdminService multiPartnerAdminService;

@MockBean
@Mock
RequestValidator requestValidator;

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@Test
@WithMockUser(roles = {"PARTNER_ADMIN"})
public void approveMappingDeviceToSbi() throws Exception {
public void approveMappingDeviceToSbiTest() throws Exception {
RequestWrapperV2<SbiAndDeviceMappingRequestDto> requestWrapper = new RequestWrapperV2<>();
requestWrapper.setId("mosip.pms.approve.mapping.device.to.sbi.post");
requestWrapper.setVersion(VERSION);
requestWrapper.setRequestTime(LocalDateTime.now());
SbiAndDeviceMappingRequestDto sbiAndDeviceMappingRequestDto = new SbiAndDeviceMappingRequestDto();
requestWrapper.setRequest(sbiAndDeviceMappingRequestDto);
ResponseWrapperV2<Boolean> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setResponse(true);
Mockito.when(multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), false)).thenReturn(responseWrapper);
multiPartnerAdminServiceController.approveMappingDeviceToSbi(requestWrapper);
mockMvc.perform(post("/admin/approve-mapping-device-to-sbi").contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk());
}

@Test
@WithMockUser(roles = {"PARTNER_ADMIN"})
public void approveMappingDeviceToSbiTest1() throws Exception {
RequestWrapperV2<SbiAndDeviceMappingRequestDto> requestWrapper = new RequestWrapperV2<>();
requestWrapper.setVersion(VERSION);
requestWrapper.setRequestTime(LocalDateTime.now());
SbiAndDeviceMappingRequestDto sbiAndDeviceMappingRequestDto = new SbiAndDeviceMappingRequestDto();
requestWrapper.setRequest(sbiAndDeviceMappingRequestDto);
ResponseWrapperV2<Boolean> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setResponse(true);
Mockito.when(multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), false)).thenReturn(responseWrapper);
mockMvc.perform(post("/admin/approve-mapping-device-to-sbi").contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk());
}

@Test
@WithMockUser(roles = {"PARTNER_ADMIN"})
public void rejectMappingDeviceToSbiTest() throws Exception {
RequestWrapperV2<SbiAndDeviceMappingRequestDto> requestWrapper = new RequestWrapperV2<>();
requestWrapper.setId("mosip.pms.reject.mapping.device.to.sbi.post");
requestWrapper.setVersion(VERSION);
requestWrapper.setRequestTime(LocalDateTime.now());
SbiAndDeviceMappingRequestDto sbiAndDeviceMappingRequestDto = new SbiAndDeviceMappingRequestDto();
requestWrapper.setRequest(sbiAndDeviceMappingRequestDto);
ResponseWrapperV2<Boolean> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setResponse(true);
Mockito.when(multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), true)).thenReturn(responseWrapper);
mockMvc.perform(post("/admin/reject-mapping-device-to-sbi").contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk());
}

@Test
@WithMockUser(roles = {"PARTNER_ADMIN"})
public void rejectMappingDeviceToSbi() throws Exception {
public void rejectMappingDeviceToSbiTest1() throws Exception {
RequestWrapperV2<SbiAndDeviceMappingRequestDto> requestWrapper = new RequestWrapperV2<>();
requestWrapper.setVersion(VERSION);
requestWrapper.setRequestTime(LocalDateTime.now());
Expand All @@ -61,6 +107,7 @@ public void rejectMappingDeviceToSbi() throws Exception {
ResponseWrapperV2<Boolean> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setResponse(true);
Mockito.when(multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), true)).thenReturn(responseWrapper);
multiPartnerAdminServiceController.rejectMappingDeviceToSbi(requestWrapper);
mockMvc.perform(post("/admin/reject-mapping-device-to-sbi").contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public interface DeviceDetailSbiRepository extends JpaRepository<DeviceDetailSBI
@Query(value = "select * from device_detail_sbi dds where dds.dprovider_id=?1 and dds.sbi_id = ?2",nativeQuery = true)
List<DeviceDetailSBI> findByDeviceProviderIdAndSbiId(String dproviderId, String sbiId);

@Query(value = "select * from device_detail_sbi dds where dds.device_detail_id=?1",nativeQuery = true)
List<DeviceDetailSBI> findByDeviceDetailId(String deviceDetailId);

@Query(value = "select * from device_detail_sbi dds where dds.dprovider_id=?1 and dds.sbi_id=?2 and dds.device_detail_id=?3",nativeQuery = true)
DeviceDetailSBI findByDeviceProviderIdAndSbiIdAndDeviceDetailId(String dproviderId, String sbiId, String deviceDetailId);
}

0 comments on commit 6e914b0

Please sign in to comment.