GraphSchemaSnapshotTest.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package com.agent.management.rag.graph;
  2. import org.junit.jupiter.api.Test;
  3. import java.util.List;
  4. import java.util.Map;
  5. import static org.assertj.core.api.Assertions.assertThat;
  6. class GraphSchemaSnapshotTest {
  7. @Test
  8. void whitelistIntersectsRealSchemaAndKeepsDirectionAndProperties() {
  9. GraphSchemaSnapshot schema = new GraphSchemaSnapshot(
  10. List.of(
  11. new GraphSchemaSnapshot.NodeSchema("Mission", Map.of("name", List.of("STRING"))),
  12. new GraphSchemaSnapshot.NodeSchema("Stage", Map.of("name", List.of("STRING"), "sequence", List.of("INTEGER"), "goal", List.of("STRING"))),
  13. new GraphSchemaSnapshot.NodeSchema("Secret", Map.of("value", List.of("STRING")))
  14. ),
  15. List.of(
  16. new GraphSchemaSnapshot.RelationshipSchema("HAS_STAGE", List.of("Mission"), List.of("Stage"), Map.of()),
  17. new GraphSchemaSnapshot.RelationshipSchema("SECRET_LINK", List.of("Mission"), List.of("Secret"), Map.of())
  18. )
  19. );
  20. GraphSchemaSnapshot filtered = schema.filter(
  21. List.of("Mission", "Stage"),
  22. List.of("HAS_STAGE"),
  23. Map.of("Mission", List.of("name"), "Stage", List.of("name", "sequence", "goal"))
  24. );
  25. assertThat(filtered.labelNames()).containsExactly("Mission", "Stage");
  26. assertThat(filtered.relationshipTypeNames()).containsExactly("HAS_STAGE");
  27. assertThat(filtered.node("Stage").orElseThrow().properties()).containsOnlyKeys("name", "sequence", "goal");
  28. assertThat(filtered.relationships()).singleElement().satisfies(rel -> {
  29. assertThat(rel.startLabels()).containsExactly("Mission");
  30. assertThat(rel.endLabels()).containsExactly("Stage");
  31. });
  32. }
  33. }