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.auditlog; package ee.sm.ti.teis.commongateway.auditlog;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.auditlog.dto.EmployerAuditLogItemSearchDto; import ee.sm.ti.teis.commongateway.auditlog.dto.EmployerAuditLogItemsDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.commongateway.auditlog.request.EmployerAuditLogItemsRequest;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
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 AuditLogControllerTest extends CommonApiGatewayTestBase { class AuditLogControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/auditlogs";
@Autowired @Autowired
AuditLogController controller; MockMvcUtil mockMvcUtil;
@Test @Test
void getAuditLogItemsForEmployer_badRequest() { void getAuditLogItemsForEmployer_success() {
assertThrows(NoResponseFromRabbitException.class, () -> when(requestProcessingService.sendAndReceive(any(EmployerAuditLogItemsRequest.class)))
controller.getEmployerAuditLogItems(new EmployerAuditLogItemSearchDto(), new RequestMetaDTO())); .thenReturn(new EmployerAuditLogItemsDto());
mockMvcUtil.testGet(BASE_URL + "/employer", null, new TypeReference<EmployerAuditLogItemsDto>() {
});
verify(requestProcessingService).sendAndReceive(any(EmployerAuditLogItemsRequest.class));
} }
} }
package ee.sm.ti.teis.commongateway.auditlog; package ee.sm.ti.teis.commongateway.auditlog;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.auditlog.dto.AuditLogItemDto; import ee.sm.ti.teis.commongateway.auditlog.dto.AuditLogItemDto;
import ee.sm.ti.teis.commongateway.auditlog.dto.AuditLogItemExistsDto; import ee.sm.ti.teis.commongateway.auditlog.dto.AuditLogItemExistsDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.commongateway.auditlog.dto.AuditLogItemExistsResponseDto;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.commongateway.auditlog.request.AuditLogItemExistsRequest;
import ee.sm.ti.teis.commongateway.auditlog.request.AuditLogItemsRequest;
import ee.sm.ti.teis.commongateway.auditlog.request.CreateAuditLogItemRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import static java.util.UUID.randomUUID; import java.util.List;
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 AuditLogTestControllerTest extends CommonApiGatewayTestBase { class AuditLogTestControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(randomUUID().toString()).build(); private static final String BASE_URL = "/auditlogs";
@Autowired @Autowired
AuditLogTestController controller; MockMvcUtil mockMvcUtil;
@Test @Test
void createAuditLogItem_badRequest() { void createAuditLogItem_success() {
AuditLogItemDto logItemDto = AuditLogItemDto.builder().build(); when(requestProcessingService.sendAndReceive(any(CreateAuditLogItemRequest.class)))
.thenReturn(new AuditLogItemDto());
mockMvcUtil.testPost(BASE_URL, new AuditLogItemDto(), new TypeReference<AuditLogItemDto>() {
});
assertThrows(NoResponseFromRabbitException.class, () -> verify(requestProcessingService).sendAndReceive(any(CreateAuditLogItemRequest.class));
controller.createAuditLogItem(logItemDto, REQUEST_META_DTO));
} }
@Test @Test
void getAuditLogItems_badRequest() { void getAuditLogItems_success() {
assertThrows(NoResponseFromRabbitException.class, () -> when(requestProcessingService.sendAndReceive(any(AuditLogItemsRequest.class)))
controller.getAuditLogItems(null, null, REQUEST_META_DTO)); .thenReturn(List.of(new AuditLogItemDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<AuditLogItemDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(AuditLogItemsRequest.class));
} }
@Test @Test
void auditLogItemExists_badRequest() { void auditLogItemExists_success() {
assertThrows(NoResponseFromRabbitException.class, () -> when(requestProcessingService.sendAndReceive(any(AuditLogItemExistsRequest.class)))
controller.auditLogItemExists(new AuditLogItemExistsDto(), REQUEST_META_DTO)); .thenReturn(new AuditLogItemExistsResponseDto());
}
mockMvcUtil.testGetWithBody(BASE_URL + "/check", new AuditLogItemExistsDto(), new TypeReference<AuditLogItemExistsResponseDto>() {
});
verify(requestProcessingService).sendAndReceive(any(AuditLogItemExistsRequest.class));
}
} }
package ee.sm.ti.teis.commongateway.authorities.authoritylicences; package ee.sm.ti.teis.commongateway.authorities.authoritylicences;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.authorities.authoritylicence.AuthorityLicenceController; import ee.sm.ti.teis.commongateway.authorities.authoritylicence.dto.AuthorityLicenceDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.commongateway.authorities.authoritylicence.dto.ValidatedAuthorityLicenceDto;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.commongateway.authorities.authoritylicence.request.AuthorityLicencesRequest;
import ee.sm.ti.teis.types.enums.AuthorityLicenceType; import ee.sm.ti.teis.commongateway.authorities.authoritylicence.request.LicencedAuthoritiesRequest;
import ee.sm.ti.teis.commongateway.authorities.authoritylicence.request.ValidateAuthorityLicenceRequest;
import ee.sm.ti.teis.commongateway.person.PersonDto;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import static ee.sm.ti.teis.types.enums.AuthorityLicenceType.OH;
import static java.util.UUID.randomUUID; 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 AuthorityLicenceControllerTest extends CommonApiGatewayTestBase { class AuthorityLicenceControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/authorities/authority-licences";
@Autowired @Autowired
AuthorityLicenceController controller; MockMvcUtil mockMvcUtil;
@Test @Test
void getAuthorityLicences_badRequest() { void getAuthorityLicences_success() {
assertThrows(NoResponseFromRabbitException.class, when(requestProcessingService.sendAndReceive(any(AuthorityLicencesRequest.class)))
() -> controller.getAuthorityLicences(randomUUID(), null, null, new RequestMetaDTO())); .thenReturn(List.of(new AuthorityLicenceDto()));
parameters.add("authorityId", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL, parameters, new TypeReference<List<AuthorityLicenceDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(AuthorityLicencesRequest.class));
} }
@Test @Test
void getLicencedAuthorities_badRequest() { void getLicencedAuthorities_success() {
assertThrows(NoResponseFromRabbitException.class, when(requestProcessingService.sendAndReceive(any(LicencedAuthoritiesRequest.class)))
() -> controller.getLicencedAuthorities(AuthorityLicenceType.OH, new RequestMetaDTO())); .thenReturn(List.of(new PersonDto()));
parameters.add("licenceType", OH.name());
mockMvcUtil.testGet(BASE_URL + "/authorities", parameters, new TypeReference<List<PersonDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(LicencedAuthoritiesRequest.class));
} }
@Test @Test
void validate_badRequest() { void validate_success() {
assertThrows(NoResponseFromRabbitException.class, when(requestProcessingService.sendAndReceive(any(ValidateAuthorityLicenceRequest.class)))
() -> controller.validateAuthorityLicence(randomUUID(), AuthorityLicenceType.OH, null, new RequestMetaDTO())); .thenReturn(new ValidatedAuthorityLicenceDto());
parameters.add("authorityId", randomUUID().toString());
parameters.add("licenceType", OH.name());
mockMvcUtil.testGet(BASE_URL + "/validate", parameters, new TypeReference<ValidatedAuthorityLicenceDto>() {
});
verify(requestProcessingService).sendAndReceive(any(ValidateAuthorityLicenceRequest.class));
} }
} }
package ee.sm.ti.teis.commongateway.authorities.authoritypermissions; package ee.sm.ti.teis.commongateway.authorities.authoritypermissions;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.authorities.authoritypermission.AuthorityPermissionsController; import ee.sm.ti.teis.commongateway.authorities.authoritypermission.dto.GrantorsAuthorityPermissionDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.commongateway.authorities.authoritypermission.request.GrantorsAuthorityPermissionsRequest;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; 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 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 AuthorityPermissionsControllerTest extends CommonApiGatewayTestBase { class AuthorityPermissionsControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/authorities/authority-permissions";
@Autowired @Autowired
AuthorityPermissionsController controller; MockMvcUtil mockMvcUtil;
@Test @Test
void getGrantorsAuthorityLicences_badRequest() { void getGrantorsAuthorityLicences_success() {
assertThrows(NoResponseFromRabbitException.class, when(requestProcessingService.sendAndReceive(any(GrantorsAuthorityPermissionsRequest.class)))
() -> controller.getGrantorsAuthorityPermissions(randomUUID(), null, null, new RequestMetaDTO())); .thenReturn(List.of(new GrantorsAuthorityPermissionDto()));
parameters.add("grantorId", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL + "/grantor", parameters, new TypeReference<List<GrantorsAuthorityPermissionDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(GrantorsAuthorityPermissionsRequest.class));
} }
} }
package ee.sm.ti.teis.commongateway.classifier; package ee.sm.ti.teis.commongateway.classifier;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.classifier.search.ClassifierItemSearchFilterDto; import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import static org.junit.jupiter.api.Assertions.assertThrows; 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 ClassifierControllerTest extends CommonApiGatewayTestBase { class ClassifierControllerTest extends CommonApiGatewayTestBase {
@Autowired @Autowired
ClassifierController controller; MockMvcUtil mockMvcUtil;
@Test @Test
void getClassifier_test() { void getClassifiers_success() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getClassifier("id", null, null, new RequestMetaDTO())); when(requestProcessingService.sendAndReceive(any(ClassifierItemsRequest.class)))
.thenReturn(List.of(new ClassifierItemDto()));
mockMvcUtil.testGet("/classifier-items", null, new TypeReference<List<ClassifierItemDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(ClassifierItemsRequest.class));
} }
@Test @Test
void getClassifiers_test() { void getClassifier_success() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getClassifiers(new ClassifierItemSearchFilterDto(), new RequestMetaDTO())); when(requestProcessingService.sendAndReceive(any(ClassifierItemRequest.class)))
.thenReturn(new ClassifierItemDto());
mockMvcUtil.testGet("/classifier-items/" + randomUUID(), null, new TypeReference<ClassifierItemDto>() {
});
verify(requestProcessingService).sendAndReceive(any(ClassifierItemRequest.class));
} }
@Test @Test
void getDefinition_test() { void getDefinition_success() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getDefinition("id", new RequestMetaDTO())); when(requestProcessingService.sendAndReceive(any(ClassifierDefinitionRequest.class)))
} .thenReturn(new ClassifierItemDto());
mockMvcUtil.testGet("/classifier-definitions/" + randomUUID() + "/default-value", null, new TypeReference<ClassifierItemDto>() {
});
verify(requestProcessingService).sendAndReceive(any(ClassifierDefinitionRequest.class));
}
} }
package ee.sm.ti.teis.commongateway.dumonitor; package ee.sm.ti.teis.commongateway.dumonitor;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.UUID; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when;
@WithMockUser
class DUMonitorTestControllerTest extends CommonApiGatewayTestBase { class DUMonitorTestControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build(); private static final String BASE_URL = "/dumonitor";
@Autowired @Autowired
DUMonitorTestController controller; MockMvcUtil mockMvcUtil;
@Test @Test
void send_test() { void send_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.send(new PersonalDataUsageDto(), REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(SendPersonalDataUsageRequest.class)))
.thenReturn("{}");
mockMvcUtil.testPost(BASE_URL, new PersonalDataUsageDto(), new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(SendPersonalDataUsageRequest.class));
} }
} }
package ee.sm.ti.teis.commongateway.violation; package ee.sm.ti.teis.commongateway.file;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.file.FileController;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;
import java.util.UUID;
import static ee.sm.ti.teis.commongateway.file.FileObjectType.VIOLATION; import static ee.sm.ti.teis.commongateway.file.FileObjectType.VIOLATION;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
class FileControllerTest extends CommonApiGatewayTestBase { class FileControllerTest extends CommonApiGatewayTestBase {
...@@ -27,13 +25,13 @@ class FileControllerTest extends CommonApiGatewayTestBase { ...@@ -27,13 +25,13 @@ class FileControllerTest extends CommonApiGatewayTestBase {
@Test @Test
void delete() { void delete() {
assertThrows(NoResponseFromRabbitException.class, () -> assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(VIOLATION, "", "", new RequestMetaDTO())); controller.delete(VIOLATION, randomUUID(), randomUUID(), new RequestMetaDTO()));
} }
@Test @Test
void download_() { void download_() {
assertThrows(NoResponseFromRabbitException.class, () -> assertThrows(NoResponseFromRabbitException.class, () ->
controller.download(VIOLATION, UUID.randomUUID().toString(), UUID.randomUUID().toString(), "", controller.download(VIOLATION, randomUUID().toString(), randomUUID().toString(), "",
new MockHttpServletResponse(), new RequestMetaDTO())); new MockHttpServletResponse(), new RequestMetaDTO()));
} }
} }
package ee.sm.ti.teis.commongateway.location; package ee.sm.ti.teis.commongateway.location;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; 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 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 LocationControllerTest extends CommonApiGatewayTestBase { class LocationControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(randomUUID().toString()).build(); private static final String BASE_URL = "/locations/";
@Autowired @Autowired
LocationController controller; MockMvcUtil mockMvcUtil;
@Test @Test