Clover icon

Magnolia Resources Module 2.4.2

  1. Project Clover database Fri Nov 6 2015 16:15:26 CET
  2. Package info.magnolia.module.resources.setup

File InstallBinaryResourcesTaskTest.java

 

Code metrics

0
16
7
2
118
53
7
0.44
2.29
3.5
1

Classes

Class Line # Actions
InstallBinaryResourcesTaskTest 50 13 0% 4 0
1.0100%
InstallBinaryResourcesTaskTest.TestInstallBinaryResourcesTask 102 3 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /**
2    * This file Copyright (c) 2014-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.module.resources.setup;
35   
36    import static info.magnolia.test.hamcrest.NodeMatchers.hasNode;
37    import static org.junit.Assert.assertThat;
38    import static org.mockito.Mockito.*;
39   
40    import info.magnolia.module.InstallContext;
41    import info.magnolia.module.resources.ResourcesModule;
42    import info.magnolia.test.mock.jcr.MockSession;
43   
44    import org.junit.Before;
45    import org.junit.Test;
46   
47    /**
48    * Test for {@link InstallBinaryResourcesTask}.
49    */
 
50    public class InstallBinaryResourcesTaskTest {
51   
52    private static final String resourcePath = "templating-kit/img/magnolia-logoTest";
53    private static final String imageNameWithJCRInvalidChars = "templating-kit/img/imagename@with invalid%chars";
54    private InstallBinaryResourcesTask task;
55    private InstallContext installContext;
56    private MockSession session;
57   
 
58  3 toggle @Before
59    public void setUp() throws Exception {
60  3 installContext = mock(InstallContext.class);
61  3 session = new MockSession(ResourcesModule.DEFAULT_WORKSPACE);
62  3 when(installContext.getJCRSession(ResourcesModule.DEFAULT_WORKSPACE)).thenReturn(session);
63    }
64   
 
65  1 toggle @Test
66    public void testExecuteDontStripExtensions() throws Exception {
67    // GIVEN
68  1 boolean stripExtension = false;
69  1 task = new TestInstallBinaryResourcesTask(null, null, "/templating-kit/img/*.*", false, stripExtension);
70   
71    // WHEN
72  1 task.execute(installContext);
73   
74    // THEN
75  1 assertThat(session.getRootNode(), hasNode(resourcePath + ".png"));
76    }
77   
 
78  1 toggle @Test
79    public void testExecuteStripExtensions() throws Exception {
80    // GIVEN
81  1 task = new TestInstallBinaryResourcesTask("/templating-kit/img/*.*");
82   
83    // WHEN
84  1 task.execute(installContext);
85   
86    // THEN
87  1 assertThat(session.getRootNode(), hasNode(resourcePath));
88    }
89   
 
90  1 toggle @Test
91    public void testInvalidJcrCharsAreReplaced() throws Exception {
92    // GIVEN
93  1 task = new TestInstallBinaryResourcesTask("/templating-kit/img/imagename@with invalid%chars.png");
94   
95    // WHEN
96  1 task.execute(installContext);
97   
98    // THEN
99  1 assertThat(session.getRootNode(), hasNode("templating-kit/img/imagename-with-invalid-chars"));
100    }
101   
 
102    private class TestInstallBinaryResourcesTask extends InstallBinaryResourcesTask {
103   
 
104  2 toggle public TestInstallBinaryResourcesTask(String pattern) {
105  2 super(pattern);
106    }
107   
 
108  1 toggle public TestInstallBinaryResourcesTask(String taskName, String taskDescription, String pattern, boolean preserveResourcesParameters, boolean stripExtension) {
109  1 super(taskName, taskDescription, pattern, preserveResourcesParameters, stripExtension);
110    }
111   
 
112  3 toggle @Override
113    protected String[] findResources() {
114  3 return new String[] { resourcePath + ".png" , imageNameWithJCRInvalidChars + ".png"};
115    }
116    }
117   
118    }