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; |
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 |
|
@link |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 6 |
Complexity Density: 0.27 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
68 |
4 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
4 |
@After... |
84 |
|
public void tearDown() { |
85 |
4 |
MgnlContext.setInstance(null); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void createLinkForVariationWithExtensionSet() throws Exception { |
90 |
|
|
91 |
1 |
DefaultVariation variation = new DefaultVariation(); |
92 |
1 |
variation.setName("bar"); |
93 |
|
|
94 |
1 |
parent.setProperty(FileProperties.EXTENSION, "png"); |
95 |
|
|
96 |
|
|
97 |
1 |
String link = imagingSupport.createLink(binaryProperty, "bar"); |
98 |
|
|
99 |
|
|
100 |
1 |
assertThat(link, is(expectedPath + ".png")); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
103 |
1 |
@Test... |
104 |
|
public void createLinkForNonExistingVariationDefaultsToOriginalImage() throws Exception { |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
1 |
String link = imagingSupport.createLink(binaryProperty, "bar"); |
109 |
|
|
110 |
|
|
111 |
1 |
assertThat(link, is(expectedPath + ".jpg")); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
114 |
1 |
@Test... |
115 |
|
public void createLinkForNullVariationDefaultsToOriginalImage() throws Exception { |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
1 |
String link = imagingSupport.createLink(binaryProperty, null); |
120 |
|
|
121 |
|
|
122 |
1 |
assertThat(link, is(expectedPath + ".jpg")); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void createLinkForOriginalVariation() throws Exception { |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
1 |
String link = imagingSupport.createLink(binaryProperty, ImagingSupport.VARIATION_ORIGINAL); |
131 |
|
|
132 |
|
|
133 |
1 |
assertThat(link, is(expectedPath + ".jpg")); |
134 |
|
|
135 |
|
|
136 |
1 |
link = imagingSupport.createLink(binaryProperty); |
137 |
|
|
138 |
|
|
139 |
1 |
assertThat(link, is(expectedPath + ".jpg")); |
140 |
|
} |
141 |
|
|
142 |
|
} |