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.parameters; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
import static org.mockito.Mockito.*; |
38 |
|
|
39 |
|
import info.magnolia.cms.core.Content; |
40 |
|
import info.magnolia.cms.core.HierarchyManager; |
41 |
|
import info.magnolia.cms.util.ContentWrapper; |
42 |
|
import info.magnolia.context.Context; |
43 |
|
import info.magnolia.context.MgnlContext; |
44 |
|
import info.magnolia.imaging.ParameterProvider; |
45 |
|
|
46 |
|
import javax.jcr.RepositoryException; |
47 |
|
import javax.servlet.http.HttpServletRequest; |
48 |
|
|
49 |
|
import org.junit.After; |
50 |
|
import org.junit.Test; |
51 |
|
|
52 |
|
|
53 |
|
@link |
54 |
|
|
|
|
| 97.9% |
Uncovered Elements: 1 (47) |
Complexity: 14 |
Complexity Density: 0.42 |
|
55 |
|
public class ContentParameterProviderFactoryTest { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
9 |
@After... |
57 |
|
public void tearDown() throws Exception { |
58 |
9 |
MgnlContext.setInstance(null); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
61 |
1 |
@Test... |
62 |
|
public void testExtensionIsIgnoredIfTrimExtensionIsTrue() throws Exception { |
63 |
1 |
validPathsTests("/myGenerator/dummyWS/foo/bar/baz.jpg", "dummyWS", "/foo/bar/baz", true); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
66 |
1 |
@Test... |
67 |
|
public void testExtensionIsNotIgnoredIfTrimExtensionIsFalse() throws Exception { |
68 |
1 |
validPathsTests("/myGenerator/dummyWS/foo/bar/baz.jpg", "dummyWS", "/foo/bar/baz.jpg", false); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void testExtensionIsIgnoredAlsoForTopLevelNodeIfTrimExtensionIsTrue() throws Exception { |
73 |
1 |
validPathsTests("/myGenerator/dummyWS/foo.jpg", "dummyWS", "/foo", true); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
76 |
1 |
@Test... |
77 |
|
public void testExtensionIsNotIgnoredAlsoForTopLevelNodeIfTrimExtensionIsFalse() throws Exception { |
78 |
1 |
validPathsTests("/myGenerator/dummyWS/foo.jpg", "dummyWS", "/foo.jpg", false); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void testDeepNodeIsRetrieved() throws Exception { |
83 |
1 |
validPathsTests("/myGenerator/dummyWS/foo/bar/baz", "dummyWS", "/foo/bar/baz", true); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void testNodeAtFirstLevelIsRetrievedToo() throws Exception { |
88 |
1 |
validPathsTests("/myGenerator/dummyWS/foo", "dummyWS", "/foo", true); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
public void testCanGetTheRootNodeIfNeededButWhoWantsThis() throws Exception { |
93 |
1 |
validPathsTests("/myGenerator/dummyWS", "dummyWS", "/", true); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
|
96 |
7 |
private void validPathsTests(final String pathInfo, final String expectedWorkspaceName, final String expectedNodePath, final boolean trimExtension) throws RepositoryException {... |
97 |
7 |
final Context ctx = mock(Context.class); |
98 |
7 |
final HierarchyManager hm = mock(HierarchyManager.class); |
99 |
7 |
final Content mockNode = mock(Content.class); |
100 |
7 |
final HttpServletRequest req = mock(HttpServletRequest.class); |
101 |
7 |
MgnlContext.setInstance(ctx); |
102 |
|
|
103 |
7 |
when(req.getPathInfo()).thenReturn(pathInfo); |
104 |
7 |
when(ctx.getHierarchyManager(expectedWorkspaceName)).thenReturn(hm); |
105 |
7 |
when(hm.getContent(expectedNodePath)).thenReturn(mockNode); |
106 |
7 |
when(mockNode.getHandle()).thenReturn("/does/not/matter"); |
107 |
|
|
108 |
7 |
final ContentParameterProviderFactory f = new ContentParameterProviderFactory(); |
109 |
7 |
f.setTrimExtension(trimExtension); |
110 |
7 |
final ParameterProvider<Content> pp = f.newParameterProviderFor(req); |
111 |
7 |
final Content result = pp.getParameter(); |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
7 |
assertTrue(result instanceof SimpleEqualityContentWrapper); |
116 |
7 |
assertEquals(mockNode, ((ContentWrapper) result).getWrappedContent()); |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
public void testFailsIfNoPathInfo() throws Exception { |
121 |
1 |
failureTestForIncompletePaths(null, "Can't determine node, no pathInfo is available for uri /chalala"); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
124 |
1 |
@Test... |
125 |
|
public void testFailsIfWorkspaceNorNodePath() throws Exception { |
126 |
1 |
failureTestForIncompletePaths("/dummy", "Can't determine node from pathInfo: /dummy"); |
127 |
|
} |
128 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
129 |
2 |
private void failureTestForIncompletePaths(final String pathInfo, final String expectedExceptionMsg) {... |
130 |
2 |
final HttpServletRequest req = mock(HttpServletRequest.class); |
131 |
2 |
when(req.getPathInfo()).thenReturn(pathInfo); |
132 |
2 |
when(req.getRequestURI()).thenReturn("/chalala" + (pathInfo == null ? "" : pathInfo)); |
133 |
|
|
134 |
2 |
final ContentParameterProviderFactory f = new ContentParameterProviderFactory(); |
135 |
2 |
try { |
136 |
2 |
f.newParameterProviderFor(req); |
137 |
0 |
fail("should have failed"); |
138 |
|
} catch (IllegalArgumentException e) { |
139 |
2 |
assertEquals(expectedExceptionMsg, e.getMessage()); |
140 |
|
} |
141 |
|
} |
142 |
|
} |