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

File XARExportTest.java

 

Code metrics

10
108
5
1
256
152
10
0.09
21.6
5
2

Classes

Class Line # Actions
XARExportTest 45 108 0% 10 2
0.9837398598.4%
 

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.flamingo.test.ui;
21   
22    import java.util.ArrayList;
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import org.junit.Test;
27    import org.openqa.selenium.By;
28    import org.xwiki.flamingo.sking.test.po.ExportModal;
29    import org.xwiki.flamingo.sking.test.po.OtherFormatPane;
30    import org.xwiki.model.reference.DocumentReference;
31    import org.xwiki.test.ui.AbstractTest;
32    import org.xwiki.test.ui.po.ViewPage;
33    import org.xwiki.tree.test.po.TreeElement;
34    import org.xwiki.tree.test.po.TreeNodeElement;
35   
36    import static org.junit.Assert.assertEquals;
37    import static org.junit.Assert.assertTrue;
38   
39    /**
40    * Verify that the XAR export features works fine.
41    *
42    * @version $Id: 66a316b8721851f33c36d3a7c7bf12965eeaa620 $
43    * @since 10.9
44    */
 
45    public class XARExportTest extends AbstractTest
46    {
 
47  1 toggle @Test
48    public void scenarioExportXAR() throws Exception
49    {
50  1 setupPages();
51  1 exportXARAll();
52  1 exportXARLotOfSelectedFiles();
53  1 exportXARWithUnselect();
54    }
55   
 
56  1 toggle private void setupPages() throws Exception
57    {
58  1 getUtil().loginAsSuperAdmin();
59   
60    // Create a space Foo
61  1 getUtil().createPage("Foo", "WebHome", "Foo", "Foo");
62   
63    // Create 50 pages under that space (will be used for the test with lot of selected pages)
64  51 for (int i = 0; i < 50; i++) {
65  50 String name = "Foo_" + i;
66  50 DocumentReference documentReference = new DocumentReference("xwiki",
67    Arrays.asList("Foo", name), "WebHome");
68  50 if (!getUtil().rest().exists(documentReference)) {
69  50 getUtil().rest().savePage(documentReference);
70    }
71    }
72   
73  21 for (int i = 0; i < 20; i++) {
74  20 String name = "Foo_10_"+i;
75  20 DocumentReference documentReference = new DocumentReference("xwiki",
76    Arrays.asList("Foo", "Foo_10", name), "WebHome");
77  20 if (!getUtil().rest().exists(documentReference)) {
78  20 getUtil().rest().savePage(documentReference);
79    }
80    }
81    // change the timeout as it might take time to load all nodes
82  1 getDriver().setTimeout(20);
83    }
84   
85    /*
86    Scenario: export a XAR after opening the export window and selecting "Other Format"
87    Don't change anything in the tree of export.
88    */
 
89  1 toggle private void exportXARAll() throws Exception
90    {
91  1 getUtil().loginAsSuperAdmin();
92   
93  1 ViewPage viewPage = getUtil().gotoPage("Foo", "WebHome");
94    // modal created before the opening to avoid fade effect. (see BaseModal)
95  1 ExportModal exportModal = new ExportModal();
96  1 viewPage.clickMoreActionsSubMenuEntry("tmExport");
97   
98  1 OtherFormatPane otherFormatPane = exportModal.openOtherFormatPane();
99  1 assertTrue(otherFormatPane.isTreeAvailable());
100  1 assertTrue(otherFormatPane.isExportAsXARButtonAvailable());
101   
102  1 TreeElement treeElement = otherFormatPane.getTreeElement();
103  1 List<TreeNodeElement> topLevelNodes = treeElement.getTopLevelNodes();
104  1 assertEquals(1, topLevelNodes.size());
105   
106  1 otherFormatPane.clickExportAsXARButton();
107   
108  1 String postURL = getUtil().getURL("Foo", "WebHome",
109    "export", "format=xar&name=Foo.WebHome");
110  1 assertEquals(postURL, otherFormatPane.getForm().getAttribute("action"));
111   
112  1 List<String> expectedPages = new ArrayList<>();
113  1 expectedPages.add("xwiki:Foo.%");
114  1 assertEquals(expectedPages, otherFormatPane.getPagesValues());
115   
116  1 List<String> expectedExcludes = new ArrayList<>();
117  1 expectedExcludes.add("");
118  1 assertEquals(expectedExcludes, otherFormatPane.getExcludesValues());
119  1 getUtil().forceGuestUser();
120    }
121   
122    /*
123    Scenario: Export a XAR after opening every pages in the pagination
124    and selecting everything
125    */
 
126  1 toggle public void exportXARLotOfSelectedFiles()
127    {
128  1 getUtil().loginAsSuperAdmin();
129   
130  1 ViewPage viewPage = getUtil().gotoPage("Foo", "WebHome");
131    // modal created before the opening to avoid fade effect. (see BaseModal)
132  1 ExportModal exportModal = new ExportModal();
133  1 viewPage.clickMoreActionsSubMenuEntry("tmExport");
134   
135  1 OtherFormatPane otherFormatPane = exportModal.openOtherFormatPane();
136  1 assertTrue(otherFormatPane.isTreeAvailable());
137  1 assertTrue(otherFormatPane.isExportAsXARButtonAvailable());
138   
139  1 TreeElement treeElement = otherFormatPane.getTreeElement();
140  1 List<TreeNodeElement> topLevelNodes = treeElement.getTopLevelNodes();
141  1 assertEquals(1, topLevelNodes.size());
142   
143  1 TreeNodeElement root = topLevelNodes.get(0);
144  1 root.open().waitForIt();
145   
146  1 assertEquals(16, root.getChildren().size());
147   
148  1 TreeNodeElement lastNode = null;
149  1 int size = 0;
150  4 for (int i = 15; i < 50; i += 15) {
151  3 size = root.getChildren().size();
152  3 lastNode = root.getChildren().get(size - 1);
153   
154  3 String lastNodeLabel = lastNode.getLabel();
155  3 lastNode.deselect();
156  3 lastNode.select();
157   
158  3 getDriver().waitUntilElementDisappears(exportModal.getContainer(), By.linkText(lastNodeLabel));
159    }
160   
161  1 assertEquals(50, root.getChildren().size());
162   
163  1 otherFormatPane.clickExportAsXARButton();
164   
165  1 String postURL = getUtil().getURL("Foo", "WebHome",
166    "export", "format=xar&name=Foo.WebHome");
167  1 assertEquals(postURL, otherFormatPane.getForm().getAttribute("action"));
168   
169  1 List<String> expectedPages = new ArrayList<>();
170  1 expectedPages.add("xwiki:Foo.%");
171  1 assertEquals(expectedPages, otherFormatPane.getPagesValues());
172   
173  1 List<String> expectedExcludes = new ArrayList<>();
174  1 expectedExcludes.add("");
175  1 assertEquals(expectedExcludes, otherFormatPane.getExcludesValues());
176   
177  1 getUtil().forceGuestUser();
178    }
179   
180    /*
181    Scenario: Export a XAR after opening main tree and a subtree and unselecting
182    nodes including the pagination node of the subtree.
183    */
 
184  1 toggle public void exportXARWithUnselect()
185    {
186  1 getUtil().loginAsSuperAdmin();
187  1 ViewPage viewPage = getUtil().gotoPage("Foo", "WebHome");
188    // modal created before the opening to avoid fade effect. (see BaseModal)
189  1 ExportModal exportModal = new ExportModal();
190  1 viewPage.clickMoreActionsSubMenuEntry("tmExport");
191   
192  1 OtherFormatPane otherFormatPane = exportModal.openOtherFormatPane();
193  1 assertTrue(otherFormatPane.isTreeAvailable());
194  1 assertTrue(otherFormatPane.isExportAsXARButtonAvailable());
195   
196  1 TreeElement treeElement = otherFormatPane.getTreeElement();
197  1 List<TreeNodeElement> topLevelNodes = treeElement.getTopLevelNodes();
198  1 assertEquals(1, topLevelNodes.size());
199   
200  1 TreeNodeElement root = topLevelNodes.get(0);
201  1 root = root.open().waitForIt();
202   
203  1 assertEquals(16, root.getChildren().size());
204   
205  1 TreeNodeElement node2 = root.getChildren().get(2);
206  1 TreeNodeElement node4 = root.getChildren().get(4);
207  1 TreeNodeElement node6 = root.getChildren().get(6);
208   
209   
210    // nodes are ordered using alphabetical order:
211    // 1 -> Foo_1
212    // 2 -> Foo_10
213    // ...
214    // 4 -> Foo_12
215    // 6 -> Foo_14
216   
217  1 node4.deselect();
218  1 node6.deselect();
219  1 node2.open().waitForIt();
220   
221    // the DOM is rebuilt
222  1 node2 = root.getChildren().get(2);
223   
224  1 assertEquals(16, node2.getChildren().size());
225  1 node2.deselect();
226   
227    // 1 -> Foo_10/Foo_10_1
228  1 node2.getChildren().get(1).select();
229   
230    // 2 -> Foo_10/Foo_10_15
231  1 node2.getChildren().get(7).select();
232   
233   
234  1 otherFormatPane.clickExportAsXARButton();
235   
236  1 String postURL = getUtil().getURL("Foo", "WebHome",
237    "export", "format=xar&name=Foo.WebHome");
238  1 assertEquals(postURL, otherFormatPane.getForm().getAttribute("action"));
239   
240  1 List<String> expectedPages = new ArrayList<>();
241  1 expectedPages.add("xwiki:Foo.%");
242  1 expectedPages.add("xwiki:Foo.Foo_10.Foo_10_1.WebHome");
243  1 expectedPages.add("xwiki:Foo.Foo_10.Foo_10_15.WebHome");
244   
245  1 List<String> expectedExcludes = new ArrayList<>();
246  1 expectedExcludes.add("xwiki%3AFoo.Foo_10.%25&xwiki%3AFoo.Foo_12.WebHome&xwiki%3AFoo.Foo_14.WebHome");
247    // we must keep the same number of argument as for pages
248  1 expectedExcludes.add("");
249  1 expectedExcludes.add("");
250   
251  1 assertEquals(expectedPages, otherFormatPane.getPagesValues());
252  1 assertEquals(expectedExcludes, otherFormatPane.getExcludesValues());
253   
254  1 getUtil().forceGuestUser();
255    }
256    }