1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.util;
17
18 import static org.junit.Assert.assertEquals;
19
20 import java.lang.annotation.Retention;
21 import java.lang.annotation.RetentionPolicy;
22
23 import org.junit.Test;
24 import org.kuali.rice.krad.uif.util.ObjectPathExpressionParser.PathEntry;
25
26 public class ObjectPathExpressionParserTest extends ProcessLoggingUnitTest {
27
28 @Retention(RetentionPolicy.RUNTIME)
29 public @interface TestAnnotation {
30 String afoo();
31 }
32
33 private static class DoIt implements PathEntry {
34
35 @Override
36 public String parse(Object node, String next, boolean inherit) {
37 if (next == null) {
38 return "";
39 }
40 String snode = (String) node;
41 StringBuilder rv = new StringBuilder();
42 if (snode != null && snode.length() > 0) {
43 rv.append(snode);
44 }
45 if (inherit) {
46 rv.append('<');
47 } else if (rv.length() > 0) {
48 rv.append('+');
49 }
50 rv.append(next);
51 if (inherit) {
52 rv.append('>');
53 }
54
55 return rv.toString();
56 }
57
58 @Override
59 public Object prepare(Object prev) {
60 return prev;
61 }
62
63 @Override
64 public String dereference(Object prev) {
65 return (String) prev;
66 }
67
68 }
69
70 @Test
71 public void testParsePathExpression() {
72 assertEquals("foo+bar",
73 ObjectPathExpressionParser.parsePathExpression(null, "foo.bar", new DoIt())
74 .toString());
75 assertEquals("foo<bar>",
76 ObjectPathExpressionParser.parsePathExpression(null, "foo[bar]", new DoIt())
77 .toString());
78 assertEquals("foo<bar>+baz",
79 ObjectPathExpressionParser
80 .parsePathExpression(null, "foo[bar].baz", new DoIt())
81 .toString());
82 assertEquals(
83 "foo<bar<baz>>",
84 ObjectPathExpressionParser.parsePathExpression(null, "foo[bar[baz]]",
85 new DoIt()).toString());
86 assertEquals(
87 "foo+bar-bar.baz+fez",
88 ObjectPathExpressionParser.parsePathExpression(null, "foo(bar-bar.baz)+fez",
89 new DoIt()).toString());
90 }
91
92 }