Clover icon

magnolia-module-groovy 2.4.7

  1. Project Clover database Thu Dec 1 2016 10:48:40 CET
  2. Package info.magnolia.module.groovy.support.nodes

File MgnlGroovyNodeTest.java

 

Code metrics

0
25
5
1
150
72
5
0.2
5
5
1
30.2% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
MgnlGroovyNodeTest 51 25 30.2% 5 0
1.0100%
 

Contributing tests

This file is covered by 6 tests. .

Source view

1    /**
2    * This file Copyright (c) 2012-2016 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
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   
 
51    public class MgnlGroovyNodeTest {
52    protected static final BigDecimal ONE = new BigDecimal(1);
53    protected MockContent content;
54   
 
55  6 toggle @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   
 
63  1 toggle @Test
64    public void lookUpName() throws Exception {
65    //GIVEN see setUp()
66   
67    //WHEN
68  1 MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content);
69   
70    //THEN
71  1 assertEquals("qux", wrappedContent.get("name"));
72  1 assertEquals("IAmCalledNameButAmDifferentFromNodeName", wrappedContent.get("@name"));
73    }
74   
 
75  1 toggle @Test
76    public void lookUpPropertyWithAndWithoutAtNotationReturnsSameValue() throws Exception {
77    //GIVEN see setUp()
78   
79    //WHEN
80  1 MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content);
81   
82    //THEN
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   
 
91    toggle @Test
92    public void getChildren() throws Exception {
93    // GIVEN
94    content.addContent(new MockContent("baz"));
95    content.addContent(new MockContent("bar"));
96    MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content);
97   
98    // WHEN
99    Collection<Content> children = (Collection<Content>) wrappedContent.get("children");
100   
101    // THEN
102    assertEquals(2, children.size());
103    }
104   
 
105    toggle @Test
106    public void getChildrenWithContentNode() throws Exception {
107    // GIVEN
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    // WHEN
114    Collection<Content> children = (Collection<Content>) wrappedContent.get("children");
115   
116    // THEN
117    assertEquals(3, children.size());
118    }
119   
 
120  1 toggle @Test
121    public void iterator() throws Exception {
122    // GIVEN
123  1 content.addContent(new MockContent("baz"));
124  1 content.addContent(new MockContent("bar"));
125  1 MgnlGroovyNode wrappedContent = new MgnlGroovyNode(content);
126   
127    // WHEN
128  1 Iterator<Content> iter = wrappedContent.iterator();
129   
130    // THEN
131  1 Object[] children = IteratorUtils.toArray(iter);
132  1 assertEquals(2, children.length);
133    }
134   
 
135  1 toggle @Test
136    public void iteratorWithContentNode() throws Exception {
137    // GIVEN
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    // WHEN
144  1 Iterator<Content> iter = wrappedContent.iterator();
145   
146    // THEN
147  1 Object[] children = IteratorUtils.toArray(iter);
148  1 assertEquals(3, children.length);
149    }
150    }