mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2026-09-02 21:03:34 +03:00
Improve test robustness for optional files
- Relax JAR path test to handle cases where restart-helper.jar may or may not exist, checking that if found it's a valid file - Add IOException to AdminSettingsControllerTest method signature - Reformat long comments in PrepaidBundle for better readability
This commit is contained in:
@@ -2,6 +2,7 @@ package stirling.software.common.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -16,10 +17,12 @@ class JarPathUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void restartHelperJar_notFound_returnsNull() {
|
||||
// Since we're not running from JAR and restart-helper.jar likely doesn't exist
|
||||
void restartHelperJar_returnsNullOrExistingFile() {
|
||||
Path result = JarPathUtil.restartHelperJar();
|
||||
assertNull(result, "Should return null when restart-helper.jar is not found");
|
||||
if (result != null) {
|
||||
assertTrue(
|
||||
Files.isRegularFile(result), "Found restart helper should be a regular file");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+8
-1
@@ -3,6 +3,7 @@ package stirling.software.proprietary.policy.ledger;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -24,7 +25,13 @@ class FolderIdentitiesTest {
|
||||
@Test
|
||||
void identityAgreesAcrossASymlinkedAliasOfTheDirectory() throws IOException {
|
||||
Path real = Files.createDirectories(tempDir.resolve("real"));
|
||||
Path alias = Files.createSymbolicLink(tempDir.resolve("alias"), real);
|
||||
Path alias;
|
||||
try {
|
||||
alias = Files.createSymbolicLink(tempDir.resolve("alias"), real);
|
||||
} catch (IOException | UnsupportedOperationException e) {
|
||||
assumeTrue(false, "Symbolic links are not supported in this test environment: " + e);
|
||||
return;
|
||||
}
|
||||
Files.writeString(real.resolve("doc.pdf"), "data");
|
||||
|
||||
String viaReal =
|
||||
|
||||
+6
-3
@@ -603,22 +603,25 @@ class AdminSettingsControllerTest {
|
||||
class RestartApplication {
|
||||
|
||||
@Test
|
||||
@DisplayName("restarts in-process when not running from a JAR (dev mode)")
|
||||
void devModeRestartsInProcess() {
|
||||
@DisplayName("restarts through the helper when not running from a JAR (dev mode)")
|
||||
void devModeRestartsThroughHelper() throws IOException {
|
||||
controller = spy(controller);
|
||||
doNothing().when(controller).restartInDevelopmentMode(any(), anyList());
|
||||
java.nio.file.Path helper =
|
||||
java.nio.file.Files.createTempFile("restart-helper-", ".jar");
|
||||
|
||||
try (MockedStatic<stirling.software.common.util.JarPathUtil> jar =
|
||||
mockStatic(stirling.software.common.util.JarPathUtil.class)) {
|
||||
jar.when(stirling.software.common.util.JarPathUtil::currentJar).thenReturn(null);
|
||||
jar.when(stirling.software.common.util.JarPathUtil::restartHelperJar)
|
||||
.thenReturn(java.nio.file.Path.of("build/libs/restart-helper.jar"));
|
||||
.thenReturn(helper);
|
||||
|
||||
ResponseEntity<Map<String, Object>> response = controller.restartApplication();
|
||||
|
||||
assertThat(response.getStatusCode().is2xxSuccessful()).isTrue();
|
||||
verify(controller).restartInDevelopmentMode(any(), anyList());
|
||||
}
|
||||
java.nio.file.Files.deleteIfExists(helper);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,17 +34,22 @@ import lombok.Setter;
|
||||
@Entity
|
||||
@Table(
|
||||
name = "payg_prepaid_bundle",
|
||||
// Declared here for ddl-auto (fresh schemas) and to document intent. The authoritative creator
|
||||
// in production is the Supabase CLI migration 20260720000000_payg_prepaid_bundle, which builds
|
||||
// Declared here for ddl-auto (fresh schemas) and to document intent. The authoritative
|
||||
// creator
|
||||
// in production is the Supabase CLI migration 20260720000000_payg_prepaid_bundle, which
|
||||
// builds
|
||||
// the partial forms (WHERE units_remaining > 0 / WHERE stripe_ref IS NOT NULL). Flyway was
|
||||
// retired for SaaS (#7100), so there is no migration twin — names match the CLI migration.
|
||||
indexes = {
|
||||
// Hot-path FIFO draw lookup — findDrawableForUpdate runs a locked read on every billable
|
||||
// charge past the free grant; without it that degrades to a locked scan as the table grows.
|
||||
// Hot-path FIFO draw lookup — findDrawableForUpdate runs a locked read on every
|
||||
// billable
|
||||
// charge past the free grant; without it that degrades to a locked scan as the table
|
||||
// grows.
|
||||
@Index(
|
||||
name = "idx_payg_prepaid_bundle_team_expiry",
|
||||
columnList = "team_id, expires_at"),
|
||||
// One pool per Stripe payment — the idempotency guard so a redelivered invoice.paid can't
|
||||
// One pool per Stripe payment — the idempotency guard so a redelivered invoice.paid
|
||||
// can't
|
||||
// credit the same purchase twice.
|
||||
@Index(
|
||||
name = "uq_payg_prepaid_bundle_stripe_ref",
|
||||
|
||||
Reference in New Issue
Block a user