1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.pdf.impl; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
import java.util.Collections; |
24 |
|
|
25 |
|
import javax.xml.transform.Source; |
26 |
|
import javax.xml.transform.stream.StreamSource; |
27 |
|
|
28 |
|
import org.apache.commons.io.IOUtils; |
29 |
|
import org.junit.Assert; |
30 |
|
import org.junit.Test; |
31 |
|
import org.xwiki.model.EntityType; |
32 |
|
import org.xwiki.model.reference.AttachmentReference; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
|
35 |
|
import com.xpn.xwiki.XWikiContext; |
36 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
37 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
38 |
|
|
39 |
|
import static org.mockito.Mockito.*; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 2 |
Complexity Density: 0.1 |
|
47 |
|
public class PDFURIResolverTest |
48 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
49 |
1 |
@Test... |
50 |
|
public void resolveWhenNoMap() throws Exception |
51 |
|
{ |
52 |
1 |
XWikiContext context = mock(XWikiContext.class); |
53 |
1 |
PDFURIResolver resolver = new PDFURIResolver(context); |
54 |
1 |
Source source = resolver.resolve("href", "base"); |
55 |
1 |
Assert.assertNull(source); |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
58 |
1 |
@Test... |
59 |
|
public void resolveWhenMapItemExists() throws Exception |
60 |
|
{ |
61 |
1 |
DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); |
62 |
1 |
AttachmentReference attachmentReference = new AttachmentReference("fileName", documentReference); |
63 |
1 |
com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class); |
64 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
65 |
1 |
XWikiAttachment attachment = mock(XWikiAttachment.class); |
66 |
|
|
67 |
1 |
XWikiContext context = mock(XWikiContext.class); |
68 |
|
|
69 |
|
|
70 |
1 |
String url = "encoded+url"; |
71 |
1 |
when(context.get("pdfExportImageURLMap")).thenReturn(Collections.singletonMap(url, attachmentReference)); |
72 |
1 |
when(context.getWiki()).thenReturn(xwiki); |
73 |
1 |
when(xwiki.getDocument(attachmentReference.extractReference(EntityType.DOCUMENT), context)).thenReturn( |
74 |
|
document); |
75 |
1 |
when(document.getAttachment("fileName")).thenReturn(attachment); |
76 |
1 |
when(attachment.getContentInputStream(context)).thenReturn(new ByteArrayInputStream("content".getBytes())); |
77 |
|
|
78 |
1 |
PDFURIResolver resolver = new PDFURIResolver(context); |
79 |
1 |
Source source = resolver.resolve(url, "base"); |
80 |
1 |
Assert.assertEquals(StreamSource.class, source.getClass()); |
81 |
1 |
Assert.assertEquals("content", IOUtils.readLines(((StreamSource) source).getInputStream()).get(0)); |
82 |
|
} |
83 |
|
} |