1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.index.test.ui

File AllDocsTest.java

 

Code metrics

2
64
5
1
189
113
6
0.09
12.8
5
1.2

Classes

Class Line # Actions
AllDocsTest 49 64 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.Test;
28    import org.openqa.selenium.By;
29    import org.openqa.selenium.WebElement;
30    import org.xwiki.index.test.po.AllDocsPage;
31    import org.xwiki.index.tree.test.po.DocumentTreeElement;
32    import org.xwiki.test.ui.AbstractTest;
33    import org.xwiki.test.ui.TestUtils;
34    import org.xwiki.test.ui.browser.IgnoreBrowser;
35    import org.xwiki.test.ui.browser.IgnoreBrowsers;
36    import org.xwiki.test.ui.po.LiveTableElement;
37    import org.xwiki.tree.test.po.TreeNodeElement;
38   
39    import static org.junit.Assert.assertEquals;
40    import static org.junit.Assert.assertFalse;
41    import static org.junit.Assert.assertTrue;
42   
43    /**
44    * Tests for the AllDocs page.
45    *
46    * @version $Id: b842dc674151ef6af21055cd406533aa553c0c60 $
47    * @since 2.4M2
48    */
 
49    public class AllDocsTest extends AbstractTest
50    {
 
51  1 toggle @Test
52    public void tableViewTabActions() throws Exception
53    {
54    // Test 1: Verify that the Action column is displayed only for logged in users
55    // Create a test user
56  1 getUtil().createUserAndLogin(getTestClassName() + "_" + getTestMethodName(), "password");
57  1 AllDocsPage page = AllDocsPage.gotoPage();
58  1 LiveTableElement livetable = page.clickIndexTab();
59  1 assertTrue("No Actions column found", livetable.hasColumn("Actions"));
60   
61    // Logs out to be guest to verify that the Action columns is no longer displayed
62  1 getUtil().forceGuestUser();
63   
64  1 page = AllDocsPage.gotoPage();
65  1 livetable = page.clickIndexTab();
66  1 assertFalse("Actions column shouldn't be visible for guests", livetable.hasColumn("Actions"));
67   
68    // Test 2: Verify filtering works by filtering on the document name
69  1 livetable = page.clickIndexTab();
70  1 livetable.filterColumn("xwiki-livetable-alldocs-filter-2", getTestMethodName());
71    // We get one result for the user we've created
72  1 assertEquals(1, livetable.getRowCount());
73  1 assertTrue(livetable.hasRow("Title", getTestClassName() + "_" + getTestMethodName()));
74    }
75   
 
76  1 toggle @Test
77    public void recycleBinTab() throws Exception
78    {
79  1 getUtil().loginAsSuperAdminAndGotoPage(AllDocsPage.getURL());
80  1 AllDocsPage page = new AllDocsPage();
81  1 assertTrue("Deleted documents tab is not visible to Admin", page.hasDeletedDocsTab());
82  1 assertTrue("Deleted attachments tab is not visible to Admin", page.hasDeletedAttachmentsTab());
83   
84    // Logs out to be guest to verify that Deleted attachments/documents are not visible to guests
85  1 getUtil().forceGuestUser();
86   
87  1 assertFalse("Deleted documents shouldn't be visible to guests", page.hasDeletedDocsTab());
88  1 assertFalse("Deleted attachments shouldn't be visible to guests", page.hasDeletedAttachmentsTab());
89   
90    }
91   
92    /**
93    * Validate the tree view.
94    */
 
95  1 toggle @Test
96    public void treeViewTab() throws Exception
97    {
98    // Create a tree structure.
99  1 String spaceName = getTestMethodName();
100  1 getUtil().createPage(spaceName, "WebHome", null, null);
101  1 getUtil().createPageWithAttachment(Arrays.asList(spaceName, "A", "B"), "C", null, "Child Page", null, null,
102    "file.txt", getClass().getResourceAsStream("/file.txt"), TestUtils.SUPER_ADMIN_CREDENTIALS);
103   
104  1 DocumentTreeElement tree = AllDocsPage.gotoPage().clickTreeTab();
105   
106  1 TreeNodeElement root = tree.getDocumentNode(spaceName, "WebHome");
107  1 assertEquals(spaceName, root.getLabel());
108   
109  1 assertFalse(tree.hasDocument(spaceName, "A", "WebHome"));
110  1 root.open().waitForIt();
111  1 TreeNodeElement alice = tree.getDocumentNode(spaceName, "A", "WebHome");
112  1 assertEquals("A", alice.getLabel());
113   
114  1 assertFalse(tree.hasDocument(spaceName, "A", "B", "WebHome"));
115  1 alice.open().waitForIt();
116  1 TreeNodeElement bob = tree.getDocumentNode(spaceName, "A", "B", "WebHome");
117  1 assertEquals("B", bob.getLabel());
118   
119  1 assertFalse(tree.hasDocument(spaceName, "A", "B", "C"));
120  1 bob.open().waitForIt();
121  1 TreeNodeElement child = tree.getDocumentNode(spaceName, "A", "B", "C");
122  1 assertEquals("Child Page", child.getLabel());
123   
124  1 assertFalse(tree.hasAttachment(spaceName, "A", "B", "C", "file.txt"));
125    // Open the Attachments node.
126  1 child.open().waitForIt().getChildren().get(0).open().waitForIt();
127  1 TreeNodeElement file = tree.getAttachmentNode(spaceName, "A", "B", "C", "file.txt");
128  1 assertEquals("file.txt", file.getLabel());
129    }
130   
131    /**
132    * @see "XWIKI-5187: XWiki Explorer doesn't support very well spaces and pages with special characters in their
133    * names"
134    */
 
135  1 toggle @Test
136    public void treeViewTabWithSpecialCharactersInEntityNames()
137    {
138    // Create a tree structure.
139  1 String spaceName = getTestMethodName() + ".0";
140  1 getUtil().createPage(Arrays.asList(spaceName, "Level.1", "Level{[(2)]}", "Level@3"), "End", null, null);
141   
142  1 DocumentTreeElement tree = AllDocsPage.gotoPage().clickTreeTab();
143  1 tree.openToDocument(spaceName, "Level.1", "Level{[(2)]}", "Level@3", "End");
144   
145  1 assertTrue(tree.hasDocument(spaceName, "Level.1", "WebHome"));
146  1 assertTrue(tree.hasDocument(spaceName, "Level.1", "Level{[(2)]}", "WebHome"));
147  1 assertTrue(tree.hasDocument(spaceName, "Level.1", "Level{[(2)]}", "Level@3", "WebHome"));
148    }
149   
150    /**
151    * This test is against XWiki Enterprise XE-701 http://jira.xwiki.org/jira/browse/XE-701 (fixed in 2.5M1) WARN:
152    * calling isReady() and waitUntilReady() from LiveTableElement.java inside this class fails.
153    */
 
154  1 toggle @Test
155    @IgnoreBrowsers({
156    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146"),
157    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See http://jira.xwiki.org/browse/XE-1177")})
158    public void attachmentsTabFiltering() throws Exception
159    {
160    // Create 2 pages with attachments so that this test filter returns only one.
161    // Note that we need to be logged in.
162  1 getUtil().createPageWithAttachment(getTestClassName(), "Page", null, null, "attachment1.txt",
163    new ByteArrayInputStream("attachment content1".getBytes()), TestUtils.SUPER_ADMIN_CREDENTIALS);
164  1 getUtil().createPageWithAttachment(getTestClassName(), "OtherPage", null, null, "attachment2.txt",
165    new ByteArrayInputStream("attachment content2".getBytes()), TestUtils.SUPER_ADMIN_CREDENTIALS);
166   
167  1 AllDocsPage docsPage = AllDocsPage.gotoPage();
168  1 LiveTableElement liveTable = docsPage.clickAttachmentsTab();
169    // Here we test if all the Columns are displayed
170  1 Assert.assertTrue("No Filename column found", liveTable.hasColumn("Filename"));
171  1 Assert.assertTrue("No Space column found", liveTable.hasColumn("Space"));
172  1 Assert.assertTrue("No Date column found", liveTable.hasColumn("Date"));
173  1 Assert.assertTrue("No Author column found", liveTable.hasColumn("Author"));
174  1 Assert.assertTrue("No Type column found", liveTable.hasColumn("Type"));
175  1 Assert.assertTrue("No Page column found", liveTable.hasColumn("Page"));
176   
177    // Here we filter the livetable
178  1 liveTable.filterColumn("xwiki-livetable-allattachments-filter-2", "th");
179  1 List<WebElement> pageResults = getDriver().findElements(By.xpath("//td[@class='pagename']"));
180  1 Assert.assertEquals(1, pageResults.size());
181   
182    // Here we get the results that remain after applying the filter
183    // and we check if there is a result that doesn't contain the filter, the test will fail
184  2 for (int i = 0; i < pageResults.size(); i++) {
185  1 String text = pageResults.get(i).getText();
186  1 Assert.assertTrue("This [" + text + "] should not be here !", text.toLowerCase().contains("th"));
187    }
188    }
189    }