Commit ebdc38d1 authored by Enriko Käsper's avatar Enriko Käsper
Browse files

Merge branch 'develop' into 'master'

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

See merge request teis/classifiers-service!60
parents 1dc79171 a48185de
# classifiers-service
# Classifiers service
Klassifikaatorite teenus
\ No newline at end of file
Classifiers service is a microservice which provides classifier management for TeIS application users.
## Features
Classifiers service is a Spring Boot application providing the following functionality:
* classifiers management
## Requirements
* [OpenJDK 11](https://openjdk.java.net/projects/jdk/11/)
* [Rabbit MQ](https://www.rabbitmq.com/)
* [PostgreSQL](https://www.postgresql.org/)
See [how to run required dependencies](../../docs/blob/master/run-requirements.md).
Classifiers service depends on other TeIS libraries:
* [TeIS Gradle plugin](../../teis-gradle-plugin)
* [TeIS public commons libraries](../../commons-public)
* [TeIS commons libraries](../../commons)
* [TeIS common API gateway library](../../common-api-gateway)
* [TeIS office API gateway library](../../office-api-gateway)
* [TeIS scheduler service libraries](../../scheduler-service)
## Run application
Spring Boot project can be run directly from [ClassifierServiceApp.main()](service/src/main/java/ee/sm/ti/teis/ClassifierServiceApp.java)
method or via executable jar file. More info on running Spring applications:
[running your application.](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html)
Visit [how to run application](../../docs/blob/master/run-application.md).
## Build and configure
Visit [how to build](../../docs/blob/master/build-configure.md) for more info.
## Default profiles
Visit [environment profiles](../../docs/blob/master/default-profiles.md) for more info.
## Tests
Run [integration](service/src/integTest) and [unit tests](service/src/test) via IDE or with Gradle in command line:
```jshelllanguage
./gradlew test
```
\ No newline at end of file
......@@ -61,18 +61,5 @@ allprojects {
compile "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
compile "ee.sm.ti.teis:scheduler-service-lib:${schedulerVersion}"
compile "ee.sm.ti.teis:office-api-gateway-lib:${officeApiGatewayVersion}"
compile("com.querydsl:querydsl-core:${querydslVersion}")
compile("com.querydsl:querydsl-jpa:${querydslVersion}")
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
annotationProcessor(
"org.mapstruct:mapstruct-processor:${mapstructVersion}",
"com.querydsl:querydsl-apt:${querydslVersion}:jpa",
"org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
"javax.annotation:javax.annotation-api:1.3.2",
)
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
}
}
theGroup=ee.sm.ti.teis
theVersion=1.11.0
theVersion=1.12.0
commonsVersion=1.10.0
commonApiGatewayVersion=1.11.0
officeApiGatewayVersion=1.11.0
......
......@@ -18,7 +18,20 @@ dependencies {
compile "org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter-webapp:3.2.1"
// Misc
compile 'org.apache.commons:commons-lang3:3.8.1'
compile("com.querydsl:querydsl-core:${querydslVersion}")
compile("com.querydsl:querydsl-jpa:${querydslVersion}")
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
annotationProcessor(
"org.mapstruct:mapstruct-processor:${mapstructVersion}",
"com.querydsl:querydsl-apt:${querydslVersion}:jpa",
"org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
"javax.annotation:javax.annotation-api:1.3.2",
)
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
}
// Define the main class for the application
mainClassName = 'ee.sm.ti.teis.classifiers.App'
mainClassName = 'ee.sm.ti.teis.App'
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;
......@@ -13,9 +11,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 = ClassifierServiceApp.class)
@ActiveProfiles("integtest")
......@@ -42,17 +37,4 @@ public abstract class ClassifierTestBase {
}
}
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;
}
}
......@@ -7,19 +7,24 @@ import ee.sm.ti.teis.officegateway.classifiers.dto.ClassifierAttributeValueDto;
import ee.sm.ti.teis.officegateway.classifiers.request.CreateClassifierAttributesRequest;
import ee.sm.ti.teis.officegateway.classifiers.response.CreateClassifierAttributesResponse;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.RolePrivilegeCode;
import org.junit.jupiter.api.Test;
import javax.inject.Inject;
import java.util.List;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_CLASSIFIERS;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("squid:S00100")
class ClassifierAttributesOfficeListenerTest extends ClassifierTestBase {
private static final String CLASSIFIER_ATTRIBUTE_DEFINITION_ID_2 = "TEST_ATTRIBUTE_DEFINITION2";
private static final String USER_ID = "c5d7ab7d-182c-47d3-828a-5b7447b3584f";
private static final String CLASSIFIER_ITEM_ID = "TEST_EDITABLENONHIERARCHICAL__TEST001";
private static final String CLASSIFIER_ATTRIBUTE_DEFINITION_ID = "TEST_ATTRIBUTE_DEFINITION";
@Inject
ClassifierAttributesOfficeListener listener;
......@@ -27,25 +32,25 @@ class ClassifierAttributesOfficeListenerTest extends ClassifierTestBase {
@Test
void createAttribute_success() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
ClassifierAttributeValueDto payload = ClassifierAttributeValueDto.builder()
.classifierItemId("TEST_EDITABLENONHIERARCHICAL__TEST001")
.classifierAttributeDefinitionId("TEST_ATTRIBUTE_DEFINITION")
.classifierItemId(CLASSIFIER_ITEM_ID)
.classifierAttributeDefinitionId(CLASSIFIER_ATTRIBUTE_DEFINITION_ID)
.build();
request.setPayload(List.of(payload), requestMetaDTO);
CreateClassifierAttributesResponse response = listener.create(request);
assertThat(response.getPayload().get(0).getValue()).isNull();
assertThat(response.getPayload().get(0).getClassifierAttributeDefinitionId()).isEqualTo("TEST_ATTRIBUTE_DEFINITION");
assertThat(response.getPayload().get(0).getClassifierAttributeDefinitionId()).isEqualTo(CLASSIFIER_ATTRIBUTE_DEFINITION_ID);
}
@Test
void createAttribute__not_same_definition() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
ClassifierAttributeValueDto payload = ClassifierAttributeValueDto.builder()
.classifierItemId("INSPECTION_DOCUMENT__001")
.classifierAttributeDefinitionId("TEST_ATTRIBUTE_DEFINITION")
.classifierAttributeDefinitionId(CLASSIFIER_ATTRIBUTE_DEFINITION_ID)
.build();
request.setPayload(List.of(payload), requestMetaDTO);
CreateClassifierAttributesResponse response = listener.create(request);
......@@ -54,8 +59,8 @@ class ClassifierAttributesOfficeListenerTest extends ClassifierTestBase {
@Test
void createAttribute__not_editable() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
ClassifierAttributeValueDto payload = ClassifierAttributeValueDto.builder()
.classifierItemId("COUNTRY__AF")
.classifierAttributeDefinitionId("COUNTRY")
......@@ -65,14 +70,13 @@ class ClassifierAttributesOfficeListenerTest extends ClassifierTestBase {
assertThat(response.getError().getCode()).isEqualTo(ClassifierErrorCode.CLASSIFIERS_1001.getCode());
}
@Test
void createAttribute_missing_value() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
ClassifierAttributeValueDto payload = ClassifierAttributeValueDto.builder()
.classifierItemId("TEST_EDITABLENONHIERARCHICAL__TEST001")
.classifierAttributeDefinitionId("TEST_ATTRIBUTE_DEFINITION2")
.classifierItemId(CLASSIFIER_ITEM_ID)
.classifierAttributeDefinitionId(CLASSIFIER_ATTRIBUTE_DEFINITION_ID_2)
.build();
request.setPayload(List.of(payload), requestMetaDTO);
CreateClassifierAttributesResponse response = listener.create(request);
......@@ -81,11 +85,11 @@ class ClassifierAttributesOfficeListenerTest extends ClassifierTestBase {
@Test
void createAttribute_incorrect_boolean_value() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
ClassifierAttributeValueDto payload = ClassifierAttributeValueDto.builder()
.classifierItemId("TEST_EDITABLENONHIERARCHICAL__TEST001")
.classifierAttributeDefinitionId("TEST_ATTRIBUTE_DEFINITION2")
.classifierItemId(CLASSIFIER_ITEM_ID)
.classifierAttributeDefinitionId(CLASSIFIER_ATTRIBUTE_DEFINITION_ID_2)
.value("janesed")
.build();
request.setPayload(List.of(payload), requestMetaDTO);
......@@ -95,10 +99,10 @@ class ClassifierAttributesOfficeListenerTest extends ClassifierTestBase {
@Test
void createAttribute_incorrect_int_value() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
ClassifierAttributeValueDto payload = ClassifierAttributeValueDto.builder()
.classifierItemId("TEST_EDITABLENONHIERARCHICAL__TEST001")
.classifierItemId(CLASSIFIER_ITEM_ID)
.classifierAttributeDefinitionId("TEST_ATTRIBUTE_DEFINITION3")
.value("12.5")
.build();
......@@ -109,10 +113,10 @@ class ClassifierAttributesOfficeListenerTest extends ClassifierTestBase {
@Test
void createAttribute_incorrect_double_value() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
ClassifierAttributeValueDto payload = ClassifierAttributeValueDto.builder()
.classifierItemId("TEST_EDITABLENONHIERARCHICAL__TEST001")
.classifierItemId(CLASSIFIER_ITEM_ID)
.classifierAttributeDefinitionId("TEST_ATTRIBUTE_DEFINITION4")
.value("12.353a")
.build();
......@@ -123,16 +127,16 @@ class ClassifierAttributesOfficeListenerTest extends ClassifierTestBase {
@Test
void createAttribute_correct_boolean_value() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
ClassifierAttributeValueDto payload = ClassifierAttributeValueDto.builder()
.classifierItemId("TEST_EDITABLENONHIERARCHICAL__TEST001")
.classifierAttributeDefinitionId("TEST_ATTRIBUTE_DEFINITION2")
.classifierItemId(CLASSIFIER_ITEM_ID)
.classifierAttributeDefinitionId(CLASSIFIER_ATTRIBUTE_DEFINITION_ID_2)
.value("FaLse")
.build();
request.setPayload(List.of(payload), requestMetaDTO);
CreateClassifierAttributesResponse response = listener.create(request);
assertThat(response.getPayload().get(0).getValue()).isEqualTo("FaLse");
assertThat(response.getPayload().get(0).getClassifierAttributeDefinitionId()).isEqualTo("TEST_ATTRIBUTE_DEFINITION2");
assertThat(response.getPayload().get(0).getClassifierAttributeDefinitionId()).isEqualTo(CLASSIFIER_ATTRIBUTE_DEFINITION_ID_2);
}
}
......@@ -22,8 +22,8 @@ import javax.inject.Inject;
import java.util.List;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseForbidden;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseNotFound;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_CLASSIFIERS;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -36,12 +36,14 @@ class ClassifierDefinitionGwListenerTest extends ClassifierTestBase {
RequestMetaDTO requestMetaDTO;
ClassifierDefinitionRequest request = new ClassifierDefinitionRequest();
ClassifierDefinitionsOfficeRequest definitionsOfficeRequest = new ClassifierDefinitionsOfficeRequest();
ClassifierDefinitionOfficeRequest definitionOfficeRequest = new ClassifierDefinitionOfficeRequest();
PatchClassifierDefinitionOfficeRequest patchRequest = new PatchClassifierDefinitionOfficeRequest();
ClassifierDefinitionRequest.Parameters payload = new ClassifierDefinitionRequest.Parameters();
@Test
void patchDefinition_success() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
PatchClassifierDefinitionDto patchDto = PatchClassifierDefinitionDto.builder().defaultValue("TEST001").id("TEST_EDITABLENONHIERARCHICAL").build();
patchRequest.setPayload(patchDto, requestMetaDTO);
PatchClassifierDefinitionOfficeResponse response = classifierDefinitionListener.patchClassifierDefinition(patchRequest);
......@@ -50,7 +52,7 @@ class ClassifierDefinitionGwListenerTest extends ClassifierTestBase {
@Test
void patchDefinition_remove_default_value_success() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
PatchClassifierDefinitionDto patchDto = PatchClassifierDefinitionDto.builder().id("TEST_EDITABLEHIERARCHICAL_2").build();
patchRequest.setPayload(patchDto, requestMetaDTO);
PatchClassifierDefinitionOfficeResponse response = classifierDefinitionListener.patchClassifierDefinition(patchRequest);
......@@ -59,7 +61,7 @@ class ClassifierDefinitionGwListenerTest extends ClassifierTestBase {
@Test
void patchDefinition_not_editable() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
PatchClassifierDefinitionDto patchDto = PatchClassifierDefinitionDto.builder().id("TEST_NONHIERARCHICAL").build();
patchRequest.setPayload(patchDto, requestMetaDTO);
PatchClassifierDefinitionOfficeResponse response = classifierDefinitionListener.patchClassifierDefinition(patchRequest);
......@@ -69,45 +71,40 @@ class ClassifierDefinitionGwListenerTest extends ClassifierTestBase {
@Test
void getGwDefinitions_missingPrivilege() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), emptyList());
ClassifierDefinitionsOfficeRequest request = new ClassifierDefinitionsOfficeRequest();
request.setRequestMetaDTO(requestMetaDTO);
ClassifierDefinitionsOfficeResponse response = classifierDefinitionListener.getClassifierDefinitions(request);
definitionsOfficeRequest.setRequestMetaDTO(requestMetaDTO);
ClassifierDefinitionsOfficeResponse response = classifierDefinitionListener.getClassifierDefinitions(definitionsOfficeRequest);
assertResponseForbidden(response.getError());
}
@Test
void getGwDefinitions_success() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
ClassifierDefinitionsOfficeRequest request = new ClassifierDefinitionsOfficeRequest();
request.setRequestMetaDTO(requestMetaDTO);
ClassifierDefinitionsOfficeResponse response = classifierDefinitionListener.getClassifierDefinitions(request);
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(TI_MANAGE_CLASSIFIERS.name()));
definitionsOfficeRequest.setRequestMetaDTO(requestMetaDTO);
ClassifierDefinitionsOfficeResponse response = classifierDefinitionListener.getClassifierDefinitions(definitionsOfficeRequest);
assertThat(response.getPayload().size()).isGreaterThan(1);
}
@Test
void getGwDefinition_success() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
ClassifierDefinitionOfficeRequest request = new ClassifierDefinitionOfficeRequest();
request.setPayload(new ClassifierDefinitionOfficeRequest.Parameters("COUNTRY"), requestMetaDTO);
ClassifierDefinitionOfficeResponse response = classifierDefinitionListener.getClassifierDefinition(request);
definitionOfficeRequest.setPayload(new ClassifierDefinitionOfficeRequest.Parameters("COUNTRY"), requestMetaDTO);
ClassifierDefinitionOfficeResponse response = classifierDefinitionListener.getClassifierDefinition(definitionOfficeRequest);
assertThat(response.getPayload().getName()).isEqualTo("Riigid");
}
@Test
void getGwDefinition_badRequest() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
ClassifierDefinitionOfficeRequest request = new ClassifierDefinitionOfficeRequest();
request.setPayload(new ClassifierDefinitionOfficeRequest.Parameters("JANESED"), requestMetaDTO);
ClassifierDefinitionOfficeResponse response = classifierDefinitionListener.getClassifierDefinition(request);
definitionOfficeRequest.setPayload(new ClassifierDefinitionOfficeRequest.Parameters("JANESED"), requestMetaDTO);
ClassifierDefinitionOfficeResponse response = classifierDefinitionListener.getClassifierDefinition(definitionOfficeRequest);
assertResponseNotFound(response.getError());
}
@Test
void getGwDefinition_forbidden() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(RolePrivilegeCode.TI_CHANGE_PROCEEDING_DATES.name()));
ClassifierDefinitionOfficeRequest request = new ClassifierDefinitionOfficeRequest();
request.setPayload(new ClassifierDefinitionOfficeRequest.Parameters("JANESED"), requestMetaDTO);
ClassifierDefinitionOfficeResponse response = classifierDefinitionListener.getClassifierDefinition(request);
definitionOfficeRequest.setPayload(new ClassifierDefinitionOfficeRequest.Parameters("JANESED"), requestMetaDTO);
ClassifierDefinitionOfficeResponse response = classifierDefinitionListener.getClassifierDefinition(definitionOfficeRequest);
assertResponseForbidden(response.getError());
}
......
......@@ -22,6 +22,7 @@ import java.util.Optional;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.Collections.emptyList;
import static java.util.List.of;
import static java.util.UUID.randomUUID;
......
......@@ -19,12 +19,15 @@ import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("squid:S00100")
class ClassifierItemLinkOfficeListenerTest extends ClassifierTestBase {
private static final String USER_ID = "c5d7ab7d-182c-47d3-828a-5b7447b3584f";
private static final String TEST_EDITABLENONHIERARCHICAL__TEST_003 = "TEST_EDITABLENONHIERARCHICAL__TEST003";
@Inject
ClassifierItemLinkOfficeListener itemLinkOfficeListener;
......@@ -34,70 +37,66 @@ class ClassifierItemLinkOfficeListenerTest extends ClassifierTestBase {
@Test
void createClassifierItemLink_success() {
ClassifierItemOfficeDto source = ClassifierItemOfficeDto.builder().id("TEST_EDITABLENONHIERARCHICAL__TEST001").build();
ClassifierItemOfficeDto target = ClassifierItemOfficeDto.builder().id("TEST_EDITABLENONHIERARCHICAL__TEST003").build();
ClassifierItemOfficeDto target = ClassifierItemOfficeDto.builder().id(TEST_EDITABLENONHIERARCHICAL__TEST_003).build();
ClassifierItemLinkOfficeDto link = ClassifierItemLinkOfficeDto.builder()
.sourceClassifierItem(source)
.targetClassifierItem(target)
.build();
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
request.setPayload(link, requestMetaDTO);
CreateClassifierItemLinkResponse response = itemLinkOfficeListener.create(request);
assertThat(response.getPayload().getSourceClassifierItem().getId()).isEqualTo("TEST_EDITABLENONHIERARCHICAL__TEST001");
assertThat(response.getPayload().getTargetClassifierItem().getId()).isEqualTo("TEST_EDITABLENONHIERARCHICAL__TEST003");
assertThat(response.getPayload().getTargetClassifierItem().getId()).isEqualTo(TEST_EDITABLENONHIERARCHICAL__TEST_003);
}
@Test
void createClassifierItemLink_not_editable() {
ClassifierItemOfficeDto source = ClassifierItemOfficeDto.builder().id("CREATOR_TYPE__OFFICIAL").build();
ClassifierItemOfficeDto target = ClassifierItemOfficeDto.builder().id("TEST_EDITABLENONHIERARCHICAL__TEST003").build();
ClassifierItemOfficeDto target = ClassifierItemOfficeDto.builder().id(TEST_EDITABLENONHIERARCHICAL__TEST_003).build();
ClassifierItemLinkOfficeDto link = ClassifierItemLinkOfficeDto.builder()
.sourceClassifierItem(source)
.targetClassifierItem(target)
.build();
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
request.setPayload(link, requestMetaDTO);
CreateClassifierItemLinkResponse response = itemLinkOfficeListener.create(request);
assertThat(response.getError().getCode()).isEqualTo(ClassifierErrorCode.CLASSIFIERS_1001.getCode());
}
@Test
void deleteClassifierItemLink_success() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
deleteRequest.setPayload(UUID.fromString("1ab6dc2c-22b5-4cb3-a570-9a108a522a74"), requestMetaDTO);
DeleteClassifierItemLinkResponse response = itemLinkOfficeListener.delete(deleteRequest);
assertThat(response.getError()).isNull();
}
@Test
void deleteClassifierItemLink_not_found() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
deleteRequest.setPayload(UUID.fromString("1ab6dc2c-22b5-4cb3-a530-9a128a522a74"), requestMetaDTO);
DeleteClassifierItemLinkResponse response = itemLinkOfficeListener.delete(deleteRequest);
assertThat(response.getError().getCode()).isEqualTo(CommonErrorCode.RESOURCE_NOT_FOUND.getCode());
}
@Test
void deleteClassifierItemLink_not_editable() {
RequestMetaDTO requestMetaDTO = createRequestMeta("c5d7ab7d-182c-47d3-828a-5b7447b3584f", OFFICIAL_USER,
RequestMetaDTO requestMetaDTO = createRequestMeta(USER_ID, OFFICIAL_USER,
randomUUID().toString(), List.of(RolePrivilegeCode.TI_MANAGE_CLASSIFIERS.name()));
deleteRequest.setPayload(UUID.fromString("dd68d8cd-1a36-476a-bfbf-dbfe8b828586"), requestMetaDTO);
DeleteClassifierItemLinkResponse response = itemLinkOfficeListener.delete(deleteRequest);
assertThat(response.getError().getCode()).isEqualTo(ClassifierErrorCode.CLASSIFIERS_1001.getCode());
}
}
......@@ -13,7 +13,6 @@ import static ee.sm.ti.teis.classifiers.rabbit.QueueConfig.ClassifierItemDomainR
import static ee.sm.ti.teis.classifiers.rabbit.QueueConfig.ClassifierItemsDomainRequest;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("squid:S00100")
class ClassifierItemsMsListenerTest extends ClassifierTestBase {
public static final String CLASSIFIER_DEFINITION_COUNTRY = "COUNTRY";
......
......@@ -27,10 +27,10 @@ import java.util.List;
import java.util.Optional;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("squid:S00100")
class ClassifierItemsOfficeListenerTest extends ClassifierTestBase {
@Inject
......
......@@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SuppressWarnings("squid:S00100")
class ClassifierItemsPublicListenerTest extends ClassifierTestBase {
public static final String CLASSIFIER_DEFINITION_COUNTRY = "COUNTRY";
......
......@@ -12,7 +12,6 @@ import java.util.List;
@Component
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
@SuppressWarnings("squid:S1610")
public interface ClassifierAttributeMapper {
......
......@@ -10,7 +10,6 @@ import java.util.List;
@Component
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
@SuppressWarnings("squid:S1610")
public interface ClassifierDefinitionMapper {
ClassifierDefinition toDomain(ClassifierDefinitionEntity classifierdefinitionEntity);
......
......@@ -6,11 +6,7 @@ import ee.sm.ti.teis.commongateway.classifier.ClassifierItemDto;
import ee.sm.ti.teis.domain.ClassifierAttributeLight;
import ee.sm.ti.teis.domain.ClassifierItem;
import ee.sm.ti.teis.officegateway.classifiers.dto.ClassifierItemOfficeDto;
import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;