Clover icon

Magnolia REST Content Delivery 2.1

  1. Project Clover database Fri Mar 16 2018 18:21:08 CET
  2. Package info.magnolia.rest.setup

File RestContentDeliveryModuleVersionHandlerTest.java

 

Code metrics

4
25
6
1
135
73
9
0.36
4.17
6
1.5

Classes

Class Line # Actions
RestContentDeliveryModuleVersionHandlerTest 66 25 0% 9 3
0.914285791.4%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /**
2    * This file Copyright (c) 2013-2018 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.rest.setup;
35   
36    import static org.junit.Assert.assertTrue;
37    import static org.mockito.Mockito.mock;
38   
39    import info.magnolia.cms.security.MgnlRoleManager;
40    import info.magnolia.cms.security.SecuritySupport;
41    import info.magnolia.cms.security.SecuritySupportImpl;
42    import info.magnolia.context.MgnlContext;
43    import info.magnolia.init.MagnoliaConfigurationProperties;
44    import info.magnolia.jcr.util.NodeNameHelper;
45    import info.magnolia.jcr.util.NodeTypes;
46    import info.magnolia.jcr.util.NodeUtil;
47    import info.magnolia.module.ModuleVersionHandler;
48    import info.magnolia.module.ModuleVersionHandlerTestCase;
49    import info.magnolia.repository.RepositoryConstants;
50    import info.magnolia.test.ComponentsTestUtil;
51   
52    import java.util.Arrays;
53    import java.util.List;
54   
55    import javax.jcr.Node;
56    import javax.jcr.NodeIterator;
57    import javax.jcr.RepositoryException;
58    import javax.jcr.Session;
59   
60    import org.junit.Before;
61    import org.junit.Test;
62   
63    /**
64    * Tests for the module version handler ({@link RestContentDeliveryModuleVersionHandler}).
65    */
 
66    public class RestContentDeliveryModuleVersionHandlerTest extends ModuleVersionHandlerTestCase {
67   
68    private SecuritySupportImpl securitySupport;
69   
 
70  1 toggle @Override
71    protected String getModuleDescriptorPath() {
72  1 return "/META-INF/magnolia/rest-content-delivery.xml";
73    }
74   
 
75  1 toggle @Override
76    protected List<String> getModuleDescriptorPathsForTests() {
77  1 return Arrays.asList(
78    "/META-INF/magnolia/core.xml"
79    );
80    }
81   
 
82  1 toggle @Override
83    protected ModuleVersionHandler newModuleVersionHandlerForTests() {
84  1 return new RestContentDeliveryModuleVersionHandler();
85    }
86   
 
87  1 toggle @Override
88    @Before
89    public void setUp() throws Exception {
90  1 super.setUp();
91  1 Session session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
92   
93    // Creating servlet node
94  1 Node server = NodeUtil.createPath(session.getRootNode(), "/server", NodeTypes.ContentNode.NAME);
95  1 server.setProperty("admin", "");
96   
97  1 NodeNameHelper nodeNameHelper = new NodeNameHelper(mock(MagnoliaConfigurationProperties.class));
98   
99    // Security Support
100  1 securitySupport = new SecuritySupportImpl();
101  1 securitySupport.setRoleManager(new MgnlRoleManager(nodeNameHelper));
102  1 ComponentsTestUtil.setInstance(SecuritySupport.class, securitySupport);
103    }
104   
 
105  1 toggle @Test
106    public void basicInstallRestEditorRoleGrantedPermission() throws Exception {
107    // GIVEN
108  1 Session rolesSession = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES);
109  1 NodeUtil.createPath(rolesSession.getRootNode(), "/rest-editor", NodeTypes.Role.NAME);
110  1 NodeUtil.createPath(rolesSession.getRootNode(), "/rest-anonymous", NodeTypes.Role.NAME);
111   
112    // WHEN
113  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null);
114   
115    // THEN
116  1 Node restEditor = rolesSession.getNode("/rest-editor/acl_uri");
117  1 Node restAnonymous = rolesSession.getNode("/rest-anonymous/acl_uri");
118   
119  1 assertTrue(verifyRoleNode(restEditor));
120  1 assertTrue(verifyRoleNode(restAnonymous));
121   
122    }
123   
 
124  2 toggle private boolean verifyRoleNode(Node roleNode) throws RepositoryException {
125  2 NodeIterator restEditorNodes = roleNode.getNodes();
126  2 while (restEditorNodes.hasNext()) {
127  2 Node node = (Node) restEditorNodes.next();
128  2 if ("/.rest/delivery/*".equals(node.getProperty("path").getString()) && new Long(8).equals(node.getProperty("permissions").getLong())) {
129  2 return true;
130    }
131    }
132  0 return false;
133    }
134   
135    }