Commit 425beb1c authored by Kristel Meikas's avatar Kristel Meikas
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Kristel Meikas

See merge request teis/common-api-gateway!199
parents 705744ec c3294cc5
......@@ -16,6 +16,7 @@ variables:
API_CONTEXT_PATH: "/api-common"
API: "common"
API_TESTS_ROOT: "api-tests/"
USE_METRICS: "true"
include:
- project: "teis/dev-ops"
......
# Changelog
## [1.22.0] - 2021-03-22
* TEIS-2063: added functionality for accepting GET tasks/count requests
* TEIS-2041: added missing USE_METRICS: "true" configuration parameter for services and gateways, which use Prometheus
monitoring
* TEIS-2041: started using MockMvcUtil to make gateway controller tests more useful
* TEIS-2072: Functionality update for POST/PUT tasks/action-plans request parameter deadline data type
* TEIS-2072: GET tasks/action-plans request parameters deadlineFrom, deadlineUntil, completedAtFrom and completedAtUntil
are now Date instead of DateTime format
* Fixed FileReferenceAccessController String parameter mappings (refactored to UUID)
## [1.21.0] - 2021-03-08
* TEIS-1961: new endpoint for getting authority permissions by grantor.
* TEIS-1959: new endpoint for validating authority's licences.
* Updated Minio client dependency to latest version; Code refactor due to MinioClient SDK breaking changes
......
......@@ -4,7 +4,7 @@ import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import static org.springframework.util.StringUtils.isEmpty;
import static org.springframework.util.StringUtils.hasText;
public class CreateFileReferenceRequest extends AbstractDTO<FileReferenceDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.CreateFileReferenceRequest";
......@@ -20,7 +20,7 @@ public class CreateFileReferenceRequest extends AbstractDTO<FileReferenceDto, Er
@Override
public String routingKey() {
if (isEmpty(objectType)) {
if (!hasText(objectType)) {
return ROUTING_KEY;
}
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
......@@ -6,9 +6,12 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import static org.springframework.util.StringUtils.isEmpty;
import java.util.UUID;
public class DeleteFileRequest extends AbstractDTO<DeleteFileRequest.Parameters, ErrorDTO> {
import static ee.sm.ti.teis.commongateway.file.request.DeleteFileRequest.Parameters;
import static org.springframework.util.StringUtils.hasText;
public class DeleteFileRequest extends AbstractDTO<Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.DeleteFileRequest";
......@@ -23,7 +26,7 @@ public class DeleteFileRequest extends AbstractDTO<DeleteFileRequest.Parameters,
@Override
public String routingKey() {
if (isEmpty(objectType)) {
if (!hasText(objectType)) {
return ROUTING_KEY;
}
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......@@ -33,8 +36,8 @@ public class DeleteFileRequest extends AbstractDTO<DeleteFileRequest.Parameters,
@AllArgsConstructor
@NoArgsConstructor
public static class Parameters {
private String objectId;
private String fileId;
private UUID objectId;
private UUID fileId;
private boolean hard;
}
......
......@@ -4,7 +4,7 @@ import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import static org.springframework.util.StringUtils.isEmpty;
import static org.springframework.util.StringUtils.hasText;
public class FileReferenceContextUpdatePublicRequest extends AbstractDTO<FileReferenceDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.FileReferenceContextUpdatePublicRequest";
......@@ -20,7 +20,7 @@ public class FileReferenceContextUpdatePublicRequest extends AbstractDTO<FileRef
@Override
public String routingKey() {
if (isEmpty(objectType)) {
if (!hasText(objectType)) {
return ROUTING_KEY;
}
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
......@@ -4,7 +4,7 @@ import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.file.FileMetadataDto;
import static org.springframework.util.StringUtils.isEmpty;
import static org.springframework.util.StringUtils.hasText;
public class FileRequest extends AbstractDTO<FileMetadataDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.FileRequest";
......@@ -20,7 +20,7 @@ public class FileRequest extends AbstractDTO<FileMetadataDto, ErrorDTO> {
@Override
public String routingKey() {
if (isEmpty(objectType)) {
if (!hasText(objectType)) {
return ROUTING_KEY;
}
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
......@@ -3,7 +3,7 @@ package ee.sm.ti.teis.commongateway.file.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import static org.springframework.util.StringUtils.isEmpty;
import static org.springframework.util.StringUtils.hasText;
public class FilesMetadataRequest extends AbstractDTO<String, ErrorDTO> {
public static final String ROUTING_KEY = "api.FilesMetadataRequest";
......@@ -19,7 +19,7 @@ public class FilesMetadataRequest extends AbstractDTO<String, ErrorDTO> {
@Override
public String routingKey() {
if (isEmpty(objectType)) {
if (!hasText(objectType)) {
return ROUTING_KEY;
}
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
......@@ -3,7 +3,7 @@ package ee.sm.ti.teis.commongateway.file.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import static org.springframework.util.StringUtils.isEmpty;
import static org.springframework.util.StringUtils.hasText;
public class FilesMetadataTestRequest extends AbstractDTO<String, ErrorDTO> {
public static final String ROUTING_KEY = "api.FilesMetadataTestRequest";
......@@ -19,7 +19,7 @@ public class FilesMetadataTestRequest extends AbstractDTO<String, ErrorDTO> {
@Override
public String routingKey() {
if (isEmpty(objectType)) {
if (!hasText(objectType)) {
return ROUTING_KEY;
}
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
......@@ -7,7 +7,7 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.time.LocalDate;
@Data
@NoArgsConstructor
......@@ -15,11 +15,11 @@ import java.time.LocalDateTime;
@Builder
public class GetTaskActionPlansDto extends AbstractPagingDto {
private LocalDateTime deadlineFrom;
private LocalDateTime deadlineUntil;
private LocalDate deadlineFrom;
private LocalDate deadlineUntil;
private TaskStatusType status;
private String description;
private String responsiblePerson;
private LocalDateTime completedAtFrom;
private LocalDateTime completedAtUntil;
private LocalDate completedAtFrom;
private LocalDate completedAtUntil;
}
......@@ -7,7 +7,7 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.time.LocalDate;
@Data
@NoArgsConstructor
......@@ -16,7 +16,7 @@ import java.time.LocalDateTime;
public class TaskActionPlanDto {
@NotNull
private LocalDateTime deadline;
private LocalDate deadline;
private String reference;
@NotBlank
private String description;
......
......@@ -3,7 +3,7 @@ package ee.sm.ti.teis.commongateway.tasks.task.actionplan.dto;
import lombok.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.UUID;
@Data
......@@ -16,7 +16,7 @@ public class UpdateTaskActionPlanDto extends TaskActionPlanDto {
private UUID id;
@Builder(builderMethodName = "updateTaskActionPlanDtoBuilder")
public UpdateTaskActionPlanDto(LocalDateTime deadline, String reference, String description,
public UpdateTaskActionPlanDto(LocalDate deadline, String reference, String description,
String responsiblePerson, Boolean highPriority, UUID id) {
super(deadline, reference, description, responsiblePerson, highPriority);
this.id = id;
......
package ee.sm.ti.teis.commongateway.tasks.task.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.util.UUID;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GetTasksCountDto {
@NotNull
private UUID employerId;
private String taskDefinitionCode;
private String tag;
private Integer nextDays;
}
package ee.sm.ti.teis.commongateway.tasks.task.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TasksCountDto {
private long totalTasksCount;
private long overdueTasksCount;
private long tagTasksCount;
private long nextDaysTasksCount;
}
package ee.sm.ti.teis.commongateway.tasks.task.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.tasks.task.dto.GetTasksCountDto;
public class TasksCountRequest extends AbstractDTO<GetTasksCountDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.TasksCountRequest";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.commongateway.tasks.task.response;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.tasks.task.dto.TasksCountDto;
public class TasksCountResponse extends AbstractDTO<TasksCountDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.TasksCountResponse";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
......@@ -11,12 +11,17 @@ apply from: this.getClass().getClassLoader().getResource('teis.microservice.grad
dependencies {
implementation 'javax.ws.rs:javax.ws.rs-api:2.1.1'
compile "ee.sm.ti.teis:files-client-lib:${commonsVersion}"
compile "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
compile "ee.sm.ti.teis:gateway-common-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:files-client-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:gateway-common-lib:${commonsVersion}"
implementation "io.micrometer:micrometer-registry-prometheus"
integTestImplementation "ee.sm.ti.teis:files-client-lib:${commonsVersion}"
integTestImplementation "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
integTestImplementation "ee.sm.ti.teis:gateway-common-lib:${commonsVersion}"
integTestImplementation 'org.springframework.security:spring-security-test:5.4.1'
compile project(':common-api-gateway-lib')
}
......
package ee.sm.ti.teis.commongateway;
import ee.sm.ti.teis.CommonApiGateway;
import ee.sm.ti.teis.gatewaycommon.config.JacksonIntegTestConfig;
import ee.sm.ti.teis.gatewaycommon.rabbit.RequestProcessingService;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.LinkedMultiValueMap;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Testcontainers;
import static ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase.Initializer;
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = CommonApiGateway.class)
@AutoConfigureMockMvc
@ActiveProfiles({"mockauth", "integtest", "no_keycloak"})
@Testcontainers
@ContextConfiguration(initializers = {CommonApiGatewayTestBase.Initializer.class})
@ContextConfiguration(initializers = {Initializer.class}, classes = JacksonIntegTestConfig.class)
public abstract class CommonApiGatewayTestBase {
protected LinkedMultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
private static final GenericContainer<?> rabbitMQContainer;
@MockBean
public RequestProcessingService requestProcessingService;
// to speed up tests, lets use static container, it is used in all test classes that are executed inside one Spring Context
static {
rabbitMQContainer = new GenericContainer<>("rabbitmq:latest").withExposedPorts(5672);
......
package ee.sm.ti.teis.commongateway.admin;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import ee.sm.ti.teis.commongateway.messages.message.dto.MessageFileReferenceDto;
import ee.sm.ti.teis.commongateway.messages.message.request.CreateMessageFileReferencesRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import java.util.UUID;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
public class AdminForTestingControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/admin/";
@Autowired
AdminForTestingController controller;
MockMvcUtil mockMvcUtil;
@Test
void resetMessageEmail_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.resetMessageEmail(randomUUID(), new RequestMetaDTO()));
void resetMessageEmail_success() {
when(requestProcessingService.sendAndReceive(any(ResetMessageEmailRequest.class)))
.thenReturn(randomUUID());
mockMvcUtil.testGet(BASE_URL + "reset-message-email/" + randomUUID(), null, new TypeReference<UUID>() {
});
verify(requestProcessingService).sendAndReceive(any(ResetMessageEmailRequest.class));
}
@Test
void getMessages_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.createFileReferences(randomUUID(), emptyList(), new RequestMetaDTO()));
}
void createFileReferences_success() {
when(requestProcessingService.sendAndReceive(any(CreateMessageFileReferencesRequest.class)))
.thenReturn(List.of(new FileReferenceDto()));
mockMvcUtil.testPost(BASE_URL + "message/" + randomUUID() + "/file-references", List.of(new MessageFileReferenceDto()),
new TypeReference<List<FileReferenceDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateMessageFileReferencesRequest.class));
}
}
package ee.sm.ti.teis.commongateway.admin;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.LocalDateTime;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class DeadlineControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/deadline";
@Autowired
DeadlineController controller;
MockMvcUtil mockMvcUtil;
@Test
void getDeadline_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getDeadline(new GetDeadlineDto(), new RequestMetaDTO()));
}
void getDeadline_success() {
when(requestProcessingService.sendAndReceive(any(CalculateDeadlineGwRequest.class)))
.thenReturn(LocalDateTime.now());
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<LocalDateTime>() {
});
verify(requestProcessingService).sendAndReceive(any(CalculateDeadlineGwRequest.class));
}
}
package ee.sm.ti.teis.commongateway.admin;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static java.util.UUID.randomUUID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class FeatureFlagControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/feature-flags/";
@Autowired
FeatureFlagController controller;
MockMvcUtil mockMvcUtil;
@Test
void getFeatureFlag_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getFeatureFlag("", new RequestMetaDTO()));
}
void getFeatureFlag_success() {
when(requestProcessingService.sendAndReceive(any(FeatureFlagRequest.class)))
.thenReturn(new FeatureFlagDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<FeatureFlagDto>() {
});
verify(requestProcessingService).sendAndReceive(any(FeatureFlagRequest.class));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment