package jnpf.limsService.provider;
|
|
import org.junit.Test;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
import jnpf.limsService.LimsTestWorkItemSnapshotService;
|
|
import javax.sql.DataSource;
|
import java.sql.SQLException;
|
|
import static org.junit.Assert.*;
|
|
public class LimsElnSourceRuntimeTest {
|
@Test
|
public void auditDisabledDoesNotIntroduceNewStartupDependencies() {
|
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
context.getEnvironment().getPropertySources().addFirst(new org.springframework.core.env.MapPropertySource(
|
"audit-disabled", java.util.Collections.singletonMap("audit.enabled", "false")));
|
context.register(LimsElnSourceAuditAspect.class);
|
context.refresh();
|
assertTrue(context.getBeansOfType(LimsElnSourceAuditAspect.class).isEmpty());
|
}
|
}
|
|
@Test
|
public void publishedSourceResponseKeepsCamelCaseAndHidesPhysicalDefinition() throws Exception {
|
com.fasterxml.jackson.databind.ObjectMapper mapper = new jnpf.config.JacksonConfig().objectMapper();
|
LimsElnSourceCatalog.Version version = new LimsElnSourceCatalog.Version("v1", "0", "sample.batch",
|
1, "PUBLISHED", "Batch", "TEXT", "{}", "{\"table\":\"private_table\"}",
|
"task-a", "analyst", "2026-09-06T00:00:00Z", 1);
|
|
com.fasterxml.jackson.databind.JsonNode response = mapper.readTree(mapper.writeValueAsString(version));
|
|
assertEquals("sample.batch", response.path("propertyCode").asText());
|
assertFalse(response.toString().contains("private_table"));
|
assertFalse(response.has("frozenDefinitionJson"));
|
assertFalse(response.has("frozen_definition_json"));
|
}
|
|
@Test
|
public void unavailablePrimarySettingsDoNotReplaceOrBorrowTheBusinessDataSource() throws Exception {
|
DataSource business = new DriverManagerDataSource("jdbc:postgresql://127.0.0.1:1/not_used");
|
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
context.registerBean("dataSource", DataSource.class, () -> business);
|
context.registerBean(LimsTestWorkItemSnapshotService.class, () -> (request, tenant, user) -> {
|
throw new AssertionError("Startup must not access business tasks");
|
});
|
context.register(LimsElnSourceConfiguration.class);
|
context.refresh();
|
|
assertEquals(1, context.getBeansOfType(DataSource.class).size());
|
assertSame(business, context.getBean(DataSource.class));
|
assertNotNull(context.getBean(LimsElnSourceCatalog.class));
|
assertNotNull(context.getBean(LimsElnReadonlyResolver.class));
|
try {
|
context.getBean(LimsElnReadonlyPool.class).dataSource().getConnection();
|
fail("Unavailable settings must not cause the source reader to borrow business connections");
|
} catch (SQLException expected) {
|
assertEquals("08001", expected.getSQLState());
|
}
|
}
|
}
|
}
|