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

File ImportTest.java

 

Code metrics

6
51
6
1
195
117
9
0.18
8.5
6
1.5

Classes

Class Line # Actions
ImportTest 42 51 0% 9 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.administration.test.ui;
21   
22    import java.net.URL;
23   
24    import org.junit.*;
25    import org.openqa.selenium.By;
26    import org.openqa.selenium.WebElement;
27    import org.xwiki.administration.test.po.AdministrationPage;
28    import org.xwiki.administration.test.po.ImportAdministrationSectionPage;
29    import org.xwiki.test.ui.AbstractTest;
30    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
31    import org.xwiki.test.ui.browser.IgnoreBrowser;
32    import org.xwiki.test.ui.browser.IgnoreBrowsers;
33    import org.xwiki.test.ui.po.HistoryPane;
34    import org.xwiki.test.ui.po.ViewPage;
35   
36    /**
37    * Test the Import XAR feature.
38    *
39    * @version $Id: 78d5817d1b2964044544d966d99e7dfe128e040d $
40    * @since 2.3M1
41    */
 
42    public class ImportTest extends AbstractTest
43    {
44    @Rule
45    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
46   
47    private static final String PACKAGE_WITHOUT_HISTORY = "Main.TestPage-no-history.xar";
48   
49    private static final String PACKAGE_WITH_HISTORY = "Main.TestPage-with-history.xar";
50   
51    private static final String BACKUP_PACKAGE = "Main.TestPage-backup.xar";
52   
53    private AdministrationPage adminPage;
54   
55    private ImportAdministrationSectionPage sectionPage;
56   
 
57  5 toggle @Before
58    public void setUp() throws Exception
59    {
60    // Delete Test Page we import from XAR to ensure to start with a predefined state.
61  5 getUtil().rest().deletePage("Main", "TestPage");
62   
63  5 this.adminPage = AdministrationPage.gotoPage();
64  5 this.sectionPage = this.adminPage.clickImportSection();
65   
66    // Remove our packages if they're there already, to ensure to start with a predefined state.
67  5 if (this.sectionPage.isPackagePresent(PACKAGE_WITH_HISTORY)) {
68  1 this.sectionPage.deletePackage(PACKAGE_WITH_HISTORY);
69    }
70  5 if (this.sectionPage.isPackagePresent(PACKAGE_WITHOUT_HISTORY)) {
71  1 this.sectionPage.deletePackage(PACKAGE_WITHOUT_HISTORY);
72    }
73  5 if (this.sectionPage.isPackagePresent(BACKUP_PACKAGE)) {
74  1 this.sectionPage.deletePackage(BACKUP_PACKAGE);
75    }
76    }
77   
78    /**
79    * Verify that the Import page doesn't list any package by default in default XE.
80    *
81    * @since 2.6RC1
82    */
 
83  1 toggle @Test
84    public void testImportHasNoPackageByDefault()
85    {
86  1 Assert.assertEquals(0, this.sectionPage.getPackageNames().size());
87    }
88   
 
89  1 toggle @Test
90    @IgnoreBrowsers({
91    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
92    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
93    })
94    public void testImportWithHistory()
95    {
96  1 URL fileUrl = this.getClass().getResource("/" + PACKAGE_WITH_HISTORY);
97   
98  1 this.sectionPage.attachPackage(fileUrl);
99  1 this.sectionPage.selectPackage(PACKAGE_WITH_HISTORY);
100   
101  1 this.sectionPage.selectReplaceHistoryOption();
102  1 this.sectionPage.importPackage();
103   
104  1 ViewPage importedPage = this.sectionPage.clickImportedPage("Main.TestPage");
105   
106    // Since the page by default opens the comments pane, if we instantly click on the history, the two tabs
107    // will race for completion. Let's wait for comments first.
108  1 importedPage.openCommentsDocExtraPane();
109  1 HistoryPane history = importedPage.openHistoryDocExtraPane();
110   
111  1 Assert.assertEquals("3.1", history.getCurrentVersion());
112  1 Assert.assertEquals("A third version of the document", history.getCurrentVersionComment());
113  1 Assert.assertTrue(history.hasVersionWithSummary("A new version of the document"));
114    }
115   
 
116  1 toggle @Test
117    @IgnoreBrowsers({
118    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
119    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
120    })
121    public void testImportWithNewHistoryVersion()
122    {
123  1 URL fileUrl = this.getClass().getResource("/" + PACKAGE_WITHOUT_HISTORY);
124   
125  1 this.sectionPage.attachPackage(fileUrl);
126  1 this.sectionPage.selectPackage(PACKAGE_WITHOUT_HISTORY);
127   
128  1 this.sectionPage.importPackage();
129   
130  1 ViewPage importedPage = this.sectionPage.clickImportedPage("Main.TestPage");
131   
132    // Since the page by default opens the comments pane, if we instantly click on the history, the two tabs
133    // will race for completion. Let's wait for comments first.
134  1 importedPage.openCommentsDocExtraPane();
135  1 HistoryPane history = importedPage.openHistoryDocExtraPane();
136   
137  1 Assert.assertEquals("1.1", history.getCurrentVersion());
138  1 Assert.assertEquals("Imported from XAR", history.getCurrentVersionComment());
139    }
140   
 
141  1 toggle @Test
142    @IgnoreBrowsers({
143    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
144    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
145    })
146    public void testImportAsBackup()
147    {
148  1 URL fileUrl = this.getClass().getResource("/" + BACKUP_PACKAGE);
149   
150  1 this.sectionPage.attachPackage(fileUrl);
151  1 this.sectionPage.selectPackage(BACKUP_PACKAGE);
152   
153  1 WebElement importAsBackup = getDriver().findElement(By.name("importAsBackup"));
154  1 Assert.assertTrue(importAsBackup.isSelected());
155   
156  1 this.sectionPage.importPackage();
157   
158  1 ViewPage importedPage = this.sectionPage.clickImportedPage("Main.TestPage");
159   
160    // Since the page by default opens the comments pane, if we instantly click on the history, the two tabs
161    // will race for completion. Let's wait for comments first.
162  1 importedPage.openCommentsDocExtraPane();
163  1 HistoryPane history = importedPage.openHistoryDocExtraPane();
164   
165  1 Assert.assertEquals("JohnDoe", history.getCurrentAuthor());
166    }
167   
 
168  1 toggle @Test
169    @IgnoreBrowsers({
170    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
171    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
172    })
173    public void testImportWhenImportAsBackupIsNotSelected()
174    {
175  1 URL fileUrl = this.getClass().getResource("/" + BACKUP_PACKAGE);
176   
177  1 this.sectionPage.attachPackage(fileUrl);
178  1 this.sectionPage.selectPackage(BACKUP_PACKAGE);
179   
180  1 WebElement importAsBackup = getDriver().findElement(By.name("importAsBackup"));
181  1 importAsBackup.click();
182  1 Assert.assertFalse(importAsBackup.isSelected());
183   
184  1 this.sectionPage.importPackage();
185   
186  1 ViewPage importedPage = this.sectionPage.clickImportedPage("Main.TestPage");
187   
188    // Since the page by default opens the comments pane, if we instantly click on the history, the two tabs
189    // will race for completion. Let's wait for comments first.
190  1 importedPage.openCommentsDocExtraPane();
191  1 HistoryPane history = importedPage.openHistoryDocExtraPane();
192   
193  1 Assert.assertEquals("superadmin", history.getCurrentAuthor());
194    }
195    }