View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Unit test for {@link org.kuali.rice.krad.data.util.ReferenceLinker}.
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
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          // first let's check 'a'
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          // now let's check 'b'
54          assertTrue(decomposed.containsKey("b"));
55          paths = decomposed.get("b");
56          assertTrue(paths.contains("1.2.3"));
57          assertEquals(1, paths.size());
58  
59          // now let's check for the 'c's
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          // check c[0]
66          paths = decomposed.get("c[0]");
67          assertTrue(paths.contains("a"));
68          assertEquals(1, paths.size());
69  
70          // check c[1]
71          paths = decomposed.get("c[1]");
72          assertTrue(paths.contains("b"));
73          assertEquals(1, paths.size());
74  
75          // check c['2']
76          paths = decomposed.get("c['2']");
77          assertTrue(paths.contains("c"));
78          assertEquals(1, paths.size());
79  
80          // check c["a.b.c"]
81          paths = decomposed.get("c[\"a.b.c\"]");
82          assertTrue(paths.contains("b.a"));
83          assertEquals(1, paths.size());
84  
85          // all told, there should have been 6 keys
86          assertEquals(6, decomposed.size());
87  
88      }
89  
90  }