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

File DefaultImagingSupportTest.java

 

Code metrics

0
22
6
1
142
62
6
0.27
3.67
6
1

Classes

Class Line # Actions
DefaultImagingSupportTest 54 22 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 4 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.imaging;
35   
36    import static org.hamcrest.core.Is.is;
37    import static org.junit.Assert.assertThat;
38   
39    import info.magnolia.cms.beans.runtime.FileProperties;
40    import info.magnolia.context.MgnlContext;
41    import info.magnolia.imaging.variation.DefaultVariation;
42    import info.magnolia.test.mock.MockWebContext;
43    import info.magnolia.test.mock.jcr.MockNode;
44    import info.magnolia.test.mock.jcr.MockProperty;
45    import info.magnolia.test.mock.jcr.MockSession;
46   
47    import org.junit.After;
48    import org.junit.Before;
49    import org.junit.Test;
50   
51    /**
52    * Tests for {@link ImagingSupport}.
53    */
 
54    public class DefaultImagingSupportTest {
55   
56    private final static String CONTEXT_PATH = "myCtx";
57    private final static String NODE_NAME = "home";
58    private final static String WORKSPACE_NAME = "myworkspace";
59   
60    private DefaultImagingSupport imagingSupport;
61   
62    private MockNode parent;
63   
64    private MockProperty binaryProperty;
65   
66    private String expectedPath;
67   
 
68  4 toggle @Before
69    public void setUp() throws Exception {
70  4 MockWebContext ctx = new MockWebContext();
71  4 ctx.setContextPath(CONTEXT_PATH);
72  4 MgnlContext.setInstance(ctx);
73   
74  4 imagingSupport = new DefaultImagingSupport();
75   
76  4 parent = new MockNode(new MockSession(WORKSPACE_NAME));
77  4 parent.setName(NODE_NAME);
78  4 binaryProperty = new MockProperty("image", "", parent);
79   
80  4 expectedPath = String.format("%s/.imaging/default/%s/%s", CONTEXT_PATH, WORKSPACE_NAME, NODE_NAME);
81    }
82   
 
83  4 toggle @After
84    public void tearDown() {
85  4 MgnlContext.setInstance(null);
86    }
87   
 
88  1 toggle @Test
89    public void createLinkForVariationWithExtensionSet() throws Exception {
90    // GIVEN
91  1 DefaultVariation variation = new DefaultVariation();
92  1 variation.setName("bar");
93   
94  1 parent.setProperty(FileProperties.EXTENSION, "png");
95   
96    // WHEN
97  1 String link = imagingSupport.createLink(binaryProperty, "bar");
98   
99    // THEN
100  1 assertThat(link, is(expectedPath + ".png"));
101    }
102   
 
103  1 toggle @Test
104    public void createLinkForNonExistingVariationDefaultsToOriginalImage() throws Exception {
105    // GIVEN
106   
107    // WHEN
108  1 String link = imagingSupport.createLink(binaryProperty, "bar");
109   
110    // THEN
111  1 assertThat(link, is(expectedPath + ".jpg"));
112    }
113   
 
114  1 toggle @Test
115    public void createLinkForNullVariationDefaultsToOriginalImage() throws Exception {
116    // GIVEN
117   
118    // WHEN
119  1 String link = imagingSupport.createLink(binaryProperty, null);
120   
121    // THEN
122  1 assertThat(link, is(expectedPath + ".jpg"));
123    }
124   
 
125  1 toggle @Test
126    public void createLinkForOriginalVariation() throws Exception {
127    // GIVEN
128   
129    // WHEN
130  1 String link = imagingSupport.createLink(binaryProperty, ImagingSupport.VARIATION_ORIGINAL);
131   
132    // THEN
133  1 assertThat(link, is(expectedPath + ".jpg"));
134   
135    // WHEN
136  1 link = imagingSupport.createLink(binaryProperty);
137   
138    // THEN
139  1 assertThat(link, is(expectedPath + ".jpg"));
140    }
141   
142    }