Clover Coverage Report - magnolia-module-templating 4.4.5
Coverage timestamp: Mon Sep 12 2011 16:32:30 CEST
27   107   4   9
2   55   0.15   3
3     1.33  
1    
 
  JspTemplateRendererTest       Line # 60 27 0% 4 0 100% 1.0
 
  (1)
 
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.renderers;
35   
36    import info.magnolia.cms.core.SystemProperty;
37    import info.magnolia.module.templating.RenderableDefinition;
38    import info.magnolia.module.templating.RenderingModel;
39    import info.magnolia.cms.core.AggregationState;
40    import info.magnolia.cms.core.Content;
41    import info.magnolia.cms.util.ContentWrapper;
42    import info.magnolia.context.MgnlContext;
43    import info.magnolia.context.WebContext;
44    import info.magnolia.module.templating.AbstractRenderer;
45    import info.magnolia.module.templating.engine.DefaultRenderingEngine;
46    import info.magnolia.module.templating.engine.RenderingEngine;
47    import info.magnolia.module.templating.paragraphs.JspParagraphRenderer;
48    import info.magnolia.test.ComponentsTestUtil;
49    import junit.framework.TestCase;
50    import static org.easymock.EasyMock.*;
51   
52    import java.lang.reflect.Method;
53    import java.util.HashMap;
54    import java.util.Map;
55   
56    /**
57    * @author gjoseph
58    * @version $Revision: $ ($Author: $)
59    */
 
60    public class JspTemplateRendererTest extends TestCase {
61   
 
62  1 toggle protected void tearDown() throws Exception {
63  1 MgnlContext.setInstance(null);
64  1 ComponentsTestUtil.clear();
65  1 SystemProperty.getProperties().clear();
66  1 super.tearDown();
67    }
68   
 
69  1 toggle public void testExposesNodesAsMaps() throws Exception {
70  1 final WebContext magnoliaCtx = createStrictMock(WebContext.class);
71  1 MgnlContext.setInstance(magnoliaCtx);
72  1 ComponentsTestUtil.setImplementation(RenderingEngine.class, DefaultRenderingEngine.class);
73    // the page node is exposed twice, once as "actpage", once as "content"
74  1 final Content page = createStrictMock(Content.class);
75  1 expect(page.getHandle()).andReturn("/myPage").times(2);
76   
77  1 final AggregationState aggState = new AggregationState();
78  1 aggState.setMainContent(page);
79  1 expect(magnoliaCtx.getAggregationState()).andStubReturn(aggState);
80   
81  1 replay(magnoliaCtx, page);
82  1 final Map templateCtx = new HashMap();
83  1 final JspParagraphRenderer renderer = new JspParagraphRenderer();
84   
85    // ugly hack to exexute renderer.setupContext()
86  1 Method setupContextMethod = AbstractRenderer.class.getDeclaredMethod("setupContext", new Class[]{Map.class, Content.class, RenderableDefinition.class, RenderingModel.class, Object.class});
87  1 setupContextMethod.setAccessible(true);
88  1 setupContextMethod.invoke(renderer, new Object[]{templateCtx, page, null, null, null});
89   
90    // other tests should verify the other objects !
91  1 assertEquals("Unexpected amount of objects in context", 7, templateCtx.size());
92  1 assertTrue(templateCtx.get("actpage") instanceof Map);
93  1 assertEquals(page, unwrap((Content) templateCtx.get("actpage")));
94   
95  1 assertTrue(templateCtx.get("content") instanceof Map);
96  1 assertEquals(page, unwrap((Content) templateCtx.get("content")));
97   
98  1 verify(magnoliaCtx, page);
99    }
100   
 
101  6 toggle private Content unwrap(Content c) {
102  6 if (c instanceof ContentWrapper) {
103  4 return unwrap(((ContentWrapper) c).getWrappedContent());
104    }
105  2 return c;
106    }
107    }