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

File UpgradeTest.java

 

Code metrics

14
118
10
1
381
218
17
0.14
11.8
10
1.7

Classes

Class Line # Actions
UpgradeTest 63 118 0% 17 13
0.908450790.8%
 

Contributing tests

This file is covered by 2 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.test.ui;
21   
22    import java.net.URLEncoder;
23    import java.nio.charset.StandardCharsets;
24    import java.util.Arrays;
25    import java.util.HashSet;
26    import java.util.List;
27    import java.util.Set;
28    import java.util.stream.Collectors;
29   
30    import org.apache.commons.configuration2.PropertiesConfiguration;
31    import org.junit.BeforeClass;
32    import org.junit.Rule;
33    import org.junit.Test;
34    import org.xwiki.extension.ExtensionId;
35    import org.xwiki.extension.internal.ExtensionUtils;
36    import org.xwiki.extension.internal.converter.ExtensionIdConverter;
37    import org.xwiki.extension.test.po.ExtensionPane;
38    import org.xwiki.extension.test.po.ExtensionProgressPane;
39    import org.xwiki.extension.test.po.LogItemPane;
40    import org.xwiki.extension.test.po.distribution.DistributionStepIcon;
41    import org.xwiki.extension.test.po.distribution.ExtensionsDistributionStep;
42    import org.xwiki.extension.test.po.distribution.FlavorDistributionStep;
43    import org.xwiki.extension.test.po.distribution.ReportDistributionStep;
44    import org.xwiki.extension.test.po.distribution.WelcomeDistributionStep;
45    import org.xwiki.extension.test.po.flavor.FlavorPane;
46    import org.xwiki.extension.test.po.flavor.FlavorPicker;
47    import org.xwiki.extension.test.po.flavor.FlavorPickerInstallStep;
48    import org.xwiki.logging.LogLevel;
49    import org.xwiki.test.integration.XWikiExecutor;
50    import org.xwiki.test.ui.po.ViewPage;
51   
52    import static org.junit.jupiter.api.Assertions.assertEquals;
53    import static org.junit.jupiter.api.Assertions.assertFalse;
54    import static org.junit.jupiter.api.Assertions.assertTrue;
55    import static org.junit.jupiter.api.Assertions.fail;
56   
57    /**
58    * Validate the Distribution Wizard part of the upgrade process.
59    *
60    * @version $Id: 08b96077db103ab0bfd7023a0d3efd73b4cbc2e5 $
61    * @since 10.7RC1
62    */
 
