Skip to content

Commit

Permalink
Applying spotless and fixing some warnings
Browse files Browse the repository at this point in the history
pom changes and annotations-on-same-line are all spotless.
Other changes are based on warnings in IDE (deprecations and sonar warnings)
  • Loading branch information
BertScholten committed Jan 31, 2025
1 parent 82b106c commit 9e29c55
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 47 deletions.
4 changes: 1 addition & 3 deletions source/file-server-client/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright the State of the Netherlands
Expand All @@ -17,8 +16,7 @@
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nl.aerius</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class FileServerClientTest {
private static final String FILE_CONTENTS = "test";
private MockWebServer mockWebServer;

@Mock
private FileServerProperties properties;
@Mock private FileServerProperties properties;

private FileServerClient fileServerClient;

Expand All @@ -74,7 +73,7 @@ void destroy() throws IOException {
}

@Test
void testRetrieveFile() throws IOException, InterruptedException {
void testRetrieveFile() throws InterruptedException {
final String expectedFileName = "fileServiceResponse.json";

mockFileServiceResponse(expectedFileName, FILE_CONTENTS.getBytes(StandardCharsets.UTF_8), HttpStatus.OK.value());
Expand All @@ -90,7 +89,7 @@ void testRetrieveFile() throws IOException, InterruptedException {
}

@Test
void testRetrieveFileServiceNotFoundError() throws IOException, InterruptedException {
void testRetrieveFileServiceNotFoundError() throws InterruptedException {
mockFileServiceResponse("", new byte[0], HttpStatus.NOT_FOUND.value());

final ResponseStatusException exception = assertThrows(ResponseStatusException.class,
Expand All @@ -103,7 +102,7 @@ void testRetrieveFileServiceNotFoundError() throws IOException, InterruptedExcep
}

@Test
void testRetrieveFileServiceClientError() throws IOException, InterruptedException {
void testRetrieveFileServiceClientError() throws InterruptedException {
mockFileServiceResponse("", new byte[0], HttpStatus.FORBIDDEN.value());

final ResponseStatusException exception = assertThrows(ResponseStatusException.class,
Expand All @@ -118,7 +117,7 @@ void testRetrieveFileServiceClientError() throws IOException, InterruptedExcepti
}

@Test
void testRetrieveFileServiceServerError() throws IOException, InterruptedException {
void testRetrieveFileServiceServerError() throws InterruptedException {
mockFileServiceResponse("", new byte[0], HttpStatus.BAD_GATEWAY.value());

final ResponseStatusException exception = assertThrows(ResponseStatusException.class,
Expand All @@ -131,15 +130,15 @@ void testRetrieveFileServiceServerError() throws IOException, InterruptedExcepti
}

@Test
void testWrite() throws IOException, InterruptedException {
void testWrite() throws InterruptedException {
mockFileServiceResponse(HttpStatus.OK.value());

fileServerClient.writeJson(UUID_CODE, ExampleFileServerFile.VALIDATION, FileServerExpireTag.NEVER, "test");
assertRecordedRequest(HttpMethod.PUT, UUID_CODE);
}

@Test
void testCopy() throws IOException, InterruptedException {
void testCopy() throws InterruptedException {
mockFileServiceResponse(HttpStatus.OK.value());
final String destinationCode = "456";
final String filename = "SomeFile";
Expand All @@ -149,27 +148,27 @@ void testCopy() throws IOException, InterruptedException {
}

@Test
void testDelete() throws IOException, InterruptedException {
void testDelete() throws InterruptedException {
mockFileServiceResponse("", new byte[0], HttpStatus.OK.value());

fileServerClient.deleteFilesForId(UUID_CODE);
assertRecordedRequest(HttpMethod.DELETE, UUID_CODE);
}

@Test
void testDeleteFileServerError() throws IOException, InterruptedException {
void testDeleteFileServerError() throws InterruptedException {
mockFileServiceResponse("", new byte[0], HttpStatus.INTERNAL_SERVER_ERROR.value());

assertDoesNotThrow(() -> fileServerClient.deleteFilesForId(UUID_CODE), "A file service error should not cause an exception.");
assertRecordedRequest(HttpMethod.DELETE, UUID_CODE);
}

private void mockFileServiceResponse(final int status) throws IOException {
private void mockFileServiceResponse(final int status) {
mockWebServer.enqueue(new MockResponse()
.setResponseCode(status));
}

private void mockFileServiceResponse(final String fileName, final byte[] fileContents, final int status) throws IOException {
private void mockFileServiceResponse(final String fileName, final byte[] fileContents, final int status) {
try (final Buffer buffer = new Buffer()) {
mockWebServer.enqueue(new MockResponse()
.setResponseCode(status)
Expand Down
4 changes: 1 addition & 3 deletions source/file-server/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright the State of the Netherlands
Expand All @@ -17,8 +16,7 @@
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nl.aerius</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package nl.aerius.fileserver;

import jakarta.servlet.Filter;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
Expand Down Expand Up @@ -43,7 +45,7 @@ public static void main(final String[] args) {
* CORS filter to allow client calls to be made on a different port.
*/
@Bean
public FilterRegistrationBean<?> corsFilter() {
public FilterRegistrationBean<Filter> corsFilter() {
final CorsConfiguration config = new CorsConfiguration();

config.addAllowedOriginPattern("*");
Expand All @@ -52,7 +54,7 @@ public FilterRegistrationBean<?> corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

source.registerCorsConfiguration("/**", config);
final FilterRegistrationBean<?> bean = new FilterRegistrationBean<>(new CorsFilter(source));
final FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>(new CorsFilter(source));

bean.setOrder(0);
return bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
import org.springframework.beans.factory.annotation.Autowired;
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.http.HttpHeaders;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

import nl.aerius.fileserver.storage.StorageService;
Expand All @@ -69,14 +69,11 @@ class LocalFileControllerTest {
private static final String URL_BAD_FILENAME = HTTP_LOCALHOST + UUID_CODE + "/" + "1".repeat(1000);
private static final String EXPIRE_TAG_VALUE = "never";

@Autowired
private MockMvc mvc;
@Autowired private MockMvc mvc;

@MockBean
private StorageService storageService;
@MockitoBean private StorageService storageService;

@TempDir
File tempDir;
@TempDir File tempDir;

@Test
void testPutFile() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class LocalFileStorageSeviceTest {
private static final String CONTENT = "AERIUS";
private static final String UUID_CODE = "123";
private static final String FILENAME = "test.gml";
@TempDir
File tempDir;
@TempDir File tempDir;

private LocalFileStorageSevice service;
private File expectedFile;
Expand Down Expand Up @@ -90,7 +89,7 @@ void testGetFile() throws IOException {
}

@Test
void testGetFileNotFound() throws FileNotFoundException {
void testGetFileNotFound() {
assertThrows(FileNotFoundException.class, () -> service.getFile(UUID_CODE, FILENAME), "Expects the file to not be found.");
}

Expand All @@ -105,7 +104,7 @@ void testCopyFile() throws IOException {
}

@Test
void testCopyFileNotFound() throws IOException {
void testCopyFileNotFound() {
final String destinationUuid = UUID.randomUUID().toString();
assertFalse(expectedFile.exists(), "Check if file does not exist before trying to copy non existing file.");
assertThrows(FileNotFoundException.class, () -> service.copyFile(UUID_CODE, destinationUuid, FILENAME, null),
Expand All @@ -120,7 +119,7 @@ void testDeleteFile() throws IOException {
}

@Test
void testDeleteNotFound() throws IOException {
void testDeleteNotFound() {
assertFalse(expectedFile.exists(), "Check if file does not exist before trying to delete non existing file.");
assertThrows(NoSuchFileException.class, () -> service.deleteFile(UUID_CODE, FILENAME), "Should throw exception when file not found.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import org.springframework.beans.factory.annotation.Autowired;
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.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

import nl.aerius.fileserver.storage.StorageService;
Expand All @@ -44,11 +44,9 @@ class AmazonS3ControllerTest {
private static final String UUID_CODE = "00000000-0000-0000-0000-000000000001";
private static final Object AMAZON_URL = "https://s3/uuid/filename";

@Autowired
private MockMvc mvc;
@Autowired private MockMvc mvc;

@MockBean
private StorageService storageService;
@MockitoBean private StorageService storageService;

@Test
void testGetFile() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -94,7 +94,7 @@ class AmazonS3StorageServiceTest {
private AmazonS3StorageService service;

@BeforeEach
void beforeEach() throws IOException {
void beforeEach() {
final AmazonS3StorageProperties properties = new AmazonS3StorageProperties();

properties.setBucketName(BUCKET_NAME);
Expand Down Expand Up @@ -134,12 +134,12 @@ void testGetFile(final String uuid, final String expectedFullPath) throws IOExce
final Builder builder = S3Utilities.builder();
builder.region(REGION);
doReturn(presignedGetObjectRequest).when(presigner).presignGetObject(any(GetObjectPresignRequest.class));
doAnswer(a -> new URL(expectedFullPath)).when(presignedGetObjectRequest).url();
doAnswer(a -> new URI(expectedFullPath).toURL()).when(presignedGetObjectRequest).url();
assertEquals(expectedFullPath, service.getFile(uuid, FILENAME), "Expects the complete path to file.");
}

@Test
void testGetFileNotFound() throws FileNotFoundException {
void testGetFileNotFound() {
doThrow(S3Exception.builder().build()).when(s3Client).getObjectAttributes(any(GetObjectAttributesRequest.class));
assertThrows(FileNotFoundException.class, () -> service.getFile(UUID_CODE, FILENAME), "Expects the file to not be found.");
}
Expand All @@ -159,7 +159,7 @@ void testCopyFile() throws IOException {
}

@Test
void testCopyFileNotFound() throws IOException {
void testCopyFileNotFound() {
final String destinationUuid = UUID.randomUUID().toString();
doThrow(S3Exception.builder().build()).when(s3Client).copyObject(any(CopyObjectRequest.class));
assertThrows(IOException.class, () -> service.copyFile(UUID_CODE, destinationUuid, FILENAME, null),
Expand All @@ -176,7 +176,7 @@ void testDeleteFile() throws IOException {
}

@Test
void testDeleteNotFound() throws IOException {
void testDeleteNotFound() {
doThrow(S3Exception.builder().build()).when(s3Client).deleteObjects(any(DeleteObjectsRequest.class));
assertThrows(IOException.class, () -> service.deleteFile(UUID_CODE, FILENAME), "Should throw exception when file not found.");
}
Expand Down
6 changes: 2 additions & 4 deletions source/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright the State of the Netherlands
Expand All @@ -17,8 +16,7 @@
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nl.aerius</groupId>
Expand Down Expand Up @@ -75,7 +73,7 @@
<module>file-server</module>
<module>file-server-client</module>
</modules>

<profiles>
<profile>
<id>dependency-check</id>
Expand Down

0 comments on commit 9e29c55

Please sign in to comment.