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.variation; |
35 |
|
|
36 |
|
import static org.hamcrest.CoreMatchers.is; |
37 |
|
import static org.junit.Assert.*; |
38 |
|
import static org.mockito.Mockito.*; |
39 |
|
|
40 |
|
import info.magnolia.cms.beans.runtime.FileProperties; |
41 |
|
import info.magnolia.context.MgnlContext; |
42 |
|
import info.magnolia.test.mock.MockWebContext; |
43 |
|
import info.magnolia.test.mock.jcr.MockNode; |
44 |
|
|
45 |
|
import javax.jcr.Property; |
46 |
|
import javax.jcr.RepositoryException; |
47 |
|
import javax.jcr.Session; |
48 |
|
import javax.jcr.Workspace; |
49 |
|
|
50 |
|
import org.junit.After; |
51 |
|
import org.junit.Before; |
52 |
|
import org.junit.Test; |
53 |
|
|
54 |
|
|
55 |
|
@link |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (43) |
Complexity: 6 |
Complexity Density: 0.16 |
|
57 |
|
public class DefaultVariationTest { |
58 |
|
|
59 |
|
private static final String CONTEXT_PATH = "/test"; |
60 |
|
private static final String WORKSPACE_NAME = "some-workspace"; |
61 |
|
|
62 |
|
private DefaultVariation variation; |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
64 |
4 |
@Before... |
65 |
|
public void setUp() { |
66 |
4 |
MockWebContext ctx = new MockWebContext(); |
67 |
4 |
ctx.setContextPath(CONTEXT_PATH); |
68 |
4 |
MgnlContext.setInstance(ctx); |
69 |
|
|
70 |
4 |
variation = new DefaultVariation(); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
4 |
@After... |
74 |
|
public void tearDown() { |
75 |
4 |
MgnlContext.setInstance(null); |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
78 |
1 |
@Test... |
79 |
|
public void variationReturnsNullWhenBinaryIsNull() throws Exception { |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
1 |
String link = variation.createLink(null); |
84 |
|
|
85 |
|
|
86 |
1 |
assertNull(link); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
89 |
1 |
@Test... |
90 |
|
public void defaultVariationReturnsLinkToParent() throws Exception { |
91 |
|
|
92 |
1 |
final String parentNodeName = "parent"; |
93 |
1 |
MockNode parent = new MockNode(parentNodeName); |
94 |
1 |
Property binary = mock(Property.class); |
95 |
1 |
Session session = mock(Session.class); |
96 |
1 |
Workspace workspace = mock(Workspace.class); |
97 |
|
|
98 |
1 |
when(workspace.getName()).thenReturn(WORKSPACE_NAME); |
99 |
1 |
when(session.getWorkspace()).thenReturn(workspace); |
100 |
1 |
when(binary.getSession()).thenReturn(session); |
101 |
1 |
when(binary.getParent()).thenReturn(parent); |
102 |
|
|
103 |
|
|
104 |
1 |
String link = variation.createLink(binary); |
105 |
|
|
106 |
|
|
107 |
1 |
assertThat(link, is(String.format("%s/.imaging/default/%s/%s.jpg", CONTEXT_PATH, WORKSPACE_NAME, parentNodeName))); |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
110 |
1 |
@Test... |
111 |
|
public void defaultVariationReturnsLinkToParentWithExtension() throws Exception { |
112 |
|
|
113 |
1 |
final String pngExtension = "png"; |
114 |
1 |
final String parentNodeName = "anotherParent"; |
115 |
1 |
MockNode parent = new MockNode(parentNodeName); |
116 |
1 |
parent.setProperty(FileProperties.EXTENSION, pngExtension); |
117 |
1 |
Property binary = mock(Property.class); |
118 |
1 |
Session session = mock(Session.class); |
119 |
1 |
Workspace workspace = mock(Workspace.class); |
120 |
|
|
121 |
1 |
when(workspace.getName()).thenReturn(WORKSPACE_NAME); |
122 |
1 |
when(session.getWorkspace()).thenReturn(workspace); |
123 |
1 |
when(binary.getSession()).thenReturn(session); |
124 |
1 |
when(binary.getParent()).thenReturn(parent); |
125 |
|
|
126 |
|
|
127 |
1 |
String link = variation.createLink(binary); |
128 |
|
|
129 |
|
|
130 |
1 |
assertThat(link, is(String.format("%s/.imaging/default/%s/%s.%s", CONTEXT_PATH, WORKSPACE_NAME, parentNodeName, pngExtension))); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
133 |
1 |
@Test... |
134 |
|
public void defaultVariationReturnsNullWhenException() throws Exception { |
135 |
|
|
136 |
1 |
MockNode parent = new MockNode("parent"); |
137 |
1 |
Property binary = mock(Property.class); |
138 |
|
|
139 |
1 |
when(binary.getSession()).thenThrow(new RepositoryException("This exception is thrown on purpose.")); |
140 |
1 |
when(binary.getParent()).thenReturn(parent); |
141 |
|
|
142 |
|
|
143 |
1 |
String link = variation.createLink(binary); |
144 |
|
|
145 |
|
|
146 |
1 |
assertNull(link); |
147 |
|
} |
148 |
|
|
149 |
|
} |