1. Project Clover database Fri Apr 29 2016 13:24:33 CEST
  2. Package info.magnolia.module.blossom.template

File TemplateDefinitionBuilderAvailableTest.java

 

Code metrics

0
31
15
8
191
113
15
0.48
2.07
1.88
1

Classes

Class Line # Actions
TemplateDefinitionBuilderAvailableTest 56 24 0% 8 0
1.0100%
TemplateDefinitionBuilderAvailableTest.TestTemplate 69 1 0% 1 2
0.00%
TemplateDefinitionBuilderAvailableTest.BaseTemplate 77 1 0% 1 2
0.00%
TemplateDefinitionBuilderAvailableTest.InheritsAndOverrides 86 1 0% 1 2
0.00%
TemplateDefinitionBuilderAvailableTest.InheritsAndReuses 95 0 - 0 0
-1.0 -
TemplateDefinitionBuilderAvailableTest.InheritsAndOverridesWithAnnotation 99 1 0% 1 0
1.0100%
TemplateDefinitionBuilderAvailableTest.InheritsWithAnnotation 109 1 0% 1 0
1.0100%
TemplateDefinitionBuilderAvailableTest.TemplateWithMultipleAvailableMethods 173 2 0% 2 4
0.00%
 

Contributing tests

This file is covered by 6 tests. .

Source view

1    /**
2    * This file Copyright (c) 2010-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.blossom.template;
35   
36    import static org.junit.Assert.assertEquals;
37    import static org.junit.Assert.assertFalse;
38    import static org.junit.Assert.assertNotNull;
39   
40    import info.magnolia.module.blossom.annotation.Available;
41    import info.magnolia.module.blossom.annotation.Template;
42    import info.magnolia.rendering.template.TemplateAvailability;
43    import info.magnolia.rendering.template.configured.DefaultTemplateAvailability;
44    import info.magnolia.test.ComponentsTestUtil;
45    import info.magnolia.test.mock.jcr.MockNode;
46   
47    import javax.jcr.Node;
48   
49    import org.junit.After;
50    import org.junit.Before;
51    import org.junit.Test;
52   
53    /**
54    * @since 1.1
55    */
 
56    public class TemplateDefinitionBuilderAvailableTest {
57   
 
58  6 toggle @Before
59    public void setUp() {
60  6 ComponentsTestUtil.setImplementation(TemplateAvailability.class, DefaultTemplateAvailability.class);
61    }
62   
 
63  6 toggle @After
64    public void tearDown() {
65  6 ComponentsTestUtil.clear();
66    }
67   
68    @Template(title = "Text", id = "base")
 
69    public static class TestTemplate {
70   
 
71  0 toggle @Available
72    public boolean isAvailable(Node node) {
73  0 return true;
74    }
75    }
76   
 
77    public static class BaseTemplate {
78   
 
79  0 toggle @Available
80    public boolean isAvailable(Node node) {
81  0 return true;
82    }
83    }
84   
85    @Template(title = "Overrides", id = "overrides")
 
86    public static class InheritsAndOverrides extends BaseTemplate {
87   
 
88  0 toggle @Override
89    public boolean isAvailable(Node node) {
90  0 return false;
91    }
92    }
93   
94    @Template(title = "Inherits", id = "inherits")
 
95    public static class InheritsAndReuses extends BaseTemplate {
96    }
97   
98    @Template(title = "InheritsAndOverridesWithAnnotation", id = "InheritsAndOverridesWithAnnotation")
 
99    public static class InheritsAndOverridesWithAnnotation extends BaseTemplate {
100   
 
101  1 toggle @Override
102    @Available
103    public boolean isAvailable(Node node) {
104  1 return false;
105    }
106    }
107   
108    @Template(title = "InheritsWithAnnotation", id = "InheritsWithAnnotation")
 
109    public static class InheritsWithAnnotation extends BaseTemplate {
110   
 
111  1 toggle @Available
112    public boolean available(Node node) {
113  1 return false;
114    }
115    }
116   
 
117  1 toggle @Test
118    public void testTemplateAvailability() throws Exception {
119   
120  1 TestTemplate template = new TestTemplate();
121   
122  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(template);
123   
124  1 assertNotNull(description.getTemplateAvailability());
125    }
126   
 
127  1 toggle @Test
128    public void testAvailableOverriding() throws Exception {
129  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(new InheritsAndOverrides());
130   
131  1 assertEquals("Overrides", description.getTitle());
132  1 assertEquals("overrides", description.getId());
133   
134  1 assertFalse("info.magnolia.module.blossom.template.TemplateDefinitionBuilder.DefaultTemplateAvailability".equals(description.getTemplateAvailability().getClass().getName()));
135    }
136   
 
137  1 toggle @Test
138    public void testAvailableInheritance() throws Exception {
139   
140  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(new InheritsAndReuses());
141   
142  1 assertEquals("Inherits", description.getTitle());
143  1 assertEquals("inherits", description.getId());
144   
145  1 assertNotNull(description.getTemplateAvailability());
146    }
147   
 
148  1 toggle @Test
149    public void testAvailableOverridingWithAnnotation() throws Exception {
150   
151  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(new InheritsAndOverridesWithAnnotation());
152   
153  1 assertEquals("InheritsAndOverridesWithAnnotation", description.getTitle());
154  1 assertEquals("InheritsAndOverridesWithAnnotation", description.getId());
155   
156  1 assertNotNull(description.getTemplateAvailability());
157  1 assertFalse(description.getTemplateAvailability().isAvailable(new MockNode("mock"), description));
158    }
159   
 
160  1 toggle @Test
161    public void testAvailableInheritsAndOverridesWithAnnotation() throws Exception {
162   
163  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(new InheritsWithAnnotation());
164   
165  1 assertEquals("InheritsWithAnnotation", description.getTitle());
166  1 assertEquals("InheritsWithAnnotation", description.getId());
167   
168  1 assertNotNull(description.getTemplateAvailability());
169  1 assertFalse(description.getTemplateAvailability().isAvailable(new MockNode("mock"), description));
170    }
171   
172    @Template(title = "Too many available methods", id = "notUsed")
 
173    public static class TemplateWithMultipleAvailableMethods {
174   
 
175  0 toggle @Available
176    public boolean available1(Node content) {
177  0 return true;
178    }
179   
 
180  0 toggle @Available
181    public boolean available2(Node content) {
182  0 return false;
183    }
184    }
185   
 
186  1 toggle @Test(expected = IllegalStateException.class)
187    public void testAvailableMultiple() {
188  1 TemplateDefinitionBuilderTest.buildTemplateDefinition(new TemplateWithMultipleAvailableMethods());
189    }
190   
191    }