Clover Coverage Report - magnolia-module-templating 4.4.5
Coverage timestamp: Mon Sep 12 2011 16:32:30 CEST
34   130   4   8.5
0   63   0.12   4
4     1  
1    
 
  ParagraphManagerTest       Line # 47 34 0% 4 0 100% 1.0
 
  (4)
 
1    /**
2    * This file Copyright (c) 2003-2011 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.templating;
35   
36    import info.magnolia.cms.core.Content;
37    import info.magnolia.test.MgnlTestCase;
38    import info.magnolia.test.mock.MockUtil;
39   
40    import javax.jcr.RepositoryException;
41    import java.io.IOException;
42   
43    /**
44    * @author gjoseph
45    * @version $Revision: $ ($Author: $)
46    */
 
47    public class ParagraphManagerTest extends MgnlTestCase {
 
48  1 toggle public void testJspIsDefaultTypeIfNotSpecified() throws IOException, RepositoryException {
49  1 final Content paraNode = MockUtil.createHierarchyManager(PARA_NOTYPE).getContent("/modules/test/paragraph/foo");
50  1 final ParagraphManager pm = new ParagraphManager();
51  1 pm.addParagraphToCache(paraNode);
52  1 final Paragraph p = pm.getParagraphDefinition("foo");
53  1 assertEquals("jsp", p.getType());
54  1 assertEquals("foo", p.getName());
55    }
56   
57    // TODO : this is not implemented at all - no checks are done on the paragraph config node
58    // public void testShouldNotBeAbleToAddAnIrrelevantNode() throws IOException, RepositoryException {
59    // final Content n = MockUtil.createHierarchyManager(PARA_TEST).getContent("/modules/test/paragraph");
60    // final ParagraphManager pm = new ParagraphManager();
61    // pm.addParagraphToCache(n);
62    // assertEquals(0, pm.getParagraphs().size());
63    // }
64    //
65    // public void testShouldNotBeAbleToRegisterTwoParagraphsWithIdenticalNames() {
66    // fail("not implemented yet");
67    // }
68    //
69    // public void testExceptionOnUnknownParagraph ?() {
70    // fail("not implemented yet");
71    // }
72   
 
73  1 toggle public void testShouldUseNodeNameIfNoNameProperty() throws IOException, RepositoryException {
74  1 final Content paraNode = MockUtil.createHierarchyManager(PARA_NONAME).getContent("/modules/test/paragraph/noname");
75  1 final ParagraphManager pm = new ParagraphManager();
76  1 pm.addParagraphToCache(paraNode);
77  1 final Paragraph p = pm.getParagraphDefinition("noname");
78  1 assertEquals("noname", p.getName());
79  1 assertEquals("jsp", p.getType());
80    }
81   
 
82  1 toggle public void testNamePropertyShouldPrevailOverNodeName() throws IOException, RepositoryException {
83  1 final Content n = MockUtil.createHierarchyManager(PARA_TEST).getContent("/modules/test/paragraph");
84  1 final ParagraphManager pm = new ParagraphManager();
85  1 pm.onRegister(n);
86  1 Paragraph baz = pm.getParagraphDefinition("baz");
87  1 assertEquals("baz", baz.getName());
88  1 assertEquals(null, pm.getParagraphDefinition("bar"));
89  1 Paragraph foo = pm.getParagraphDefinition("foo");
90  1 assertEquals("foo", foo.getName());
91    }
92   
 
93  1 toggle public void testDialogNameShouldBeEqualsToParagraphNameIfNotSpecified() throws IOException, RepositoryException {
94  1 final Content n = MockUtil.createHierarchyManager(PARA_TEST).getContent("/modules/test/paragraph");
95  1 final Content c2 = MockUtil.createHierarchyManager(PARA_NONAME).getContent("/modules/test/paragraph");
96  1 final ParagraphManager pm = new ParagraphManager();
97  1 pm.onRegister(n);
98  1 pm.onRegister(c2);
99   
100  1 final Paragraph baz = pm.getParagraphDefinition("foo");
101  1 assertEquals("foo", baz.getName());
102  1 assertEquals("fooDialog", baz.getDialog());
103   
104  1 final Paragraph bar = pm.getParagraphDefinition("baz");
105  1 assertEquals("baz", bar.getName());
106  1 assertEquals("baz", bar.getDialog());
107   
108  1 final Paragraph noname = pm.getParagraphDefinition("noname");
109  1 assertEquals("noname", noname.getName());
110  1 assertEquals("noname", noname.getDialog());
111    }
112   
113    private static final String PARA_NOTYPE = "" +
114    "modules.test.paragraph.foo.@type=mgnl:contentNode\n" +
115    "modules.test.paragraph.foo.name=foo";
116   
117    private static final String PARA_NONAME = "" +
118    "modules.test.paragraph.noname.@type=mgnl:contentNode";
119   
120    private static final String PARA_TEST = "" +
121    //"modules.test.paragraph.@type=mgnl:contentNode\n" +
122    "modules.test.paragraph.foo.@type=mgnl:contentNode\n" +
123    "modules.test.paragraph.foo.name=foo\n" +
124    "modules.test.paragraph.foo.type=jsp\n" +
125    "modules.test.paragraph.foo.dialog=fooDialog\n" +
126    "modules.test.paragraph.bar.@type=mgnl:contentNode\n" +
127    "modules.test.paragraph.bar.name=baz\n" +
128    "modules.test.paragraph.bar.type=jsp";
129   
130    }