/
XARExportIT.java
252 lines (202 loc) · 9.28 KB
/
XARExportIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.flamingo.test.ui;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.openqa.selenium.By;
import org.xwiki.flamingo.skin.test.po.ExportModal;
import org.xwiki.flamingo.skin.test.po.OtherFormatPane;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.test.ui.AbstractTest;
import org.xwiki.test.ui.po.ViewPage;
import org.xwiki.tree.test.po.TreeElement;
import org.xwiki.tree.test.po.TreeNodeElement;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Verify that the XAR export features works fine.
*
* @version $Id$
* @since 10.9
*/
public class XARExportIT extends AbstractTest
{
@Test
public void scenarioExportXAR() throws Exception
{
setupPages();
exportXARAll();
exportXARLotOfSelectedFiles();
exportXARWithUnselect();
}
private void setupPages() throws Exception
{
getUtil().loginAsSuperAdmin();
// Create a space Foo
getUtil().createPage("Foo", "WebHome", "Foo", "Foo");
// Create 50 pages under that space (will be used for the test with lot of selected pages)
for (int i = 0; i < 50; i++) {
String name = "Foo_" + i;
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Foo", name), "WebHome");
if (!getUtil().rest().exists(documentReference)) {
getUtil().rest().savePage(documentReference);
}
}
for (int i = 0; i < 20; i++) {
String name = "Foo_10_" + i;
DocumentReference documentReference =
new DocumentReference("xwiki", Arrays.asList("Foo", "Foo_10", name), "WebHome");
if (!getUtil().rest().exists(documentReference)) {
getUtil().rest().savePage(documentReference);
}
}
// Change the timeout as it might take time to load all nodes
getDriver().setTimeout(20);
}
/**
* Scenario: export a XAR after opening the export window and selecting "Other Format". Don't change anything in the
* tree of export.
*/
private void exportXARAll() throws Exception
{
getUtil().loginAsSuperAdmin();
ViewPage viewPage = getUtil().gotoPage("Foo", "WebHome");
// modal created before the opening to avoid fade effect. (see BaseModal)
ExportModal exportModal = new ExportModal();
viewPage.clickMoreActionsSubMenuEntry("tmExport");
OtherFormatPane otherFormatPane = exportModal.openOtherFormatPane();
assertTrue(otherFormatPane.isTreeAvailable());
assertTrue(otherFormatPane.isExportAsXARButtonAvailable());
TreeElement treeElement = otherFormatPane.getTreeElement();
List<TreeNodeElement> topLevelNodes = treeElement.getTopLevelNodes();
assertEquals(1, topLevelNodes.size());
otherFormatPane.clickExportAsXARButton();
String postURL = getUtil().getURL("Foo", "WebHome", "export", "format=xar&name=Foo.WebHome&");
assertEquals(postURL, otherFormatPane.getForm().getAttribute("action"));
List<String> expectedPages = new ArrayList<>();
expectedPages.add("xwiki:Foo.%");
assertEquals(expectedPages, otherFormatPane.getPagesValues());
List<String> expectedExcludes = new ArrayList<>();
expectedExcludes.add("");
assertEquals(expectedExcludes, otherFormatPane.getExcludesValues());
getUtil().forceGuestUser();
}
/**
* Scenario: test with lots of selected pages in the XAR expor and spanning several pages to ensure that everything
* selected is taken into account (See XWIKI-15444). To achieve this, we open every page in the pagination and
* select everything.
*/
public void exportXARLotOfSelectedFiles()
{
getUtil().loginAsSuperAdmin();
ViewPage viewPage = getUtil().gotoPage("Foo", "WebHome");
// modal created before the opening to avoid fade effect. (see BaseModal)
ExportModal exportModal = new ExportModal();
viewPage.clickMoreActionsSubMenuEntry("tmExport");
OtherFormatPane otherFormatPane = exportModal.openOtherFormatPane();
assertTrue(otherFormatPane.isTreeAvailable());
assertTrue(otherFormatPane.isExportAsXARButtonAvailable());
TreeElement treeElement = otherFormatPane.getTreeElement();
List<TreeNodeElement> topLevelNodes = treeElement.getTopLevelNodes();
assertEquals(1, topLevelNodes.size());
TreeNodeElement root = topLevelNodes.get(0);
root.open().waitForIt();
assertEquals(16, root.getChildren().size());
TreeNodeElement lastNode;
int size = 0;
for (int i = 15; i < 50; i += 15) {
size = root.getChildren().size();
lastNode = root.getChildren().get(size - 1);
String lastNodeLabel = lastNode.getLabel();
lastNode.deselect();
lastNode.select();
getDriver().waitUntilElementDisappears(exportModal.getContainer(), By.linkText(lastNodeLabel));
}
assertEquals(50, root.getChildren().size());
otherFormatPane.clickExportAsXARButton();
String postURL = getUtil().getURL("Foo", "WebHome", "export", "format=xar&name=Foo.WebHome&");
assertEquals(postURL, otherFormatPane.getForm().getAttribute("action"));
List<String> expectedPages = new ArrayList<>();
expectedPages.add("xwiki:Foo.%");
assertEquals(expectedPages, otherFormatPane.getPagesValues());
List<String> expectedExcludes = new ArrayList<>();
expectedExcludes.add("");
assertEquals(expectedExcludes, otherFormatPane.getExcludesValues());
getUtil().forceGuestUser();
}
/**
* Scenario: Export a XAR after opening main tree and a subtree and unselecting nodes including the pagination node
* of the subtree.
*/
public void exportXARWithUnselect()
{
getUtil().loginAsSuperAdmin();
ViewPage viewPage = getUtil().gotoPage("Foo", "WebHome");
// modal created before the opening to avoid fade effect. (see BaseModal)
ExportModal exportModal = new ExportModal();
viewPage.clickMoreActionsSubMenuEntry("tmExport");
OtherFormatPane otherFormatPane = exportModal.openOtherFormatPane();
assertTrue(otherFormatPane.isTreeAvailable());
assertTrue(otherFormatPane.isExportAsXARButtonAvailable());
TreeElement treeElement = otherFormatPane.getTreeElement();
List<TreeNodeElement> topLevelNodes = treeElement.getTopLevelNodes();
assertEquals(1, topLevelNodes.size());
TreeNodeElement root = topLevelNodes.get(0);
root = root.open().waitForIt();
assertEquals(16, root.getChildren().size());
TreeNodeElement node2 = root.getChildren().get(2);
TreeNodeElement node4 = root.getChildren().get(4);
TreeNodeElement node6 = root.getChildren().get(6);
// nodes are ordered using alphabetical order:
// 1 -> Foo_1
// 2 -> Foo_10
// ...
// 4 -> Foo_12
// 6 -> Foo_14
node4.deselect();
node6.deselect();
node2.open().waitForIt();
// the DOM is rebuilt
node2 = root.getChildren().get(2);
assertEquals(16, node2.getChildren().size());
node2.deselect();
// 1 -> Foo_10/Foo_10_1
node2.getChildren().get(1).select();
// 2 -> Foo_10/Foo_10_15
node2.getChildren().get(7).select();
otherFormatPane.clickExportAsXARButton();
String postURL = getUtil().getURL("Foo", "WebHome", "export", "format=xar&name=Foo.WebHome&");
assertEquals(postURL, otherFormatPane.getForm().getAttribute("action"));
List<String> expectedPages = new ArrayList<>();
expectedPages.add("xwiki:Foo.%");
expectedPages.add("xwiki:Foo.Foo_10.Foo_10_1.WebHome");
expectedPages.add("xwiki:Foo.Foo_10.Foo_10_15.WebHome");
List<String> expectedExcludes = new ArrayList<>();
expectedExcludes.add("xwiki%3AFoo.Foo_10.%25&xwiki%3AFoo.Foo_12.WebHome&xwiki%3AFoo.Foo_14.WebHome");
// we must keep the same number of argument as for pages
expectedExcludes.add("");
expectedExcludes.add("");
assertEquals(expectedPages, otherFormatPane.getPagesValues());
assertEquals(expectedExcludes, otherFormatPane.getExcludesValues());
getUtil().forceGuestUser();
}
}