1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.imaging.functions; |
35 |
|
|
36 |
|
import static org.hamcrest.CoreMatchers.*; |
37 |
|
import static org.junit.Assert.assertThat; |
38 |
|
import static org.mockito.Matchers.any; |
39 |
|
import static org.mockito.Mockito.*; |
40 |
|
|
41 |
|
import info.magnolia.context.MgnlContext; |
42 |
|
import info.magnolia.imaging.DefaultImagingSupport; |
43 |
|
import info.magnolia.imaging.ImagingSupport; |
44 |
|
import info.magnolia.jcr.util.ContentMap; |
45 |
|
import info.magnolia.rendering.template.TemplateAvailability; |
46 |
|
import info.magnolia.rendering.template.configured.ConfiguredTemplateDefinition; |
47 |
|
import info.magnolia.test.mock.MockWebContext; |
48 |
|
|
49 |
|
import javax.jcr.Node; |
50 |
|
import javax.jcr.Property; |
51 |
|
import javax.jcr.RepositoryException; |
52 |
|
import javax.jcr.Session; |
53 |
|
import javax.jcr.Workspace; |
54 |
|
|
55 |
|
import org.apache.jackrabbit.JcrConstants; |
56 |
|
import org.junit.After; |
57 |
|
import org.junit.Before; |
58 |
|
import org.junit.Test; |
59 |
|
|
60 |
|
|
61 |
|
@link |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 3 |
Complexity Density: 0.18 |
|
63 |
|
public class ImagingTemplatingFunctionsTest { |
64 |
|
|
65 |
|
private MockWebContext context; |
66 |
|
private ImagingTemplatingFunctions imagingTemplatingFunctions; |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
68 |
11 |
@Before... |
69 |
|
public void setUp() { |
70 |
11 |
context = new MockWebContext(); |
71 |
11 |
context.setContextPath("/ctx"); |
72 |
11 |
MgnlContext.setInstance(context); |
73 |
|
|
74 |
11 |
ImagingSupport imagingSupport = new DefaultImagingSupport(); |
75 |
11 |
imagingTemplatingFunctions = new ImagingTemplatingFunctions(imagingSupport); |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
11 |
@After... |
79 |
|
public void tearDown() { |
80 |
11 |
MgnlContext.setInstance(null); |
81 |
|
} |
82 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
83 |
|
@Test... |
84 |
|
public void getImageVariationLinkFromBinaryWhenNull() { |
85 |
|
|
86 |
|
Node node = null; |
87 |
|
String variation = null; |
88 |
|
|
89 |
|
String link = imagingTemplatingFunctions.getImageVariationLinkFromBinary(node, variation); |
90 |
|
|
91 |
|
assertThat(link, nullValue()); |
92 |
|
} |
93 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
94 |
|
@Test... |
95 |
|
public void getImageVariationLinkFromBinary() throws RepositoryException { |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
String link = imagingTemplatingFunctions.getImageVariationLinkFromBinary(mockNode(), ImagingSupport.VARIATION_ORIGINAL); |
100 |
|
|
101 |
|
|
102 |
|
assertThat(link, is("/ctx/.imaging/default/workspace/path/to/this/parent/node.jpg")); |
103 |
|
} |
104 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
105 |
|
@Test... |
106 |
|
public void getImageVariationLinkFromBinaryContentMap() throws RepositoryException { |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
String link = imagingTemplatingFunctions.getImageVariationLinkFromBinary(new ContentMap(mockNode()), ImagingSupport.VARIATION_ORIGINAL); |
111 |
|
|
112 |
|
|
113 |
|
assertThat(link, is("/ctx/.imaging/default/workspace/path/to/this/parent/node.jpg")); |
114 |
|
} |
115 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
116 |
|
@Test... |
117 |
|
public void getImageVariationLinkFromBinaryContentMapWhenNull() throws RepositoryException { |
118 |
|
|
119 |
|
final ContentMap contentMap = null; |
120 |
|
|
121 |
|
|
122 |
|
String link = imagingTemplatingFunctions.getImageVariationLinkFromBinary(contentMap, ImagingSupport.VARIATION_ORIGINAL); |
123 |
|
|
124 |
|
|
125 |
|
assertThat(link, nullValue()); |
126 |
|
} |
127 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
128 |
|
@Test... |
129 |
|
public void getImageVariationLinkFromBinaryAndTemplateDefinition() throws RepositoryException { |
130 |
|
|
131 |
|
TemplateAvailability templateAvailability = mock(TemplateAvailability.class); |
132 |
|
ConfiguredTemplateDefinition templateDefinition = new ConfiguredTemplateDefinition(templateAvailability); |
133 |
|
templateDefinition.addParameter(ImagingTemplatingFunctions.PROPERTY_IMAGE_VARIATION, ImagingSupport.VARIATION_ORIGINAL); |
134 |
|
|
135 |
|
|
136 |
|
String link = imagingTemplatingFunctions.getImageVariationLinkFromBinary(mockNode(), templateDefinition); |
137 |
|
|
138 |
|
|
139 |
|
assertThat(link, is("/ctx/.imaging/default/workspace/path/to/this/parent/node.jpg")); |
140 |
|
} |
141 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
142 |
|
@Test... |
143 |
|
public void getImageVariationLinkFromBinaryAndTemplateDefinitionContentMap() throws RepositoryException { |
144 |
|
|
145 |
|
TemplateAvailability templateAvailability = mock(TemplateAvailability.class); |
146 |
|
ConfiguredTemplateDefinition templateDefinition = new ConfiguredTemplateDefinition(templateAvailability); |
147 |
|
templateDefinition.addParameter(ImagingTemplatingFunctions.PROPERTY_IMAGE_VARIATION, ImagingSupport.VARIATION_ORIGINAL); |
148 |
|
|
149 |
|
|
150 |
|
String link = imagingTemplatingFunctions.getImageVariationLinkFromBinary(new ContentMap(mockNode()), templateDefinition); |
151 |
|
|
152 |
|
|
153 |
|
assertThat(link, is("/ctx/.imaging/default/workspace/path/to/this/parent/node.jpg")); |
154 |
|
} |
155 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
156 |
|
@Test... |
157 |
|
public void getImageVariationLinkFromBinaryAndTemplateDefinitionContentMapWhenNull() throws RepositoryException { |
158 |
|
|
159 |
|
ContentMap contentMap = null; |
160 |
|
ConfiguredTemplateDefinition templateDefinition = null; |
161 |
|
|
162 |
|
|
163 |
|
String link = imagingTemplatingFunctions.getImageVariationLinkFromBinary(contentMap, templateDefinition); |
164 |
|
|
165 |
|
|
166 |
|
assertThat(link, nullValue()); |
167 |
|
} |
168 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
169 |
|
@Test... |
170 |
|
public void getImageVariationLinkFromBinaryAndTemplateDefinitionWithoutParameter() throws RepositoryException { |
171 |
|
|
172 |
|
TemplateAvailability templateAvailability = mock(TemplateAvailability.class); |
173 |
|
ConfiguredTemplateDefinition templateDefinition = new ConfiguredTemplateDefinition(templateAvailability); |
174 |
|
|
175 |
|
|
176 |
|
String link = imagingTemplatingFunctions.getImageVariationLinkFromBinary(mockNode(), templateDefinition); |
177 |
|
|
178 |
|
|
179 |
|
assertThat(link, is("/ctx/.imaging/default/workspace/path/to/this/parent/node.jpg")); |
180 |
|
} |
181 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
182 |
|
@Test... |
183 |
|
public void getImageVariationLinkFromBinaryAndTemplateDefinitionWhenNull() throws RepositoryException { |
184 |
|
|
185 |
|
ConfiguredTemplateDefinition templateDefinition = null; |
186 |
|
|
187 |
|
|
188 |
|
String link = imagingTemplatingFunctions.getImageVariationLinkFromBinary(mockNode(), templateDefinition); |
189 |
|
|
190 |
|
|
191 |
|
assertThat(link, is("/ctx/.imaging/default/workspace/path/to/this/parent/node.jpg")); |
192 |
|
} |
193 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
194 |
|
@Test... |
195 |
|
public void getImageVariationLinkFromBinaryWhenException() throws RepositoryException { |
196 |
|
|
197 |
|
Node node = mock(Node.class); |
198 |
|
when(node.getProperty(anyString())).thenThrow(new RepositoryException("This exception is thrown on purpose")); |
199 |
|
|
200 |
|
|
201 |
|
String encodedLink = imagingTemplatingFunctions.getImageVariationLinkFromBinary(node, ImagingSupport.VARIATION_ORIGINAL); |
202 |
|
|
203 |
|
|
204 |
|
assertThat(encodedLink, nullValue()); |
205 |
|
} |
206 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
207 |
|
@Test... |
208 |
|
public void getImageVariationLinkFromBinaryEscapedText() { |
209 |
|
|
210 |
|
String unEncodedString = "this string is not encoded"; |
211 |
|
Node node = mock(Node.class); |
212 |
|
|
213 |
|
ImagingSupport imagingSupport = mock(ImagingSupport.class); |
214 |
|
ImagingTemplatingFunctions imagingTemplatingFunctions = new ImagingTemplatingFunctions(imagingSupport); |
215 |
|
|
216 |
|
when(imagingSupport.createLink(any(Property.class), anyString())).thenReturn(unEncodedString); |
217 |
|
|
218 |
|
|
219 |
|
String encodedLink = imagingTemplatingFunctions.getImageVariationLinkFromBinary(node, ImagingSupport.VARIATION_ORIGINAL); |
220 |
|
|
221 |
|
|
222 |
|
assertThat(encodedLink, is("this%20string%20is%20not%20encoded")); |
223 |
|
} |
224 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
225 |
6 |
private Node mockNode() throws RepositoryException {... |
226 |
6 |
Session session = mock(Session.class); |
227 |
6 |
Workspace workspace = mock(Workspace.class); |
228 |
6 |
Node node = mock(Node.class); |
229 |
6 |
Property binaryProperty = mock(Property.class); |
230 |
|
|
231 |
6 |
when(session.getWorkspace()).thenReturn(workspace); |
232 |
6 |
when(workspace.getName()).thenReturn("workspace"); |
233 |
6 |
when(node.getProperty(JcrConstants.JCR_DATA)).thenReturn(binaryProperty); |
234 |
6 |
when(node.getPath()).thenReturn("/path/to/this/parent/node"); |
235 |
6 |
when(binaryProperty.getParent()).thenReturn(node); |
236 |
6 |
when(binaryProperty.getSession()).thenReturn(session); |
237 |
|
|
238 |
6 |
return node; |
239 |
|
} |
240 |
|
|
241 |
|
} |