Commit 707c7e2c authored by Siiri Tann's avatar Siiri Tann
Browse files

Merge branch 'TEIS-2109-5' into 'develop'

TEIS-2109: improved tests.

Closes TEIS-2109

See merge request teis/common-api-gateway!217
parents 2a105610 86063054
...@@ -3,22 +3,16 @@ package ee.sm.ti.teis.commongateway.file; ...@@ -3,22 +3,16 @@ package ee.sm.ti.teis.commongateway.file;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.file.request.DeleteFileRequest; 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.FilesMetadataTestRequest;
import ee.sm.ti.teis.commongateway.file.request.FilesMetadataRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil; 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.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.test.context.support.WithMockUser; import org.springframework.security.test.context.support.WithMockUser;
import java.util.List; import java.util.List;
import static ee.sm.ti.teis.commongateway.file.FileObjectType.VIOLATION; import static ee.sm.ti.teis.commongateway.file.FileObjectType.VIOLATION;
import static java.util.UUID.randomUUID; import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
...@@ -28,50 +22,25 @@ class FileTestControllerTest extends CommonApiGatewayTestBase { ...@@ -28,50 +22,25 @@ class FileTestControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/" + VIOLATION.name() + "/" + randomUUID() + "/files/"; private static final String BASE_URL = "/" + VIOLATION.name() + "/" + randomUUID() + "/files/";
@Autowired
FileController controller;
@Autowired @Autowired
MockMvcUtil mockMvcUtil; MockMvcUtil mockMvcUtil;
@Test @Test
void upload_throwError() { void delete_success() {
assertThrows(NoResponseFromRabbitException.class, () -> mockMvcUtil.testDelete(BASE_URL + randomUUID() + "/true");
controller.upload(VIOLATION, randomUUID(), new MockHttpServletRequest(), new RequestMetaDTO()));
}
@Test
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)); verify(requestProcessingService).sendAndReceive(any(DeleteFileRequest.class));
} }
@Test @Test
void getFilesMetadata_success() { void getFilesMetadata_success() {
when(requestProcessingService.sendAndReceive(any(FilesMetadataRequest.class))) when(requestProcessingService.sendAndReceive(any(FilesMetadataTestRequest.class)))
.thenReturn(List.of(new FileReferenceDto())); .thenReturn(List.of(new FileReferenceDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<FileReferenceDto>>() { mockMvcUtil.testGet(BASE_URL + "test", null, new TypeReference<List<FileReferenceDto>>() {
}); });
verify(requestProcessingService).sendAndReceive(any(FilesMetadataRequest.class)); verify(requestProcessingService).sendAndReceive(any(FilesMetadataTestRequest.class));
} }
@Test
void download_throwError() {
assertThrows(NullPointerException.class, () ->
controller.download(VIOLATION, randomUUID().toString(), randomUUID().toString(), "",
new MockHttpServletResponse(), new RequestMetaDTO()));
}
@Test
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteFileRequest.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