1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.data.util;
17
18 import junit.framework.TestCase;
19 import org.kuali.rice.krad.data.util.ReferenceLinker;
20
21 import java.util.HashSet;
22 import java.util.Map;
23 import java.util.Set;
24
25
26
27
28
29
30 public class ReferenceLinkerTest extends TestCase {
31
32 private ReferenceLinker referenceLinker = new ReferenceLinker();
33
34 public void testDecomposePropertyPaths() throws Exception {
35 Set<String> changes = new HashSet<String>();
36 changes.add("a.b.c.e");
37 changes.add("a.b2.c.e");
38 changes.add("b.1.2.3");
39 changes.add("c[0].a");
40 changes.add("c[1].b");
41 changes.add("c['2'].c");
42 changes.add("c[\"a.b.c\"].b.a");
43
44 Map<String, Set<String>> decomposed = referenceLinker.decomposePropertyPaths(changes);
45
46
47 assertTrue(decomposed.containsKey("a"));
48 Set<String> paths = decomposed.get("a");
49 assertTrue(paths.contains("b.c.e"));
50 assertTrue(paths.contains("b2.c.e"));
51 assertEquals(2, paths.size());
52
53
54 assertTrue(decomposed.containsKey("b"));
55 paths = decomposed.get("b");
56 assertTrue(paths.contains("1.2.3"));
57 assertEquals(1, paths.size());
58
59
60 assertTrue(decomposed.containsKey("c[0]"));
61 assertTrue(decomposed.containsKey("c[1]"));
62 assertTrue(decomposed.containsKey("c['2']"));
63 assertTrue(decomposed.containsKey("c[\"a.b.c\"]"));
64
65
66 paths = decomposed.get("c[0]");
67 assertTrue(paths.contains("a"));
68 assertEquals(1, paths.size());
69
70
71 paths = decomposed.get("c[1]");
72 assertTrue(paths.contains("b"));
73 assertEquals(1, paths.size());
74
75
76 paths = decomposed.get("c['2']");
77 assertTrue(paths.contains("c"));
78 assertEquals(1, paths.size());
79
80
81 paths = decomposed.get("c[\"a.b.c\"]");
82 assertTrue(paths.contains("b.a"));
83 assertEquals(1, paths.size());
84
85
86 assertEquals(6, decomposed.size());
87
88 }
89
90 }