Commit 8a5e50e7 authored by Siiri Tann's avatar Siiri Tann
Browse files

Merge branch 'TEIS-3104' into 'develop'

TEIS-3104: new endpoint for updating feature flag

Closes TEIS-3104

See merge request teis/admin-service!81
parents 9230cfb4 b91a4d3e
theGroup=ee.sm.ti.teis
theVersion=1.25.0
theVersion=1.26.0-SNAPSHOT
pluginVersion=1.5.0
commonsVersion=1.34.0
commonApiGatewayVersion=1.34.0
commonsVersion=1.36.0-SNAPSHOT
commonApiGatewayVersion=1.36.0-SNAPSHOT
......@@ -26,10 +26,10 @@ public class DeadlineListenerTests extends AdminAppTestBase {
@Autowired
DeadlineListener deadlineListener;
private CalculateDeadlineRequest request;
private CalculateDeadlineGwRequest gwRequest;
private RequestMetaDTO requestMetaDTO;
private GetDeadline payload;
CalculateDeadlineRequest request;
CalculateDeadlineGwRequest gwRequest;
RequestMetaDTO requestMetaDTO;
GetDeadline payload;
@BeforeEach
void setUp() {
......@@ -45,7 +45,9 @@ public class DeadlineListenerTests extends AdminAppTestBase {
payload.setStartDate(LocalDate.of(2019, 12, 16));
payload.setOnlyWorkDay(false);
request.setPayload(payload, requestMetaDTO);
CalculateDeadlineResponse deadline = deadlineListener.getDeadline(request);
assertThat(deadline.getPayload().getDeadline()).isEqualTo(LocalDateTime.of(2019, 12, 21, 23, 59, 59));
}
......@@ -55,7 +57,9 @@ public class DeadlineListenerTests extends AdminAppTestBase {
payload.setStartDate(LocalDate.of(2019, 12, 23));
payload.setOnlyWorkDay(true);
request.setPayload(payload, requestMetaDTO);
CalculateDeadlineResponse deadline = deadlineListener.getDeadline(request);
assertThat(deadline.getPayload().getDeadline()).isEqualTo(LocalDateTime.of(2019, 12, 31, 23, 59, 59));
}
......@@ -65,7 +69,9 @@ public class DeadlineListenerTests extends AdminAppTestBase {
payload.setStartDate(LocalDate.of(2019, 12, 19));
payload.setOnlyWorkDay(true);
request.setPayload(payload, requestMetaDTO);
CalculateDeadlineResponse deadline = deadlineListener.getDeadline(request);
assertThat(deadline.getPayload().getDeadline()).isEqualTo(LocalDateTime.of(2019, 12, 30, 23, 59, 59));
}
......@@ -75,7 +81,9 @@ public class DeadlineListenerTests extends AdminAppTestBase {
payload.setStartDate(LocalDate.of(2019, 12, 16));
payload.setOnlyWorkDay(true);
request.setPayload(payload, requestMetaDTO);
CalculateDeadlineResponse deadline = deadlineListener.getDeadline(request);
assertThat(deadline.getPayload().getDeadline()).isEqualTo(LocalDateTime.of(2019, 12, 23, 23, 59, 59));
}
......@@ -85,7 +93,9 @@ public class DeadlineListenerTests extends AdminAppTestBase {
payload.setStartDate(LocalDate.of(2019, 2, 21));
payload.setOnlyWorkDay(true);
request.setPayload(payload, requestMetaDTO);
CalculateDeadlineResponse deadline = deadlineListener.getDeadline(request);
assertThat(deadline.getPayload().getDeadline()).isEqualTo(LocalDateTime.of(2019, 2, 28, 23, 59, 59));
}
......@@ -95,7 +105,9 @@ public class DeadlineListenerTests extends AdminAppTestBase {
payload.setStartDate(LocalDate.of(2019, 12, 30));
payload.setOnlyWorkDay(true);
request.setPayload(payload, requestMetaDTO);
CalculateDeadlineResponse deadline = deadlineListener.getDeadline(request);
assertThat(deadline.getPayload().getDeadline()).isEqualTo(LocalDateTime.of(2020, 1, 7, 23, 59, 59));
}
......@@ -107,9 +119,10 @@ public class DeadlineListenerTests extends AdminAppTestBase {
.onlyWorkDay(true)
.build();
gwRequest.setPayload(gwPayload, requestMetaDTO);
CalculateDeadlineGwResponse deadline = deadlineListener.getGwDeadline(gwRequest);
assertThat(deadline.getPayload()).isEqualTo(LocalDateTime.of(2020, 1, 7, 23, 59, 59));
}
}
package ee.sm.ti.teis.adminservice.featureflag;
import ee.sm.ti.teis.AdminAppTestBase;
import ee.sm.ti.teis.adminservice.config.AdminQueueConfig;
import ee.sm.ti.teis.adminservice.config.AdminQueueConfig.FeatureFlagMsRequest;
import ee.sm.ti.teis.adminservice.config.AdminQueueConfig.FeatureFlagMsResponse;
import ee.sm.ti.teis.domain.admin.FeatureFlag;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
......@@ -9,28 +9,20 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
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.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static ee.sm.ti.teis.utils.TestUtils.assertBadRequest;
import static org.assertj.core.api.Assertions.assertThat;
public class FeatureFlagMsListenerTest extends AdminAppTestBase {
@Autowired
private FeatureFlagMsListener listener;
FeatureFlagMsListener listener;
private AdminQueueConfig.FeatureFlagMsRequest request;
private RequestMetaDTO requestMetaDTO;
FeatureFlagMsRequest request;
RequestMetaDTO requestMetaDTO = new RequestMetaDTO();
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(),
emptyList());
request = new AdminQueueConfig.FeatureFlagMsRequest();
request = new FeatureFlagMsRequest();
request.setRequestMetaDTO(requestMetaDTO);
}
......@@ -45,11 +37,26 @@ public class FeatureFlagMsListenerTest extends AdminAppTestBase {
}
@Test
void getFeatureFlag_missing() {
void get_idMissing_badRequest() {
FeatureFlag payload = FeatureFlag.builder().id(null).build();
request.setPayload(payload, requestMetaDTO);
FeatureFlagMsResponse response = listener.getFeatureFlag(request);
assertBadRequest(response.getError());
assertThat(response.getError().getViolations().stream()
.anyMatch(violation -> violation.getFieldName().contains("getDomain.id")
&& violation.getCode().equals("NotBlank")))
.isTrue();
}
@Test
void getFeatureFlag_idNotExists_notFound() {
FeatureFlag payload = FeatureFlag.builder().id("X-TEST-3").build();
request.setPayload(payload, requestMetaDTO);
FeatureFlagMsResponse response = listener.getFeatureFlag(request);
assertThat(response.getError().getMessage()).isEqualTo("Feature Flag not found.");
}
......
package ee.sm.ti.teis.adminservice.featureflag;
import ee.sm.ti.teis.AdminAppTestBase;
import ee.sm.ti.teis.commongateway.admin.FeatureFlagRequest;
import ee.sm.ti.teis.commongateway.admin.FeatureFlagResponse;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static ee.sm.ti.teis.utils.TestUtils.assertBadRequest;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseNotFound;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.shaded.org.apache.commons.lang.RandomStringUtils.random;
public class GetFeatureFlagGwListenerTest extends AdminAppTestBase {
private static final String FLAG_ID = "X-TEST-1";
@Autowired
FeatureFlagGwListener listener;
FeatureFlagRequest request;
FeatureFlagResponse response;
RequestMetaDTO requestMetaDTO = new RequestMetaDTO();
@BeforeEach
void setUp() {
request = new FeatureFlagRequest();
request.setRequestMetaDTO(requestMetaDTO);
}
@Test
void get_success() {
request.setPayload(FLAG_ID, requestMetaDTO);
response = listener.get(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID);
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag");
assertThat(response.getPayload().isEnabled()).isFalse();
}
@Test
void get_idMissing_badRequest() {
request.setPayload(null, requestMetaDTO);
response = listener.get(request);
assertBadRequest(response.getError());
assertThat(response.getError().getViolations().stream()
.anyMatch(violation -> violation.getFieldName().contains("getDto.id")
&& violation.getCode().equals("NotBlank")))
.isTrue();
}
@Test
void get_idNotExists_notFound() {
request.setPayload(random(2, "abc"), requestMetaDTO);
response = listener.get(request);
assertResponseNotFound(response.getError());
assertThat(response.getError().getMessage()).isEqualTo("Feature Flag not found.");
}
}
package ee.sm.ti.teis.adminservice.featureflag;
import ee.sm.ti.teis.AdminAppTestBase;
import ee.sm.ti.teis.commongateway.admin.UpdateFeatureFlagDto;
import ee.sm.ti.teis.commongateway.admin.UpdateFeatureFlagRequest;
import ee.sm.ti.teis.commongateway.admin.UpdateFeatureFlagResponse;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import javax.transaction.Transactional;
import java.util.List;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_PARAMETERS;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_VIOLATION;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.shaded.org.apache.commons.lang.RandomStringUtils.random;
@Transactional
public class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
private static final String FLAG_ID = "X-TEST-1";
private static final String FLAG_ID_2 = "X-TEST-2";
@Autowired
FeatureFlagGwListener listener;
UpdateFeatureFlagRequest request;
UpdateFeatureFlagResponse response;
UpdateFeatureFlagDto dto;
RequestMetaDTO requestMetaDTO;
@BeforeEach
void setUp() {
requestMetaDTO = createRandomOfficialUser(List.of(TI_MANAGE_PARAMETERS.name()));
request = new UpdateFeatureFlagRequest();
dto = UpdateFeatureFlagDto.builder().id(FLAG_ID).enabled(true).build();
request.setRequestMetaDTO(requestMetaDTO);
}
@Test
void update_changeFalseToTrue_success() {
request.setPayload(dto, requestMetaDTO);
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID);
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag");
assertThat(response.getPayload().isEnabled()).isTrue();
}
@Test
void update_changeFalseToFalse_success() {
dto.setEnabled(false);
request.setPayload(dto, requestMetaDTO);
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID);
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag");
assertThat(response.getPayload().isEnabled()).isFalse();
}
@Test
void update_changeTrueToTrue_success() {
dto.setId(FLAG_ID_2);
request.setPayload(dto, requestMetaDTO);
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2);
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag 2");
assertThat(response.getPayload().isEnabled()).isTrue();
}
@Test
void update_changeTrueToFalse_success() {
dto.setId(FLAG_ID_2);
dto.setEnabled(false);
request.setPayload(dto, requestMetaDTO);
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2);
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag 2");
assertThat(response.getPayload().isEnabled()).isFalse();
}
@Test
void update_idMissing_badRequest() {
dto.setId(null);
request.setPayload(dto, requestMetaDTO);
response = listener.update(request);
assertBadRequest(response.getError());
assertThat(response.getError().getViolations().stream()
.anyMatch(violation -> violation.getFieldName().contains("update.dto.id")
&& violation.getCode().equals("NotBlank")))
.isTrue();
}
@Test
void update_idNotExists_notFound() {
dto.setId(random(2, "abc"));
request.setPayload(dto, requestMetaDTO);
response = listener.update(request);
assertResponseNotFound(response.getError());
assertThat(response.getError().getMessage()).isEqualTo("Feature Flag not found.");
}
@Test
public void missingRequiredPrivilege_forbidden() {
requestMetaDTO.setPrivileges(List.of(TI_MANAGE_VIOLATION.name()));
request.setPayload(dto, requestMetaDTO);
response = listener.update(request);
assertResponseForbidden(response.getError());
}
@Test
public void wrongUserType_forbidden() {
requestMetaDTO.setUserType(PERSON);
request.setPayload(dto, requestMetaDTO);
response = listener.update(request);
assertResponseForbidden(response.getError());
}
}
package ee.sm.ti.teis.adminservice.parameter.listener;
package ee.sm.ti.teis.adminservice.parameter;
import ee.sm.ti.teis.AdminAppTestBase;
import ee.sm.ti.teis.adminservice.parameter.listener.ParameterGwListener;
import ee.sm.ti.teis.commongateway.parameter.dto.AdminParameterDto;
import ee.sm.ti.teis.commongateway.parameter.request.AdminParametersRequest;
import ee.sm.ti.teis.commongateway.parameter.response.AdminParametersResponse;
......@@ -11,35 +12,30 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.adminservice.parameter.ParameterGwListenerTest.PARAMETER_CODE_TRIPLEDEV;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.DataType.TEXT;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_PARAMETERS;
import static ee.sm.ti.teis.types.enums.ScopeType.PUBLIC;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseForbidden;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static ee.sm.ti.teis.utils.TestUtils.createRandomOfficialUser;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
public class AdminParameterGwListenerTest extends AdminAppTestBase {
private static final String PARAMETER_CODE_TRIPLEDEV = "X-TEST-TRIPLEDEV_URL";
@Autowired
ParameterGwListener listener;
AdminParametersRequest request;
RequestMetaDTO requestMetaDTO;
@Autowired
ParameterGwListener listener;
AdminParametersResponse response;
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(),
List.of(TI_MANAGE_PARAMETERS.name()));
requestMetaDTO = createRandomOfficialUser(List.of(TI_MANAGE_PARAMETERS.name()));
request = new AdminParametersRequest();
request.setRequestMetaDTO(requestMetaDTO);
}
......@@ -49,7 +45,7 @@ public class AdminParameterGwListenerTest extends AdminAppTestBase {
requestMetaDTO.setPrivileges(emptyList());
request.setPayload(null, requestMetaDTO);
AdminParametersResponse response = listener.getAdminParameters(request);
response = listener.getAdminParameters(request);
assertResponseForbidden(response.getError());
}
......@@ -59,7 +55,7 @@ public class AdminParameterGwListenerTest extends AdminAppTestBase {
requestMetaDTO.setUserType(PERSON);
request.setPayload(null, requestMetaDTO);
AdminParametersResponse response = listener.getAdminParameters(request);
response = listener.getAdminParameters(request);
assertResponseForbidden(response.getError());
}
......@@ -68,9 +64,9 @@ public class AdminParameterGwListenerTest extends AdminAppTestBase {
void getAdminParameters_success() {
request.setPayload(null, requestMetaDTO);
AdminParametersResponse response = listener.getAdminParameters(request);
response = listener.getAdminParameters(request);
assertThat(response.getPayload().size()).isGreaterThanOrEqualTo(10);
assertThat(response.getPayload()).hasSizeGreaterThanOrEqualTo(10);
AdminParameterDto dto = response.getPayload().stream()
.filter(parameter -> parameter.getCode().equals(PARAMETER_CODE_TRIPLEDEV))
......
package ee.sm.ti.teis.adminservice.parameter.listener;
package ee.sm.ti.teis.adminservice.parameter;
import ee.sm.ti.teis.AdminAppTestBase;
import ee.sm.ti.teis.adminservice.parameter.listener.ParameterGwListener;
import ee.sm.ti.teis.commongateway.parameter.dto.ParameterDto;
import ee.sm.ti.teis.commongateway.parameter.request.GetParameterByCodeTestRequest;
import ee.sm.ti.teis.commongateway.parameter.request.ParametersRequest;
......@@ -13,52 +14,44 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.types.enums.ScopeType.*;
import static ee.sm.ti.teis.utils.TestUtils.assertBadRequest;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
public class ParameterGwListenerTest extends AdminAppTestBase {
private static final String PARAMETER_CODE_TEHIK = "X-TEST-TEHIK_URL";
public static final String PARAMETER_CODE_TEHIK = "X-TEST-TEHIK_URL";
public static final String PARAMETER_CODE_TEHIK_NAME = "TEHIK homepage URL";
public static final String PARAMETER_CODE_TEHIK_VALUE = "https://www.tehik.ee/?id={regCode}&test";
private static final String PARAMETER_CODE_NETI = "X-TEST-NETI_URL";
private static final String PARAMETER_CODE_TEATMIK = "LEGAL_PERSON_TEATMIK_WEB_LINK";
private static final String PARAMETER_CODE_GOOGLE = "X-TEST-GOOGLE_URL";
private static final String PARAMETER_CODE_ITI = "LEGAL_PERSON_ITI_WEB_LINK";
private static final String PARAMETER_CODE_TRIPLEDEV = "X-TEST-TRIPLEDEV_URL";
public static final String PARAMETER_CODE_TRIPLEDEV = "X-TEST-TRIPLEDEV_URL";
public static final String PARAMETER_CODE_REG_CODE = "X-TEST-TRIPLEDEV_REG_CODE";
public static final String PARAMETER_CODE_REG_CODE_NAME = "Tripledev registration number";
public static final String PARAMETER_CODE_REG_CODE_VALUE = "12055727";
ParametersRequest request;
RequestMetaDTO requestMetaDTO;
@Autowired
ParameterGwListener listener;
ParametersRequest parametersRequest;
RequestMetaDTO requestMetaDTO = new RequestMetaDTO();
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(),
emptyList());
request = new ParametersRequest();
request.setRequestMetaDTO(requestMetaDTO);
parametersRequest = new ParametersRequest();
parametersRequest.setRequestMetaDTO(requestMetaDTO);
}
@Test
void getParameters_scopeCommon_success() {
request.setPayload(COMMON, requestMetaDTO);
parametersRequest.setPayload(COMMON, requestMetaDTO);
ParametersResponse response = listener.getParameters(request);
ParametersResponse response = listener.getParameters(parametersRequest);
assertThat(response.getPayload().size()).isGreaterThanOrEqualTo(2);
assertThat(response.getPayload()).extracting("code").contains(PARAMETER_CODE_TEHIK, PARAMETER_CODE_NETI, PARAMETER_CODE_TRIPLEDEV);
......@@ -69,16 +62,16 @@ public class ParameterGwListenerTest extends AdminAppTestBase {
.findFirst()
.orElse(new ParameterDto());
assertThat(dto.getName()).isEqualTo("TEHIK homepage URL");
assertThat(dto.getValue()).isEqualTo("https://www.tehik.ee/?id={regCode}&test");
assertThat(dto.getName()).isEqualTo(PARAMETER_CODE_TEHIK_NAME);
assertThat(dto.getValue()).isEqualTo(PARAMETER_CODE_TEHIK_VALUE);
assertThat(dto.getScopes()).isEqualTo(new HashSet<>(asList(COMMON, OFFICE)));
}
@Test
void getParameters_scopeOffice_success() {
request.setPayload(OFFICE, requestMetaDTO);
parametersRequest.setPayload(OFFICE, requestMetaDTO);
ParametersResponse response = listener.getParameters(request);
ParametersResponse response = listener.getParameters(parametersRequest);
assertThat(response.getPayload().size()).isGreaterThanOrEqualTo(3);
assertThat(response.getPayload()).extracting("code").contains(PARAMETER_CODE_TEHIK,
......@@ -97,9 +90,9 @@ public class ParameterGwListenerTest extends AdminAppTestBase {
@Test
void getParameters_scopeAdmin_success() {
request.setPayload(ADMIN, requestMetaDTO);
parametersRequest.setPayload(ADMIN, requestMetaDTO);
ParametersResponse response = listener.getParameters(request);
ParametersResponse response = listener.getParameters(parametersRequest);
assertThat(response.getPayload().size()).isGreaterThanOrEqualTo(5);
assertThat(response.getPayload()).extracting("code").contains(PARAMETER_CODE_TEHIK,
......@@ -108,9 +101,9 @@ public class ParameterGwListenerTest extends AdminAppTestBase {
@Test
void getParameters_scopeMissing_badRequest() {