Skip to content
Snippets Groups Projects
Commit 6970a510 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6944 remove runtime exception handling on file download in AntragraumService

parent 0d6b48a1
Branches
Tags
No related merge requests found
......@@ -34,7 +34,6 @@ import java.util.stream.Stream;
import jakarta.annotation.PostConstruct;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.opensaml.saml.saml2.core.Response;
import org.springframework.beans.factory.annotation.Qualifier;
......@@ -175,12 +174,7 @@ public class AntragraumService {
}
public void getAttachmentContent(AttachmentFileRequest request, OutputStream outputStream) {
try {
verifyAccessToFile(request);
} catch (RuntimeException e) {
IOUtils.closeQuietly(outputStream);
throw e;
}
verifyAccessToFile(request);
ozgCloudFileService.writeFileDataToStream(OzgCloudFileId.from(request.getFileId()), outputStream);
}
......
......@@ -13,15 +13,12 @@ import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Spy;
import org.opensaml.saml.saml2.core.Response;
......@@ -596,61 +593,23 @@ class AntragraumServiceTest {
private final AttachmentFileRequest request = AttachmentFileRequestTestFactory.create();
@Nested
class OnSuccessfullVerification {
@BeforeEach
void mock() {
doNothing().when(service).verifyAccessToFile(request);
}
@Test
void shouldCallVerifyAccessToFile() {
callGetAttachmentContent();
verify(service).verifyAccessToFile(request);
}
@Test
void shouldCallOzgCloudFileServiceToWriteData() {
callGetAttachmentContent();
verify(ozgCloudFileService).writeFileDataToStream(OzgCloudFileId.from(AttachmentFileRequestTestFactory.FILE_ID), outputStream);
}
@BeforeEach
void mock() {
doNothing().when(service).verifyAccessToFile(request);
}
@Nested
class OnUnsuccessfullVerification {
private MockedStatic<IOUtils> mockedIOUtils;
private RuntimeException exception;
@BeforeEach
@SneakyThrows
void setUpMock() {
doThrow(exception = new RuntimeException()).when(service).verifyAccessToFile(request);
mockedIOUtils = mockStatic(IOUtils.class);
}
@Test
void shouldCallVerifyAccessToFile() {
callGetAttachmentContent();
@AfterEach
void cleanUp() {
mockedIOUtils.close();
}
verify(service).verifyAccessToFile(request);
}
@Test
void shouldClosePipedOutPutStream() {
try {
callGetAttachmentContent();
} catch (RuntimeException e) {
}
mockedIOUtils.verify(() -> IOUtils.closeQuietly(outputStream));
}
@Test
void shouldCallOzgCloudFileServiceToWriteData() {
callGetAttachmentContent();
@Test
void shouldRethrowException() {
assertThatThrownBy(() -> callGetAttachmentContent()).isEqualTo(exception);
}
verify(ozgCloudFileService).writeFileDataToStream(OzgCloudFileId.from(AttachmentFileRequestTestFactory.FILE_ID), outputStream);
}
@SneakyThrows
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment