Skip to content

Commit ffcec15

Browse files
committed
test: add DocumentLinksResolveTest to validate document link resolution
1 parent 74332fa commit ffcec15

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package blue.language;
2+
3+
import blue.language.model.Node;
4+
import blue.language.provider.BasicNodeProvider;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static blue.language.utils.Properties.DICTIONARY_TYPE_BLUE_ID;
8+
import static blue.language.utils.Properties.TEXT_TYPE_BLUE_ID;
9+
import static org.junit.jupiter.api.Assertions.*;
10+
11+
public class DocumentLinksResolveTest {
12+
13+
@Test
14+
public void resolvesDocumentLinksDictionaries() throws Exception {
15+
BasicNodeProvider nodeProvider = new BasicNodeProvider();
16+
17+
String linkYaml =
18+
"name: Link\n" +
19+
"description: 'Abstract base class for all link types.'\n" +
20+
"anchor:\n" +
21+
" type:\n" +
22+
" blueId: " + TEXT_TYPE_BLUE_ID + "\n" +
23+
" description: 'Target anchor key on the destination document.'\n";
24+
nodeProvider.addSingleDocs(linkYaml);
25+
String linkBlueId = nodeProvider.getBlueIdByName("Link");
26+
27+
String documentLinkYaml =
28+
"name: Document Link\n" +
29+
"type:\n" +
30+
" blueId: " + linkBlueId + "\n" +
31+
"description: 'Link targeting a specific Blue document by its stable documentId (initial blueId before any processing). Used to point to a logical document regardless of session.'\n" +
32+
"documentId:\n" +
33+
" type:\n" +
34+
" blueId: " + TEXT_TYPE_BLUE_ID + "\n" +
35+
" description: 'Stable document identifier (original BlueId) of the target document.'\n";
36+
nodeProvider.addSingleDocs(documentLinkYaml);
37+
38+
System.out.println( nodeProvider.getBlueIdByName("Document Link"));
39+
40+
String documentLinksYaml =
41+
"name: Document Links\n" +
42+
"description: 'Dictionary of named outgoing connections from this document to anchors on other documents or sessions. MyOS indexes supported link variants to power discovery.'\n" +
43+
"type:\n" +
44+
" blueId: " + DICTIONARY_TYPE_BLUE_ID + "\n" +
45+
"keyType:\n" +
46+
" blueId: " + TEXT_TYPE_BLUE_ID + "\n" +
47+
"valueType:\n" +
48+
" blueId: " + linkBlueId + "\n";
49+
nodeProvider.addSingleDocs(documentLinksYaml);
50+
51+
Blue blue = new Blue(nodeProvider);
52+
53+
String yaml =
54+
"contracts:\n" +
55+
" links:\n" +
56+
" type:\n" +
57+
" blueId: " + nodeProvider.getBlueIdByName("Document Links") + "\n" +
58+
" link1:\n" +
59+
" type:\n" +
60+
" blueId: " + nodeProvider.getBlueIdByName("Document Link") + "\n" +
61+
" anchor: anchorA\n" +
62+
" documentId: doc-123\n";
63+
64+
Node node = blue.yamlToNode(yaml);
65+
assertNotNull(node);
66+
67+
Node resolved = blue.resolve(node);
68+
assertNotNull(resolved);
69+
70+
Node contracts = resolved.getProperties().get("contracts");
71+
assertNotNull(contracts);
72+
73+
Node linksNode = contracts.getProperties().get("links");
74+
assertNotNull(linksNode);
75+
assertEquals("Link", linksNode.getValueType().getName());
76+
77+
Node link1 = linksNode.getProperties().get("link1");
78+
assertNotNull(link1);
79+
assertEquals("Document Link", link1.getType().getName());
80+
assertEquals("doc-123", link1.getProperties().get("documentId").getValue());
81+
}
82+
}
83+
84+

0 commit comments

Comments
 (0)