63    public class UpgradeTest extends AbstractTest
64    {
65    private static final String PREVIOUSFLAVOR_NAME = System.getProperty("previousFlavorName");
66   
67    private static final ExtensionId PREVIOUSFLAVOR_ID =
68    ExtensionIdConverter.toExtensionId(System.getProperty("previousFlavorId"), null);
69   
70    private static final String FLAVOR_NAME = System.getProperty("flavorName");
71   
72    private static final String FLAVOR_SUMMARY = System.getProperty("flavorSummary");
73   
74    private static final ExtensionId FLAVOR_ID =
75    ExtensionIdConverter.toExtensionId(System.getProperty("flavorId"), null);
76   
77    private static final List<ExtensionId> KNOW_VALID_FLAVORS_IDS = ExtensionIdConverter
78    .toExtensionIdList(ExtensionUtils.importPropertyStringList(System.getProperty("knowValidFlavors"), true), null);
79   
80    private static final Set<String> KNOW_VALID_FLAVORS =
81    KNOW_VALID_FLAVORS_IDS.stream().map(extensionId -> extensionId.getId()).collect(Collectors.toSet());
82   
83    private static final Set<String> KNOW_INVALID_FLAVORS =
84    new HashSet<>(ExtensionUtils.importPropertyStringList(System.getProperty("knowInvalidFlavors"), true));
85   
86    private static final String STEP_ADMIN_NAME = "Admin user";
87   
88    private static final String STEP_FLAVOR_NAME = "Flavor";
89   
90    private static final String STEP_EXTENSIONS_NAME = "Extensions";
91   
92    /**
93    * Automatically register as Admin user.
94    */
95    @Rule
96    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
97   
98    /**
99    * Prepare and start XWiki.
100    *
101    * @throws Exception when failing to configure XWiki
102    */
 
103  2 toggle @BeforeClass
104    public static void init() throws Exception
105    {
106  2 XWikiExecutor executor = new XWikiExecutor(0);
107   
108    // Initializing XWiki takes longer with the migrations
109  2 executor.setTimeoutSeconds(300);
110   
111    /////////////////////
112    // Configure
113   
114  2 PropertiesConfiguration properties = executor.loadXWikiPropertiesConfiguration();
115   
116    // Disable extension repositories to make sure it only look at local extensions
117  2 properties.setProperty("extension.repositories", "");
118   
119  2 executor.saveXWikiProperties();
120   
121    /////////////////////
122    // Init and start
123   
124  2 init(Arrays.asList(executor));
125    }
126   
127    // Test
128   
129    /**
130    * Execute the Distribution Wizard for an upgrade from previous version to current SNAPSHOT.
131    *
132    * @throws Exception when failing the test
133    */
 
134  2 toggle @Test
135    public void upgrade() throws Exception
136    {
137    // Access home page (and be automatically redirected)
138  2 getUtil().gotoPage("Main", "WebHome");
139   
140    // Make sure we are redirected to the Distribution Wizard
141  2 assertEquals(
142    getUtil().getBaseBinURL() + "distribution/XWiki/Distribution?xredirect="
143    + URLEncoder.encode("/xwiki/bin/view/Main/WebHome", StandardCharsets.UTF_8.name()),
144    getUtil().getDriver().getCurrentUrl());
145   
146    ////////////////////
147    // Validate Welcome step
148   
149  2 welcomeStep();
150   
151    ////////////////////
152    // Validate Flavor step
153   
154  2 flavorStep();
155   
156    ////////////////////
157    // Validate Flavor step
158   
159  2 extensionsStep();
160   
161    ////////////////////
162    // Validate Report step
163   
164  2 reportStep();
165   
166    // Make sure we have back on home page
167  2 ViewPage page = new ViewPage();
168   
169  2 assertEquals("xwiki:Main.WebHome", page.getMetaDataValue("reference"));
170    }
171   
 
172  2 toggle private void welcomeStep()
173    {
174  2 WelcomeDistributionStep welcomeStep = new WelcomeDistributionStep();
175   
176    // Steps
177   
178  2 List<DistributionStepIcon> icons = welcomeStep.getIcons();
179   
180  2 assertFalse(icons.get(0).isDone());
181  2 assertFalse(icons.get(0).isActive());
182  2 assertEquals(1, icons.get(0).getNumber());
183  2 assertEquals(STEP_ADMIN_NAME, icons.get(0).getName());
184  2 assertFalse(icons.get(1).isDone());
185  2 assertFalse(icons.get(1).isActive());
186  2 assertEquals(2, icons.get(1).getNumber());
187  2 assertEquals(STEP_FLAVOR_NAME, icons.get(1).getName());
188  2 assertFalse(icons.get(2).isDone());
189  2 assertFalse(icons.get(2).isActive());
190  2 assertEquals(3, icons.get(2).getNumber());
191  2 assertEquals(STEP_EXTENSIONS_NAME, icons.get(2).getName());
192   
193    // Go to next step
194  2 welcomeStep.clickCompleteStep();
195    }
196   
 
197  2 toggle private void flavorStep() throws Exception
198    {
199  2 FlavorDistributionStep flavorStep = new FlavorDistributionStep();
200   
201    // Steps
202  2 List<DistributionStepIcon> icons = flavorStep.getIcons();
203   
204  2 assertTrue(icons.get(0).isDone());
205  2 assertFalse(icons.get(0).isActive());
206  2 assertEquals(STEP_ADMIN_NAME, icons.get(0).getName());
207  2 assertEquals(2, icons.get(1).getNumber());
208  2 assertFalse(icons.get(1).isDone());
209  2 assertTrue(icons.get(1).isActive());
210  2 assertEquals(STEP_FLAVOR_NAME, icons.get(1).getName());
211  2 assertFalse(icons.get(2).isDone());
212  2 assertFalse(icons.get(2).isActive());
213  2 assertEquals(3, icons.get(2).getNumber());
214  2 assertEquals(STEP_EXTENSIONS_NAME, icons.get(2).getName());
215   
216    // Make sure complete step is disabled
217  2 assertFalse(flavorStep.isCompleteStepDisabled());
218   
219    // Check current flavor
220  2 ExtensionPane currentFlavor = flavorStep.getCurrentFlavorExtensionPane();
221  2 assertEquals(PREVIOUSFLAVOR_NAME, currentFlavor.getName());
222  2 assertEquals(PREVIOUSFLAVOR_ID.getVersion().getValue(), currentFlavor.getVersion());
223  2 assertEquals("installed-invalid", currentFlavor.getStatus());
224   
225    // Flavor upgrade
226  2 if (KNOW_VALID_FLAVORS.contains(PREVIOUSFLAVOR_ID.getId())) {
227  1 flavorStepKnownValidUpgrade(flavorStep);
228  1 } else if (KNOW_INVALID_FLAVORS.contains(PREVIOUSFLAVOR_ID.getId())) {
229  1 flavorStepKnownInvalidUpgrade(flavorStep);
230    } else {
231    // TODO
232  0 fail("Unsupported Flavor step use case");
233    }
234    }
235   
 
236  1 toggle private void flavorStepKnownValidUpgrade(FlavorDistributionStep flavorStep) throws Exception
237    {
238  1 upgrade(flavorStep.getKnownValieFlavorUpgradeExtensionPane());
239   
240    // Go to next step
241  1 flavorStep.clickCompleteStep();
242    }
243   
 
244  1 toggle private void flavorStepKnownInvalidUpgrade(FlavorDistributionStep flavorStep) throws Exception
245    {
246  1 FlavorPicker flavorPicker = flavorStep.getKnowInvalidFlavorFlavorPicker();
247   
248  1 assertFalse(flavorPicker.isInstallFlavorEnabled());
249   
250  1 List<FlavorPane> flavors = flavorPicker.getFlavors();
251   
252  1 assertEquals(1, flavors.size());
253   
254  1 FlavorPane flavor = flavors.get(0);
255   
256  1 assertEquals(FLAVOR_NAME, flavor.getName());
257  1 assertEquals(FLAVOR_ID.getVersion().getValue(), flavor.getVersion());
258  1 assertEquals(FLAVOR_SUMMARY, flavor.getSummary());
259  1 assertEquals("By XWiki Development Team", flavor.getAuthors());
260   
261    // Select the flavor
262  1 flavor.select();
263   
264    // Install the flavor
265  1 FlavorPickerInstallStep flavorInstall = flavorPicker.installSelectedFlavor();
266   
267  1 upgrade(flavorInstall.getFlavorExtensionPane());
268   
269    // Go to next step
270  1 flavorInstall.clickCompleteStep();
271    }
272   
 
273  2 toggle private void upgrade(ExtensionPane extension)
274    {
275  2 ExtensionPane upgradeFlavor = extension;
276  2 assertEquals(FLAVOR_NAME, upgradeFlavor.getName());
277  2 assertEquals(FLAVOR_ID.getVersion().getValue(), upgradeFlavor.getVersion());
278  2 assertEquals("remote-installed-invalid", upgradeFlavor.getStatus());
279   
280    // Upgrade the flavor
281  2 int timeout = getUtil().getDriver().getTimeout();
282  2 try {
283    // 10 minutes should be more than enough to calculate the install plan and do the install
284  2 getUtil().getDriver().setTimeout(600);
285   
286    // Start upgrade
287  2 upgradeFlavor = upgradeFlavor.upgrade();
288   
289    // Make sure there hasn't been any error or warning during the install plan
290  2 assertNoErrorWarningLog("Unexpected error(s) or warning(s) found in the log during flavor install plan.",
291    upgradeFlavor.openProgressSection());
292   
293    // Confirm upgrade
294  2 upgradeFlavor = upgradeFlavor.confirm();
295   
296  2 if (upgradeFlavor.getStatus().equals("loading")) {
297  2 ExtensionProgressPane extensionProgress = upgradeFlavor.openProgressSection();
298   
299  2 if (extensionProgress.getUnusedPages() != null) {
300    // Confirm delete unused pages
301  2 upgradeFlavor = upgradeFlavor.confirm();
302  0 } else if (extensionProgress.getMergeConflict() != null) {
303  0 fail("Merge conflict hit during flavor upgrade");
304    } else {
305  0 fail("The flavor upgrade is waiting");
306    }
307    }
308   
309    // Make sure there hasn't been any error or warning during the install
310  2 assertNoErrorWarningLog("Unexpected error(s) or warning(s) found in the log during flavor install.",
311    upgradeFlavor.openProgressSection());
312    } finally {
313  2 getUtil().getDriver().setTimeout(timeout);
314    }
315   
316  2 assertEquals("installed", upgradeFlavor.getStatus());
317    }
318   
 
319  4 toggle private void assertNoErrorWarningLog(String message, ExtensionProgressPane progress)
320    {
321  4 List<LogItemPane> logs = progress.getJobLog(LogLevel.WARN, LogLevel.ERROR);
322   
323  4 if (!logs.isEmpty()) {
324  0 fail("First one is [" + logs.get(0).getMessage() + "]");
325    }
326    }
327   
 
328  2 toggle private void extensionsStep()
329    {
330  2 ExtensionsDistributionStep extensionsStep = new ExtensionsDistributionStep();
331   
332    // Steps
333   
334  2 List<DistributionStepIcon> icons = extensionsStep.getIcons();
335   
336    // Make sure the extensions step is active
337  2 if (!icons.get(2).isActive()) {
338  0 return;
339    }
340   
341  2 assertTrue(icons.get(0).isDone());
342  2 assertFalse(icons.get(0).isActive());
343  2 assertEquals(STEP_ADMIN_NAME, icons.get(0).getName());
344  2 assertTrue(icons.get(1).isDone());
345  2 assertFalse(icons.get(1).isActive());
346  2 assertEquals(STEP_FLAVOR_NAME, icons.get(1).getName());
347  2 assertFalse(icons.get(2).isDone());
348  2 assertTrue(icons.get(2).isActive());
349  2 assertEquals(3, icons.get(2).getNumber());
350  2 assertEquals(STEP_EXTENSIONS_NAME, icons.get(2).getName());
351   
352    // Search for extension update
353  2 extensionsStep.checkForUpdates();
354   
355    // TODO: check some stuff
356   
357    // Go to next step
358  2 extensionsStep.clickCompleteStep();
359    }
360   
 
361  2 toggle private void reportStep()
362    {
363  2 ReportDistributionStep reportStep = new ReportDistributionStep();
364   
365    // Steps
366  2 List<DistributionStepIcon> icons = reportStep.getIcons();
367   
368  2 assertTrue(icons.get(0).isDone());
369  2 assertFalse(icons.get(0).isActive());
370  2 assertEquals(STEP_ADMIN_NAME, icons.get(0).getName());
371  2 assertTrue(icons.get(1).isDone());
372  2 assertFalse(icons.get(1).isActive());
373  2 assertEquals(STEP_FLAVOR_NAME, icons.get(1).getName());
374  2 assertTrue(icons.get(2).isDone());
375  2 assertFalse(icons.get(2).isActive());
376  2 assertEquals(STEP_EXTENSIONS_NAME, icons.get(2).getName());
377   
378    // Finish
379  2 reportStep.clickCompleteStep();
380    }
381    }