1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.vfs.test.ui; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
import java.io.ByteArrayOutputStream; |
24 |
|
import java.io.InputStream; |
25 |
|
import java.util.zip.ZipEntry; |
26 |
|
import java.util.zip.ZipOutputStream; |
27 |
|
|
28 |
|
import org.junit.Rule; |
29 |
|
import org.junit.Test; |
30 |
|
import org.openqa.selenium.By; |
31 |
|
import org.xwiki.test.ui.AbstractTest; |
32 |
|
import org.xwiki.test.ui.SuperAdminAuthenticationRule; |
33 |
|
import org.xwiki.test.ui.po.ViewPage; |
34 |
|
import org.xwiki.tree.test.po.TreeElement; |
35 |
|
import org.xwiki.tree.test.po.TreeNodeElement; |
36 |
|
|
37 |
|
import static org.junit.Assert.assertEquals; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 4 |
Complexity Density: 0.17 |
|
45 |
|
public class VfsTest extends AbstractTest |
46 |
|
{ |
47 |
|
@Rule |
48 |
|
public SuperAdminAuthenticationRule superAdminAuthenticationRule = new SuperAdminAuthenticationRule(getUtil()); |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
50 |
1 |
@Test... |
51 |
|
public void testVfsMacro() throws Exception |
52 |
|
{ |
53 |
|
|
54 |
1 |
getUtil().rest().deletePage(getTestClassName(), getTestMethodName()); |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
1 |
getUtil().attachFile(getTestClassName(), getTestMethodName(), "test.zip", createZipInputStream(), false); |
61 |
1 |
String content = "{{vfsTree root=\"attach:test.zip\"/}}"; |
62 |
1 |
ViewPage vp = getUtil().createPage(getTestClassName(), getTestMethodName(), content, "VFS Test"); |
63 |
|
|
64 |
|
|
65 |
1 |
TreeElement tree = new TreeElement(getDriver().findElement(By.cssSelector(".xtree"))); |
66 |
1 |
tree.waitForIt(); |
67 |
1 |
TreeNodeElement node = tree.getNode("//directory"); |
68 |
1 |
node = node.open(); |
69 |
1 |
node.waitForIt(); |
70 |
1 |
node.getChildren().get(0).select(); |
71 |
1 |
assertEquals("content2", getDriver().findElement(By.tagName("body")).getText()); |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.25 |
|
74 |
1 |
private InputStream createZipInputStream() throws Exception... |
75 |
|
{ |
76 |
1 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
77 |
1 |
try (ZipOutputStream zos = new ZipOutputStream(baos)) { |
78 |
|
|
79 |
1 |
ZipEntry entry = new ZipEntry("node1"); |
80 |
1 |
zos.putNextEntry(entry); |
81 |
1 |
zos.write("content1".getBytes()); |
82 |
1 |
zos.closeEntry(); |
83 |
|
|
84 |
1 |
entry = new ZipEntry("directory/node2"); |
85 |
1 |
zos.putNextEntry(entry); |
86 |
1 |
zos.write("content2".getBytes()); |
87 |
1 |
zos.closeEntry(); |
88 |
|
} |
89 |
1 |
return new ByteArrayInputStream(baos.toByteArray()); |
90 |
|
} |
91 |
|
|
92 |
|
} |