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

File AllDocsTest.java

 

Code metrics

0
81
6
1
224
134
6
0.07
13.5
6
1

Classes

Class Line # Actions
AllDocsTest 48 81 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 5 tests. .

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.index.test.ui;
21   
22    import java.io.ByteArrayInputStream;
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import org.junit.Assert;
27    import org.junit.Before;
28    import org.junit.Test;
29    import org.openqa.selenium.By;
30    import org.openqa.selenium.WebElement;
31    import org.xwiki.index.test.po.AllDocsPage;
32    import org.xwiki.index.tree.test.po.DocumentTreeElement;
33    import org.xwiki.test.ui.AbstractTest;
34    import org.xwiki.test.ui.TestUtils;
35    import org.xwiki.test.ui.browser.IgnoreBrowser;
36    import org.xwiki.test.ui.browser.IgnoreBrowsers;
37    import org.xwiki.test.ui.po.LiveTableElement;
38    import org.xwiki.tree.test.po.TreeNodeElement;
39   
40    import static org.junit.Assert.*;
41   
42    /**
43    * Tests for the AllDocs page.
44    *
45    * @version $Id: 439bca72eb1904f7bdd09fa640fafd1fb748de31 $
46    * @since 2.4M2
47    */
 
48    public class AllDocsTest extends AbstractTest
49    {
 
50  5 toggle @Before
51    public void setUp() throws Exception
52    {
53  5 getUtil().loginAsSuperAdmin();
54  5 getUtil().deleteSpace(getTestClassName());
55    }
56   
 
57  1 toggle @Test
58    public void tableViewTabActions() throws Exception
59    {
60    // Test 1: Verify that the Action column is displayed only for logged in users
61    // Create a test user
62  1 getUtil().createUserAndLogin(getTestClassName() + "_" + getTestMethodName(), "password");
63  1 AllDocsPage page = AllDocsPage.gotoPage();
64  1 LiveTableElement livetable = page.clickIndexTab();
65  1 assertTrue("No Actions column found", livetable.hasColumn("Actions"));
66   
67    // Logs out to be guest to verify that the Action columns is no longer displayed
68  1 getUtil().forceGuestUser();
69   
70  1 page = AllDocsPage.gotoPage();
71  1 livetable = page.clickIndexTab();
72  1 assertFalse("Actions column shouldn't be visible for guests", livetable.hasColumn("Actions"));
73   
74    // Test 2: Verify filtering works by filtering on the document name
75  1 livetable = page.clickIndexTab();
76  1 livetable.filterColumn("xwiki-livetable-alldocs-filter-2", getTestMethodName());
77    // We get one result for the user we've created
78  1 assertEquals(1, livetable.getRowCount());
79  1 assertTrue(livetable.hasRow("Title", getTestClassName() + "_" + getTestMethodName()));
80    }
81   
 
82  1 toggle @Test
83    public void recycleBinTab() throws Exception
84    {
85    // Create a document and delete it
86  1 getUtil().createPageWithAttachment(Arrays.asList(getTestClassName(), "DeleteableSpace"),"document",
87    null, "Document", null, null, "file.txt",
88    getClass().getResourceAsStream("/file.txt"), TestUtils.SUPER_ADMIN_CREDENTIALS);
89   
90  1 getUtil().loginAsSuperAdmin();
91  1 getUtil().deleteSpace(getTestClassName());
92  1 getUtil().gotoPage(AllDocsPage.getURL());
93   
94  1 AllDocsPage page = new AllDocsPage();
95  1 assertTrue("Deleted documents tab is not visible to Admin", page.hasDeletedDocsTab());
96  1 assertTrue("Deleted attachments tab is not visible to Admin", page.hasDeletedAttachmentsTab());
97   
98    // Logs out to be guest to verify that Deleted attachments/documents are not visible to guests
99  1 getUtil().forceGuestUser();
100   
101  1 assertFalse("Deleted documents shouldn't be visible to guests", page.hasDeletedDocsTab());
102  1 assertFalse("Deleted attachments shouldn't be visible to guests", page.hasDeletedAttachmentsTab());
103   
104    }
105   
106    /**
107    * Validate the tree view.
108    */
 
109  1 toggle @Test
110    public void treeViewTab() throws Exception
111    {
112    // Create a tree structure.
113  1 String spaceName = getTestClassName();
114  1 getUtil().createPage(spaceName, "WebHome", null, null);
115  1 getUtil().createPageWithAttachment(Arrays.asList(spaceName, "A", "B"), "C", null, "Child Page", null, null,
116    "file.txt", getClass().getResourceAsStream("/file.txt"), TestUtils.SUPER_ADMIN_CREDENTIALS);
117   
118  1 DocumentTreeElement tree = AllDocsPage.gotoPage().clickTreeTab();
119   
120  1 TreeNodeElement root = tree.getDocumentNode(spaceName, "WebHome");
121  1 assertEquals(spaceName, root.getLabel());
122   
123  1 assertFalse(tree.hasDocument(spaceName, "A", "WebHome"));
124  1 root.open().waitForIt();
125  1 TreeNodeElement alice = tree.getDocumentNode(spaceName, "A", "WebHome");
126  1 assertEquals("A", alice.getLabel());
127   
128  1 assertFalse(tree.hasDocument(spaceName, "A", "B", "WebHome"));
129  1 alice.open().waitForIt();
130  1 TreeNodeElement bob = tree.getDocumentNode(spaceName, "A", "B", "WebHome");
131  1 assertEquals("B", bob.getLabel());
132   
133  1 assertFalse(tree.hasDocument(spaceName, "A", "B", "C"));
134  1 bob.open().waitForIt();
135  1 TreeNodeElement child = tree.getDocumentNode(spaceName, "A", "B", "C");
136  1 assertEquals("Child Page", child.getLabel());
137   
138  1 assertFalse(tree.hasAttachment(spaceName, "A", "B", "C", "file.txt"));
139    // Open the Attachments node.
140  1 child.open().waitForIt().getChildren().get(0).open().waitForIt();
141  1 TreeNodeElement file = tree.getAttachmentNode(spaceName, "A", "B", "C", "file.txt");
142  1 assertEquals("file.txt", file.getLabel());
143    }
144   
145    /**
146    * @see "XWIKI-5187: XWiki Explorer doesn't support very well spaces and pages with special characters in their
147    * names"
148    */
 
149  1 toggle @Test
150    public void treeViewTabWithSpecialCharactersInEntityNames()
151    {
152    // Create a tree structure.
153  1 String spaceName = getTestMethodName() + ".0";
154  1 getUtil().createPage(Arrays.asList(spaceName, "Level.1", "Level{[(2)]}", "Level@3"), "End", null, null);
155   
156  1 DocumentTreeElement tree = AllDocsPage.gotoPage().clickTreeTab();
157  1 tree.openToDocument(spaceName, "Level.1", "Level{[(2)]}", "Level@3", "End");
158   
159  1 assertTrue(tree.hasDocument(spaceName, "Level.1", "WebHome"));
160  1 assertTrue(tree.hasDocument(spaceName, "Level.1", "Level{[(2)]}", "WebHome"));
161  1 assertTrue(tree.hasDocument(spaceName, "Level.1", "Level{[(2)]}", "Level@3", "WebHome"));
162    }
163   
164    /**
165    * This test is against XWiki Enterprise XE-701 https://jira.xwiki.org/browse/XE-701 (fixed in 2.5M1) WARN:
166    * calling isReady() and waitUntilReady() from LiveTableElement.java inside this class fails.
167    */
 
168  1 toggle @Test
169    @IgnoreBrowsers({
170    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"),
171    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177")})
172    public void attachmentsTabFilteringAndSorting() throws Exception
173    {
174    // Create 2 pages with attachments so that this test filter returns only one.
175    // Note that we need to be logged in.
176  1 getUtil().createPageWithAttachment(getTestClassName(), "Page", null, null, "attachment1.txt",
177    new ByteArrayInputStream("attachment content1".getBytes()), TestUtils.SUPER_ADMIN_CREDENTIALS);
178  1 getUtil().createPageWithAttachment(getTestClassName(), "OtherPage", null, null, "attachment2.txt",
179    new ByteArrayInputStream("attachment content2".getBytes()), TestUtils.SUPER_ADMIN_CREDENTIALS);
180   
181  1 AllDocsPage docsPage = AllDocsPage.gotoPage();
182  1 LiveTableElement liveTable = docsPage.clickAttachmentsTab();
183   
184    // Here we test if all the Columns are displayed.
185  1 assertTrue("No Type column found", liveTable.hasColumn("Type"));
186  1 assertTrue("No Name column found", liveTable.hasColumn("Name"));
187  1 assertTrue("No Location column found", liveTable.hasColumn("Location"));
188  1 assertTrue("No Size column found", liveTable.hasColumn("Size"));
189  1 assertTrue("No Date column found", liveTable.hasColumn("Date"));
190  1 assertTrue("No Author column found", liveTable.hasColumn("Author"));
191   
192  1 assertEquals(2, liveTable.getRowCount());
193   
194    // Filter by attachment file name.
195  1 liveTable.filterColumn("xwiki-livetable-allattachments-filter-2", "t1");
196  1 assertEquals(1, liveTable.getRowCount());
197  1 assertEquals("attachment1.txt", liveTable.getCell(liveTable.getRow(1), 2).getText());
198   
199    // Clear the filter.
200  1 liveTable.filterColumn("xwiki-livetable-allattachments-filter-2", "");
201   
202    // Filter by attachment location.
203  1 liveTable.filterColumn("xwiki-livetable-allattachments-filter-3", "th");
204  1 assertEquals(1, liveTable.getRowCount());
205  1 assertEquals("AllDocsTestOtherPage", liveTable.getCell(liveTable.getRow(1), 3).getText());
206   
207    // Clear the filter.
208  1 liveTable.filterColumn("xwiki-livetable-allattachments-filter-3", "");
209   
210    // Sort by attachment file name. The live table should be already sorted by file name ascending. This will
211    // reverse the order.
212  1 assertEquals("attachment2.txt", liveTable.getCell(liveTable.getRow(2), 2).getText());
213  1 liveTable.sortBy("Name");
214  1 assertEquals(2, liveTable.getRowCount());
215  1 assertEquals("attachment2.txt", liveTable.getCell(liveTable.getRow(1), 2).getText());
216   
217    // Sort by attachment location.
218  1 liveTable.sortBy("Location");
219  1 assertEquals("AllDocsTestPage", liveTable.getCell(liveTable.getRow(2), 3).getText());
220  1 liveTable.sortBy("Location");
221  1 assertEquals(2, liveTable.getRowCount());
222  1 assertEquals("AllDocsTestPage", liveTable.getCell(liveTable.getRow(1), 3).getText());
223    }
224    }