1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.groovy.support.nodes; |
35 |
|
|
36 |
|
import static org.junit.Assert.assertEquals; |
37 |
|
|
38 |
|
import info.magnolia.cms.core.Content; |
39 |
|
import info.magnolia.cms.core.ItemType; |
40 |
|
import info.magnolia.test.mock.MockContent; |
41 |
|
|
42 |
|
import java.math.BigDecimal; |
43 |
|
import java.util.Collection; |
44 |
|
import java.util.Iterator; |
45 |
|
|
46 |
|
import org.apache.commons.collections.IteratorUtils; |
47 |
|
import org.junit.Before; |
48 |
|
import org.junit.Test; |
49 |
|
|
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 5 |
Complexity Density: 0.2 |
|
51 |
|
public class MgnlGroovyNodeTest { |
52 |
|
protected static final BigDecimal ONE = new BigDecimal(1); |
53 |
|
protected MockContent content; |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
55 |
6 |
@Before... |
56 |
|
public void setUp() { |
57 |
6 |
content = new MockContent("qux"); |
58 |
6 |
content.addNodeData("foo", 1); |
59 |
6 |
content.addNodeData("bar", "IAmBar"); |
60 |
6 |
content.addNodeData("name", "IAmCalledNameButAmDifferentFromNodeName"); |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
63 |
1 |
@Test... |
64 |
|
public void lookUpName() throws Exception { |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
1 |
MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content); |
69 |
|
|
70 |
|
|
71 |
1 |
assertEquals("qux", wrappedContent.get("name")); |
72 |
1 |
assertEquals("IAmCalledNameButAmDifferentFromNodeName", wrappedContent.get("@name")); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
75 |
1 |
@Test... |
76 |
|
public void lookUpPropertyWithAndWithoutAtNotationReturnsSameValue() throws Exception { |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
1 |
MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content); |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
1 |
assertEquals(ONE, wrappedContent.get("foo")); |
85 |
1 |
assertEquals(ONE, wrappedContent.get("@foo")); |
86 |
|
|
87 |
1 |
assertEquals("IAmBar", wrappedContent.get("bar")); |
88 |
1 |
assertEquals("IAmBar", wrappedContent.get("@bar")); |
89 |
|
} |
90 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
91 |
|
@Test... |
92 |
|
public void getChildren() throws Exception { |
93 |
|
|
94 |
|
content.addContent(new MockContent("baz")); |
95 |
|
content.addContent(new MockContent("bar")); |
96 |
|
MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content); |
97 |
|
|
98 |
|
|
99 |
|
Collection<Content> children = (Collection<Content>) wrappedContent.get("children"); |
100 |
|
|
101 |
|
|
102 |
|
assertEquals(2, children.size()); |
103 |
|
} |
104 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
105 |
|
@Test... |
106 |
|
public void getChildrenWithContentNode() throws Exception { |
107 |
|
|
108 |
|
content.addContent(new MockContent("bar")); |
109 |
|
content.addContent(new MockContent("baz", ItemType.CONTENTNODE)); |
110 |
|
content.addContent(new MockContent("qux", ItemType.CONTENTNODE)); |
111 |
|
MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content); |
112 |
|
|
113 |
|
|
114 |
|
Collection<Content> children = (Collection<Content>) wrappedContent.get("children"); |
115 |
|
|
116 |
|
|
117 |
|
assertEquals(3, children.size()); |
118 |
|
} |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
120 |
1 |
@Test... |
121 |
|
public void iterator() throws Exception { |
122 |
|
|
123 |
1 |
content.addContent(new MockContent("baz")); |
124 |
1 |
content.addContent(new MockContent("bar")); |
125 |
1 |
MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content); |
126 |
|
|
127 |
|
|
128 |
1 |
Iterator<Content> iter = wrappedContent.iterator(); |
129 |
|
|
130 |
|
|
131 |
1 |
Object[] children = IteratorUtils.toArray(iter); |
132 |
1 |
assertEquals(2, children.length); |
133 |
|
} |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
135 |
1 |
@Test... |
136 |
|
public void iteratorWithContentNode() throws Exception { |
137 |
|
|
138 |
1 |
content.addContent(new MockContent("bar")); |
139 |
1 |
content.addContent(new MockContent("baz", ItemType.CONTENTNODE)); |
140 |
1 |
content.addContent(new MockContent("qux", ItemType.CONTENTNODE)); |
141 |
1 |
MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content); |
142 |
|
|
143 |
|
|
144 |
1 |
Iterator<Content> iter = wrappedContent.iterator(); |
145 |
|
|
146 |
|
|
147 |
1 |
Object[] children = IteratorUtils.toArray(iter); |
148 |
1 |
assertEquals(3, children.length); |
149 |
|
} |
150 |
|
} |