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

File PreexecutionUtilsTest.java

 

Code metrics

0
30
4
1
124
60
5
0.17
7.5
4
1.25

Classes

Class Line # Actions
PreexecutionUtilsTest 58 30 0% 5 1
0.970588297.1%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /**
2    * This file Copyright (c) 2014-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.preexecution;
35   
36    import static org.junit.Assert.assertFalse;
37    import static org.junit.Assert.assertTrue;
38    import static org.junit.Assert.fail;
39   
40    import info.magnolia.context.MgnlContext;
41    import info.magnolia.jcr.RuntimeRepositoryException;
42    import info.magnolia.test.MgnlTestCase;
43    import info.magnolia.test.mock.MockWebContext;
44    import info.magnolia.test.mock.jcr.MockNode;
45   
46    import javax.jcr.Node;
47    import javax.jcr.RepositoryException;
48   
49    import org.junit.Test;
50    import org.mockito.Mockito;
51    import org.springframework.mock.web.MockHttpServletRequest;
52   
53    /**
54    * Test case for {@link PreexecutionUtils}
55    *
56    * @since 3.0.5
57    */
 
58    public class PreexecutionUtilsTest extends MgnlTestCase {
59   
 
60  1 toggle @Test
61    public void testIsPreexecutingReturnsFalseWhenPreexecutionContextIsNotSet() {
62   
63    // GIVEN
64  1 MockWebContext webContext = (MockWebContext) MgnlContext.getInstance();
65  1 webContext.setRequest(new MockHttpServletRequest());
66   
67    // THEN
68  1 assertFalse(PreexecutionUtils.isPreexecuting());
69    }
70   
 
71  1 toggle @Test
72    public void testIsPreexecutingReturnsFalseWhenPreexecutighOtherNode() {
73   
74    // GIVEN
75  1 MockWebContext webContext = (MockWebContext) MgnlContext.getInstance();
76  1 webContext.setRequest(new MockHttpServletRequest());
77  1 MockNode currentContentNode = new MockNode();
78  1 currentContentNode.setIdentifier("some-other-uuid");
79  1 webContext.getAggregationState().setCurrentContentNode(currentContentNode);
80  1 PreexecutionContext preexecutionContext = new PreexecutionContext("uuid");
81  1 PreexecutionContextHolder.put(webContext.getRequest(), preexecutionContext);
82   
83    // THEN
84  1 assertFalse(PreexecutionUtils.isPreexecuting());
85    }
86   
 
87  1 toggle @Test
88    public void testIsPreexecutingReturnsTrueWhenPreexecutingCurrentNode() {
89   
90    // GIVEN
91  1 MockWebContext webContext = (MockWebContext) MgnlContext.getInstance();
92  1 webContext.setRequest(new MockHttpServletRequest());
93  1 MockNode currentContentNode = new MockNode();
94  1 currentContentNode.setIdentifier("uuid");
95  1 webContext.getAggregationState().setCurrentContentNode(currentContentNode);
96  1 PreexecutionContext preexecutionContext = new PreexecutionContext("uuid");
97  1 PreexecutionContextHolder.put(webContext.getRequest(), preexecutionContext);
98   
99    // THEN
100  1 assertTrue(PreexecutionUtils.isPreexecuting());
101    }
102   
 
103  1 toggle @Test
104    public void testRepositoryExceptionIsWrappedInRuntimeRepositoryException() throws RepositoryException {
105   
106    // GIVEN
107  1 MockWebContext webContext = (MockWebContext) MgnlContext.getInstance();
108  1 webContext.setRequest(new MockHttpServletRequest());
109  1 Node currentContentNode = Mockito.mock(Node.class);
110  1 Mockito.when(currentContentNode.getIdentifier()).thenThrow(new RepositoryException(""));
111  1 webContext.getAggregationState().setCurrentContentNode(currentContentNode);
112  1 PreexecutionContext preexecutionContext = new PreexecutionContext("uuid");
113  1 PreexecutionContextHolder.put(webContext.getRequest(), preexecutionContext);
114   
115    // WHEN
116  1 try {
117  1 PreexecutionUtils.isPreexecuting();
118  0 fail();
119    } catch (RuntimeRepositoryException e) {
120    // THEN
121  1 assertTrue(e.getCause() instanceof RepositoryException);
122    }
123    }
124    }