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

File ExtensionTestUtils.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
21
6
1
133
57
9
0.43
3.5
6
1.5

Classes

Class Line # Actions
ExtensionTestUtils 39 21 0% 9 1
0.96296396.3%
 

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.extension.test;
21   
22    import java.io.InputStream;
23    import java.util.HashMap;
24    import java.util.Map;
25   
26    import org.apache.commons.httpclient.UsernamePasswordCredentials;
27    import org.apache.commons.io.IOUtils;
28    import org.openqa.selenium.By;
29    import org.xwiki.extension.ExtensionId;
30    import org.xwiki.model.reference.LocalDocumentReference;
31    import org.xwiki.test.ui.TestUtils;
32   
33    /**
34    * Utility methods for extension manager functional tests.
35    *
36    * @version $Id: b756fe4caa1d29e9345e8dc5649ce73c780fb229 $
37    * @since 4.2M1
38    */
 
39    public class ExtensionTestUtils
40    {
41    /**
42    * The key used to store an instance of this class in the context.
43    */
44    public final static String PROPERTY_KEY = "extensionUtils";
45   
46    /**
47    * The reference of the service page.
48    */
49    private static final LocalDocumentReference SERVICE_REFERENCE = new LocalDocumentReference("ExtensionTest", "Service");
50   
51    /**
52    * The generic test utility methods.
53    */
54    private final TestUtils utils;
55   
56    /**
57    * Creates a new instance.
58    *
59    * @param utils the generic test utility methods
60    */
 
61  2 toggle public ExtensionTestUtils(TestUtils utils)
62    {
63  2 this.utils = utils;
64   
65    // Create the service page if it does not exist
66  2 try (InputStream extensionTestService = this.getClass().getResourceAsStream("/extensionTestService.wiki")) {
67    // Make sure to save the service with superadmin
68  2 UsernamePasswordCredentials currentCredentials =
69    utils.setDefaultCredentials(TestUtils.SUPER_ADMIN_CREDENTIALS);
70   
71    // Save the service
72  2 utils.rest().savePage(SERVICE_REFERENCE, IOUtils.toString(extensionTestService), "");
73   
74    // Restore previous credentials
75  2 utils.setDefaultCredentials(currentCredentials);
76    } catch (Exception e) {
77  0 throw new RuntimeException("Failed to setup the service", e);
78    }
79    }
80   
81    /**
82    * Uninstalls the specified extension removing it also from the local cache.
83    *
84    * @param extensionId the id of the extension to uninstall
85    */
 
86  45 toggle public void uninstall(String extensionId)
87    {
88  45 uninstall(extensionId, false);
89    }
90   
91    /**
92    * Uninstalls the specified extension, optionally removing it from the local cache.
93    *
94    * @param extensionId the id of the extension to uninstall
95    * @param keepLocalCache whether to keep the local cached extension or not
96    */
 
97  46 toggle public void uninstall(String extensionId, boolean keepLocalCache)
98    {
99  46 Map<String, String> parameters = new HashMap<String, String>();
100  46 parameters.put("extensionId", extensionId);
101  46 parameters.put("keepLocalCache", String.valueOf(keepLocalCache));
102  46 doAction("uninstall", parameters);
103    }
104   
105    /**
106    * Installs the specified extension.
107    *
108    * @param extensionId the id of the extension to install
109    */
 
110  6 toggle public void install(ExtensionId extensionId)
111    {
112  6 Map<String, String> parameters = new HashMap<String, String>();
113  6 parameters.put("extensionId", extensionId.getId());
114  6 parameters.put("extensionVersion", extensionId.getVersion().getValue());
115  6 doAction("install", parameters);
116    }
117   
118    /**
119    * Finishes the current job if there is one and its current state is WAITING.
120    */
 
121  15 toggle public void finishCurrentJob()
122    {
123  15 doAction("finish", new HashMap<String, String>());
124    }
125   
 
126  67 toggle private void doAction(String action, Map<String, String> parameters)
127    {
128  67 parameters.put("action", action);
129  67 parameters.put("outputSyntax", "plain");
130  67 utils.gotoPage(SERVICE_REFERENCE, "get", parameters);
131  67 utils.getDriver().waitUntilElementHasTextContent(By.tagName("body"), "Done!");
132    }
133    }