Commit 86063054 authored by Siiri's avatar Siiri
Browse files

TEIS-2109: improved tests.

parent 2a105610
......@@ -3,22 +3,16 @@ 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.commongateway.file.request.FilesMetadataTestRequest;
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.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
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.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
......@@ -28,50 +22,25 @@ class FileTestControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/" + VIOLATION.name() + "/" + randomUUID() + "/files/";
@Autowired
FileController controller;
@Autowired
MockMvcUtil mockMvcUtil;
@Test
void upload_throwError() {
assertThrows(NoResponseFromRabbitException.class, () ->
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>() {
});
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID() + "/true");
verify(requestProcessingService).sendAndReceive(any(FileReferenceContextUpdatePublicRequest.class));
verify(requestProcessingService).sendAndReceive(any(DeleteFileRequest.class));
}
@Test
void getFilesMetadata_success() {
when(requestProcessingService.sendAndReceive(any(FilesMetadataRequest.class)))
when(requestProcessingService.sendAndReceive(any(FilesMetadataTestRequest.class)))
.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