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

File AbstractBlossomTestCase.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
32
6
1
152
90
9
0.28
5.33
6
1.5
4.8% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
AbstractBlossomTestCase 69 32 4.8% 9 2
0.9595%
 

Contributing tests

This file is covered by 2 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.blossom.suite;
35   
36    import static org.junit.Assert.fail;
37   
38    import javax.servlet.ServletContext;
39   
40    import org.junit.After;
41    import org.junit.Before;
42    import org.springframework.mock.web.MockServletContext;
43   
44    import info.magnolia.module.blossom.dialog.DialogCreationContext;
45    import info.magnolia.module.blossom.dialog.DialogCreationContextHolder;
46    import info.magnolia.module.blossom.module.BlossomModuleSupport;
47    import info.magnolia.module.site.DefaultSiteManager;
48    import info.magnolia.module.site.SiteManager;
49    import info.magnolia.module.site.functions.SiteFunctions;
50    import info.magnolia.objectfactory.Components;
51    import info.magnolia.registry.RegistrationException;
52    import info.magnolia.rendering.template.TemplateAvailability;
53    import info.magnolia.rendering.template.configured.DefaultTemplateAvailability;
54    import info.magnolia.repository.RepositoryConstants;
55    import info.magnolia.test.ComponentsTestUtil;
56    import info.magnolia.test.MgnlTestCase;
57    import info.magnolia.test.mock.MockUtil;
58    import info.magnolia.test.mock.jcr.MockSession;
59    import info.magnolia.test.mock.jcr.SessionTestUtil;
60    import info.magnolia.ui.dialog.definition.DialogDefinition;
61    import info.magnolia.ui.dialog.registry.DialogDefinitionRegistry;
62   
63    /**
64    * Abstract base class for tests that needs to set up a complete environment with dispatcher servlet and the module
65    * initialized.
66    *
67    * @since 1.2.4
68    */
 
69    public abstract class AbstractBlossomTestCase extends MgnlTestCase {
70   
71    protected MockSession session;
72    protected BlossomModuleSupport moduleSupport;
73    protected MockServletContext servletContext;
74   
 
75  3 toggle @Override
76    @Before
77    public void setUp() throws Exception {
78  3 super.setUp();
79   
80  3 ComponentsTestUtil.setImplementation(TemplateAvailability.class, DefaultTemplateAvailability.class);
81   
82  3 DefaultSiteManager siteManager = new DefaultSiteManager(null, null);
83  3 SiteFunctions siteFunctions = new SiteFunctions(siteManager, null, null);
84  3 ComponentsTestUtil.setInstance(SiteManager.class, siteManager);
85  3 ComponentsTestUtil.setInstance(SiteFunctions.class, siteFunctions);
86   
87  3 session = SessionTestUtil.createSession(RepositoryConstants.CONFIG, "/modules/blossom");
88   
89  3 MockUtil.setSystemContextSessionAndHierarchyManager(session);
90   
91  3 servletContext = new MockServletContext();
92   
93  3 servletContext = new MockServletContext();
94  3 moduleSupport = new BlossomModuleSupport() {
95   
 
96    toggle @Override
97    public ServletContext getServletContext() {
98    return servletContext;
99    }
100    };
101   
102  3 String rootWebApplicationConfigLocation = getRootWebApplicationConfigLocation();
103  3 if (rootWebApplicationConfigLocation != null) {
104  1 moduleSupport.initRootWebApplicationContext(rootWebApplicationConfigLocation);
105    }
106   
107  3 moduleSupport.initBlossomDispatcherServlet("blossom", getDispatcherServletConfigLocation());
108    }
109   
 
110  3 toggle @After
111    @Override
112    public void tearDown() throws Exception {
113  3 moduleSupport.destroyDispatcherServlets();
114  3 moduleSupport.closeRootWebApplicationContext();
115  3 ComponentsTestUtil.clear();
116  3 super.tearDown();
117    }
118   
 
119  1 toggle protected String getRootWebApplicationConfigLocation() {
120  1 return null;
121    }
122   
123    protected abstract String getDispatcherServletConfigLocation();
124   
 
125  8 toggle protected DialogDefinition getDialogDefinition(String id) throws RegistrationException {
126  8 DialogDefinitionRegistry dialogDefinitionRegistry = Components.getComponent(DialogDefinitionRegistry.class);
127  8 try {
128  8 DialogCreationContext context = new DialogCreationContext();
129  8 DialogCreationContextHolder.set(context);
130  8 return dialogDefinitionRegistry.getDialogDefinition(id);
131    } finally {
132  8 DialogCreationContextHolder.remove();
133    }
134    }
135   
 
136  2 toggle protected void assertDialogIsNotRegistered(String id) {
137  2 try {
138  2 getDialogDefinition(id);
139  0 fail("Dialog [" + id + "] should not be registered");
140    } catch (RegistrationException e) {
141    // expected because it throws when not found
142    }
143    }
144   
 
145  6 toggle protected void assertDialogIsRegistered(String id) {
146  6 try {
147  6 getDialogDefinition(id);
148    } catch (RegistrationException e) {
149  0 fail("Dialog [" + id + "] is not registered");
150    }
151    }
152    }