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

File ActiveInstallsTest.java

 

Code metrics

4
52
1
1
181
100
4
0.08
52
1
4

Classes

Class Line # Actions
ActiveInstallsTest 38 52 0% 4 1
0.9824561598.2%
 

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.activeinstalls.test.ui;
21   
22    import org.junit.*;
23    import org.xwiki.activeinstalls.test.po.ActiveInstallsHomePage;
24    import org.xwiki.panels.test.po.ApplicationsPanel;
25    import org.xwiki.test.ui.AbstractTest;
26    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
27    import org.xwiki.test.ui.po.ViewPage;
28   
29    import static org.junit.Assert.*;
30    import static com.github.tlrx.elasticsearch.test.EsSetup.*;
31   
32    /**
33    * Verify the overall Active Installs feature.
34    *
35    * @version $Id: 0edb1943d93ce8c75c1e45601f0a6545f8464ca1 $
36    * @since 5.2M2
37    */
 
38    public class ActiveInstallsTest extends AbstractTest
39    {
40    @Rule
41    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
42   
 
43  1 toggle @Test
44    public void verifyActiveInstalls() throws Exception
45    {
46    // Note that we verify that the ES Runner has been initialized as this allows us to more easily debug the test
47    // by manually starting an XWiki instance and an ES instance prior to running this test (in this case we don't
48    // provision ES).
49  1 if (ElasticSearchRunner.esSetup != null) {
50    // When XWiki was started by ElasticSearchRunner from AllTests, a page was checked to verify that the XWiki
51    // instance was up. This, in turn, triggered the send of an asynchronous ping to the ES instance
52    // (started prior to the XWiki start in ElasticSearchRunner).
53    //
54    // Since the ping may take some time to be sent to our ES instance, we wait till we have 1 index in ES or
55    // till the timeout expires.
56  1 long count = 0;
57  1 long time = System.currentTimeMillis();
58  2 while (count != 1 && (System.currentTimeMillis() - time) < 5000L) {
59  1 count = ElasticSearchRunner.esSetup.countAll();
60  1 Thread.sleep(100L);
61    }
62   
63    // In order to verify backward compatibility with the previous Active Install format, we also add an index
64    // in the older format.
65  1 ElasticSearchRunner.esSetup.execute(index("installs", "install", "156231f3-705b-44c6-afe3-e191bcc4b746")
66    .withSource("{ \"formatVersion\": \"1.0\", \"distributionVersion\": \"5.2\", "
67    + "\"distributionId\": \"org.xwiki.platform:xwiki-platform-web\", "
68    + "\"date\": \"2013-09-16T20:00:34.277Z\", \"extensions\": [ ] }"));
69    }
70   
71    // Navigate to the ActiveInstalls app by clicking in the Application Panel.
72    // This verifies that the ActiveInstalls application is registered in the Applications Panel.
73    // It also verifies that the Translation is registered properly.
74  1 ApplicationsPanel applicationPanel = ApplicationsPanel.gotoPage();
75  1 ViewPage vp = applicationPanel.clickApplication("Active Installs");
76   
77    // Verify we're on the right page!
78  1 Assert.assertEquals(ActiveInstallsHomePage.getSpace(), vp.getMetaDataValue("space"));
79  1 Assert.assertEquals(ActiveInstallsHomePage.getPage(), vp.getMetaDataValue("page"));
80   
81    // Configure the Active Installs feature to count "org.xwiki.*" distribution ids.
82  1 getUtil().updateObject("ActiveInstalls", "ActiveInstallsConfig", "ActiveInstalls.ActiveInstallsConfig", 0,
83    "distributionId", "org.xwiki.*");
84   
85    // By default we don't show SNAPSHOTs, verify that!
86   
87    // The default query doesn't show SNAPSHOT versions and thus we expect 0
88  1 getUtil().gotoPage("ActiveInstalls", "ActiveCounterValue2");
89  1 vp = new ViewPage();
90  1 assertEquals("0", vp.getContent());
91   
92    // The default query doesn't show SNAPSHOT versions and thus we expect 0
93  1 getUtil().gotoPage("ActiveInstalls", "TotalCounterValue2");
94  1 vp = new ViewPage();
95  1 assertEquals("0", vp.getContent());
96   
97    // Configure the Active Installs feature to count SNAPSHOTs and to count
98    // "org.xwiki.platform:xwiki-platform-web" distribution ids.
99  1 getUtil().updateObject("ActiveInstalls", "ActiveInstallsConfig", "ActiveInstalls.ActiveInstallsConfig", 0,
100    "snapshots", true);
101   
102    // Navigate to the Active Installs Counter Value page to verify that the ping has been received
103  1 getUtil().gotoPage("ActiveInstalls", "ActiveCounterValue2");
104  1 vp = new ViewPage();
105  1 assertEquals("1", vp.getContent());
106   
107    // Also verify the Active Installs Counter for the old format
108  1 getUtil().gotoPage("ActiveInstalls", "ActiveCounterValue1");
109  1 vp = new ViewPage();
110  1 assertEquals("0", vp.getContent());
111   
112    // Navigate to the Total Installs Counter Value page to verify that the ping has been received
113  1 getUtil().gotoPage("ActiveInstalls", "TotalCounterValue2");
114  1 vp = new ViewPage();
115  1 assertEquals("1", vp.getContent());
116   
117    // Also verify the Total Installs Counter for the old format
118  1 getUtil().gotoPage("ActiveInstalls", "TotalCounterValue1");
119  1 vp = new ViewPage();
120  1 assertEquals("1", vp.getContent());
121   
122    // Verify JavaVersion data
123  1 getUtil().gotoPage("ActiveInstalls", "JavaVersionsData");
124  1 vp = new ViewPage();
125  1 assertTrue("Got [" + vp.getContent() + "]",
126    vp.getContent().matches("Java Version Active Installs Count\\r?\\n1\\.[0-9_\\.]* 1"));
127   
128    // Verify Databases data
129  1 getUtil().gotoPage("ActiveInstalls", "DatabasesData");
130  1 vp = new ViewPage();
131  1 assertTrue("Got [" + vp.getContent() + "]",
132    vp.getContent().matches("Database Active Installs Count\\r?\\nHSQL Database Engine 1"));
133   
134    // Verify Distribution data
135  1 getUtil().gotoPage("ActiveInstalls", "DistributionData");
136  1 vp = new ViewPage();
137  1 assertTrue("Got [" + vp.getContent() + "]",
138    vp.getContent().matches("Distributions Active Installs Count\\r?\\n"
139    + "org.xwiki.platform:xwiki-platform-web 1"));
140   
141    // Verify top 10 XWiki versions data
142  1 getUtil().gotoPage("ActiveInstalls", "XWikiVersionsData");
143  1 vp = new ViewPage();
144  1 assertTrue("Got [" + vp.getContent() + "]",
145    vp.getContent().matches("XWiki Version Active Installs Count\\r?\\n[0-9]\\.[0-9].* 1"));
146   
147    // Verify XWiki Cycle versions data
148  1 getUtil().gotoPage("ActiveInstalls", "XWikiVersionsCycleData");
149  1 vp = new ViewPage();
150  1 assertTrue("Got [" + vp.getContent() + "]",
151    vp.getContent().matches("XWiki Version Active Installs Count\\r?\\n[0-9]+\\.x 1"));
152   
153    // Verify ServletContainers data
154  1 getUtil().gotoPage("ActiveInstalls", "ServletContainersData");
155  1 vp = new ViewPage();
156  1 assertTrue("Got [" + vp.getContent() + "]",
157    vp.getContent().matches("Servlet Container Active Installs Count\\r?\\njetty 1"));
158   
159    // Verify Extension Count
160    // Create a page calling the Extension Count macro
161  1 String content = "{{include reference=\"ActiveInstalls.ExtensionCount\"/}}\n"
162    + "\n"
163    + "{{velocity}}\n"
164    + "#set ($extensionIds = [\n"
165    + " 'org.xwiki.contrib:xwiki-totem-application',\n"
166    + " 'jsimard:event-reporter-application',\n"
167    + " 'mouhb:likeapplication'\n"
168    + "])\n"
169    + "|=Extension Id|=Count\n"
170    + "#foreach($extensionId in $extensionIds)\n"
171    + " #countActiveInstallsUsingExtension($extensionId $count)\n"
172    + " |$extensionId|$count\n"
173    + "#end\n"
174    + "{{/velocity}}";
175  1 vp = getUtil().createPage(getTestClassName(), "ExtensionCountExample", content, "Example");
176  1 assertTrue("Got [" + vp.getContent() + "]", vp.getContent().matches("Extension Id Count\n"
177    + "org.xwiki.contrib:xwiki-totem-application 0\n"
178    + "jsimard:event-reporter-application 0\n"
179    + "mouhb:likeapplication 0"));
180    }
181    }