Clover icon

Magnolia Imaging Module 3.2.3

  1. Project Clover database Fri Nov 6 2015 14:54:03 CET
  2. Package info.magnolia.imaging.parameters

File NodeDataParameterProviderFactoryTest.java

 

Code metrics

0
29
5
1
118
70
6
0.21
5.8
5
1.2

Classes

Class Line # Actions
NodeDataParameterProviderFactoryTest 59 29 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /**
2    * This file Copyright (c) 2009-2015 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.imaging.parameters;
35   
36    import static org.junit.Assert.*;
37    import static org.mockito.Mockito.*;
38   
39    import info.magnolia.cms.core.Content;
40    import info.magnolia.cms.core.HierarchyManager;
41    import info.magnolia.cms.core.NodeData;
42    import info.magnolia.cms.core.NonExistingNodeData;
43    import info.magnolia.cms.util.ContentUtil;
44    import info.magnolia.cms.util.NodeDataWrapper;
45    import info.magnolia.context.MgnlContext;
46    import info.magnolia.imaging.AbstractRepositoryTestCase;
47    import info.magnolia.imaging.ParameterProvider;
48   
49    import javax.jcr.NoSuchWorkspaceException;
50    import javax.jcr.RepositoryException;
51    import javax.servlet.http.HttpServletRequest;
52   
53    import org.junit.Before;
54    import org.junit.Test;
55   
56    /**
57    * Tests for {@link info.magnolia.imaging.parameters.NodeDataParameterProviderFactory}.
58    */
 
59    public class NodeDataParameterProviderFactoryTest extends AbstractRepositoryTestCase {
60    private NodeData srcProp;
61    private HttpServletRequest req;
62   
 
63  4 toggle @Before
64    @Override
65    public void setUp() throws Exception {
66  4 super.setUp();
67  4 final HierarchyManager srcHM = MgnlContext.getHierarchyManager("website");
68  4 final Content src = ContentUtil.createPath(srcHM, "/some/node");
69  4 srcProp = src.createNodeData("chalala", "tralala");
70  4 srcHM.save();
71   
72  4 req = mock(HttpServletRequest.class);
73    }
74   
 
75  1 toggle @Test
76    public void testWrapsNodeDataSuchThatEqualsAndHashCodeAreImplementedBasedOnPathAndHierarchyManagerName() throws RepositoryException {
77  1 final HierarchyManager hm = MgnlContext.getHierarchyManager("website");
78  1 assertNotSame(srcProp, hm.getNodeData("/some/node/chalala"));
79   
80  1 when(req.getPathInfo()).thenReturn("/generator/website/some/node/chalala");
81  1 final NodeDataParameterProviderFactory factory = new NodeDataParameterProviderFactory();
82  1 final ParameterProvider<NodeData> param1 = factory.newParameterProviderFor(req);
83  1 final ParameterProvider<NodeData> param2 = factory.newParameterProviderFor(req);
84  1 assertNotSame("2 calls to ParameterProviderFactory should return 2 *different instances*.",
85    param1.getParameter(), param2.getParameter());
86  1 assertEquals("2 calls to ParameterProviderFactory should return 2 *equivalent instances*.",
87    param1.getParameter(), param2.getParameter());
88    }
89   
 
90  1 toggle @Test
91    public void testReturnsWrappedNonExistingNodeDataIfPropertyDoesNotExist() throws Exception {
92  1 when(req.getPathInfo()).thenReturn("/generator/website/some/node/booyah");
93  1 final NodeDataParameterProviderFactory factory = new NodeDataParameterProviderFactory();
94  1 final ParameterProvider<NodeData> pp = factory.newParameterProviderFor(req);
95  1 final NodeData data = pp.getParameter();
96  1 assertTrue(((NodeDataWrapper) data).getWrappedNodeData() instanceof NonExistingNodeData);
97    }
98   
 
99  1 toggle @Test
100    public void testYieldsAProperExceptionIfGeneratorNameIsOmmitted() throws Exception {
101  1 when(req.getPathInfo()).thenReturn("/website/some/node/chalala");
102  1 final NodeDataParameterProviderFactory factory = new NodeDataParameterProviderFactory();
103  1 try {
104  1 factory.newParameterProviderFor(req);
105    } catch (Throwable t) {
106  1 assertTrue(t.getCause() instanceof NoSuchWorkspaceException);
107  1 assertTrue(t.getMessage().contains("some"));
108    }
109    }
110   
 
111  1 toggle @Test
112    public void testExistingPropertyJustWorks() throws RepositoryException {
113  1 when(req.getPathInfo()).thenReturn("/generator/website/some/node/chalala");
114  1 final NodeDataParameterProviderFactory factory = new NodeDataParameterProviderFactory();
115  1 final ParameterProvider<NodeData> pp = factory.newParameterProviderFor(req);
116  1 pp.getParameter();
117    }
118    }