mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-05 16:52:02 +00:00
Refactor test imports (#3170)
# Description of Changes Please provide a summary of the changes, including: Refactor test imports and update Gradle file to include all Java files from the src directory --- ## 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.
This commit is contained in:
parent
4408ecfa5b
commit
0cb745b9ae
@ -256,7 +256,7 @@ launch4j {
|
|||||||
|
|
||||||
spotless {
|
spotless {
|
||||||
java {
|
java {
|
||||||
target project.fileTree('src/main/java')
|
target project.fileTree('src').include('**/*.java')
|
||||||
|
|
||||||
googleJavaFormat("1.25.2").aosp().reorderImports(false)
|
googleJavaFormat("1.25.2").aosp().reorderImports(false)
|
||||||
|
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
package stirling.software.SPDF;
|
package stirling.software.SPDF;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -16,22 +11,15 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.ApplicationProperties;
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
import static java.nio.file.Files.createDirectories;
|
|
||||||
import static java.nio.file.Files.createFile;
|
|
||||||
import static java.nio.file.Files.delete;
|
|
||||||
import static java.nio.file.Files.exists;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class SPDFApplicationTest {
|
public class SPDFApplicationTest {
|
||||||
|
|
||||||
@Mock
|
@Mock private Environment env;
|
||||||
private Environment env;
|
|
||||||
|
|
||||||
@Mock
|
@Mock private ApplicationProperties applicationProperties;
|
||||||
private ApplicationProperties applicationProperties;
|
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks private SPDFApplication sPDFApplication;
|
||||||
private SPDFApplication sPDFApplication;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@ -48,5 +36,4 @@ public class SPDFApplicationTest {
|
|||||||
public void testGetStaticPort() {
|
public void testGetStaticPort() {
|
||||||
assertEquals("8080", SPDFApplication.getStaticPort());
|
assertEquals("8080", SPDFApplication.getStaticPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,29 @@
|
|||||||
package stirling.software.SPDF.config.security;
|
package stirling.software.SPDF.config.security;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import static org.mockito.Mockito.mock;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
|
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.ApplicationProperties;
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class CustomLogoutSuccessHandlerTest {
|
class CustomLogoutSuccessHandlerTest {
|
||||||
|
|
||||||
@Mock
|
@Mock private ApplicationProperties applicationProperties;
|
||||||
private ApplicationProperties applicationProperties;
|
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks private CustomLogoutSuccessHandler customLogoutSuccessHandler;
|
||||||
private CustomLogoutSuccessHandler customLogoutSuccessHandler;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSuccessfulLogout() throws IOException {
|
void testSuccessfulLogout() throws IOException {
|
||||||
@ -44,7 +46,8 @@ class CustomLogoutSuccessHandlerTest {
|
|||||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||||
OAuth2AuthenticationToken oAuth2AuthenticationToken = mock(OAuth2AuthenticationToken.class);
|
OAuth2AuthenticationToken oAuth2AuthenticationToken = mock(OAuth2AuthenticationToken.class);
|
||||||
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
||||||
ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class);
|
ApplicationProperties.Security.OAUTH2 oauth =
|
||||||
|
mock(ApplicationProperties.Security.OAUTH2.class);
|
||||||
|
|
||||||
when(response.isCommitted()).thenReturn(false);
|
when(response.isCommitted()).thenReturn(false);
|
||||||
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
||||||
@ -70,7 +73,8 @@ class CustomLogoutSuccessHandlerTest {
|
|||||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||||
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
||||||
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
||||||
ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class);
|
ApplicationProperties.Security.OAUTH2 oauth =
|
||||||
|
mock(ApplicationProperties.Security.OAUTH2.class);
|
||||||
|
|
||||||
when(response.isCommitted()).thenReturn(false);
|
when(response.isCommitted()).thenReturn(false);
|
||||||
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
||||||
@ -100,7 +104,8 @@ class CustomLogoutSuccessHandlerTest {
|
|||||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||||
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
||||||
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
||||||
ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class);
|
ApplicationProperties.Security.OAUTH2 oauth =
|
||||||
|
mock(ApplicationProperties.Security.OAUTH2.class);
|
||||||
|
|
||||||
when(response.isCommitted()).thenReturn(false);
|
when(response.isCommitted()).thenReturn(false);
|
||||||
when(request.getParameter(error)).thenReturn("true");
|
when(request.getParameter(error)).thenReturn("true");
|
||||||
@ -125,7 +130,8 @@ class CustomLogoutSuccessHandlerTest {
|
|||||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||||
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
||||||
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
||||||
ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class);
|
ApplicationProperties.Security.OAUTH2 oauth =
|
||||||
|
mock(ApplicationProperties.Security.OAUTH2.class);
|
||||||
|
|
||||||
when(response.isCommitted()).thenReturn(false);
|
when(response.isCommitted()).thenReturn(false);
|
||||||
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
||||||
@ -151,7 +157,8 @@ class CustomLogoutSuccessHandlerTest {
|
|||||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||||
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
||||||
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
||||||
ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class);
|
ApplicationProperties.Security.OAUTH2 oauth =
|
||||||
|
mock(ApplicationProperties.Security.OAUTH2.class);
|
||||||
|
|
||||||
when(response.isCommitted()).thenReturn(false);
|
when(response.isCommitted()).thenReturn(false);
|
||||||
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
||||||
@ -179,7 +186,8 @@ class CustomLogoutSuccessHandlerTest {
|
|||||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||||
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
||||||
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
||||||
ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class);
|
ApplicationProperties.Security.OAUTH2 oauth =
|
||||||
|
mock(ApplicationProperties.Security.OAUTH2.class);
|
||||||
|
|
||||||
when(response.isCommitted()).thenReturn(false);
|
when(response.isCommitted()).thenReturn(false);
|
||||||
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
||||||
@ -209,7 +217,8 @@ class CustomLogoutSuccessHandlerTest {
|
|||||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||||
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
||||||
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
||||||
ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class);
|
ApplicationProperties.Security.OAUTH2 oauth =
|
||||||
|
mock(ApplicationProperties.Security.OAUTH2.class);
|
||||||
|
|
||||||
when(response.isCommitted()).thenReturn(false);
|
when(response.isCommitted()).thenReturn(false);
|
||||||
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
||||||
@ -240,7 +249,8 @@ class CustomLogoutSuccessHandlerTest {
|
|||||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||||
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class);
|
||||||
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
ApplicationProperties.Security security = mock(ApplicationProperties.Security.class);
|
||||||
ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class);
|
ApplicationProperties.Security.OAUTH2 oauth =
|
||||||
|
mock(ApplicationProperties.Security.OAUTH2.class);
|
||||||
|
|
||||||
when(response.isCommitted()).thenReturn(false);
|
when(response.isCommitted()).thenReturn(false);
|
||||||
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null);
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
package stirling.software.SPDF.config.security.database;
|
package stirling.software.SPDF.config.security.database;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
@ -8,18 +14,14 @@ import org.junit.jupiter.params.ParameterizedTest;
|
|||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.ApplicationProperties;
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
import stirling.software.SPDF.model.exception.UnsupportedProviderException;
|
import stirling.software.SPDF.model.exception.UnsupportedProviderException;
|
||||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class DatabaseConfigTest {
|
class DatabaseConfigTest {
|
||||||
|
|
||||||
@Mock
|
@Mock private ApplicationProperties applicationProperties;
|
||||||
private ApplicationProperties applicationProperties;
|
|
||||||
|
|
||||||
private DatabaseConfig databaseConfig;
|
private DatabaseConfig databaseConfig;
|
||||||
|
|
||||||
|
@ -1,25 +1,19 @@
|
|||||||
package stirling.software.SPDF.controller.api;
|
package stirling.software.SPDF.controller.api;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.CsvSource;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import stirling.software.SPDF.service.CustomPDFDocumentFactory;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.CsvSource;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import stirling.software.SPDF.service.CustomPDFDocumentFactory;
|
||||||
|
|
||||||
class RearrangePagesPDFControllerTest {
|
class RearrangePagesPDFControllerTest {
|
||||||
|
|
||||||
@ -33,9 +27,7 @@ class RearrangePagesPDFControllerTest {
|
|||||||
sut = new RearrangePagesPDFController(mockPdfDocumentFactory);
|
sut = new RearrangePagesPDFController(mockPdfDocumentFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Tests the behavior of the oddEvenMerge method when there are no pages in the document. */
|
||||||
* Tests the behavior of the oddEvenMerge method when there are no pages in the document.
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
void oddEvenMerge_noPages() {
|
void oddEvenMerge_noPages() {
|
||||||
int totalNumberOfPages = 0;
|
int totalNumberOfPages = 0;
|
||||||
@ -60,7 +52,8 @@ class RearrangePagesPDFControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the behavior of the oddEvenMerge method when there are even total pages in the document.
|
* Tests the behavior of the oddEvenMerge method when there are even total pages in the
|
||||||
|
* document.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void oddEvenMerge_evenTotalPageNumber() {
|
void oddEvenMerge_evenTotalPageNumber() {
|
||||||
@ -76,7 +69,7 @@ class RearrangePagesPDFControllerTest {
|
|||||||
* Tests the behavior of the oddEvenMerge method with multiple test cases of multiple pages.
|
* Tests the behavior of the oddEvenMerge method with multiple test cases of multiple pages.
|
||||||
*
|
*
|
||||||
* @param totalNumberOfPages The total number of pages in the document.
|
* @param totalNumberOfPages The total number of pages in the document.
|
||||||
* @param expectedPageOrder The expected order of the pages after rearranging.
|
* @param expectedPageOrder The expected order of the pages after rearranging.
|
||||||
*/
|
*/
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@CsvSource({
|
@CsvSource({
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package stirling.software.SPDF.controller.api.converters;
|
package stirling.software.SPDF.controller.api.converters;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -9,9 +12,6 @@ import stirling.software.SPDF.config.RuntimePathConfig;
|
|||||||
import stirling.software.SPDF.model.api.converters.UrlToPdfRequest;
|
import stirling.software.SPDF.model.api.converters.UrlToPdfRequest;
|
||||||
import stirling.software.SPDF.service.CustomPDFDocumentFactory;
|
import stirling.software.SPDF.service.CustomPDFDocumentFactory;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
|
|
||||||
public class ConvertWebsiteToPdfTest {
|
public class ConvertWebsiteToPdfTest {
|
||||||
|
|
||||||
@Mock private CustomPDFDocumentFactory mockPdfDocumentFactory;
|
@Mock private CustomPDFDocumentFactory mockPdfDocumentFactory;
|
||||||
|
@ -1,31 +1,32 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.jupiter.params.provider.CsvSource;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.CsvSource;
|
||||||
|
|
||||||
public class FileInfoTest {
|
public class FileInfoTest {
|
||||||
|
|
||||||
@ParameterizedTest(name = "{index}: fileSize={0}")
|
@ParameterizedTest(name = "{index}: fileSize={0}")
|
||||||
@CsvSource({
|
@CsvSource({
|
||||||
"0, '0 Bytes'",
|
"0, '0 Bytes'",
|
||||||
"1023, '1023 Bytes'",
|
"1023, '1023 Bytes'",
|
||||||
"1024, '1.00 KB'",
|
"1024, '1.00 KB'",
|
||||||
"1048575, '1024.00 KB'", // Do we really want this as result?
|
"1048575, '1024.00 KB'", // Do we really want this as result?
|
||||||
"1048576, '1.00 MB'",
|
"1048576, '1.00 MB'",
|
||||||
"1073741823, '1024.00 MB'", // Do we really want this as result?
|
"1073741823, '1024.00 MB'", // Do we really want this as result?
|
||||||
"1073741824, '1.00 GB'"
|
"1073741824, '1.00 GB'"
|
||||||
})
|
})
|
||||||
void testGetFormattedFileSize(long fileSize, String expectedFormattedSize) {
|
void testGetFormattedFileSize(long fileSize, String expectedFormattedSize) {
|
||||||
FileInfo fileInfo = new FileInfo(
|
FileInfo fileInfo =
|
||||||
"example.txt",
|
new FileInfo(
|
||||||
"/path/to/example.txt",
|
"example.txt",
|
||||||
LocalDateTime.now(),
|
"/path/to/example.txt",
|
||||||
fileSize,
|
LocalDateTime.now(),
|
||||||
LocalDateTime.now().minusDays(1));
|
fileSize,
|
||||||
|
LocalDateTime.now().minusDays(1));
|
||||||
|
|
||||||
assertEquals(expectedFormattedSize, fileInfo.getFormattedFileSize());
|
assertEquals(expectedFormattedSize, fileInfo.getFormattedFileSize());
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import stirling.software.SPDF.model.api.converters.HTMLToPdfRequest;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import stirling.software.SPDF.model.api.converters.HTMLToPdfRequest;
|
||||||
|
|
||||||
public class FileToPdfTest {
|
public class FileToPdfTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the HTML to PDF conversion.
|
* Test the HTML to PDF conversion. This test expects an IOException when an empty HTML input is
|
||||||
* This test expects an IOException when an empty HTML input is provided.
|
* provided.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testConvertHtmlToPdf() {
|
public void testConvertHtmlToPdf() {
|
||||||
@ -31,8 +34,8 @@ public class FileToPdfTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test sanitizeZipFilename with null or empty input.
|
* Test sanitizeZipFilename with null or empty input. It should return an empty string in these
|
||||||
* It should return an empty string in these cases.
|
* cases.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSanitizeZipFilename_NullOrEmpty() {
|
public void testSanitizeZipFilename_NullOrEmpty() {
|
||||||
@ -41,8 +44,8 @@ public class FileToPdfTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test sanitizeZipFilename to ensure it removes path traversal sequences.
|
* Test sanitizeZipFilename to ensure it removes path traversal sequences. This includes
|
||||||
* This includes removing both forward and backward slash sequences.
|
* removing both forward and backward slash sequences.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSanitizeZipFilename_RemovesTraversalSequences() {
|
public void testSanitizeZipFilename_RemovesTraversalSequences() {
|
||||||
@ -58,9 +61,7 @@ public class FileToPdfTest {
|
|||||||
assertEquals(expected, FileToPdf.sanitizeZipFilename(input));
|
assertEquals(expected, FileToPdf.sanitizeZipFilename(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Test sanitizeZipFilename to ensure that it removes leading drive letters and slashes. */
|
||||||
* Test sanitizeZipFilename to ensure that it removes leading drive letters and slashes.
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testSanitizeZipFilename_RemovesLeadingDriveAndSlashes() {
|
public void testSanitizeZipFilename_RemovesLeadingDriveAndSlashes() {
|
||||||
String input = "C:\\folder\\file.txt";
|
String input = "C:\\folder\\file.txt";
|
||||||
@ -72,9 +73,7 @@ public class FileToPdfTest {
|
|||||||
assertEquals(expected, FileToPdf.sanitizeZipFilename(input));
|
assertEquals(expected, FileToPdf.sanitizeZipFilename(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Test sanitizeZipFilename to verify that safe filenames remain unchanged. */
|
||||||
* Test sanitizeZipFilename to verify that safe filenames remain unchanged.
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testSanitizeZipFilename_NoChangeForSafeNames() {
|
public void testSanitizeZipFilename_NoChangeForSafeNames() {
|
||||||
String input = "folder/subfolder/file.txt";
|
String input = "folder/subfolder/file.txt";
|
||||||
|
@ -1,161 +1,157 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class GeneralUtilsTest {
|
public class GeneralUtilsTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithAll() {
|
void testParsePageListWithAll() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"all"}, 5, false);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"all"}, 5, false);
|
||||||
assertEquals(List.of(0, 1, 2, 3, 4), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(0, 1, 2, 3, 4), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithAllOneBased() {
|
void testParsePageListWithAllOneBased() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"all"}, 5, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"all"}, 5, true);
|
||||||
assertEquals(List.of(1, 2, 3, 4, 5), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(1, 2, 3, 4, 5), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc() {
|
void nFunc() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"n"}, 5, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"n"}, 5, true);
|
||||||
assertEquals(List.of(1, 2, 3, 4, 5), result, "'n' keyword should return all pages.");
|
assertEquals(List.of(1, 2, 3, 4, 5), result, "'n' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced() {
|
void nFuncAdvanced() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"4n"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, true);
|
||||||
//skip 0 as not valid
|
// skip 0 as not valid
|
||||||
assertEquals(List.of(4, 8), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(4, 8), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvancedZero() {
|
void nFuncAdvancedZero() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"4n"}, 9, false);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, false);
|
||||||
//skip 0 as not valid
|
// skip 0 as not valid
|
||||||
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced2() {
|
void nFuncAdvanced2() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"4n-1"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n-1"}, 9, true);
|
||||||
// skip -1 as not valid
|
// skip -1 as not valid
|
||||||
assertEquals(List.of(3, 7), result, "4n-1 should do (0-1), (4-1), (8-1)");
|
assertEquals(List.of(3, 7), result, "4n-1 should do (0-1), (4-1), (8-1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced3() {
|
void nFuncAdvanced3() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"4n+1"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n+1"}, 9, true);
|
||||||
assertEquals(List.of(5, 9), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(5, 9), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_spaces() {
|
void nFunc_spaces() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"n + 1"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"n + 1"}, 9, true);
|
||||||
assertEquals(List.of(2, 3, 4, 5, 6, 7, 8, 9), result);
|
assertEquals(List.of(2, 3, 4, 5, 6, 7, 8, 9), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_consecutive_Ns_nnn() {
|
void nFunc_consecutive_Ns_nnn() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"nnn"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"nnn"}, 9, true);
|
||||||
assertEquals(List.of(1, 8), result);
|
assertEquals(List.of(1, 8), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_consecutive_Ns_nn() {
|
void nFunc_consecutive_Ns_nn() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"nn"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"nn"}, 9, true);
|
||||||
assertEquals(List.of(1, 4, 9), result);
|
assertEquals(List.of(1, 4, 9), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_opening_closing_round_brackets() {
|
void nFunc_opening_closing_round_brackets() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"(n-1)(n-2)"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)(n-2)"}, 9, true);
|
||||||
assertEquals(List.of(2, 6), result);
|
assertEquals(List.of(2, 6), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_opening_round_brackets() {
|
void nFunc_opening_round_brackets() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"2(n-1)"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"2(n-1)"}, 9, true);
|
||||||
assertEquals(List.of(2, 4, 6, 8), result);
|
assertEquals(List.of(2, 4, 6, 8), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_opening_round_brackets_n() {
|
void nFunc_opening_round_brackets_n() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"n(n-1)"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"n(n-1)"}, 9, true);
|
||||||
assertEquals(List.of(2, 6), result);
|
assertEquals(List.of(2, 6), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_closing_round_brackets() {
|
void nFunc_closing_round_brackets() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"(n-1)2"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)2"}, 9, true);
|
||||||
assertEquals(List.of(2, 4, 6, 8), result);
|
assertEquals(List.of(2, 4, 6, 8), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_closing_round_brackets_n() {
|
void nFunc_closing_round_brackets_n() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"(n-1)n"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)n"}, 9, true);
|
||||||
assertEquals(List.of(2, 6), result);
|
assertEquals(List.of(2, 6), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_function_surrounded_with_brackets() {
|
void nFunc_function_surrounded_with_brackets() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"(n-1)"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)"}, 9, true);
|
||||||
assertEquals(List.of(1, 2, 3, 4, 5, 6, 7, 8), result);
|
assertEquals(List.of(1, 2, 3, 4, 5, 6, 7, 8), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced4() {
|
void nFuncAdvanced4() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"3+2n"}, 9, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"3+2n"}, 9, true);
|
||||||
assertEquals(List.of(5, 7, 9), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(5, 7, 9), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvancedZerobased() {
|
void nFuncAdvancedZerobased() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"4n"}, 9, false);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, false);
|
||||||
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced2Zerobased() {
|
void nFuncAdvanced2Zerobased() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"4n-1"}, 9, false);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n-1"}, 9, false);
|
||||||
assertEquals(List.of(2, 6), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(2, 6), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeOneBasedOutput() {
|
void testParsePageListWithRangeOneBasedOutput() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"1-3"}, 5, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1-3"}, 5, true);
|
||||||
assertEquals(List.of(1, 2, 3), result, "Range should be parsed correctly.");
|
assertEquals(List.of(1, 2, 3), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeZeroBaseOutput() {
|
void testParsePageListWithRangeZeroBaseOutput() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"1-3"}, 5, false);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1-3"}, 5, false);
|
||||||
assertEquals(List.of(0, 1, 2), result, "Range should be parsed correctly.");
|
assertEquals(List.of(0, 1, 2), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeOneBasedOutputFull() {
|
void testParsePageListWithRangeOneBasedOutputFull() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"1,3,7-8"}, 8, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 8, true);
|
||||||
assertEquals(List.of(1, 3, 7, 8), result, "Range should be parsed correctly.");
|
assertEquals(List.of(1, 3, 7, 8), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeOneBasedOutputFullOutOfRange() {
|
void testParsePageListWithRangeOneBasedOutputFullOutOfRange() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"1,3,7-8"}, 5, true);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 5, true);
|
||||||
assertEquals(List.of(1, 3), result, "Range should be parsed correctly.");
|
assertEquals(List.of(1, 3), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeZeroBaseOutputFull() {
|
void testParsePageListWithRangeZeroBaseOutputFull() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[]{"1,3,7-8"}, 8, false);
|
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 8, false);
|
||||||
assertEquals(List.of(0, 2, 6, 7), result, "Range should be parsed correctly.");
|
assertEquals(List.of(0, 2, 6, 7), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class ImageProcessingUtilsTest {
|
public class ImageProcessingUtilsTest {
|
||||||
|
|
||||||
@ -14,7 +16,8 @@ public class ImageProcessingUtilsTest {
|
|||||||
BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
||||||
fillImageWithColor(sourceImage, Color.RED);
|
fillImageWithColor(sourceImage, Color.RED);
|
||||||
|
|
||||||
BufferedImage convertedImage = ImageProcessingUtils.convertColorType(sourceImage, "greyscale");
|
BufferedImage convertedImage =
|
||||||
|
ImageProcessingUtils.convertColorType(sourceImage, "greyscale");
|
||||||
|
|
||||||
assertNotNull(convertedImage);
|
assertNotNull(convertedImage);
|
||||||
assertEquals(BufferedImage.TYPE_BYTE_GRAY, convertedImage.getType());
|
assertEquals(BufferedImage.TYPE_BYTE_GRAY, convertedImage.getType());
|
||||||
@ -32,7 +35,8 @@ public class ImageProcessingUtilsTest {
|
|||||||
BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
||||||
fillImageWithColor(sourceImage, Color.RED);
|
fillImageWithColor(sourceImage, Color.RED);
|
||||||
|
|
||||||
BufferedImage convertedImage = ImageProcessingUtils.convertColorType(sourceImage, "blackwhite");
|
BufferedImage convertedImage =
|
||||||
|
ImageProcessingUtils.convertColorType(sourceImage, "blackwhite");
|
||||||
|
|
||||||
assertNotNull(convertedImage);
|
assertNotNull(convertedImage);
|
||||||
assertEquals(BufferedImage.TYPE_BYTE_BINARY, convertedImage.getType());
|
assertEquals(BufferedImage.TYPE_BYTE_BINARY, convertedImage.getType());
|
||||||
@ -49,7 +53,8 @@ public class ImageProcessingUtilsTest {
|
|||||||
BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
||||||
fillImageWithColor(sourceImage, Color.RED);
|
fillImageWithColor(sourceImage, Color.RED);
|
||||||
|
|
||||||
BufferedImage convertedImage = ImageProcessingUtils.convertColorType(sourceImage, "fullcolor");
|
BufferedImage convertedImage =
|
||||||
|
ImageProcessingUtils.convertColorType(sourceImage, "fullcolor");
|
||||||
|
|
||||||
assertNotNull(convertedImage);
|
assertNotNull(convertedImage);
|
||||||
assertEquals(sourceImage, convertedImage);
|
assertEquals(sourceImage, convertedImage);
|
||||||
@ -60,7 +65,8 @@ public class ImageProcessingUtilsTest {
|
|||||||
BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
||||||
fillImageWithColor(sourceImage, Color.RED);
|
fillImageWithColor(sourceImage, Color.RED);
|
||||||
|
|
||||||
BufferedImage convertedImage = ImageProcessingUtils.convertColorType(sourceImage, "invalidtype");
|
BufferedImage convertedImage =
|
||||||
|
ImageProcessingUtils.convertColorType(sourceImage, "invalidtype");
|
||||||
|
|
||||||
assertNotNull(convertedImage);
|
assertNotNull(convertedImage);
|
||||||
assertEquals(sourceImage, convertedImage);
|
assertEquals(sourceImage, convertedImage);
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.pdfbox.cos.COSName;
|
import org.apache.pdfbox.cos.COSName;
|
||||||
import org.apache.pdfbox.pdmodel.PDPage;
|
import org.apache.pdfbox.pdmodel.PDPage;
|
||||||
import org.apache.pdfbox.pdmodel.PDResources;
|
import org.apache.pdfbox.pdmodel.PDResources;
|
||||||
@ -8,13 +18,6 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
public class PdfUtilsTest {
|
public class PdfUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -46,6 +49,4 @@ public class PdfUtilsTest {
|
|||||||
|
|
||||||
assertTrue(PdfUtils.hasImagesOnPage(page));
|
assertTrue(PdfUtils.hasImagesOnPage(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.jupiter.api.Test;
|
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.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class ProcessExecutorTest {
|
public class ProcessExecutorTest {
|
||||||
|
|
||||||
@ -27,7 +30,8 @@ public class ProcessExecutorTest {
|
|||||||
command.add("-version");
|
command.add("-version");
|
||||||
|
|
||||||
// Execute the command
|
// Execute the command
|
||||||
ProcessExecutor.ProcessExecutorResult result = processExecutor.runCommandWithOutputHandling(command);
|
ProcessExecutor.ProcessExecutorResult result =
|
||||||
|
processExecutor.runCommandWithOutputHandling(command);
|
||||||
|
|
||||||
// Check the exit code and output messages
|
// Check the exit code and output messages
|
||||||
assertEquals(0, result.getRc());
|
assertEquals(0, result.getRc());
|
||||||
@ -41,15 +45,21 @@ public class ProcessExecutorTest {
|
|||||||
command.add("nonexistent-command");
|
command.add("nonexistent-command");
|
||||||
|
|
||||||
// Execute the command and expect an IOException
|
// Execute the command and expect an IOException
|
||||||
IOException thrown = assertThrows(IOException.class, () -> {
|
IOException thrown =
|
||||||
processExecutor.runCommandWithOutputHandling(command);
|
assertThrows(
|
||||||
});
|
IOException.class,
|
||||||
|
() -> {
|
||||||
|
processExecutor.runCommandWithOutputHandling(command);
|
||||||
|
});
|
||||||
|
|
||||||
// Log the actual error message
|
// Log the actual error message
|
||||||
System.out.println("Caught IOException: " + thrown.getMessage());
|
System.out.println("Caught IOException: " + thrown.getMessage());
|
||||||
|
|
||||||
// Check the exception message to ensure it indicates the command was not found
|
// Check the exception message to ensure it indicates the command was not found
|
||||||
String errorMessage = thrown.getMessage();
|
String errorMessage = thrown.getMessage();
|
||||||
assertTrue(errorMessage.contains("error=2") || errorMessage.contains("No such file or directory"), "Unexpected error message: " + errorMessage);
|
assertTrue(
|
||||||
|
errorMessage.contains("error=2")
|
||||||
|
|| errorMessage.contains("No such file or directory"),
|
||||||
|
"Unexpected error message: " + errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class PropertyConfigsTest {
|
public class PropertyConfigsTest {
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class RequestUriUtilsTest {
|
public class RequestUriUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class UrlUtilsTest {
|
public class UrlUtilsTest {
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@ -8,11 +15,6 @@ import org.springframework.http.MediaType;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
public class WebResponseUtilsTest {
|
public class WebResponseUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -22,7 +24,8 @@ public class WebResponseUtilsTest {
|
|||||||
baos.write("Sample PDF content".getBytes());
|
baos.write("Sample PDF content".getBytes());
|
||||||
String docName = "sample.pdf";
|
String docName = "sample.pdf";
|
||||||
|
|
||||||
ResponseEntity<byte[]> responseEntity = WebResponseUtils.boasToWebResponse(baos, docName);
|
ResponseEntity<byte[]> responseEntity =
|
||||||
|
WebResponseUtils.boasToWebResponse(baos, docName);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
@ -32,7 +35,8 @@ public class WebResponseUtilsTest {
|
|||||||
assertNotNull(headers);
|
assertNotNull(headers);
|
||||||
assertEquals(MediaType.APPLICATION_PDF, headers.getContentType());
|
assertEquals(MediaType.APPLICATION_PDF, headers.getContentType());
|
||||||
assertNotNull(headers.getContentDisposition());
|
assertNotNull(headers.getContentDisposition());
|
||||||
//assertEquals("attachment; filename=\"sample.pdf\"", headers.getContentDisposition().toString());
|
// assertEquals("attachment; filename=\"sample.pdf\"",
|
||||||
|
// headers.getContentDisposition().toString());
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fail("Exception thrown: " + e.getMessage());
|
fail("Exception thrown: " + e.getMessage());
|
||||||
@ -43,9 +47,11 @@ public class WebResponseUtilsTest {
|
|||||||
public void testMultiPartFileToWebResponse() {
|
public void testMultiPartFileToWebResponse() {
|
||||||
try {
|
try {
|
||||||
byte[] fileContent = "Sample file content".getBytes();
|
byte[] fileContent = "Sample file content".getBytes();
|
||||||
MockMultipartFile file = new MockMultipartFile("file", "sample.txt", "text/plain", fileContent);
|
MockMultipartFile file =
|
||||||
|
new MockMultipartFile("file", "sample.txt", "text/plain", fileContent);
|
||||||
|
|
||||||
ResponseEntity<byte[]> responseEntity = WebResponseUtils.multiPartFileToWebResponse(file);
|
ResponseEntity<byte[]> responseEntity =
|
||||||
|
WebResponseUtils.multiPartFileToWebResponse(file);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
@ -68,7 +74,8 @@ public class WebResponseUtilsTest {
|
|||||||
String docName = "sample.txt";
|
String docName = "sample.txt";
|
||||||
MediaType mediaType = MediaType.TEXT_PLAIN;
|
MediaType mediaType = MediaType.TEXT_PLAIN;
|
||||||
|
|
||||||
ResponseEntity<byte[]> responseEntity = WebResponseUtils.bytesToWebResponse(bytes, docName, mediaType);
|
ResponseEntity<byte[]> responseEntity =
|
||||||
|
WebResponseUtils.bytesToWebResponse(bytes, docName, mediaType);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
@ -79,7 +86,6 @@ public class WebResponseUtilsTest {
|
|||||||
assertEquals(MediaType.TEXT_PLAIN, headers.getContentType());
|
assertEquals(MediaType.TEXT_PLAIN, headers.getContentType());
|
||||||
assertNotNull(headers.getContentDisposition());
|
assertNotNull(headers.getContentDisposition());
|
||||||
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fail("Exception thrown: " + e.getMessage());
|
fail("Exception thrown: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -92,7 +98,8 @@ public class WebResponseUtilsTest {
|
|||||||
document.addPage(new org.apache.pdfbox.pdmodel.PDPage());
|
document.addPage(new org.apache.pdfbox.pdmodel.PDPage());
|
||||||
String docName = "sample.pdf";
|
String docName = "sample.pdf";
|
||||||
|
|
||||||
ResponseEntity<byte[]> responseEntity = WebResponseUtils.pdfDocToWebResponse(document, docName);
|
ResponseEntity<byte[]> responseEntity =
|
||||||
|
WebResponseUtils.pdfDocToWebResponse(document, docName);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
@ -103,7 +110,6 @@ public class WebResponseUtilsTest {
|
|||||||
assertEquals(MediaType.APPLICATION_PDF, headers.getContentType());
|
assertEquals(MediaType.APPLICATION_PDF, headers.getContentType());
|
||||||
assertNotNull(headers.getContentDisposition());
|
assertNotNull(headers.getContentDisposition());
|
||||||
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fail("Exception thrown: " + e.getMessage());
|
fail("Exception thrown: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,25 @@
|
|||||||
package stirling.software.SPDF.utils.validation;
|
package stirling.software.SPDF.utils.validation;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.UsernameAttribute;
|
import stirling.software.SPDF.model.UsernameAttribute;
|
||||||
import stirling.software.SPDF.model.provider.GitHubProvider;
|
import stirling.software.SPDF.model.provider.GitHubProvider;
|
||||||
import stirling.software.SPDF.model.provider.GoogleProvider;
|
import stirling.software.SPDF.model.provider.GoogleProvider;
|
||||||
import stirling.software.SPDF.model.provider.KeycloakProvider;
|
|
||||||
import stirling.software.SPDF.model.provider.Provider;
|
import stirling.software.SPDF.model.provider.Provider;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class ValidatorTest {
|
class ValidatorTest {
|
||||||
|
|
||||||
@ -41,14 +42,10 @@ class ValidatorTest {
|
|||||||
|
|
||||||
public static Stream<Arguments> providerParams() {
|
public static Stream<Arguments> providerParams() {
|
||||||
Provider generic = null;
|
Provider generic = null;
|
||||||
var google = new GoogleProvider(null, "clientSecret", List.of("scope"), UsernameAttribute.EMAIL);
|
var google =
|
||||||
|
new GoogleProvider(null, "clientSecret", List.of("scope"), UsernameAttribute.EMAIL);
|
||||||
var github = new GitHubProvider("clientId", "", List.of("scope"), UsernameAttribute.LOGIN);
|
var github = new GitHubProvider("clientId", "", List.of("scope"), UsernameAttribute.LOGIN);
|
||||||
|
|
||||||
return Stream.of(
|
return Stream.of(Arguments.of(generic), Arguments.of(google), Arguments.of(github));
|
||||||
Arguments.of(generic),
|
|
||||||
Arguments.of(google),
|
|
||||||
Arguments.of(github)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user