Commit 1a303ae6 authored by Siiri Tann's avatar Siiri Tann
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Siiri Tann

See merge request teis/common-api-gateway!218
parents 99d71205 9cd87e57
# Changelog
## [1.26.0] - 2021-06-14
* TEIS-2109: improved integration tests. removed unnecessary isSingle from PatchTaskDto. refactored PersonProcessingService.
## [1.25.0] - 2021-05-31
* TEIS-2082: new endpoint for testing getRolesByEmailRecipient. added email recipient field to RoleDefinitionPublicDto.
......
......@@ -34,8 +34,4 @@ public class PatchTaskDto extends TaskRequestParamDto {
this.tag = tag;
this.responsiblePerson = responsiblePerson;
}
public boolean isSingle() {
return this.getId() != null;
}
}
package ee.sm.ti.teis.commongateway.file;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.file.request.DeleteFileRequest;
import ee.sm.ti.teis.commongateway.file.request.FileReferenceContextUpdatePublicRequest;
import ee.sm.ti.teis.commongateway.file.request.FilesMetadataRequest;
import ee.sm.ti.teis.fileclient.FileStorageServiceClient;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import static ee.sm.ti.teis.commongateway.file.FileObjectType.VIOLATION;
import static java.nio.charset.Charset.defaultCharset;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testcontainers.shaded.org.apache.commons.io.IOUtils.toInputStream;
@WithMockUser
class FileControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/" + VIOLATION.name() + "/" + randomUUID() + "/files/";
@Autowired
FileController controller;
@Autowired
MockMvcUtil mockMvcUtil;
@MockBean
FileStorageServiceClient fileStorageServiceClient;
@Test
void getFilesMetadata() {
void upload_throwError() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getFilesMetadata(VIOLATION, "", new RequestMetaDTO()));
controller.upload(VIOLATION, randomUUID(), new MockHttpServletRequest(), new RequestMetaDTO()));
}
@Test
void delete() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(VIOLATION, randomUUID(), randomUUID(), new RequestMetaDTO()));
void updateContext_success() {
when(requestProcessingService.sendAndReceive(any(FileReferenceContextUpdatePublicRequest.class)))
.thenReturn(new FileReferenceDto());
mockMvcUtil.testPatch(BASE_URL + randomUUID() + "/context", new FileReferenceDto(), new TypeReference<FileReferenceDto>() {
});
verify(requestProcessingService).sendAndReceive(any(FileReferenceContextUpdatePublicRequest.class));
}
@Test
void download_() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.download(VIOLATION, randomUUID().toString(), randomUUID().toString(), "",
new MockHttpServletResponse(), new RequestMetaDTO()));
void getFilesMetadata_success() {
when(requestProcessingService.sendAndReceive(any(FilesMetadataRequest.class)))
.thenReturn(List.of(new FileReferenceDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<FileReferenceDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(FilesMetadataRequest.class));
}
@Test
void download_success() {
String fileId = randomUUID().toString();
when(requestProcessingService.sendAndReceive(any()))
.thenReturn(FileMetadataDto.builder()
.contentType("application/text")
.size(12439L)
.bucket("test-bucket")
.build());
when(fileStorageServiceClient.getFileStream(anyString(), anyString()))
.thenReturn(toInputStream("test", defaultCharset()));
mockMvcUtil.testGet(BASE_URL + fileId + "/download/test-file",
null, null, true);
verify(fileStorageServiceClient).getFileStream(eq("test-bucket"), eq(fileId));
}
@Test
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteFileRequest.class));
}
}
package ee.sm.ti.teis.commongateway.file;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.file.request.DeleteFileRequest;
import ee.sm.ti.teis.commongateway.file.request.FilesMetadataTestRequest;
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 static ee.sm.ti.teis.commongateway.file.FileObjectType.VIOLATION;
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 FileTestControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/" + VIOLATION.name() + "/" + randomUUID() + "/files/";
@Autowired
MockMvcUtil mockMvcUtil;
@Test
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID() + "/true");
verify(requestProcessingService).sendAndReceive(any(DeleteFileRequest.class));
}
@Test
void getFilesMetadata_success() {
when(requestProcessingService.sendAndReceive(any(FilesMetadataTestRequest.class)))
.thenReturn(List.of(new FileReferenceDto()));
mockMvcUtil.testGet(BASE_URL + "test", null, new TypeReference<List<FileReferenceDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(FilesMetadataTestRequest.class));
}
}
package ee.sm.ti.teis.commongateway.xroadgateway;
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 java.math.BigInteger;
import java.util.UUID;
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 XroadArControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
private static final String BASE_URL = "/xroad/ar/";
@Autowired
XroadArController controller;
MockMvcUtil mockMvcUtil;
@Test
void getCompanyFromAR_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getCompanyFromAR("name", BigInteger.valueOf(999), REQUEST_META_DTO));
void getCompanyRepresentativesFromAR_success() {
when(requestProcessingService.sendAndReceive(any(ArRepresentativesXroadRequest.class)))
.thenReturn("test");
mockMvcUtil.testGet(BASE_URL + "company-representatives/" + randomUUID(), null, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(ArRepresentativesXroadRequest.class));
}
@Test
void getCompanyFromAR_success() {
when(requestProcessingService.sendAndReceive(any(ArCompanyXroadRequest.class)))
.thenReturn("test");
parameters.add("name", "test");
parameters.add("regCode", BigInteger.valueOf(999).toString());
mockMvcUtil.testGet(BASE_URL + "company", parameters, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(ArCompanyXroadRequest.class));
}
@Test
void getCompanyRepresentativesFromAR_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getCompanyRepresentativesFromAR("id", REQUEST_META_DTO));
void getCompanyDetailsFromAr_success() {
when(requestProcessingService.sendAndReceive(any(ArCompanyDetailsXroadRequest.class)))
.thenReturn("{}");
parameters.add("id", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL + "company-details/" + randomUUID(), parameters, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(ArCompanyDetailsXroadRequest.class));
}
}
package ee.sm.ti.teis.commongateway.xroadgateway;
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 java.util.UUID;
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 XroadArTestControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
@Autowired
XroadArTestController controller;
MockMvcUtil mockMvcUtil;
@Test
void getRepresentationsFromAR_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getRepresentationsFromAR("id", REQUEST_META_DTO));
void getRepresentationsFromAR_success() {
when(requestProcessingService.sendAndReceive(any(ArRepresentationsXroadRequest.class)))
.thenReturn("test");
parameters.add("id", "id");
mockMvcUtil.testGet("/xroad/ar/company-representations/" + randomUUID(), parameters, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(ArRepresentationsXroadRequest.class));
}
}
package ee.sm.ti.teis.commongateway.xroadgateway;
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 java.util.UUID;
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
class XroadCacheTestControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
private static final String BASE_URL = "/xroadgateway/cache/";
@Autowired
XroadCacheTestController controller;
MockMvcUtil mockMvcUtil;
@Test
void getXroadCacheObjectById_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getXroadCacheObjectById("name", "id", REQUEST_META_DTO));
void getXroadCacheObjectById_success() {
when(requestProcessingService.sendAndReceive(any(XroadGatewayCacheRequest.class)))
.thenReturn("{}");
parameters.add("id", "id");
mockMvcUtil.testGet(BASE_URL + "test", parameters, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(XroadGatewayCacheRequest.class));
}
@Test
void createXroadCacheObjects_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.createXroadCacheObjects("name", "id", REQUEST_META_DTO));
void createXroadCacheObjects_success() {
when(requestProcessingService.sendAndReceive(any(UpdateXroadGatewayCacheRequest.class)))
.thenReturn("{}");
mockMvcUtil.testPost(BASE_URL + "test", new UpdateXroadGatewayCacheRequest.Parameters(), new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(UpdateXroadGatewayCacheRequest.class));
}
@Test
void deleteXroadCacheObject_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.deleteXroadCacheObject("name", "id", REQUEST_META_DTO));
void deleteXroadCacheObject_success() {
when(requestProcessingService.sendAndReceive(any(DeleteXroadGatewayCacheRequest.class)))
.thenReturn("{}");
parameters.add("id", "test");
mockMvcUtil.testDelete(BASE_URL + "name?id=id");
verify(requestProcessingService).sendAndReceive(any(DeleteXroadGatewayCacheRequest.class));
}
}
package ee.sm.ti.teis.commongateway.xroadgateway;
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 java.util.UUID;
import java.time.LocalDate;
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
class XroadEmtakTestControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
private static final String BASE_URL = "/xroad/emtak/";
@Autowired
XroadEmtakTestController controller;
MockMvcUtil mockMvcUtil;
@Test
void getEmtakChanges_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getEmtakChanges(null, null, REQUEST_META_DTO));
void getEmtakChanges_success() {
when(requestProcessingService.sendAndReceive(any(EmtakXroadRequest.class)))
.thenReturn("test");
parameters.add("startDate", LocalDate.now().toString());
mockMvcUtil.testGet(BASE_URL, parameters, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(EmtakXroadRequest.class));
}
@Test
void getEmtakItems_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getEmtakItems(REQUEST_META_DTO));
void getEmtakItems_success() {
when(requestProcessingService.sendAndReceive(any(EmtakItemsXroadRequest.class)))
.thenReturn("test");
parameters.add("startDate", LocalDate.now().toString());
mockMvcUtil.testGet(BASE_URL + "items", parameters, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(EmtakItemsXroadRequest.class));
}
}
package ee.sm.ti.teis.commongateway.xroadgateway;
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 java.util.UUID;
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 XroadTorControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
@Autowired
XroadTorController controller;
MockMvcUtil mockMvcUtil;
@Test
void getEmployeesFromTor_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getEmployeesFromTor("emplId", REQUEST_META_DTO));
void getEmployeesFromTor_success() {
when(requestProcessingService.sendAndReceive(any(TorEmployeesXroadRequest.class)))
.thenReturn("test");
mockMvcUtil.testGet("/xroad/tor/employees/" + randomUUID(), null, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(TorEmployeesXroadRequest.class));
}
}
package ee.sm.ti.teis.commongateway.xroadgateway;
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 java.util.UUID;
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 XroadTorTestControllerTest extends CommonApiGatewayTestBase {
private static final String EMPL_ID_PARAMETER = "emplId";
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
private static final String BASE_URL = "/xroad/tor/";
@Autowired
XroadTorTestController controller;
MockMvcUtil mockMvcUtil;
@Test
void geNumberOfEmployeesFromTor_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.geNumberOfEmployeesFromTor(EMPL_ID_PARAMETER, REQUEST_META_DTO));
void getEmployersFromTor_success() {
when(requestProcessingService.sendAndReceive(any(TorEmployersXroadRequest.class)))
.thenReturn("test");
parameters.add("employeeId", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL + "employers/" + randomUUID(), parameters, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(TorEmployersXroadRequest.class));
}
@Test
void getEmployersFromTor_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getEmployersFromTor(EMPL_ID_PARAMETER, REQUEST_META_DTO));
void getLocationsFromTor_success() {
when(requestProcessingService.sendAndReceive(any(TorLocationsXroadRequest.class)))
.thenReturn("test");
parameters.add("employeeId", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL + "locations/" + randomUUID(), parameters, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(TorLocationsXroadRequest.class));
}
@Test
void getLocationsFromTor_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getLocationsFromTor(EMPL_ID_PARAMETER, REQUEST_META_DTO));
void getNumberOfEmployeesFromTor_success() {
when(requestProcessingService.sendAndReceive(any(TorNrOfEmployeesXroadRequest.class)))
.thenReturn("test");
parameters.add("employeeId", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL + "number-of-employees/" + randomUUID(), parameters, new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(TorNrOfEmployeesXroadRequest.class));
}
}
......@@ -3,9 +3,14 @@ package ee.sm.ti.teis.commongateway.file;
import com.fasterxml.jackson.databind.ObjectMapper;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.commongateway.file.request.CreateFileReferenceRequest;
import ee.sm.ti.teis.commongateway.file.request.FileRequest;
import ee.sm.ti.teis.commongateway.file.request.FileStorageUploadFailedRequest;
import ee.sm.ti.teis.commongateway.file.request.UpdateFileMetaRequest;