From 214404b5c96da7545aab582353476e2dfa4c0acb Mon Sep 17 00:00:00 2001 From: Ludy Date: Tue, 27 May 2025 22:13:36 +0200 Subject: [PATCH] Include `common` in Spotless formatting (#3605) # Description of Changes Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --- .vscode/settings.json | 3 + build.gradle | 7 +- .../common/configuration/AppConfig.java | 9 +- .../FileFallbackTemplateResolver.java | 1 + .../configuration/InstallationPathConfig.java | 24 +- .../YamlPropertySourceFactory.java | 1 + .../common/model/ApplicationProperties.java | 17 +- .../api/converters/HTMLToPdfRequest.java | 1 + .../common/model/oauth2/GitHubProvider.java | 2 + .../common/model/oauth2/GoogleProvider.java | 2 + .../common/model/oauth2/KeycloakProvider.java | 2 + .../common/model/oauth2/Provider.java | 5 +- .../software/common/util/FileMonitor.java | 1 + .../software/common/util/PdfUtils.java | 1 + .../software/common/util/ProviderUtils.java | 3 +- .../util/misc/CustomColorReplaceStrategy.java | 1 + .../util/misc/InvertFullColorStrategy.java | 1 + .../StringToArrayListPropertyEditor.java | 5 +- .../StringToMapPropertyEditor.java | 3 +- .../software/common/util/FileMonitorTest.java | 1 + .../common/util/ProviderUtilsTest.java | 5 +- .../common/util/RequestUriUtilsTest.java | 306 +++++++++--------- .../HighContrastColorReplaceDeciderTest.java | 8 +- .../misc/InvertFullColorStrategyTest.java | 1 + .../ReplaceAndInvertColorStrategyTest.java | 1 + .../StringToArrayListPropertyEditorTest.java | 11 +- 26 files changed, 229 insertions(+), 193 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bfc406300..e45bc4dd9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -49,7 +49,9 @@ ".venv*/", ".vscode/", "bin/", + "common/bin/", "build/", + "common/build/", "configs/", "customFiles/", "docs/", @@ -63,6 +65,7 @@ ".git-blame-ignore-revs", ".gitattributes", ".gitignore", + "common/.gitignore", ".pre-commit-config.yaml", ], // Enables signature help in Java. diff --git a/build.gradle b/build.gradle index e6444c8c8..5e53275c8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "java" - id 'jacoco' + id "jacoco" id "org.springframework.boot" version "3.5.0" id "io.spring.dependency-management" version "1.1.7" id "org.springdoc.openapi-gradle-plugin" version "1.9.0" @@ -374,7 +374,8 @@ launch4j { spotless { java { - target project.fileTree('src').include('**/*.java') + target sourceSets.main.allJava + target project(':common').sourceSets.main.allJava googleJavaFormat("1.27.0").aosp().reorderImports(false) @@ -543,7 +544,7 @@ dependencies { compileOnly "org.projectlombok:lombok:$lombokVersion" annotationProcessor "org.projectlombok:lombok:$lombokVersion" - // Mockito (core) + // Mockito (core) testImplementation 'org.mockito:mockito-core:5.18.0' testRuntimeOnly 'org.mockito:mockito-inline:5.2.0' } diff --git a/common/src/main/java/stirling/software/common/configuration/AppConfig.java b/common/src/main/java/stirling/software/common/configuration/AppConfig.java index 58a60ed1c..732a3b174 100644 --- a/common/src/main/java/stirling/software/common/configuration/AppConfig.java +++ b/common/src/main/java/stirling/software/common/configuration/AppConfig.java @@ -8,9 +8,7 @@ import java.util.List; import java.util.Locale; import java.util.Properties; import java.util.function.Predicate; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; + import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -23,6 +21,11 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.thymeleaf.spring6.SpringTemplateEngine; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + import stirling.software.common.model.ApplicationProperties; @Lazy diff --git a/common/src/main/java/stirling/software/common/configuration/FileFallbackTemplateResolver.java b/common/src/main/java/stirling/software/common/configuration/FileFallbackTemplateResolver.java index ef4bbc052..320d9aaac 100644 --- a/common/src/main/java/stirling/software/common/configuration/FileFallbackTemplateResolver.java +++ b/common/src/main/java/stirling/software/common/configuration/FileFallbackTemplateResolver.java @@ -10,6 +10,7 @@ import org.thymeleaf.IEngineConfiguration; import org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver; import org.thymeleaf.templateresource.FileTemplateResource; import org.thymeleaf.templateresource.ITemplateResource; + import lombok.extern.slf4j.Slf4j; import stirling.software.common.model.InputStreamTemplateResource; diff --git a/common/src/main/java/stirling/software/common/configuration/InstallationPathConfig.java b/common/src/main/java/stirling/software/common/configuration/InstallationPathConfig.java index 9d9d66e39..d087f2a7a 100644 --- a/common/src/main/java/stirling/software/common/configuration/InstallationPathConfig.java +++ b/common/src/main/java/stirling/software/common/configuration/InstallationPathConfig.java @@ -48,22 +48,22 @@ public class InstallationPathConfig { String os = System.getProperty("os.name").toLowerCase(); if (os.contains("win")) { return Paths.get( - System.getenv("APPDATA"), // parent path - "Stirling-PDF") - + File.separator; + System.getenv("APPDATA"), // parent path + "Stirling-PDF") + + File.separator; } else if (os.contains("mac")) { return Paths.get( - System.getProperty("user.home"), - "Library", - "Application Support", - "Stirling-PDF") - + File.separator; + System.getProperty("user.home"), + "Library", + "Application Support", + "Stirling-PDF") + + File.separator; } else { return Paths.get( - System.getProperty("user.home"), // parent path - ".config", - "Stirling-PDF") - + File.separator; + System.getProperty("user.home"), // parent path + ".config", + "Stirling-PDF") + + File.separator; } } return "." + File.separator; diff --git a/common/src/main/java/stirling/software/common/configuration/YamlPropertySourceFactory.java b/common/src/main/java/stirling/software/common/configuration/YamlPropertySourceFactory.java index 17ad21bfd..efb98f260 100644 --- a/common/src/main/java/stirling/software/common/configuration/YamlPropertySourceFactory.java +++ b/common/src/main/java/stirling/software/common/configuration/YamlPropertySourceFactory.java @@ -1,6 +1,7 @@ package stirling.software.common.configuration; import java.util.Properties; + import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.env.PropertySource; diff --git a/common/src/main/java/stirling/software/common/model/ApplicationProperties.java b/common/src/main/java/stirling/software/common/model/ApplicationProperties.java index cb96ee332..9472d40e4 100644 --- a/common/src/main/java/stirling/software/common/model/ApplicationProperties.java +++ b/common/src/main/java/stirling/software/common/model/ApplicationProperties.java @@ -12,11 +12,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import lombok.Data; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.extern.slf4j.Slf4j; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.core.Ordered; @@ -28,6 +24,13 @@ import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.EncodedResource; import org.springframework.stereotype.Component; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + import stirling.software.common.configuration.InstallationPathConfig; import stirling.software.common.configuration.YamlPropertySourceFactory; import stirling.software.common.model.exception.UnsupportedProviderException; @@ -61,7 +64,7 @@ public class ApplicationProperties { @Bean public PropertySource dynamicYamlPropertySource(ConfigurableEnvironment environment) - throws IOException { + throws IOException { String configPath = InstallationPathConfig.getSettingsPath(); log.debug("Attempting to load settings from: " + configPath); @@ -77,7 +80,7 @@ public class ApplicationProperties { EncodedResource encodedResource = new EncodedResource(resource); PropertySource propertySource = - new YamlPropertySourceFactory().createPropertySource(null, encodedResource); + new YamlPropertySourceFactory().createPropertySource(null, encodedResource); environment.getPropertySources().addFirst(propertySource); log.debug("Loaded properties: " + propertySource.getSource()); diff --git a/common/src/main/java/stirling/software/common/model/api/converters/HTMLToPdfRequest.java b/common/src/main/java/stirling/software/common/model/api/converters/HTMLToPdfRequest.java index 4f43dff6f..106d36f17 100644 --- a/common/src/main/java/stirling/software/common/model/api/converters/HTMLToPdfRequest.java +++ b/common/src/main/java/stirling/software/common/model/api/converters/HTMLToPdfRequest.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; + import stirling.software.common.model.api.PDFFile; @Data diff --git a/common/src/main/java/stirling/software/common/model/oauth2/GitHubProvider.java b/common/src/main/java/stirling/software/common/model/oauth2/GitHubProvider.java index a62eb21fb..ef5c15497 100644 --- a/common/src/main/java/stirling/software/common/model/oauth2/GitHubProvider.java +++ b/common/src/main/java/stirling/software/common/model/oauth2/GitHubProvider.java @@ -2,7 +2,9 @@ package stirling.software.common.model.oauth2; import java.util.ArrayList; import java.util.Collection; + import lombok.NoArgsConstructor; + import stirling.software.common.model.enumeration.UsernameAttribute; @NoArgsConstructor diff --git a/common/src/main/java/stirling/software/common/model/oauth2/GoogleProvider.java b/common/src/main/java/stirling/software/common/model/oauth2/GoogleProvider.java index 34ce9d106..b229ddc53 100644 --- a/common/src/main/java/stirling/software/common/model/oauth2/GoogleProvider.java +++ b/common/src/main/java/stirling/software/common/model/oauth2/GoogleProvider.java @@ -2,7 +2,9 @@ package stirling.software.common.model.oauth2; import java.util.ArrayList; import java.util.Collection; + import lombok.NoArgsConstructor; + import stirling.software.common.model.enumeration.UsernameAttribute; @NoArgsConstructor diff --git a/common/src/main/java/stirling/software/common/model/oauth2/KeycloakProvider.java b/common/src/main/java/stirling/software/common/model/oauth2/KeycloakProvider.java index 420230a0e..5d01fa865 100644 --- a/common/src/main/java/stirling/software/common/model/oauth2/KeycloakProvider.java +++ b/common/src/main/java/stirling/software/common/model/oauth2/KeycloakProvider.java @@ -2,7 +2,9 @@ package stirling.software.common.model.oauth2; import java.util.ArrayList; import java.util.Collection; + import lombok.NoArgsConstructor; + import stirling.software.common.model.enumeration.UsernameAttribute; @NoArgsConstructor diff --git a/common/src/main/java/stirling/software/common/model/oauth2/Provider.java b/common/src/main/java/stirling/software/common/model/oauth2/Provider.java index c5d91efdb..55b6b4257 100644 --- a/common/src/main/java/stirling/software/common/model/oauth2/Provider.java +++ b/common/src/main/java/stirling/software/common/model/oauth2/Provider.java @@ -1,13 +1,16 @@ package stirling.software.common.model.oauth2; +import static stirling.software.common.model.enumeration.UsernameAttribute.EMAIL; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; + import lombok.Data; import lombok.NoArgsConstructor; + import stirling.software.common.model.enumeration.UsernameAttribute; import stirling.software.common.model.exception.UnsupportedClaimException; -import static stirling.software.common.model.enumeration.UsernameAttribute.EMAIL; @Data @NoArgsConstructor diff --git a/common/src/main/java/stirling/software/common/util/FileMonitor.java b/common/src/main/java/stirling/software/common/util/FileMonitor.java index e236dee88..3d1fe4f58 100644 --- a/common/src/main/java/stirling/software/common/util/FileMonitor.java +++ b/common/src/main/java/stirling/software/common/util/FileMonitor.java @@ -17,6 +17,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import lombok.extern.slf4j.Slf4j; + import stirling.software.common.configuration.RuntimePathConfig; @Component diff --git a/common/src/main/java/stirling/software/common/util/PdfUtils.java b/common/src/main/java/stirling/software/common/util/PdfUtils.java index bee180f70..3986110e5 100644 --- a/common/src/main/java/stirling/software/common/util/PdfUtils.java +++ b/common/src/main/java/stirling/software/common/util/PdfUtils.java @@ -34,6 +34,7 @@ import org.springframework.web.multipart.MultipartFile; import io.github.pixee.security.Filenames; import lombok.extern.slf4j.Slf4j; + import stirling.software.common.service.CustomPDFDocumentFactory; @Slf4j diff --git a/common/src/main/java/stirling/software/common/util/ProviderUtils.java b/common/src/main/java/stirling/software/common/util/ProviderUtils.java index 1dd942f88..26dbe8aa8 100644 --- a/common/src/main/java/stirling/software/common/util/ProviderUtils.java +++ b/common/src/main/java/stirling/software/common/util/ProviderUtils.java @@ -1,9 +1,10 @@ package stirling.software.common.util; -import stirling.software.common.model.oauth2.Provider; import static stirling.software.common.util.ValidationUtils.isCollectionEmpty; import static stirling.software.common.util.ValidationUtils.isStringEmpty; +import stirling.software.common.model.oauth2.Provider; + public class ProviderUtils { public static boolean validateProvider(Provider provider) { diff --git a/common/src/main/java/stirling/software/common/util/misc/CustomColorReplaceStrategy.java b/common/src/main/java/stirling/software/common/util/misc/CustomColorReplaceStrategy.java index a5c335337..dc1781236 100644 --- a/common/src/main/java/stirling/software/common/util/misc/CustomColorReplaceStrategy.java +++ b/common/src/main/java/stirling/software/common/util/misc/CustomColorReplaceStrategy.java @@ -23,6 +23,7 @@ import org.springframework.core.io.InputStreamResource; import org.springframework.web.multipart.MultipartFile; import lombok.extern.slf4j.Slf4j; + import stirling.software.common.model.api.misc.HighContrastColorCombination; import stirling.software.common.model.api.misc.ReplaceAndInvert; diff --git a/common/src/main/java/stirling/software/common/util/misc/InvertFullColorStrategy.java b/common/src/main/java/stirling/software/common/util/misc/InvertFullColorStrategy.java index 2a41c3006..df40737d3 100644 --- a/common/src/main/java/stirling/software/common/util/misc/InvertFullColorStrategy.java +++ b/common/src/main/java/stirling/software/common/util/misc/InvertFullColorStrategy.java @@ -18,6 +18,7 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; import org.apache.pdfbox.rendering.PDFRenderer; import org.springframework.core.io.InputStreamResource; import org.springframework.web.multipart.MultipartFile; + import stirling.software.common.model.api.misc.ReplaceAndInvert; public class InvertFullColorStrategy extends ReplaceAndInvertColorStrategy { diff --git a/common/src/main/java/stirling/software/common/util/propertyeditor/StringToArrayListPropertyEditor.java b/common/src/main/java/stirling/software/common/util/propertyeditor/StringToArrayListPropertyEditor.java index ecc10400b..98cba7e8c 100644 --- a/common/src/main/java/stirling/software/common/util/propertyeditor/StringToArrayListPropertyEditor.java +++ b/common/src/main/java/stirling/software/common/util/propertyeditor/StringToArrayListPropertyEditor.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; + import stirling.software.common.model.api.security.RedactionArea; @Slf4j @@ -24,9 +25,7 @@ public class StringToArrayListPropertyEditor extends PropertyEditorSupport { } try { objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); - TypeReference> typeRef = - new TypeReference<>() { - }; + TypeReference> typeRef = new TypeReference<>() {}; List list = objectMapper.readValue(text, typeRef); setValue(list); } catch (Exception e) { diff --git a/common/src/main/java/stirling/software/common/util/propertyeditor/StringToMapPropertyEditor.java b/common/src/main/java/stirling/software/common/util/propertyeditor/StringToMapPropertyEditor.java index ad903e346..4a9afc2f6 100644 --- a/common/src/main/java/stirling/software/common/util/propertyeditor/StringToMapPropertyEditor.java +++ b/common/src/main/java/stirling/software/common/util/propertyeditor/StringToMapPropertyEditor.java @@ -14,8 +14,7 @@ public class StringToMapPropertyEditor extends PropertyEditorSupport { @Override public void setAsText(String text) throws IllegalArgumentException { try { - TypeReference> typeRef = - new TypeReference<>() {}; + TypeReference> typeRef = new TypeReference<>() {}; Map map = objectMapper.readValue(text, typeRef); setValue(map); } catch (Exception e) { diff --git a/common/src/test/java/stirling/software/common/util/FileMonitorTest.java b/common/src/test/java/stirling/software/common/util/FileMonitorTest.java index 0a0ff107a..b7d59eab8 100644 --- a/common/src/test/java/stirling/software/common/util/FileMonitorTest.java +++ b/common/src/test/java/stirling/software/common/util/FileMonitorTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; + import stirling.software.common.configuration.RuntimePathConfig; @ExtendWith(MockitoExtension.class) diff --git a/common/src/test/java/stirling/software/common/util/ProviderUtilsTest.java b/common/src/test/java/stirling/software/common/util/ProviderUtilsTest.java index 02143cc84..8788f4c91 100644 --- a/common/src/test/java/stirling/software/common/util/ProviderUtilsTest.java +++ b/common/src/test/java/stirling/software/common/util/ProviderUtilsTest.java @@ -1,7 +1,10 @@ package stirling.software.common.util; +import static org.mockito.Mockito.*; + import java.util.List; import java.util.stream.Stream; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -9,11 +12,11 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.mockito.junit.jupiter.MockitoExtension; + import stirling.software.common.model.enumeration.UsernameAttribute; import stirling.software.common.model.oauth2.GitHubProvider; import stirling.software.common.model.oauth2.GoogleProvider; import stirling.software.common.model.oauth2.Provider; -import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class ProviderUtilsTest { diff --git a/common/src/test/java/stirling/software/common/util/RequestUriUtilsTest.java b/common/src/test/java/stirling/software/common/util/RequestUriUtilsTest.java index 21cfea85f..be437951a 100644 --- a/common/src/test/java/stirling/software/common/util/RequestUriUtilsTest.java +++ b/common/src/test/java/stirling/software/common/util/RequestUriUtilsTest.java @@ -13,40 +13,40 @@ public class RequestUriUtilsTest { void testIsStaticResource() { // Test static resources without context path assertTrue( - RequestUriUtils.isStaticResource("/css/styles.css"), "CSS files should be static"); + RequestUriUtils.isStaticResource("/css/styles.css"), "CSS files should be static"); assertTrue(RequestUriUtils.isStaticResource("/js/script.js"), "JS files should be static"); assertTrue( - RequestUriUtils.isStaticResource("/images/logo.png"), - "Image files should be static"); + RequestUriUtils.isStaticResource("/images/logo.png"), + "Image files should be static"); assertTrue( - RequestUriUtils.isStaticResource("/public/index.html"), - "Public files should be static"); + RequestUriUtils.isStaticResource("/public/index.html"), + "Public files should be static"); assertTrue( - RequestUriUtils.isStaticResource("/pdfjs/pdf.worker.js"), - "PDF.js files should be static"); + RequestUriUtils.isStaticResource("/pdfjs/pdf.worker.js"), + "PDF.js files should be static"); assertTrue( - RequestUriUtils.isStaticResource("/api/v1/info/status"), - "API status should be static"); + RequestUriUtils.isStaticResource("/api/v1/info/status"), + "API status should be static"); assertTrue( - RequestUriUtils.isStaticResource("/some-path/icon.svg"), - "SVG files should be static"); + RequestUriUtils.isStaticResource("/some-path/icon.svg"), + "SVG files should be static"); assertTrue(RequestUriUtils.isStaticResource("/login"), "Login page should be static"); assertTrue(RequestUriUtils.isStaticResource("/error"), "Error page should be static"); // Test non-static resources assertFalse( - RequestUriUtils.isStaticResource("/api/v1/users"), - "API users should not be static"); + RequestUriUtils.isStaticResource("/api/v1/users"), + "API users should not be static"); assertFalse( - RequestUriUtils.isStaticResource("/api/v1/orders"), - "API orders should not be static"); + RequestUriUtils.isStaticResource("/api/v1/orders"), + "API orders should not be static"); assertFalse(RequestUriUtils.isStaticResource("/"), "Root path should not be static"); assertFalse( - RequestUriUtils.isStaticResource("/register"), - "Register page should not be static"); + RequestUriUtils.isStaticResource("/register"), + "Register page should not be static"); assertFalse( - RequestUriUtils.isStaticResource("/api/v1/products"), - "API products should not be static"); + RequestUriUtils.isStaticResource("/api/v1/products"), + "API products should not be static"); } @Test @@ -55,105 +55,105 @@ public class RequestUriUtilsTest { // Test static resources with context path assertTrue( - RequestUriUtils.isStaticResource(contextPath, contextPath + "/css/styles.css"), - "CSS with context path should be static"); + RequestUriUtils.isStaticResource(contextPath, contextPath + "/css/styles.css"), + "CSS with context path should be static"); assertTrue( - RequestUriUtils.isStaticResource(contextPath, contextPath + "/js/script.js"), - "JS with context path should be static"); + RequestUriUtils.isStaticResource(contextPath, contextPath + "/js/script.js"), + "JS with context path should be static"); assertTrue( - RequestUriUtils.isStaticResource(contextPath, contextPath + "/images/logo.png"), - "Images with context path should be static"); + RequestUriUtils.isStaticResource(contextPath, contextPath + "/images/logo.png"), + "Images with context path should be static"); assertTrue( - RequestUriUtils.isStaticResource(contextPath, contextPath + "/login"), - "Login with context path should be static"); + RequestUriUtils.isStaticResource(contextPath, contextPath + "/login"), + "Login with context path should be static"); // Test non-static resources with context path assertFalse( - RequestUriUtils.isStaticResource(contextPath, contextPath + "/api/v1/users"), - "API users with context path should not be static"); + RequestUriUtils.isStaticResource(contextPath, contextPath + "/api/v1/users"), + "API users with context path should not be static"); assertFalse( - RequestUriUtils.isStaticResource(contextPath, "/"), - "Root path with context path should not be static"); + RequestUriUtils.isStaticResource(contextPath, "/"), + "Root path with context path should not be static"); } @ParameterizedTest @ValueSource( - strings = { - "robots.txt", - "/favicon.ico", - "/icon.svg", - "/image.png", - "/site.webmanifest", - "/app/logo.svg", - "/downloads/document.png", - "/assets/brand.ico", - "/any/path/with/image.svg", - "/deep/nested/folder/icon.png" - }) + strings = { + "robots.txt", + "/favicon.ico", + "/icon.svg", + "/image.png", + "/site.webmanifest", + "/app/logo.svg", + "/downloads/document.png", + "/assets/brand.ico", + "/any/path/with/image.svg", + "/deep/nested/folder/icon.png" + }) void testIsStaticResourceWithFileExtensions(String path) { assertTrue( - RequestUriUtils.isStaticResource(path), - "Files with specific extensions should be static regardless of path"); + RequestUriUtils.isStaticResource(path), + "Files with specific extensions should be static regardless of path"); } @Test void testIsTrackableResource() { // Test non-trackable resources (returns false) assertFalse( - RequestUriUtils.isTrackableResource("/js/script.js"), - "JS files should not be trackable"); + RequestUriUtils.isTrackableResource("/js/script.js"), + "JS files should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/v1/api-docs"), - "API docs should not be trackable"); + RequestUriUtils.isTrackableResource("/v1/api-docs"), + "API docs should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("robots.txt"), - "robots.txt should not be trackable"); + RequestUriUtils.isTrackableResource("robots.txt"), + "robots.txt should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/images/logo.png"), - "Images should not be trackable"); + RequestUriUtils.isTrackableResource("/images/logo.png"), + "Images should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/styles.css"), - "CSS files should not be trackable"); + RequestUriUtils.isTrackableResource("/styles.css"), + "CSS files should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/script.js.map"), - "Map files should not be trackable"); + RequestUriUtils.isTrackableResource("/script.js.map"), + "Map files should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/icon.svg"), - "SVG files should not be trackable"); + RequestUriUtils.isTrackableResource("/icon.svg"), + "SVG files should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/popularity.txt"), - "Popularity file should not be trackable"); + RequestUriUtils.isTrackableResource("/popularity.txt"), + "Popularity file should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/script.js"), - "JS files should not be trackable"); + RequestUriUtils.isTrackableResource("/script.js"), + "JS files should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/swagger/index.html"), - "Swagger files should not be trackable"); + RequestUriUtils.isTrackableResource("/swagger/index.html"), + "Swagger files should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/api/v1/info/status"), - "API info should not be trackable"); + RequestUriUtils.isTrackableResource("/api/v1/info/status"), + "API info should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/site.webmanifest"), - "Webmanifest should not be trackable"); + RequestUriUtils.isTrackableResource("/site.webmanifest"), + "Webmanifest should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/fonts/font.woff"), - "Fonts should not be trackable"); + RequestUriUtils.isTrackableResource("/fonts/font.woff"), + "Fonts should not be trackable"); assertFalse( - RequestUriUtils.isTrackableResource("/pdfjs/viewer.js"), - "PDF.js files should not be trackable"); + RequestUriUtils.isTrackableResource("/pdfjs/viewer.js"), + "PDF.js files should not be trackable"); // Test trackable resources (returns true) assertTrue(RequestUriUtils.isTrackableResource("/login"), "Login page should be trackable"); assertTrue( - RequestUriUtils.isTrackableResource("/register"), - "Register page should be trackable"); + RequestUriUtils.isTrackableResource("/register"), + "Register page should be trackable"); assertTrue( - RequestUriUtils.isTrackableResource("/api/v1/users"), - "API users should be trackable"); + RequestUriUtils.isTrackableResource("/api/v1/users"), + "API users should be trackable"); assertTrue(RequestUriUtils.isTrackableResource("/"), "Root path should be trackable"); assertTrue( - RequestUriUtils.isTrackableResource("/some-other-path"), - "Other paths should be trackable"); + RequestUriUtils.isTrackableResource("/some-other-path"), + "Other paths should be trackable"); } @Test @@ -162,75 +162,75 @@ public class RequestUriUtilsTest { // Test with context path assertFalse( - RequestUriUtils.isTrackableResource(contextPath, "/js/script.js"), - "JS files should not be trackable with context path"); + RequestUriUtils.isTrackableResource(contextPath, "/js/script.js"), + "JS files should not be trackable with context path"); assertTrue( - RequestUriUtils.isTrackableResource(contextPath, "/login"), - "Login page should be trackable with context path"); + RequestUriUtils.isTrackableResource(contextPath, "/login"), + "Login page should be trackable with context path"); // Additional tests with context path assertFalse( - RequestUriUtils.isTrackableResource(contextPath, "/fonts/custom.woff"), - "Font files should not be trackable with context path"); + RequestUriUtils.isTrackableResource(contextPath, "/fonts/custom.woff"), + "Font files should not be trackable with context path"); assertFalse( - RequestUriUtils.isTrackableResource(contextPath, "/images/header.png"), - "Images should not be trackable with context path"); + RequestUriUtils.isTrackableResource(contextPath, "/images/header.png"), + "Images should not be trackable with context path"); assertFalse( - RequestUriUtils.isTrackableResource(contextPath, "/swagger/ui.html"), - "Swagger UI should not be trackable with context path"); + RequestUriUtils.isTrackableResource(contextPath, "/swagger/ui.html"), + "Swagger UI should not be trackable with context path"); assertTrue( - RequestUriUtils.isTrackableResource(contextPath, "/account/profile"), - "Account page should be trackable with context path"); + RequestUriUtils.isTrackableResource(contextPath, "/account/profile"), + "Account page should be trackable with context path"); assertTrue( - RequestUriUtils.isTrackableResource(contextPath, "/pdf/view"), - "PDF view page should be trackable with context path"); + RequestUriUtils.isTrackableResource(contextPath, "/pdf/view"), + "PDF view page should be trackable with context path"); } @ParameterizedTest @ValueSource( - strings = { - "/js/util.js", - "/v1/api-docs/swagger.json", - "/robots.txt", - "/images/header/logo.png", - "/styles/theme.css", - "/build/app.js.map", - "/assets/icon.svg", - "/data/popularity.txt", - "/bundle.js", - "/api/swagger-ui.html", - "/api/v1/info/health", - "/site.webmanifest", - "/fonts/roboto.woff", - "/pdfjs/viewer.js" - }) + strings = { + "/js/util.js", + "/v1/api-docs/swagger.json", + "/robots.txt", + "/images/header/logo.png", + "/styles/theme.css", + "/build/app.js.map", + "/assets/icon.svg", + "/data/popularity.txt", + "/bundle.js", + "/api/swagger-ui.html", + "/api/v1/info/health", + "/site.webmanifest", + "/fonts/roboto.woff", + "/pdfjs/viewer.js" + }) void testNonTrackableResources(String path) { assertFalse( - RequestUriUtils.isTrackableResource(path), - "Resources matching patterns should not be trackable: " + path); + RequestUriUtils.isTrackableResource(path), + "Resources matching patterns should not be trackable: " + path); } @ParameterizedTest @ValueSource( - strings = { - "/", - "/home", - "/login", - "/register", - "/pdf/merge", - "/pdf/split", - "/api/v1/users/1", - "/api/v1/documents/process", - "/settings", - "/account/profile", - "/dashboard", - "/help", - "/about" - }) + strings = { + "/", + "/home", + "/login", + "/register", + "/pdf/merge", + "/pdf/split", + "/api/v1/users/1", + "/api/v1/documents/process", + "/settings", + "/account/profile", + "/dashboard", + "/help", + "/about" + }) void testTrackableResources(String path) { assertTrue( - RequestUriUtils.isTrackableResource(path), - "App routes should be trackable: " + path); + RequestUriUtils.isTrackableResource(path), + "App routes should be trackable: " + path); } @Test @@ -252,60 +252,60 @@ public class RequestUriUtilsTest { // Always test the lowercase versions which should definitely work assertTrue( - RequestUriUtils.isStaticResource("/logo.png"), "PNG (lowercase) should be static"); + RequestUriUtils.isStaticResource("/logo.png"), "PNG (lowercase) should be static"); assertTrue( - RequestUriUtils.isStaticResource("/icon.svg"), "SVG (lowercase) should be static"); + RequestUriUtils.isStaticResource("/icon.svg"), "SVG (lowercase) should be static"); // Path with query parameters assertFalse( - RequestUriUtils.isStaticResource("/api/users?page=1"), - "Path with query params should respect base path"); + RequestUriUtils.isStaticResource("/api/users?page=1"), + "Path with query params should respect base path"); assertTrue( - RequestUriUtils.isStaticResource("/images/logo.png?v=123"), - "Static resource with query params should still be static"); + RequestUriUtils.isStaticResource("/images/logo.png?v=123"), + "Static resource with query params should still be static"); // Paths with fragments assertTrue( - RequestUriUtils.isStaticResource("/css/styles.css#section1"), - "CSS with fragment should be static"); + RequestUriUtils.isStaticResource("/css/styles.css#section1"), + "CSS with fragment should be static"); // Multiple dots in filename assertTrue( - RequestUriUtils.isStaticResource("/js/jquery.min.js"), - "JS with multiple dots should be static"); + RequestUriUtils.isStaticResource("/js/jquery.min.js"), + "JS with multiple dots should be static"); // Special characters in path assertTrue( - RequestUriUtils.isStaticResource("/images/user's-photo.png"), - "Path with special chars should be handled correctly"); + RequestUriUtils.isStaticResource("/images/user's-photo.png"), + "Path with special chars should be handled correctly"); } @Test void testComplexPaths() { // Test complex static resource paths assertTrue( - RequestUriUtils.isStaticResource("/css/theme/dark/styles.css"), - "Nested CSS should be static"); + RequestUriUtils.isStaticResource("/css/theme/dark/styles.css"), + "Nested CSS should be static"); assertTrue( - RequestUriUtils.isStaticResource("/fonts/open-sans/bold/font.woff"), - "Nested font should be static"); + RequestUriUtils.isStaticResource("/fonts/open-sans/bold/font.woff"), + "Nested font should be static"); assertTrue( - RequestUriUtils.isStaticResource("/js/vendor/jquery/3.5.1/jquery.min.js"), - "Versioned JS should be static"); + RequestUriUtils.isStaticResource("/js/vendor/jquery/3.5.1/jquery.min.js"), + "Versioned JS should be static"); // Test complex paths with context String contextPath = "/app"; assertTrue( - RequestUriUtils.isStaticResource( - contextPath, contextPath + "/css/theme/dark/styles.css"), - "Nested CSS with context should be static"); + RequestUriUtils.isStaticResource( + contextPath, contextPath + "/css/theme/dark/styles.css"), + "Nested CSS with context should be static"); // Test boundary cases for isTrackableResource assertFalse( - RequestUriUtils.isTrackableResource("/js-framework/components"), - "Path starting with js- should not be treated as JS resource"); + RequestUriUtils.isTrackableResource("/js-framework/components"), + "Path starting with js- should not be treated as JS resource"); assertFalse( - RequestUriUtils.isTrackableResource("/fonts-selection"), - "Path starting with fonts- should not be treated as font resource"); + RequestUriUtils.isTrackableResource("/fonts-selection"), + "Path starting with fonts- should not be treated as font resource"); } } diff --git a/common/src/test/java/stirling/software/common/util/misc/HighContrastColorReplaceDeciderTest.java b/common/src/test/java/stirling/software/common/util/misc/HighContrastColorReplaceDeciderTest.java index 7b01783d1..9ae3d6eb7 100644 --- a/common/src/test/java/stirling/software/common/util/misc/HighContrastColorReplaceDeciderTest.java +++ b/common/src/test/java/stirling/software/common/util/misc/HighContrastColorReplaceDeciderTest.java @@ -1,11 +1,13 @@ package stirling.software.common.util.misc; -import org.junit.jupiter.api.Test; -import stirling.software.common.model.api.misc.HighContrastColorCombination; -import stirling.software.common.model.api.misc.ReplaceAndInvert; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import org.junit.jupiter.api.Test; + +import stirling.software.common.model.api.misc.HighContrastColorCombination; +import stirling.software.common.model.api.misc.ReplaceAndInvert; + class HighContrastColorReplaceDeciderTest { @Test diff --git a/common/src/test/java/stirling/software/common/util/misc/InvertFullColorStrategyTest.java b/common/src/test/java/stirling/software/common/util/misc/InvertFullColorStrategyTest.java index d6a4fad94..61b48e4f7 100644 --- a/common/src/test/java/stirling/software/common/util/misc/InvertFullColorStrategyTest.java +++ b/common/src/test/java/stirling/software/common/util/misc/InvertFullColorStrategyTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test; import org.springframework.core.io.InputStreamResource; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; + import stirling.software.common.model.api.misc.ReplaceAndInvert; class InvertFullColorStrategyTest { diff --git a/common/src/test/java/stirling/software/common/util/misc/ReplaceAndInvertColorStrategyTest.java b/common/src/test/java/stirling/software/common/util/misc/ReplaceAndInvertColorStrategyTest.java index f5520146e..0f9471773 100644 --- a/common/src/test/java/stirling/software/common/util/misc/ReplaceAndInvertColorStrategyTest.java +++ b/common/src/test/java/stirling/software/common/util/misc/ReplaceAndInvertColorStrategyTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; import org.springframework.core.io.InputStreamResource; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; + import stirling.software.common.model.api.misc.ReplaceAndInvert; class ReplaceAndInvertColorStrategyTest { diff --git a/common/src/test/java/stirling/software/common/util/propertyeditor/StringToArrayListPropertyEditorTest.java b/common/src/test/java/stirling/software/common/util/propertyeditor/StringToArrayListPropertyEditorTest.java index 6cdfeae62..ce1535986 100644 --- a/common/src/test/java/stirling/software/common/util/propertyeditor/StringToArrayListPropertyEditorTest.java +++ b/common/src/test/java/stirling/software/common/util/propertyeditor/StringToArrayListPropertyEditorTest.java @@ -1,14 +1,17 @@ package stirling.software.common.util.propertyeditor; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import stirling.software.common.model.api.security.RedactionArea; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import stirling.software.common.model.api.security.RedactionArea; + class StringToArrayListPropertyEditorTest { private StringToArrayListPropertyEditor editor;