Commit 0c5295ba authored by Enriko Käsper's avatar Enriko Käsper

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/officials-service!37
parents cfa58611 6ec4cbb6
theGroup=ee.sm.ti.teis
theVersion=1.2.1
commonsVersion=1.4.0
officeApiGatewayVersion=1.4.0
pluginVersion=1.0.0
theVersion=1.3.0
commonsVersion=1.5.0
officeApiGatewayVersion=1.5.0
pluginVersion=1.0.1
mapstructVersion=1.3.0.Final
querydslVersion=4.1.3
package ee.sm.ti.teis;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.TestPropertyValues;
......@@ -14,9 +12,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.util.List;
import java.util.UUID;
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = OfficialsServiceApp.class)
@ActiveProfiles("integtest")
......@@ -25,7 +20,7 @@ import java.util.UUID;
@ContextConfiguration(initializers = {OfficialsAppTestBase.Initializer.class})
public abstract class OfficialsAppTestBase {
private static GenericContainer rabbitMQContainer;
private static final GenericContainer rabbitMQContainer;
// to speed up tests, lets use static container, it is used in alla test classes that are executed inside one Spring Context
static {
......@@ -33,19 +28,6 @@ public abstract class OfficialsAppTestBase {
rabbitMQContainer.start();
}
protected RequestMetaDTO createRequestMeta(String userId, UserType userType, String companyId, List<String> privileges) {
RequestMetaDTO requestMeta = RequestMetaDTO.builder()
.requestId(UUID.randomUUID().toString())
.userId(userId)
.userType(userType)
.companyId(companyId)
.build();
if (privileges != null) {
requestMeta.setPrivileges(privileges);
}
return requestMeta;
}
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
......
......@@ -12,7 +12,6 @@ import ee.sm.ti.teis.officegateway.official.response.DeleteOfficialsGroupEmtakRe
import ee.sm.ti.teis.officegateway.official.response.OfficialsGroupEmtakCodesResponse;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
import ee.sm.ti.teis.types.enums.ObjectStatus;
import ee.sm.ti.teis.types.enums.RolePrivilegeCode;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
......@@ -22,13 +21,16 @@ import java.util.Collections;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static org.assertj.core.api.Assertions.assertThat;
class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
private static final String CORRECT_GROUP_ID = "751f8528-64a5-4e0e-862a-549356014861";
private static final String DELETED_GROUP_ID = "c6bbd0d0-a614-408e-b22b-c60eed1a0dc9";
private static final String INCORRECT_GROUP_ID = "751f8528-64a5-4e0e-862a-549356014899";
private static final UUID CORRECT_GROUP_ID = UUID.fromString("751f8528-64a5-4e0e-862a-549356014861");
private static final UUID DELETED_GROUP_ID = UUID.fromString("c6bbd0d0-a614-408e-b22b-c60eed1a0dc9");
private static final UUID INCORRECT_GROUP_ID = UUID.fromString("751f8528-64a5-4e0e-862a-549356014899");
private static final String STATUS_CURRENT = "CURRENT";
@Autowired
......@@ -46,23 +48,19 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
void findEmtakCodes_test() {
OfficialsGroupEmtakCodesRequest request = composeGroupEmtakCodesRequest(CORRECT_GROUP_ID, "0113", STATUS_CURRENT);
OfficialsGroupEmtakCodesResponse response = listener.findOfficialsGroupEmtakCodes(request);
OfficialsGroupEmtakCodesResponse response = listener.getEmtakCodes(request);
assertThat(response.getPayload().stream().allMatch(g -> g.getObjectStatus() == ObjectStatus.CURRENT)).isTrue();
assertThat(response.getPayload().stream().allMatch(g -> g.getObjectStatus() == CURRENT)).isTrue();
}
@Test
void findEmtakCodes_validates_input_params() {
OfficialsGroupEmtakCodesRequest request = composeGroupEmtakCodesRequest(null, null, STATUS_CURRENT);
OfficialsGroupEmtakCodesResponse response = listener.findOfficialsGroupEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.BAD_REQUEST.getCode());
request = composeGroupEmtakCodesRequest("ss", null, STATUS_CURRENT);
response = listener.findOfficialsGroupEmtakCodes(request);
OfficialsGroupEmtakCodesResponse response = listener.getEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.BAD_REQUEST.getCode());
request = composeGroupEmtakCodesRequest(INCORRECT_GROUP_ID, null, STATUS_CURRENT);
response = listener.findOfficialsGroupEmtakCodes(request);
response = listener.getEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.RESOURCE_NOT_FOUND.getCode());
}
......@@ -71,7 +69,7 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
requestMetaDTO.setPrivileges(Collections.emptyList());
CreateOfficialsGroupEmtakCodesRequest request = composeCreateGroupEmtakCodesRequest(CORRECT_GROUP_ID, List.of("0113"));
CreateOfficialsGroupEmtakCodesResponse response = listener.createOfficialsGroupEmtakCodes(request);
CreateOfficialsGroupEmtakCodesResponse response = listener.createEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.FORBIDDEN.getCode());
}
......@@ -81,7 +79,7 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
requestMetaDTO.setUserType(UserType.PERSON);
CreateOfficialsGroupEmtakCodesRequest request = composeCreateGroupEmtakCodesRequest(CORRECT_GROUP_ID, List.of("0113"));
CreateOfficialsGroupEmtakCodesResponse response = listener.createOfficialsGroupEmtakCodes(request);
CreateOfficialsGroupEmtakCodesResponse response = listener.createEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.FORBIDDEN.getCode());
}
......@@ -89,23 +87,19 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
@Test
void createEmtakCodes_validates_group() {
CreateOfficialsGroupEmtakCodesRequest request = composeCreateGroupEmtakCodesRequest(INCORRECT_GROUP_ID, List.of("0113"));
CreateOfficialsGroupEmtakCodesResponse response = listener.createOfficialsGroupEmtakCodes(request);
CreateOfficialsGroupEmtakCodesResponse response = listener.createEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.RESOURCE_NOT_FOUND.getCode());
request = composeCreateGroupEmtakCodesRequest(DELETED_GROUP_ID, List.of("0113"));
response = listener.createOfficialsGroupEmtakCodes(request);
response = listener.createEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.RESOURCE_NOT_FOUND.getCode());
request = composeCreateGroupEmtakCodesRequest(null, List.of("0113"));
response = listener.createOfficialsGroupEmtakCodes(request);
response = listener.createEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.BAD_REQUEST.getCode());
request = composeCreateGroupEmtakCodesRequest(null, Collections.emptyList());
response = listener.createOfficialsGroupEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.BAD_REQUEST.getCode());
request = composeCreateGroupEmtakCodesRequest("BLAH", List.of("0113"));
response = listener.createOfficialsGroupEmtakCodes(request);
response = listener.createEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.BAD_REQUEST.getCode());
}
......@@ -113,7 +107,7 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
void createEmtakCodes_validates_emtaks() {
CreateOfficialsGroupEmtakCodesRequest request = composeCreateGroupEmtakCodesRequest(CORRECT_GROUP_ID, Collections.emptyList());
CreateOfficialsGroupEmtakCodesResponse response = listener.createOfficialsGroupEmtakCodes(request);
CreateOfficialsGroupEmtakCodesResponse response = listener.createEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.BAD_REQUEST.getCode());
}
......@@ -122,7 +116,7 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
void createEmtakCodes_test() {
CreateOfficialsGroupEmtakCodesRequest request = composeCreateGroupEmtakCodesRequest(CORRECT_GROUP_ID, List.of("0321"));
CreateOfficialsGroupEmtakCodesResponse response = listener.createOfficialsGroupEmtakCodes(request);
CreateOfficialsGroupEmtakCodesResponse response = listener.createEmtakCodes(request);
assertThat(response.getPayload().get(0).getEmtak().getCode()).isEqualTo("0321");
}
......@@ -130,11 +124,11 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
@Test
void createEmtakCodes_dont_make_duplicate_entries() {
OfficialsGroupEmtakCodesRequest findRequest = composeGroupEmtakCodesRequest(CORRECT_GROUP_ID, "0113", STATUS_CURRENT);
final OfficialsGroupEmtakDto existingGroupEmtak = listener.findOfficialsGroupEmtakCodes(findRequest).getPayload().get(0);
final OfficialsGroupEmtakDto existingGroupEmtak = listener.getEmtakCodes(findRequest).getPayload().get(0);
CreateOfficialsGroupEmtakCodesRequest request = composeCreateGroupEmtakCodesRequest(CORRECT_GROUP_ID, List.of("0113"));
CreateOfficialsGroupEmtakCodesResponse response = listener.createOfficialsGroupEmtakCodes(request);
CreateOfficialsGroupEmtakCodesResponse response = listener.createEmtakCodes(request);
assertThat(response.getPayload().get(0).getId()).isEqualTo(existingGroupEmtak.getId());
}
......@@ -142,64 +136,53 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
@Test
void createEmtakCodes_activates_deleted_entries() {
OfficialsGroupEmtakCodesRequest findRequest = composeGroupEmtakCodesRequest(CORRECT_GROUP_ID, "0115", "X");
final OfficialsGroupEmtakDto existingGroupEmtak = listener.findOfficialsGroupEmtakCodes(findRequest).getPayload().get(0);
final OfficialsGroupEmtakDto existingGroupEmtak = listener.getEmtakCodes(findRequest).getPayload().get(0);
CreateOfficialsGroupEmtakCodesRequest request = composeCreateGroupEmtakCodesRequest(CORRECT_GROUP_ID, List.of("0115"));
CreateOfficialsGroupEmtakCodesResponse response = listener.createOfficialsGroupEmtakCodes(request);
CreateOfficialsGroupEmtakCodesResponse response = listener.createEmtakCodes(request);
assertThat(response.getPayload().get(0).getId()).isEqualTo(existingGroupEmtak.getId());
assertThat(response.getPayload().get(0).getObjectStatus()).isEqualTo(ObjectStatus.CURRENT);
assertThat(response.getPayload().get(0).getObjectStatus()).isEqualTo(CURRENT);
}
@Test
void deleteEmtakCode__user_must_have_privileges() {
requestMetaDTO.setPrivileges(Collections.emptyList());
DeleteOfficialsGroupEmtakRequest request = composeDeleteGroupEmtakRequest("b174d4f0-7129-4e17-bd8e-88e85b7eb08b");
DeleteOfficialsGroupEmtakRequest request = composeDeleteGroupEmtakRequest(UUID.fromString("b174d4f0-7129-4e17-bd8e-88e85b7eb08b"));
DeleteOfficialsGroupEmtakResponse response = listener.deleteOfficialsGroupEmtak(request);
DeleteOfficialsGroupEmtakResponse response = listener.deleteEmtakCode(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.FORBIDDEN.getCode());
}
@Test
void deleteEmtakCode_validates_emtak_id() {
DeleteOfficialsGroupEmtakRequest request = composeDeleteGroupEmtakRequest("xx");
DeleteOfficialsGroupEmtakResponse response = listener.deleteOfficialsGroupEmtak(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.BAD_REQUEST.getCode());
request = composeDeleteGroupEmtakRequest("e54a043a-9097-4506-960f-020619096713");
response = listener.deleteOfficialsGroupEmtak(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.RESOURCE_NOT_FOUND.getCode());
}
@Test
void deleteEmtakCode__test() {
DeleteOfficialsGroupEmtakRequest request = composeDeleteGroupEmtakRequest("b174d4f0-7129-4e17-bd8e-88e85b7eb08b");
DeleteOfficialsGroupEmtakRequest request = composeDeleteGroupEmtakRequest(UUID.fromString("b174d4f0-7129-4e17-bd8e-88e85b7eb08b"));
DeleteOfficialsGroupEmtakResponse response = listener.deleteOfficialsGroupEmtak(request);
DeleteOfficialsGroupEmtakResponse response = listener.deleteEmtakCode(request);
assertThat(response.getPayload().getObjectStatus()).isEqualTo(ObjectStatus.DELETED);
assertThat(response.getPayload().getObjectStatus()).isEqualTo(DELETED);
}
private DeleteOfficialsGroupEmtakRequest composeDeleteGroupEmtakRequest(String groupEmtakId) {
private DeleteOfficialsGroupEmtakRequest composeDeleteGroupEmtakRequest(UUID groupEmtakId) {
DeleteOfficialsGroupEmtakRequest request = new DeleteOfficialsGroupEmtakRequest();
request.setPayload(new DeleteOfficialsGroupEmtakRequest.Parameters(groupEmtakId), requestMetaDTO);
request.setPayload(groupEmtakId, requestMetaDTO);
return request;
}
private OfficialsGroupEmtakCodesRequest composeGroupEmtakCodesRequest(String groupId, String emtakCode, String status) {
private OfficialsGroupEmtakCodesRequest composeGroupEmtakCodesRequest(UUID groupId, String emtakCode, String status) {
OfficialsGroupEmtakCodesRequest request = new OfficialsGroupEmtakCodesRequest();
request.setPayload(new OfficialsGroupEmtakCodesRequest.Parameters(groupId, emtakCode, status), requestMetaDTO);
return request;
}
private CreateOfficialsGroupEmtakCodesRequest composeCreateGroupEmtakCodesRequest(String groupId, List<String> emtaks) {
private CreateOfficialsGroupEmtakCodesRequest composeCreateGroupEmtakCodesRequest(UUID groupId, List<String> emtaks) {
CreateOfficialsGroupEmtakCodesRequest request = new CreateOfficialsGroupEmtakCodesRequest();
OfficialsGroupEmtakCodesData data = new OfficialsGroupEmtakCodesData();
data.setOfficialsGroupId(groupId);
data.setEmtaks(emtaks);
request.setPayload(new CreateOfficialsGroupEmtakCodesRequest.Parameters(data), requestMetaDTO);
request.setPayload(data, requestMetaDTO);
return request;
}
......
......@@ -3,7 +3,6 @@ package ee.sm.ti.teis.officials.group.service;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.officials.group.OfficialsGroupEntity;
import ee.sm.ti.teis.officials.group.OfficialsGroupRepository;
import ee.sm.ti.teis.officials.group.OfficialsGroupUpdatedMessage;
import ee.sm.ti.teis.officials.official.OfficialUserEntity;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
......@@ -16,7 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.officials.group.service.OfficialsGroupNotifyService.OfficialsGroupUpdatedMessage;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
......
package ee.sm.ti.teis.officials.office;
package ee.sm.ti.teis.officials.office.listener;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.officegateway.official.request.OfficesRequest;
......@@ -27,7 +27,7 @@ class OfficeGwListenerTest extends OfficialsAppTestBase {
OfficesRequest request = new OfficesRequest();
request.setRequestMetaDTO(REQUEST_META_DTO);
final OfficesResponse response = listener.findActiveOffices(request);
final OfficesResponse response = listener.getOffices(request);
Assertions.assertThat(response.getPayload().size()).isEqualTo(16);
}
......@@ -37,7 +37,7 @@ class OfficeGwListenerTest extends OfficialsAppTestBase {
OfficesRequest request = new OfficesRequest();
request.setRequestMetaDTO(REQUEST_META_DTO);
final OfficesResponse response = listener.findActiveOffices(request);
final OfficesResponse response = listener.getOffices(request);
Assertions.assertThat(response.getPayload().get(0).getName()).isLessThanOrEqualTo(response.getPayload().get(1).getName());
Assertions.assertThat(response.getPayload().get(1).getName()).isLessThanOrEqualTo(response.getPayload().get(2).getName());
......
package ee.sm.ti.teis.officials.office;
package ee.sm.ti.teis.officials.office.listener;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.domain.officials.Office;
import ee.sm.ti.teis.officials.config.QueueConfig.OfficeDomainRequest;
import ee.sm.ti.teis.officials.config.QueueConfig.OfficesDomainRequest;
import ee.sm.ti.teis.officials.office.OfficeMsListener.OfficeMsResponse;
import ee.sm.ti.teis.officials.office.listener.OfficeMsListener.OfficeMsResponse;
import ee.sm.ti.teis.officials.office.listener.OfficeMsListener.OfficesMsResponse;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
......@@ -26,7 +27,7 @@ class OfficeMsListenerTest extends OfficialsAppTestBase {
OfficesDomainRequest request = new OfficesDomainRequest();
request.setRequestMetaDTO(REQUEST_META_DTO);
final OfficeMsListener.OfficesMsResponse response = listener.findActiveOffices(request);
OfficesMsResponse response = listener.getOffices(request);
Assertions.assertThat(response.getPayload().size()).isEqualTo(16);
}
......@@ -40,7 +41,7 @@ class OfficeMsListenerTest extends OfficialsAppTestBase {
office.setId(officeId);
request.setPayload(office, REQUEST_META_DTO);
final OfficeMsResponse response = listener.findActiveOffice(request);
OfficeMsResponse response = listener.getOffice(request);
Assertions.assertThat(response.getPayload().getId()).isEqualTo(officeId);
}
......
package ee.sm.ti.teis.officials.official;
package ee.sm.ti.teis.officials.official.listener;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.domain.officials.OfficialUser;
import ee.sm.ti.teis.errors.CommonErrorCode;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserDto;
import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupDto;
import ee.sm.ti.teis.officegateway.official.request.CreateOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.request.DeleteOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.request.OfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.request.OfficialUsersRequest;
import ee.sm.ti.teis.officegateway.official.request.UpdateOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.response.CreateOfficialUserResponse;
import ee.sm.ti.teis.officegateway.official.response.DeleteOfficialUserResponse;
import ee.sm.ti.teis.officegateway.official.response.OfficialUserResponse;
import ee.sm.ti.teis.officegateway.official.response.OfficialUsersResponse;
import ee.sm.ti.teis.officegateway.official.response.UpdateOfficialUserResponse;
import ee.sm.ti.teis.officegateway.official.request.*;
import ee.sm.ti.teis.officegateway.official.response.*;
import ee.sm.ti.teis.officials.group.service.OfficialsGroupManagerService;
import ee.sm.ti.teis.officials.official.OfficialUserEntity;
import ee.sm.ti.teis.officials.official.service.OfficialBusinessService;
import ee.sm.ti.teis.officials.official.service.OfficialComposeService;
import ee.sm.ti.teis.officials.official.service.OfficialDataService;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
import ee.sm.ti.teis.types.enums.RolePrivilegeCode;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
......@@ -25,6 +22,9 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import java.util.ArrayList;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.List.of;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
......@@ -32,84 +32,101 @@ import static org.mockito.Mockito.*;
class OfficialsListenerPrivilegesTest extends OfficialsAppTestBase {
private static final UUID OFFICIAL_ID = UUID.fromString("0bb3c0a5-f1bc-4c0d-8664-e94eec35c1c1");
@Autowired
OfficialGwListener officialGwListener;
OfficialGwListener listener;
@Autowired
OfficialBusinessService service;
@MockBean
OfficialDataService dataService;
@MockBean
OfficialService officialService;
OfficialComposeService composeService;
@MockBean
OfficialsGroupManagerService groupManagerService;
@BeforeEach
void setUp() {
doReturn(new OfficialUserEntity()).when(officialService).composeEntityFromDto(any());
doReturn(new OfficialUserEntity()).when(officialService).updateUserGroupData(any(), any(), any());
doReturn(new OfficialUserEntity()).when(officialService).delete(any(), any());
doReturn(new OfficialUserEntity()).when(officialService).findUserById(any());
doReturn(new ArrayList<>()).when(officialService).findUsers(any(), any(), any());
doReturn(new ArrayList<>()).when(officialService).composeDtoFromEntityList(any());
doReturn(new OfficialUserEntity()).when(officialService).createOfficialUser(any(), any());
doReturn(new OfficialUserDto()).when(officialService).composeDtoFromEntity(any());
doReturn(new OfficialUserEntity()).when(dataService).getOfficialById(any());
doReturn(new OfficialUserEntity()).when(dataService).getCurrentById(any());
doReturn(new ArrayList<>()).when(dataService).queryUsersByIdAndGroupIdAndObjectStatus(any(), any(), any());
doReturn(new OfficialUserEntity()).when(composeService).composeEntity(any(OfficialUserDto.class));
doReturn(new ArrayList<>()).when(composeService).composeDtoList(any());
doReturn(new OfficialUserDto()).when(composeService).composeDto(any());
doReturn(new OfficialUserDto()).when(composeService).composeDtoWithGroupManager(any());
}
//CREATE OFFICIAL USER
@Test
void createOfficialUser_shouldBeAllowed_if_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null, null);
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), OFFICIAL_USER, null, null);
verifyCreateOfficialUserIsAllowed(requestMetaDTO);
}
@Test
void createOfficialUser_shouldBeDenied_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null, null);
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), PERSON, null, null);
verifyCreateOfficialUserAccessIsDenied(requestMetaDTO);
}
//FIND OFFICIAL USER
@Test
void findOfficialUser_shouldBeAllowed_if_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null, null);
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), OFFICIAL_USER, null, null);
verifyFindOfficialUserIsAllowed(requestMetaDTO);
}
@Test
void findOfficialUser_shouldBeDenied_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null, null);
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), PERSON, null, null);
verifyFindOfficialUserAccessIsDenied(requestMetaDTO);
}
//FIND OFFICIAL USERs
@Test
void findOfficialUsers_shouldBeAllowed_if_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null, null);
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), OFFICIAL_USER, null, null);
verifyFindOfficialUsersIsAllowed(requestMetaDTO);
}
@Test
void findOfficialUsers_shouldBeDenied_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null, null);
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), PERSON, null, null);
verifyFindOfficialUsersAccessIsDenied(requestMetaDTO);
}
//DELETE OFFICIAL USER
@Test
void deleteOfficialUsers_shouldBeAllowed_if_correctPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null,
OfficialUserEntity mockEntity = new OfficialUserEntity();
mockEntity.setId(UUID.fromString("64145afc-9d69-4ee4-9db0-c70a4e142d28"));
doReturn(mockEntity).when(dataService).getOfficialById(mockEntity.getId());
doReturn(mockEntity).when(dataService).save(any());
OfficialUser mockDomain = new OfficialUser();
mockDomain.setFirstName("anthon");
mockDomain.setLastName("higgings");
mockDomain.setId(mockEntity.getId());
doReturn(mockDomain).when(composeService).composeDomain(any());
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS.name()));
verifyDeleteOfficialUsersIsAllowed(requestMetaDTO);
}
@Test
void deleteOfficialUsers_shouldBeDenied_when_invalidPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null,
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_REPRESENTATIVES.name()));
verifyDeleteOfficialUsersAccessIsDenied(requestMetaDTO);
}
@Test
void deleteOfficialUsers_shouldBeDenied_when_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null,
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), PERSON, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS.name()));
verifyDeleteOfficialUsersAccessIsDenied(requestMetaDTO);
}
......@@ -117,21 +134,21 @@ class OfficialsListenerPrivilegesTest extends OfficialsAppTestBase {
//UPDATE OFFICIAL USER
@Test
void updateOfficialUsers_shouldBeAllowed_if_correctPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null,
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS.name()));
verifyUpdateOfficialUsersIsAllowed(requestMetaDTO);
}
@Test
void updateOfficialUsers_shouldBeDenied_when_invalidPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null,
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), OFFICIAL_USER, null,
of(RolePrivilegeCode.EX_MANAGE_REPRESENTATIVES.name()));
verifyUpdateOfficialUsersAccessIsDenied(requestMetaDTO);
}
@Test
void updateOfficialUsers_shouldBeDenied_when_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null,
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), PERSON, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS.name()));
verifyUpdateOfficialUsersAccessIsDenied(requestMetaDTO);