Commit 425beb1c authored by Kristel Meikas's avatar Kristel Meikas
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Kristel Meikas

See merge request teis/common-api-gateway!199
parents 705744ec c3294cc5
package ee.sm.ti.teis.commongateway.proceedings.violationact;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.proceedings.violationact.dto.ViolationActPublicDto;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import static java.util.UUID.randomUUID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class ViolationActControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/violation-acts/";
@Autowired
MockMvcUtil mockMvcUtil;
@Test
void getViolations_success() {
when(requestProcessingService.sendAndReceive(any(ViolationActsPublicRequest.class)))
.thenReturn(List.of(new ViolationActPublicDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<ViolationActPublicDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(ViolationActsPublicRequest.class));
}
@Test
void getViolationAct_success() {
when(requestProcessingService.sendAndReceive(any(ViolationActPublicRequest.class)))
.thenReturn(new ViolationActPublicDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<ViolationActPublicDto>() {
});
verify(requestProcessingService).sendAndReceive(any(ViolationActPublicRequest.class));
}
}
package ee.sm.ti.teis.commongateway.representative;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.representative.search.RepresentativeSearchFilterDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.role.RoleState;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class RepresentativeControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(randomUUID().toString()).build();
private static final String BASE_URL = "/representatives/";
@Autowired
RepresentativeController controller;
MockMvcUtil mockMvcUtil;
@Test
void checkRepresentative_test() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.checkRepresentative(randomUUID(), REQUEST_META_DTO));
void getRepresentative_success() {
when(requestProcessingService.sendAndReceive(any(RepresentativeRequest.class)))
.thenReturn(new RepresentativeDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<RepresentativeDto>() {
});
verify(requestProcessingService).sendAndReceive(any(RepresentativeRequest.class));
}
@Test
void delete_test() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.delete(randomUUID(), REQUEST_META_DTO));
void getRepresentatives_success() {
when(requestProcessingService.sendAndReceive(any(RepresentativeComplexRequest.class)))
.thenReturn(List.of(new RepresentativeComplexDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<RepresentativeComplexDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(RepresentativeComplexRequest.class));
}
@Test
void create_test() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.create(RepresentativeDto.builder().build(), REQUEST_META_DTO));
void createRepresentative_success() {
when(requestProcessingService.sendAndReceive(any(CreateRepresentativeRequest.class)))
.thenReturn(new RepresentativeDto());
mockMvcUtil.testPost(BASE_URL, new RepresentativeDto(), new TypeReference<RepresentativeDto>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateRepresentativeRequest.class));
}
@Test
void getRepresentative_test() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getRepresentative(randomUUID(), REQUEST_META_DTO));
void updateRepresentative_success() {
when(requestProcessingService.sendAndReceive(any(UpdateRepresentativeRequest.class)))
.thenReturn(new RepresentativeDto());
mockMvcUtil.testPut(BASE_URL + randomUUID(), new RepresentativeDto(), new TypeReference<RepresentativeDto>() {
});
verify(requestProcessingService).sendAndReceive(any(UpdateRepresentativeRequest.class));
}
@Test
void getRepresentatives_test() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getRepresentatives(RepresentativeSearchFilterDto.builder().build(), REQUEST_META_DTO));
void checkRepresentative_success() {
when(requestProcessingService.sendAndReceive(any(CheckRepresentativeRequest.class)))
.thenReturn(List.of(new RoleState()));
mockMvcUtil.testGet(BASE_URL + "check-representative/" + randomUUID(), null, new TypeReference<List<RoleState>>() {
});
verify(requestProcessingService).sendAndReceive(any(CheckRepresentativeRequest.class));
}
@Test
void getRepresentativesLastContact_test() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getRepresentativesLastContact(randomUUID(), randomUUID(), REQUEST_META_DTO));
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteRepresentativeRequest.class));
}
@Test
void update_test() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.updateRepresentative(randomUUID().toString(), RepresentativeDto.builder().build(), REQUEST_META_DTO));
void getRepresentativesLastContact_success() {
when(requestProcessingService.sendAndReceive(any(RepresentativesLastContactRequest.class)))
.thenReturn(new ContactInfoDto());
parameters.add("employerId", randomUUID().toString());
parameters.add("personId", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL + "last-contact", parameters, new TypeReference<ContactInfoDto>() {
});
verify(requestProcessingService).sendAndReceive(any(RepresentativesLastContactRequest.class));
}
@Test
void updateContacts_test() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.updateContacts(randomUUID(), new ContactInfoDto(), REQUEST_META_DTO));
void updateContacts_success() {
when(requestProcessingService.sendAndReceive(any(UpdateRepresentativeContactsRequest.class)))
.thenReturn(new RepresentativeDto());
mockMvcUtil.testPatch(BASE_URL + randomUUID() + "/contacts", new ContactInfoDto(),
new TypeReference<RepresentativeDto>() {
});
verify(requestProcessingService).sendAndReceive(any(UpdateRepresentativeContactsRequest.class));
}
}
package ee.sm.ti.teis.commongateway.representative;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
@WithMockUser
class RepresentativeTestControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/representatives/expire/";
@Autowired
RepresentativeTestController controller;
MockMvcUtil mockMvcUtil;
@Test
void checkRepresentative_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.expire(randomUUID(), new RequestMetaDTO()));
void checkRepresentative_success() {
parameters.add("roleId", randomUUID().toString());
mockMvcUtil.testParameterizedPatch(BASE_URL, parameters, null);
verify(requestProcessingService).sendAndReceive(any(ExpireRepresentativesRequest.class));
}
}
package ee.sm.ti.teis.commongateway.representative.location;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.representative.locations.RepresentativeLocationController;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import static java.util.Collections.singletonList;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class RepresentativeLocationControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/representative-locations/";
@Autowired
RepresentativeLocationController controller;
MockMvcUtil mockMvcUtil;
@Test
void deleteRepresentativeLocation_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.deleteRepresentativeLocation(randomUUID(), new RequestMetaDTO()));
void createRepresentativeLocation_success() {
when(requestProcessingService.sendAndReceive(any(CreateRepresentativeLocationsRequest.class)))
.thenReturn(List.of(new RepresentativeLocationDto()));
mockMvcUtil.testPost(BASE_URL, List.of(new CreateRepresentativeLocationDto()), new TypeReference<List<RepresentativeLocationDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateRepresentativeLocationsRequest.class));
}
@Test
void createRepresentativeLocation_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.createRepresentativeLocations(
singletonList(new CreateRepresentativeLocationDto()), new RequestMetaDTO()));
void deleteRepresentativeLocation_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteRepresentativeLocationRequest.class));
}
}
package ee.sm.ti.teis.commongateway.riskassessments.businesstype;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.riskassessments.businesstype.dto.BusinessTypePublicDto;
import ee.sm.ti.teis.commongateway.riskassessments.businesstype.dto.BusinessTypePublicLightDto;
import ee.sm.ti.teis.commongateway.riskassessments.businesstype.request.BusinessTypePublicRequest;
import ee.sm.ti.teis.commongateway.riskassessments.businesstype.request.BusinessTypesPublicRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.UUID;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static java.util.UUID.randomUUID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class BusinessTypeControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/risk-assessments/business-types/";
@Autowired
BusinessTypeController controller;
MockMvcUtil mockMvcUtil;
@Test
void getBusinessTypes_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getBusinessTypes(null, new RequestMetaDTO()));
void getBusinessTypes_success() {
when(requestProcessingService.sendAndReceive(any(BusinessTypesPublicRequest.class)))
.thenReturn(List.of(new BusinessTypePublicLightDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<BusinessTypePublicLightDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(BusinessTypesPublicRequest.class));
}
@Test
void getBusinessType_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getBusinessType(UUID.randomUUID(), null, null, new RequestMetaDTO()));
void getBusinessType_success() {
when(requestProcessingService.sendAndReceive(any(BusinessTypePublicRequest.class)))
.thenReturn(new BusinessTypePublicDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<BusinessTypePublicDto>() {
});
verify(requestProcessingService).sendAndReceive(any(BusinessTypePublicRequest.class));
}
}
package ee.sm.ti.teis.commongateway.riskassessments.riskassessment;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.riskassessments.riskassessment.dto.*;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.riskassessments.riskassessment.request.*;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.UUID;
import java.util.List;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class RiskAssessmentControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/risk-assessments";
@Autowired
RiskAssessmentController controller;
MockMvcUtil mockMvcUtil;
@Test
void getRiskAssessments_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getRiskAssessments(null, new RequestMetaDTO()));
void getRiskAssessments_success() {
when(requestProcessingService.sendAndReceive(any(GetRiskAssessmentsPublicRequest.class)))
.thenReturn(List.of(new RiskAssessmentPublicDto()));
parameters.add("employerId", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL, parameters, new TypeReference<List<RiskAssessmentPublicDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(GetRiskAssessmentsPublicRequest.class));
}
@Test
void update_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.updateTitle(randomUUID(), new UpdateRiskAssessmentTitleDto(), new RequestMetaDTO()));
void updateTitle_success() {
when(requestProcessingService.sendAndReceive(any(UpdateRiskAssessmentTitlePublicRequest.class)))
.thenReturn(new RiskAssessmentPublicDto());
mockMvcUtil.testPatch(BASE_URL + "/" + randomUUID() + "/title", new UpdateRiskAssessmentTitleDto(),
new TypeReference<RiskAssessmentPublicDto>() {
});
verify(requestProcessingService).sendAndReceive(any(UpdateRiskAssessmentTitlePublicRequest.class));
}
@Test
void create_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.create(new CreateRiskAssessmentDto(), new RequestMetaDTO()));
void create_success() {
when(requestProcessingService.sendAndReceive(any(CreateRiskAssessmentPublicRequest.class)))
.thenReturn(new RiskAssessmentPublicDto());
mockMvcUtil.testPost(BASE_URL, new CreateRiskAssessmentDto(), new TypeReference<RiskAssessmentPublicDto>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateRiskAssessmentPublicRequest.class));
}
@Test
void copy_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.copy(randomUUID(), CopyRiskAssessmentDto.builder()
.riskAssessment(RiskAssessmentPublicDto.builder().id(UUID.randomUUID()).build()).build(), new RequestMetaDTO()));
void copy_success() {
when(requestProcessingService.sendAndReceive(any(CopyRiskAssessmentPublicRequest.class)))
.thenReturn(new RiskAssessmentPublicDto());
mockMvcUtil.testPost(BASE_URL + "/" + randomUUID() + "/copy", new CopyRiskAssessmentDto(),
new TypeReference<RiskAssessmentPublicDto>() {
});
verify(requestProcessingService).sendAndReceive(any(CopyRiskAssessmentPublicRequest.class));
}
@Test
void getBusinessTypes_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getRiskAssessmentBusinessTypes(null, new RequestMetaDTO()));
void getBusinessTypes_success() {
when(requestProcessingService.sendAndReceive(any(RiskAssessmentBusinessTypePublicRequest.class)))
.thenReturn(new RiskAssessmentPublicDto());
mockMvcUtil.testGet(BASE_URL + "/" + randomUUID() + "/business-types", null,
new TypeReference<RiskAssessmentPublicDto>() {
});
verify(requestProcessingService).sendAndReceive(any(RiskAssessmentBusinessTypePublicRequest.class));
}
@Test
void getConclusion_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getConclusion(randomUUID(), new RequestMetaDTO()));
void getConclusion_success() {
when(requestProcessingService.sendAndReceive(any(RiskAssessmentConclusionPublicRequest.class)))
.thenReturn(new RiskAssessmentConclusionDto());
mockMvcUtil.testGet(BASE_URL + "/" + randomUUID() + "/conclusion", null,
new TypeReference<RiskAssessmentConclusionDto>() {
});
verify(requestProcessingService).sendAndReceive(any(RiskAssessmentConclusionPublicRequest.class));
}
@Test
void getActionPlanConclusion_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getActionPlanConclusion(randomUUID(), new RequestMetaDTO()));
void getActionPlanConclusion_success() {
when(requestProcessingService.sendAndReceive(any(RiskAssessmentActionPlanConclusionPublicRequest.class)))
.thenReturn(new RiskAssessmentActionPlanConclusionDto());
mockMvcUtil.testGet(BASE_URL + "/" + randomUUID() + "/action-plan-conclusion", null,
new TypeReference<RiskAssessmentActionPlanConclusionDto>() {
});
verify(requestProcessingService).sendAndReceive(any(RiskAssessmentActionPlanConclusionPublicRequest.class));
}
@Test
void getRiskFactorAssessment_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getRiskFactorAssessment(randomUUID(), null, new RequestMetaDTO()));
void getRiskFactorAssessment_success() {
when(requestProcessingService.sendAndReceive(any(RiskAssessmentRiskFactorAssessmentPublicRequest.class)))
.thenReturn(new RiskAssessmentPublicDto());
mockMvcUtil.testGet(BASE_URL + "/" + randomUUID() + "/risk-factor-assessments", null,
new TypeReference<RiskAssessmentPublicDto>() {
});
verify(requestProcessingService).sendAndReceive(any(RiskAssessmentRiskFactorAssessmentPublicRequest.class));
}
@Test
void updateStatus_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.updateStatus(randomUUID(), new UpdateRiskAssessmentStatusDto(), new RequestMetaDTO()));
void updateStatus_success() {
when(requestProcessingService.sendAndReceive(any(UpdateRiskAssessmentStatusPublicRequest.class)))
.thenReturn(new RiskAssessmentPublicDto());
mockMvcUtil.testPatch(BASE_URL + "/" + randomUUID() + "/status", new UpdateRiskAssessmentStatusDto(),
new TypeReference<RiskAssessmentPublicDto>() {
});
verify(requestProcessingService).sendAndReceive(any(UpdateRiskAssessmentStatusPublicRequest.class));
}
@Test
void delete_test() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.delete(randomUUID(), new RequestMetaDTO()));
}
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + "/" + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteRiskAssessmentRequest.class));
}
}
package ee.sm.ti.teis.commongateway.riskassessments.riskfactor;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.riskassessments.riskfactor.dto.RiskFactorPublicDto;
import ee.sm.ti.teis.commongateway.riskassessments.riskfactor.request.RiskFactorsPublicRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;