1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.webjars.internal; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.util.Arrays; |
24 |
|
|
25 |
|
import javax.inject.Provider; |
26 |
|
|
27 |
|
import org.apache.commons.io.FileUtils; |
28 |
|
import org.junit.After; |
29 |
|
import org.junit.Before; |
30 |
|
import org.junit.Rule; |
31 |
|
import org.junit.Test; |
32 |
|
import org.mockito.Mockito; |
33 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
34 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
35 |
|
import org.xwiki.url.filesystem.FilesystemExportContext; |
36 |
|
|
37 |
|
import static org.junit.Assert.*; |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 4 |
Complexity Density: 0.21 |
|
39 |
|
public class FilesystemResourceReferenceSerializerTest |
40 |
|
{ |
41 |
|
private static final File BASEDIR = new File(System.getProperty("java.io.tmpdir"), "xwikitest"); |
42 |
|
|
43 |
|
@Rule |
44 |
|
public MockitoComponentMockingRule<FilesystemResourceReferenceSerializer> mocker = |
45 |
|
new MockitoComponentMockingRule<>(FilesystemResourceReferenceSerializer.class); |
46 |
|
|
47 |
|
private ClassLoader originalThreadContextClassLoader; |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
49 |
2 |
@Before... |
50 |
|
public void setUp() throws Exception |
51 |
|
{ |
52 |
2 |
this.originalThreadContextClassLoader = Thread.currentThread().getContextClassLoader(); |
53 |
2 |
Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); |
54 |
2 |
FileUtils.deleteDirectory(BASEDIR); |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
2 |
@After... |
58 |
|
public void tearDown() |
59 |
|
{ |
60 |
2 |
Thread.currentThread().setContextClassLoader(this.originalThreadContextClassLoader); |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
63 |
1 |
@Test... |
64 |
|
public void serialize() throws Exception |
65 |
|
{ |
66 |
1 |
FilesystemExportContext exportContext = new FilesystemExportContext(); |
67 |
1 |
exportContext.setExportDir(BASEDIR); |
68 |
|
|
69 |
1 |
Provider<FilesystemExportContext> exportContextProvider = this.mocker.getInstance(new DefaultParameterizedType( |
70 |
|
null, Provider.class, FilesystemExportContext.class)); |
71 |
1 |
Mockito.when(exportContextProvider.get()).thenReturn(exportContext); |
72 |
|
|
73 |
1 |
WebJarsResourceReference reference = new WebJarsResourceReference("wiki:wiki", Arrays.asList( |
74 |
|
"angular-paginate-anything", "2.5.3", "paginate-anything.js")); |
75 |
|
|
76 |
|
|
77 |
1 |
assertEquals("webjars/angular-paginate-anything/2.5.3/paginate-anything.js", |
78 |
|
this.mocker.getComponentUnderTest().serialize(reference).serialize()); |
79 |
|
|
80 |
|
|
81 |
1 |
assertTrue(new File(BASEDIR, "webjars/angular-paginate-anything/2.5.3/paginate-anything.js").exists()); |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
84 |
1 |
@Test... |
85 |
|
public void serializeWithCSSPathAdjustments() throws Exception |
86 |
|
{ |
87 |
1 |
FilesystemExportContext exportContext = new FilesystemExportContext(); |
88 |
1 |
exportContext.setExportDir(BASEDIR); |
89 |
1 |
exportContext.pushCSSParentLevels(3); |
90 |
|
|
91 |
1 |
Provider<FilesystemExportContext> exportContextProvider = this.mocker.getInstance(new DefaultParameterizedType( |
92 |
|
null, Provider.class, FilesystemExportContext.class)); |
93 |
1 |
Mockito.when(exportContextProvider.get()).thenReturn(exportContext); |
94 |
|
|
95 |
1 |
WebJarsResourceReference reference = new WebJarsResourceReference("wiki:wiki", Arrays.asList( |
96 |
|
"angular-paginate-anything", "2.5.3", "paginate-anything.js")); |
97 |
|
|
98 |
|
|
99 |
1 |
assertEquals("../../../webjars/angular-paginate-anything/2.5.3/paginate-anything.js", |
100 |
|
this.mocker.getComponentUnderTest().serialize(reference).serialize()); |
101 |
|
|
102 |
|
|
103 |
1 |
assertTrue(new File(BASEDIR, "webjars/angular-paginate-anything/2.5.3/paginate-anything.js").exists()); |
104 |
|
} |
105 |
|
} |