1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.vfs.internal; |
21 |
|
|
22 |
|
import java.net.URI; |
23 |
|
import java.util.Arrays; |
24 |
|
|
25 |
|
import javax.inject.Provider; |
26 |
|
|
27 |
|
import org.junit.Before; |
28 |
|
import org.junit.Rule; |
29 |
|
import org.junit.Test; |
30 |
|
import org.xwiki.component.manager.ComponentManager; |
31 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
32 |
|
import org.xwiki.resource.ResourceReferenceSerializer; |
33 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
34 |
|
import org.xwiki.url.ExtendedURL; |
35 |
|
import org.xwiki.url.URLNormalizer; |
36 |
|
import org.xwiki.vfs.VfsResourceReference; |
37 |
|
|
38 |
|
import static org.junit.Assert.assertEquals; |
39 |
|
import static org.mockito.Mockito.when; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0.25 |
|
47 |
|
public class VfsResourceReferenceSerializerTest |
48 |
|
{ |
49 |
|
@Rule |
50 |
|
public MockitoComponentMockingRule<VfsResourceReferenceSerializer> mocker = |
51 |
|
new MockitoComponentMockingRule<>(VfsResourceReferenceSerializer.class); |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
53 |
2 |
@Before... |
54 |
|
public void setUp() throws Exception |
55 |
|
{ |
56 |
2 |
Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent( |
57 |
|
new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context"); |
58 |
2 |
when(componentManagerProvider.get()).thenReturn(this.mocker); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
61 |
1 |
@Test... |
62 |
|
public void serializeWhenNoSpecificSchemeSerializer() throws Exception |
63 |
|
{ |
64 |
1 |
VfsResourceReference reference = new VfsResourceReference( |
65 |
|
URI.create("somescheme:wiki:space.page@attachment"), "path1/path2/test.txt"); |
66 |
|
|
67 |
1 |
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList( |
68 |
|
"vfs", "somescheme:wiki:space.page@attachment", "path1", "path2", "test.txt")); |
69 |
|
|
70 |
1 |
URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance( |
71 |
|
new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath"); |
72 |
1 |
when(normalizer.normalize(extendedURL)).thenReturn(extendedURL); |
73 |
|
|
74 |
1 |
assertEquals("/vfs/somescheme%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", |
75 |
|
this.mocker.getComponentUnderTest().serialize(reference).toString()); |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
78 |
1 |
@Test... |
79 |
|
public void serializeWhenSpecificSchemeSerializer() throws Exception |
80 |
|
{ |
81 |
1 |
VfsResourceReference reference = new VfsResourceReference( |
82 |
|
URI.create("attach:attachment"), "path1/path2/test.txt"); |
83 |
|
|
84 |
1 |
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList( |
85 |
|
"vfs", "attach:wiki:space.page@attachment", "path1", "path2", "test.txt")); |
86 |
|
|
87 |
1 |
ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> serializer = this.mocker.registerMockComponent( |
88 |
|
new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, |
89 |
|
ExtendedURL.class), "attach"); |
90 |
1 |
when(serializer.serialize(reference)).thenReturn(extendedURL); |
91 |
|
|
92 |
1 |
assertEquals("/vfs/attach%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", |
93 |
|
this.mocker.getComponentUnderTest().serialize(reference).toString()); |
94 |
|
} |
95 |
|
} |