1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.vfs.test.ui

File VfsTest.java

 

Code metrics

0
23
2
1
92
50
4
0.17
11.5
2
2

Classes

Class Line # Actions
VfsTest 45 23 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Functional tests for the VFS feature.
41    *
42    * @version $Id: ba1c7942fecf353dad0dcf7182c6bc3c6fcaf253 $
43    * @since 7.4M2
44    */
 
45    public class VfsTest extends AbstractTest
46    {
47    @Rule
48    public SuperAdminAuthenticationRule superAdminAuthenticationRule = new SuperAdminAuthenticationRule(getUtil());
49   
 
50  1 toggle @Test
51    public void testVfsMacro() throws Exception
52    {
53    // Delete pages that we create in the test
54  1 getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
55   
56    // Scenario:
57    // - Attach a zip to a wiki page
58    // - Use the VFS Tree Macro to display the content of that zip
59    // - Click on a tree node to display the content of a file inside the zip
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    // Get hold of the Tree and expand the directory node and the click on the first children node
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   
 
74  1 toggle private InputStream createZipInputStream() throws Exception
75    {
76  1 ByteArrayOutputStream baos = new ByteArrayOutputStream();
77  1 try (ZipOutputStream zos = new ZipOutputStream(baos)) {
78    // Entry 1: File 1
79  1 ZipEntry entry = new ZipEntry("node1");
80  1 zos.putNextEntry(entry);
81  1 zos.write("content1".getBytes());
82  1 zos.closeEntry();
83    // Entry 2: File 2
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    }