Commit 05ca2944 authored by handolukats's avatar handolukats
Browse files

Merge remote-tracking branch 'origin/develop' into develop

parents cb942f6e 40276204
theGroup=ee.sm.ti.teis
theVersion=0.1.0-SNAPSHOT
commonsVersion=0.16.1-SNAPSHOT
officeApiGatewayVersion=0.3.30-SNAPSHOT
officeApiGatewayVersion=0.3.33-SNAPSHOT
pluginVersion=0.0.18-SNAPSHOT
mapstructVersion=1.3.0.Final
querydslVersion=4.1.3
package ee.sm.ti.teis.officials.emtak;
import ee.sm.ti.teis.errors.CommonErrorCode;
import ee.sm.ti.teis.officegateway.official.CreateOfficialsGroupEmtakCodesRequest;
import ee.sm.ti.teis.officegateway.official.CreateOfficialsGroupEmtakCodesResponse;
import ee.sm.ti.teis.officegateway.official.DeleteOfficialsGroupEmtakRequest;
import ee.sm.ti.teis.officegateway.official.DeleteOfficialsGroupEmtakResponse;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupEmtakCodesData;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupEmtakCodesRequest;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupEmtakCodesResponse;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupEmtakDto;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.errors.CommonErrorCode;
import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupEmtakCodesData;
import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupEmtakDto;
import ee.sm.ti.teis.officegateway.official.request.CreateOfficialsGroupEmtakCodesRequest;
import ee.sm.ti.teis.officegateway.official.request.DeleteOfficialsGroupEmtakRequest;
import ee.sm.ti.teis.officegateway.official.request.OfficialsGroupEmtakCodesRequest;
import ee.sm.ti.teis.officegateway.official.response.CreateOfficialsGroupEmtakCodesResponse;
import ee.sm.ti.teis.officegateway.official.response.DeleteOfficialsGroupEmtakResponse;
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;
......@@ -29,6 +29,7 @@ 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 String STATUS_CURRENT = "CURRENT";
@Autowired
OfficialsGroupEmtakListener listener;
......@@ -43,7 +44,7 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
@Test
void findEmtakCodes_test() {
OfficialsGroupEmtakCodesRequest request = composeGroupEmtakCodesRequest(CORRECT_GROUP_ID, "0113", "CURRENT");
OfficialsGroupEmtakCodesRequest request = composeGroupEmtakCodesRequest(CORRECT_GROUP_ID, "0113", STATUS_CURRENT);
OfficialsGroupEmtakCodesResponse response = listener.findOfficialsGroupEmtakCodes(request);
......@@ -53,7 +54,7 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
@Test
void findEmtakCodes_user_must_have_privileges() {
requestMetaDTO.setPrivileges(Collections.emptyList());
OfficialsGroupEmtakCodesRequest request = composeGroupEmtakCodesRequest(CORRECT_GROUP_ID, "0113", "CURRENT");
OfficialsGroupEmtakCodesRequest request = composeGroupEmtakCodesRequest(CORRECT_GROUP_ID, "0113", STATUS_CURRENT);
OfficialsGroupEmtakCodesResponse response = listener.findOfficialsGroupEmtakCodes(request);
......@@ -62,15 +63,15 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
@Test
void findEmtakCodes_validates_input_params() {
OfficialsGroupEmtakCodesRequest request = composeGroupEmtakCodesRequest(null, null, "CURRENT");
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, "CURRENT");
request = composeGroupEmtakCodesRequest("ss", null, STATUS_CURRENT);
response = listener.findOfficialsGroupEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.BAD_REQUEST.getCode());
request = composeGroupEmtakCodesRequest(INCORRECT_GROUP_ID, null, "CURRENT");
request = composeGroupEmtakCodesRequest(INCORRECT_GROUP_ID, null, STATUS_CURRENT);
response = listener.findOfficialsGroupEmtakCodes(request);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.RESOURCE_NOT_FOUND.getCode());
}
......@@ -138,7 +139,7 @@ class OfficialsGroupEmtakListenerTest extends OfficialsAppTestBase {
@Test
void createEmtakCodes_dont_make_duplicate_entries() {
OfficialsGroupEmtakCodesRequest findRequest = composeGroupEmtakCodesRequest(CORRECT_GROUP_ID, "0113", "CURRENT");
OfficialsGroupEmtakCodesRequest findRequest = composeGroupEmtakCodesRequest(CORRECT_GROUP_ID, "0113", STATUS_CURRENT);
final OfficialsGroupEmtakDto existingGroupEmtak = listener.findOfficialsGroupEmtakCodes(findRequest).getPayload().get(0);
CreateOfficialsGroupEmtakCodesRequest request = composeCreateGroupEmtakCodesRequest(CORRECT_GROUP_ID, List.of("0113"));
......
package ee.sm.ti.teis.officials.group;
import ee.sm.ti.teis.errors.CommonErrorCode;
import ee.sm.ti.teis.officegateway.official.CreateOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.CreateOfficialsGroupResponse;
import ee.sm.ti.teis.officegateway.official.DeleteOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.DeleteOfficialsGroupResponse;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupDto;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupsRequest;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupsResponse;
import ee.sm.ti.teis.officegateway.official.UpdateOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.UpdateOfficialsGroupResponse;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.errors.CommonErrorCode;
import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupDto;
import ee.sm.ti.teis.officegateway.official.request.CreateOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.request.DeleteOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.request.OfficialsGroupsRequest;
import ee.sm.ti.teis.officegateway.official.request.UpdateOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.response.CreateOfficialsGroupResponse;
import ee.sm.ti.teis.officegateway.official.response.DeleteOfficialsGroupResponse;
import ee.sm.ti.teis.officegateway.official.response.OfficialsGroupsResponse;
import ee.sm.ti.teis.officegateway.official.response.UpdateOfficialsGroupResponse;
import ee.sm.ti.teis.officials.group.listener.OfficialsGroupGwListener;
import ee.sm.ti.teis.officials.group.service.OfficialsGroupService;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
import ee.sm.ti.teis.types.enums.ObjectStatus;
......@@ -28,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
public class OfficialsGroupListenerPrivilegesTest extends OfficialsAppTestBase {
class OfficialsGroupListenerPrivilegesTest extends OfficialsAppTestBase {
@Autowired
......@@ -52,14 +54,14 @@ public class OfficialsGroupListenerPrivilegesTest extends OfficialsAppTestBase {
//FIND OFFICIALS GROUPS
@Test
public void findOfficialGroups_shouldBeAllowed_if_officialUser() {
void findOfficialGroups_shouldBeAllowed_if_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS_GROUPS.name()));
verifyFindOfficialsGroupsIsAllowed(requestMetaDTO);
}
@Test
public void findOfficialGroups_shouldBeDenied_if_notOfficialuser() {
void findOfficialGroups_shouldBeDenied_if_notOfficialuser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.PERSON, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS_GROUPS.name()));
verifyFindOfficialsGroupsAccessIsDenied(requestMetaDTO);
......@@ -67,21 +69,21 @@ public class OfficialsGroupListenerPrivilegesTest extends OfficialsAppTestBase {
//CREATE OFFICIALS GROUP
@Test
public void createOfficialGroups_shouldBeAllowed_if_correctPrivileges() {
void createOfficialGroups_shouldBeAllowed_if_correctPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS_GROUPS.name()));
verifyCreateOfficialsGroupsIsAllowed(requestMetaDTO);
}
@Test
public void createOfficialGroups_shouldBeDenied_if_wrongPrivileges() {
void createOfficialGroups_shouldBeDenied_if_wrongPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_REPRESENTATIVES.name()));
verifyCreateOfficialsGroupsAccessIsDenied(requestMetaDTO);
}
@Test
public void createOfficialGroup_shouldBeDenied_if_not_officialUser() {
void createOfficialGroup_shouldBeDenied_if_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.PERSON, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS_GROUPS.name()));
verifyCreateOfficialsGroupsAccessIsDenied(requestMetaDTO);
......@@ -89,21 +91,21 @@ public class OfficialsGroupListenerPrivilegesTest extends OfficialsAppTestBase {
//UPDATE OFFICIALS GROUP
@Test
public void updateOfficialGroup_shouldBeAllowed_if_correctPrivileges() {
void updateOfficialGroup_shouldBeAllowed_if_correctPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS_GROUPS.name()));
verifyUpdateOfficialsGroupsIsAllowed(requestMetaDTO);
}
@Test
public void updateOfficialGroup_shouldBeDenied_if_wrongPrivileges() {
void updateOfficialGroup_shouldBeDenied_if_wrongPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_REPRESENTATIVES.name()));
verifyUpdateOfficialsGroupsAccessIsDenied(requestMetaDTO);
}
@Test
public void updateOfficialGroup_shouldBeDenied_if_not_officialUser() {
void updateOfficialGroup_shouldBeDenied_if_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.PERSON, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS_GROUPS.name()));
verifyUpdateOfficialsGroupsAccessIsDenied(requestMetaDTO);
......@@ -111,21 +113,21 @@ public class OfficialsGroupListenerPrivilegesTest extends OfficialsAppTestBase {
//DELETE OFFICIALS GROUP
@Test
public void deleteOfficialGroup_shouldBeAllowed_if_correctPrivileges() {
void deleteOfficialGroup_shouldBeAllowed_if_correctPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS_GROUPS.name()));
verifyDeleteOfficialsGroupsIsAllowed(requestMetaDTO);
}
@Test
public void deleteOfficialGroup_shouldBeDenied_if_wrongPrivileges() {
void deleteOfficialGroup_shouldBeDenied_if_wrongPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_REPRESENTATIVES.name()));
verifyDeleteOfficialsGroupsAccessIsDenied(requestMetaDTO);
}
@Test
public void deleteOfficialGroup_shouldBeDenied_if_not_officialUser() {
void deleteOfficialGroup_shouldBeDenied_if_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.PERSON, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS_GROUPS.name()));
verifyDeleteOfficialsGroupsAccessIsDenied(requestMetaDTO);
......
package ee.sm.ti.teis.officials.group;
import ee.sm.ti.teis.officegateway.official.CreateOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.CreateOfficialsGroupResponse;
import ee.sm.ti.teis.officegateway.official.DeleteOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.OfficialUserDto;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupDto;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupsRequest;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupsResponse;
import ee.sm.ti.teis.officegateway.official.UpdateOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.UpdateOfficialsGroupResponse;
package ee.sm.ti.teis.officials.group.listener;
import ee.sm.ti.teis.OfficialsAppTestBase;
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.CreateOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.request.DeleteOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.request.OfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.request.OfficialsGroupsRequest;
import ee.sm.ti.teis.officegateway.official.request.UpdateOfficialsGroupRequest;
import ee.sm.ti.teis.officegateway.official.response.CreateOfficialsGroupResponse;
import ee.sm.ti.teis.officegateway.official.response.OfficialsGroupResponse;
import ee.sm.ti.teis.officegateway.official.response.OfficialsGroupsResponse;
import ee.sm.ti.teis.officegateway.official.response.UpdateOfficialsGroupResponse;
import ee.sm.ti.teis.officials.group.OfficialsGroupRepository;
import ee.sm.ti.teis.officials.official.OfficialUserRepository;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
......@@ -22,12 +25,15 @@ import org.springframework.http.HttpStatus;
import javax.transaction.Transactional;
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 java.util.Set.of;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.HttpStatus.NOT_FOUND;
@SuppressWarnings("squid:S00100")
@Transactional
class OfficialsGroupListenerTest extends OfficialsAppTestBase {
class OfficialsGroupGwListenerTest extends OfficialsAppTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().userId(UUID.randomUUID().toString()).privileges(of("TI_MANAGE_OFFICIALS_GROUPS")).userType(UserType.OFFICIAL_USER).requestId(UUID.randomUUID().toString()).build();
private static final UUID ADMIN_GROUP_ID = UUID.fromString("68b5b265-9427-457f-8f16-0bd5cf608714");
......@@ -47,7 +53,7 @@ class OfficialsGroupListenerTest extends OfficialsAppTestBase {
OfficialsGroupsResponse response = groupListener.findOfficialsGroups(request);
assertThat(response.getPayload().stream().allMatch(g -> g.getObjectStatus() == ObjectStatus.CURRENT)).isTrue();
assertThat(response.getPayload().stream().allMatch(g -> g.getObjectStatus() == CURRENT)).isTrue();
}
@Test
......@@ -59,6 +65,69 @@ class OfficialsGroupListenerTest extends OfficialsAppTestBase {
assertThat(response.getPayload().stream().anyMatch(g -> g.getObjectStatus() == ObjectStatus.DELETED)).isTrue();
}
@Test
void findOfficialGroup_success() {
OfficialsGroupRequest request = new OfficialsGroupRequest();
OfficialsGroupRequest.Parameters payload = new OfficialsGroupRequest.Parameters();
payload.setId("017b41a4-1871-4e00-9a36-cd27adbc1f5a");
request.setPayload(payload, REQUEST_META_DTO);
OfficialsGroupResponse response = groupListener.findOfficialsGroup(request);
OfficialsGroupDto responseDto = response.getPayload();
assertThat(responseDto.getId()).isEqualTo(UUID.fromString("017b41a4-1871-4e00-9a36-cd27adbc1f5a"));
assertThat(responseDto.getName()).isEqualTo("Valdkonnas pole managerit");
assertThat(responseDto.getObjectStatus()).isEqualTo(CURRENT);
}
@Test
void findOfficialGroup_hasOfficialGroupManager_success() {
OfficialsGroupRequest request = new OfficialsGroupRequest();
OfficialsGroupRequest.Parameters payload = new OfficialsGroupRequest.Parameters();
payload.setId("706bc212-ac68-4160-9c4b-7497a2de3430");
request.setPayload(payload, REQUEST_META_DTO);
OfficialsGroupResponse response = groupListener.findOfficialsGroup(request);
OfficialsGroupDto responseDto = response.getPayload();
assertThat(responseDto.getId()).isEqualTo(UUID.fromString("706bc212-ac68-4160-9c4b-7497a2de3430"));
assertThat(responseDto.getName()).isEqualTo("Automaattestide Group");
assertThat(responseDto.getObjectStatus()).isEqualTo(CURRENT);
assertThat(responseDto.getOfficialsGroupManager().getId()).isEqualTo(UUID.fromString("b429d838-758b-4ddd-b843-b6242675986f"));
assertThat(responseDto.getOfficialsGroupManager().getObjectStatus()).isEqualTo(CURRENT);
assertThat(responseDto.getOfficialsGroupManager().getFirstName()).isEqualTo("Neljas");
assertThat(responseDto.getOfficialsGroupManager().getIdCode()).isEqualTo("38802170149");
assertThat(responseDto.getOfficialsGroupManager().getLastName()).isEqualTo("Kasutaja");
}
@Test
void findOfficialGroup_statusDeleted_success() {
OfficialsGroupRequest request = new OfficialsGroupRequest();
OfficialsGroupRequest.Parameters payload = new OfficialsGroupRequest.Parameters();
payload.setId("c6bbd0d0-a614-408e-b22b-c60eed1a0dc9");
request.setPayload(payload, REQUEST_META_DTO);
OfficialsGroupResponse response = groupListener.findOfficialsGroup(request);
OfficialsGroupDto responseDto = response.getPayload();
assertThat(responseDto.getId()).isEqualTo(UUID.fromString("c6bbd0d0-a614-408e-b22b-c60eed1a0dc9"));
assertThat(responseDto.getName()).isEqualTo("Admin kasutajad (removed)");
assertThat(responseDto.getObjectStatus()).isEqualTo(DELETED);
}
@Test
void findOfficialGroup_notFound() {
OfficialsGroupRequest request = new OfficialsGroupRequest();
OfficialsGroupRequest.Parameters payload = new OfficialsGroupRequest.Parameters();
payload.setId(UUID.randomUUID().toString());
request.setPayload(payload, REQUEST_META_DTO);
OfficialsGroupResponse response = groupListener.findOfficialsGroup(request);
assertThat(response.getError().getCode()).isEqualTo("404");
assertThat(response.getError().getHttpResponse()).isEqualTo(NOT_FOUND);
}
@Test
void createOfficialsGroups_creates_group() {
String newGroupName = "New Group";
......@@ -67,7 +136,7 @@ class OfficialsGroupListenerTest extends OfficialsAppTestBase {
CreateOfficialsGroupResponse response = groupListener.createOfficialsGroup(request);
assertThat(response.getPayload().getName()).isEqualTo(newGroupName);
assertThat(response.getPayload().getObjectStatus()).isEqualTo(ObjectStatus.CURRENT);
assertThat(response.getPayload().getObjectStatus()).isEqualTo(CURRENT);
assertThat(response.getPayload().getOfficialsGroupManager().getId()).isEqualTo(ADMIN_USER_ID);
}
......
package ee.sm.ti.teis.officials.office;
import ee.sm.ti.teis.officegateway.official.OfficesRequest;
import ee.sm.ti.teis.officegateway.official.OfficesResponse;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.officegateway.official.request.OfficesRequest;
import ee.sm.ti.teis.officegateway.official.response.OfficesResponse;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
import org.assertj.core.api.Assertions;
......@@ -11,7 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.UUID;
public class OfficeGwListenerTest extends OfficialsAppTestBase {
class OfficeGwListenerTest extends OfficialsAppTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder()
.userId(UUID.randomUUID().toString())
......
package ee.sm.ti.teis.officials.official;
import ee.sm.ti.teis.errors.CommonErrorCode;
import ee.sm.ti.teis.officegateway.official.*;
import ee.sm.ti.teis.OfficialsAppTestBase;
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.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
import ee.sm.ti.teis.types.enums.RolePrivilegeCode;
......@@ -19,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
public class OfficialsListenerPrivilegesTest extends OfficialsAppTestBase {
class OfficialsListenerPrivilegesTest extends OfficialsAppTestBase {
private static final UUID OFFICIAL_ID = UUID.fromString("0bb3c0a5-f1bc-4c0d-8664-e94eec35c1c1");
......@@ -44,60 +55,60 @@ public class OfficialsListenerPrivilegesTest extends OfficialsAppTestBase {
//CREATE OFFICIAL USER
@Test
public void createOfficialUser_shouldBeAllowed_if_officialUser() {
void createOfficialUser_shouldBeAllowed_if_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null, null);
verifyCreateOfficialUserIsAllowed(requestMetaDTO);
}
@Test
public void createOfficialUser_shouldBeDenied_not_officialUser() {
void createOfficialUser_shouldBeDenied_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null, null);
verifyCreateOfficialUserAccessIsDenied(requestMetaDTO);
}
//FIND OFFICIAL USER
@Test
public void findOfficialUser_shouldBeAllowed_if_officialUser() {
void findOfficialUser_shouldBeAllowed_if_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null, null);
verifyFindOfficialUserIsAllowed(requestMetaDTO);
}
@Test
public void findOfficialUser_shouldBeDenied_not_officialUser() {
void findOfficialUser_shouldBeDenied_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null, null);
verifyFindOfficialUserAccessIsDenied(requestMetaDTO);
}
//FIND OFFICIAL USERs
@Test
public void findOfficialUsers_shouldBeAllowed_if_officialUser() {
void findOfficialUsers_shouldBeAllowed_if_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null, null);
verifyFindOfficialUsersIsAllowed(requestMetaDTO);
}
@Test
public void findOfficialUsers_shouldBeDenied_not_officialUser() {
void findOfficialUsers_shouldBeDenied_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null, null);
verifyFindOfficialUsersAccessIsDenied(requestMetaDTO);
}
//DELETE OFFICIAL USER
@Test
public void deleteOfficialUsers_shouldBeAllowed_if_correctPrivileges() {
void deleteOfficialUsers_shouldBeAllowed_if_correctPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS.name()));
verifyDeleteOfficialUsersIsAllowed(requestMetaDTO);
}
@Test
public void deleteOfficialUsers_shouldBeDenied_when_invalidPrivileges() {
void deleteOfficialUsers_shouldBeDenied_when_invalidPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_REPRESENTATIVES.name()));
verifyDeleteOfficialUsersAccessIsDenied(requestMetaDTO);
}
@Test
public void deleteOfficialUsers_shouldBeDenied_when_not_officialUser() {
void deleteOfficialUsers_shouldBeDenied_when_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS.name()));
verifyDeleteOfficialUsersAccessIsDenied(requestMetaDTO);
......@@ -105,21 +116,21 @@ public class OfficialsListenerPrivilegesTest extends OfficialsAppTestBase {
//UPDATE OFFICIAL USER
@Test
public void updateOfficialUsers_shouldBeAllowed_if_correctPrivileges() {
void updateOfficialUsers_shouldBeAllowed_if_correctPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS.name()));
verifyUpdateOfficialUsersIsAllowed(requestMetaDTO);
}
@Test
public void updateOfficialUsers_shouldBeDenied_when_invalidPrivileges() {
void updateOfficialUsers_shouldBeDenied_when_invalidPrivileges() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.OFFICIAL_USER, null,
of(RolePrivilegeCode.EX_MANAGE_REPRESENTATIVES.name()));
verifyUpdateOfficialUsersAccessIsDenied(requestMetaDTO);
}
@Test
public void updateOfficialUsers_shouldBeDenied_when_not_officialUser() {
void updateOfficialUsers_shouldBeDenied_when_not_officialUser() {
RequestMetaDTO requestMetaDTO = createRequestMeta(OFFICIAL_ID.toString(), UserType.PERSON, null,
of(RolePrivilegeCode.TI_MANAGE_OFFICIALS.name()));
verifyUpdateOfficialUsersAccessIsDenied(requestMetaDTO);
......
package ee.sm.ti.teis.officials.official;
import ee.sm.ti.teis.officegateway.official.*;
import ee.sm.ti.teis.OfficialsAppTestBase;
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.officials.group.OfficialsGroupRepository;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
......@@ -26,6 +37,7 @@ class OfficialsListenerTest extends OfficialsAppTestBase {
private static final String ACTIVE_USER_IDCODE = "38909120274";
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().userId(UUID.randomUUID().toString()).privileges(of("TI_MANAGE_OFFICIALS")).userType(UserType.OFFICIAL_USER).requestId(UUID.randomUUID().toString()).build();
private static final String ADMIN_USER_ID = "b5d59f3b-57af-4971-8110-51019e5e827d";
public static final String OFFICIAL_GROUP_ID = "ffb124d3-ce51-45e2-b8e5-343d11066998";
@Autowired
OfficialGwListener officialGwListener;
......@@ -33,7 +45,7 @@ class OfficialsListenerTest extends OfficialsAppTestBase {
OfficialsGroupRepository groupRepo;
@Test
void createOfficialUser_test() {
void createOfficialUser_test() {
OfficialUserDto newUser = OfficialUserDto.builder().firstName("First").lastName("Last").idCode("idCode").build();
CreateOfficialUserRequest request = new CreateOfficialUserRequest();
request.setRequestMetaDTO(RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build());
......@@ -48,7 +60,7 @@ class OfficialsListenerTest extends OfficialsAppTestBase {
}
@Test
void createOfficialUser_should_activate_existing_deleted_user() {
void createOfficialUser_should_activate_existing_deleted_user() {
OfficialUserRequest request = composeOfficialUserRequest(DELETED_USER_ID);
OfficialUserResponse existingUser = officialGwListener.findOfficialUser(request);
......@@ -66,7 +78,7 @@ class OfficialsListenerTest extends OfficialsAppTestBase {
}
@Test
void findOfficialUser() {
void findOfficialUser() {
OfficialUserRequest request = composeOfficialUserRequest(USER_ID);
OfficialUserResponse officialUser = officialGwListener.findOfficialUser(request);
......@@ -75,8 +87,8 @@ class OfficialsListenerTest extends OfficialsAppTestBase {
}
@Test
void findOfficialUsers_by_idCode() {
OfficialUsersRequest request = composeOfficialUsersRequest(ACTIVE_USER_IDCODE, "ffb124d3-ce51-45e2-b8e5-343d11066998", null);
void findOfficialUsers_by_idCode() {
OfficialUsersRequest request = composeOfficialUsersRequest(ACTIVE_USER_IDCODE, OFFICIAL_GROUP_ID, null);
OfficialUsersResponse officialUsers = officialGwListener.findOfficialUsers(request);