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.attach; |
21 |
|
|
22 |
|
import java.net.URI; |
23 |
|
import java.util.Arrays; |
24 |
|
|
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
28 |
|
import org.xwiki.model.reference.AttachmentReference; |
29 |
|
import org.xwiki.model.reference.AttachmentReferenceResolver; |
30 |
|
import org.xwiki.model.reference.DocumentReference; |
31 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
33 |
|
import org.xwiki.url.ExtendedURL; |
34 |
|
import org.xwiki.url.URLNormalizer; |
35 |
|
import org.xwiki.vfs.VfsResourceReference; |
36 |
|
|
37 |
|
import static org.junit.Assert.*; |
38 |
|
import static org.mockito.Mockito.*; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.1 |
|
46 |
|
public class AttachVfsResourceReferenceSerializerTest |
47 |
|
{ |
48 |
|
@Rule |
49 |
|
public MockitoComponentMockingRule<AttachVfsResourceReferenceSerializer> mocker = |
50 |
|
new MockitoComponentMockingRule<>(AttachVfsResourceReferenceSerializer.class); |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
52 |
1 |
@Test... |
53 |
|
public void serialize() throws Exception |
54 |
|
{ |
55 |
1 |
VfsResourceReference reference = new VfsResourceReference( |
56 |
|
URI.create("attach:attachment"), "path1/path2/test.txt"); |
57 |
|
|
58 |
1 |
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList( |
59 |
|
"vfs", "attach:wiki:space.page@attachment", "path1", "path2", "test.txt")); |
60 |
|
|
61 |
1 |
URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance( |
62 |
|
new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath"); |
63 |
1 |
when(normalizer.normalize(extendedURL)).thenReturn(extendedURL); |
64 |
|
|
65 |
1 |
AttachmentReferenceResolver<String> attachmentResolver = this.mocker.getInstance( |
66 |
|
AttachmentReferenceResolver.TYPE_STRING, "current"); |
67 |
1 |
AttachmentReference attachmentReference = new AttachmentReference("attachment", |
68 |
|
new DocumentReference("wiki", Arrays.asList("space"), "page")); |
69 |
1 |
when(attachmentResolver.resolve("attachment")).thenReturn(attachmentReference); |
70 |
|
|
71 |
1 |
EntityReferenceSerializer<String> entitySerializer = this.mocker.getInstance( |
72 |
|
EntityReferenceSerializer.TYPE_STRING); |
73 |
1 |
when(entitySerializer.serialize(attachmentReference)).thenReturn("wiki:space.page@attachment"); |
74 |
|
|
75 |
1 |
assertEquals("/vfs/attach%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", |
76 |
|
this.mocker.getComponentUnderTest().serialize(reference).toString()); |
77 |
|
} |
78 |
|
} |