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;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.auditlog.dto.EmployerAuditLogItemSearchDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.auditlog.dto.EmployerAuditLogItemsDto;
import ee.sm.ti.teis.commongateway.auditlog.request.EmployerAuditLogItemsRequest;
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 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 {
private static final String BASE_URL = "/auditlogs";
@Autowired
AuditLogController controller;
MockMvcUtil mockMvcUtil;
@Test
void getAuditLogItemsForEmployer_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getEmployerAuditLogItems(new EmployerAuditLogItemSearchDto(), new RequestMetaDTO()));
void getAuditLogItemsForEmployer_success() {
when(requestProcessingService.sendAndReceive(any(EmployerAuditLogItemsRequest.class)))
.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;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.auditlog.dto.AuditLogItemDto;
import ee.sm.ti.teis.commongateway.auditlog.dto.AuditLogItemExistsDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.auditlog.dto.AuditLogItemExistsResponseDto;
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.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 java.util.List;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
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
AuditLogTestController controller;
MockMvcUtil mockMvcUtil;
@Test
void createAuditLogItem_badRequest() {
AuditLogItemDto logItemDto = AuditLogItemDto.builder().build();
void createAuditLogItem_success() {
when(requestProcessingService.sendAndReceive(any(CreateAuditLogItemRequest.class)))
.thenReturn(new AuditLogItemDto());
mockMvcUtil.testPost(BASE_URL, new AuditLogItemDto(), new TypeReference<AuditLogItemDto>() {
});
assertThrows(NoResponseFromRabbitException.class, () ->
controller.createAuditLogItem(logItemDto, REQUEST_META_DTO));
verify(requestProcessingService).sendAndReceive(any(CreateAuditLogItemRequest.class));
}
@Test
void getAuditLogItems_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getAuditLogItems(null, null, REQUEST_META_DTO));
void getAuditLogItems_success() {
when(requestProcessingService.sendAndReceive(any(AuditLogItemsRequest.class)))
.thenReturn(List.of(new AuditLogItemDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<AuditLogItemDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(AuditLogItemsRequest.class));
}
@Test
void auditLogItemExists_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.auditLogItemExists(new AuditLogItemExistsDto(), REQUEST_META_DTO));
}
void auditLogItemExists_success() {
when(requestProcessingService.sendAndReceive(any(AuditLogItemExistsRequest.class)))
.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;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.authorities.authoritylicence.AuthorityLicenceController;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.AuthorityLicenceType;
import ee.sm.ti.teis.commongateway.authorities.authoritylicence.dto.AuthorityLicenceDto;
import ee.sm.ti.teis.commongateway.authorities.authoritylicence.dto.ValidatedAuthorityLicenceDto;
import ee.sm.ti.teis.commongateway.authorities.authoritylicence.request.AuthorityLicencesRequest;
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.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 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 {
private static final String BASE_URL = "/authorities/authority-licences";
@Autowired
AuthorityLicenceController controller;
MockMvcUtil mockMvcUtil;
@Test
void getAuthorityLicences_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getAuthorityLicences(randomUUID(), null, null, new RequestMetaDTO()));
void getAuthorityLicences_success() {
when(requestProcessingService.sendAndReceive(any(AuthorityLicencesRequest.class)))
.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
void getLicencedAuthorities_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getLicencedAuthorities(AuthorityLicenceType.OH, new RequestMetaDTO()));
void getLicencedAuthorities_success() {
when(requestProcessingService.sendAndReceive(any(LicencedAuthoritiesRequest.class)))
.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
void validate_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.validateAuthorityLicence(randomUUID(), AuthorityLicenceType.OH, null, new RequestMetaDTO()));
void validate_success() {
when(requestProcessingService.sendAndReceive(any(ValidateAuthorityLicenceRequest.class)))
.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;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.authorities.authoritypermission.AuthorityPermissionsController;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.authorities.authoritypermission.dto.GrantorsAuthorityPermissionDto;
import ee.sm.ti.teis.commongateway.authorities.authoritypermission.request.GrantorsAuthorityPermissionsRequest;
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 AuthorityPermissionsControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/authorities/authority-permissions";
@Autowired
AuthorityPermissionsController controller;
MockMvcUtil mockMvcUtil;
@Test
void getGrantorsAuthorityLicences_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getGrantorsAuthorityPermissions(randomUUID(), null, null, new RequestMetaDTO()));
void getGrantorsAuthorityLicences_success() {
when(requestProcessingService.sendAndReceive(any(GrantorsAuthorityPermissionsRequest.class)))
.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;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.classifier.search.ClassifierItemSearchFilterDto;
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 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 {
@Autowired
ClassifierController controller;
MockMvcUtil mockMvcUtil;
@Test
void getClassifier_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getClassifier("id", null, null, new RequestMetaDTO()));
void getClassifiers_success() {
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
void getClassifiers_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getClassifiers(new ClassifierItemSearchFilterDto(), new RequestMetaDTO()));
void getClassifier_success() {
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
void getDefinition_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getDefinition("id", new RequestMetaDTO()));
}
void getDefinition_success() {
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;
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.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 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 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
DUMonitorTestController controller;
MockMvcUtil mockMvcUtil;
@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.file.FileController;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletResponse;
import java.util.UUID;
import static ee.sm.ti.teis.commongateway.file.FileObjectType.VIOLATION;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
class FileControllerTest extends CommonApiGatewayTestBase {
......@@ -27,13 +25,13 @@ class FileControllerTest extends CommonApiGatewayTestBase {
@Test
void delete() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(VIOLATION, "", "", new RequestMetaDTO()));
controller.delete(VIOLATION, randomUUID(), randomUUID(), new RequestMetaDTO()));
}
@Test
void download_() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.download(VIOLATION, UUID.randomUUID().toString(), UUID.randomUUID().toString(), "",
controller.download(VIOLATION, randomUUID().toString(), randomUUID().toString(), "",
new MockHttpServletResponse(), new RequestMetaDTO()));
}
}
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.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.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 {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(randomUUID().toString()).build();
private static final String BASE_URL = "/locations/";
@Autowired
LocationController controller;
MockMvcUtil mockMvcUtil;
@Test
void create_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.create(new LocationDto(), REQUEST_META_DTO));
void getLocation_success() {
when(requestProcessingService.sendAndReceive(any(LocationRequest.class)))
.thenReturn(new LocationDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<LocationDto>() {
});
verify(requestProcessingService).sendAndReceive(any(LocationRequest.class));
}
@Test
void delete_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.delete(randomUUID(), REQUEST_META_DTO));
void getLocations_success() {
when(requestProcessingService.sendAndReceive(any(LocationsRequest.class)))
.thenReturn(List.of(new LocationDto()));
parameters.add("employerId", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL, parameters, new TypeReference<List<LocationDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(LocationsRequest.class));
}
@Test
void getLocation_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getLocation(randomUUID(), REQUEST_META_DTO));
void create_success() {
when(requestProcessingService.sendAndReceive(any(CreateLocationRequest.class)))
.thenReturn(new LocationDto());
mockMvcUtil.testPost(BASE_URL, new LocationDto(), new TypeReference<LocationDto>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateLocationRequest.class));
}
@Test
void getLocations_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getLocations(randomUUID(), REQUEST_META_DTO));
void update_success() {
when(requestProcessingService.sendAndReceive(any(UpdateLocationRequest.class)))
.thenReturn(new LocationDto());
mockMvcUtil.testPut(BASE_URL + randomUUID(), new LocationDto(), new TypeReference<LocationDto>() {
});
verify(requestProcessingService).sendAndReceive(any(UpdateLocationRequest.class));
}
@Test
void update_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.update(randomUUID(), new LocationDto(), REQUEST_META_DTO));
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteLocationRequest.class));
}
@Test
void createLocationsFromTor_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.createLocationsFromTor(randomUUID(), REQUEST_META_DTO));
void createLocationsFromTor_success() {
mockMvcUtil.testPost(BASE_URL + "fromTor/" + randomUUID(), randomUUID(), null, true);
verify(requestProcessingService).sendAndReceive(any(CreateLocationsRequest.class));
}
}
package ee.sm.ti.teis.commongateway.messages.message;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.messages.message.dto.CreateMessageDto;
import ee.sm.ti.teis.commongateway.messages.message.dto.MessageDto;
import ee.sm.ti.teis.commongateway.messages.message.dto.MessageWithEmployerDto;
import ee.sm.ti.teis.commongateway.messages.message.dto.PatchMessageDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.messages.message.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.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
public class MessageControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/messages/";
@Autowired
MessageController controller;
MockMvcUtil mockMvcUtil;
@Test