刘光辉
7 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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());
            }
        }
    }
}