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.module.resources; |
35 |
|
|
36 |
|
import static info.magnolia.resourceloader.dummy.DummyResourceOrigin.Differentiator.foo; |
37 |
|
import static info.magnolia.resourceloader.dummy.DummyResourceOrigin.*; |
38 |
|
import static org.junit.Assert.assertEquals; |
39 |
|
import static org.mockito.BDDMockito.given; |
40 |
|
import static org.mockito.Matchers.any; |
41 |
|
import static org.mockito.Mockito.mock; |
42 |
|
|
43 |
|
import info.magnolia.cms.core.AggregationState; |
44 |
|
import info.magnolia.objectfactory.guice.GuiceUtils; |
45 |
|
import info.magnolia.resourceloader.dummy.DummyResourceOrigin; |
46 |
|
import info.magnolia.templating.functions.TemplatingFunctions; |
47 |
|
|
48 |
|
import java.util.Date; |
49 |
|
|
50 |
|
import javax.inject.Provider; |
51 |
|
import javax.jcr.Node; |
52 |
|
|
53 |
|
import org.junit.Before; |
54 |
|
import org.junit.Ignore; |
55 |
|
import org.junit.Test; |
56 |
|
|
|
|
| 94.7% |
Uncovered Elements: 2 (38) |
Complexity: 11 |
Complexity Density: 0.41 |
|
57 |
|
public class ResourceLinkerTest { |
58 |
|
|
59 |
|
private ResourceLinker resourceLinker; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
61 |
8 |
@Before... |
62 |
|
public void setUp() throws Exception { |
63 |
|
|
64 |
|
|
65 |
8 |
final Provider<AggregationState> aggregationStateProvider = GuiceUtils.providerForInstance(mock(AggregationState.class)); |
66 |
8 |
final TemplatingFunctions templatingFunctions = mock(TemplatingFunctions.class); |
67 |
8 |
given(templatingFunctions.linkPrefix(any(Node.class))).willReturn("/ctxPath"); |
68 |
|
|
69 |
|
|
70 |
8 |
resourceLinker = new ResourceLinker(new DummyResourceOrigin(foo, constant(new Date(123l)), pathsFor("/foo/bar/qux.css")), |
71 |
|
GuiceUtils.providerForInstance(new ResourcesModule()), |
72 |
|
aggregationStateProvider, |
73 |
|
templatingFunctions); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
76 |
1 |
@Test... |
77 |
|
public void ignoresExternalLinks() { |
78 |
1 |
assertEquals("https://magnolia-cms.com", resourceLinker.linkTo("https://magnolia-cms.com", false)); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void ignoresDotResourcesPrefixForExistingResource() { |
83 |
1 |
assertEquals("/ctxPath/.resources/foo/bar/qux.css", resourceLinker.linkTo("/.resources/foo/bar/qux.css", false)); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void prependsDotResourcesPrefixForExistingResourceIfNotSpecified() { |
88 |
1 |
assertEquals("/ctxPath/.resources/foo/bar/qux.css", resourceLinker.linkTo("/foo/bar/qux.css", false)); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
public void ignoresNonExistingResource() { |
93 |
1 |
assertEquals("/ctxPath/.resources/lol/zor.css", resourceLinker.linkTo("/.resources/lol/zor.css", false)); |
94 |
1 |
assertEquals("/ctxPath/lol/zor.css", resourceLinker.linkTo("/lol/zor.css", false)); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
97 |
1 |
@Test... |
98 |
|
public void farFutureFingerPrintIsAddedForKnownResources() { |
99 |
1 |
assertEquals("/ctxPath/.resources/foo/bar/qux~1970-01-01-00-00-00-123~cache.css", resourceLinker.linkTo("/foo/bar/qux.css", true)); |
100 |
1 |
assertEquals("/ctxPath/.resources/foo/bar/qux~1970-01-01-00-00-00-123~cache.css", resourceLinker.linkTo("/.resources/foo/bar/qux.css", true)); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
103 |
1 |
@Test... |
104 |
|
public void farFutureFingerPrintCantBeAddedForUnknownResources() { |
105 |
|
|
106 |
1 |
assertEquals("/ctxPath/.resources/lol/zor.css", resourceLinker.linkTo("/.resources/lol/zor.css", true)); |
107 |
1 |
assertEquals("/ctxPath/lol/zor.css", resourceLinker.linkTo("/lol/zor.css", true)); |
108 |
|
} |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
0 |
@Ignore("We currently do not support links without protocol even though this style of links is common to be used nowadays")... |
111 |
|
@Test |
112 |
|
public void linkWithoutProtocol() { |
113 |
0 |
assertEquals("//static.addtoany.com/menu/page.js", resourceLinker.linkTo("//static.addtoany.com/menu/page.js", false)); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
116 |
1 |
@Test... |
117 |
|
public void servletMappingIsCleanedUp() { |
118 |
1 |
assertEquals("/.foo/*", newResourceLinkerWithConfiguredDownloadPath("/.foo").getServletMapping()); |
119 |
1 |
assertEquals("/.foo/*", newResourceLinkerWithConfiguredDownloadPath("/.foo/").getServletMapping()); |
120 |
1 |
assertEquals("/.foo/*", newResourceLinkerWithConfiguredDownloadPath(".foo").getServletMapping()); |
121 |
1 |
assertEquals("/.foo/*", newResourceLinkerWithConfiguredDownloadPath(".foo/").getServletMapping()); |
122 |
1 |
assertEquals("/.foo/*", newResourceLinkerWithConfiguredDownloadPath("//.foo///").getServletMapping()); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void downloadPathPrefixIsCleanedUp() { |
127 |
1 |
assertEquals("/.foo", newResourceLinkerWithConfiguredDownloadPath("/.foo").cleanDownloadPath()); |
128 |
1 |
assertEquals("/.foo", newResourceLinkerWithConfiguredDownloadPath("/.foo/").cleanDownloadPath()); |
129 |
1 |
assertEquals("/.foo", newResourceLinkerWithConfiguredDownloadPath(".foo").cleanDownloadPath()); |
130 |
1 |
assertEquals("/.foo", newResourceLinkerWithConfiguredDownloadPath(".foo/").cleanDownloadPath()); |
131 |
1 |
assertEquals("/.foo", newResourceLinkerWithConfiguredDownloadPath("//.foo///").cleanDownloadPath()); |
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
134 |
10 |
private ResourceLinker newResourceLinkerWithConfiguredDownloadPath(String configuredDownloadPath) {... |
135 |
10 |
final ResourcesModule module = new ResourcesModule(); |
136 |
10 |
module.setDownloadPath(configuredDownloadPath); |
137 |
10 |
return new ResourceLinker(new DummyResourceOrigin(), GuiceUtils.providerForInstance(module), null, null); |
138 |
|
} |
139 |
|
|
140 |
|
} |