<commit_before>/*
 * 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.activeinstalls.test.ui;

import org.junit.*;
import org.xwiki.activeinstalls.test.po.ActiveInstallsHomePage;
import org.xwiki.panels.test.po.ApplicationsPanel;
import org.xwiki.test.ui.AbstractTest;
import org.xwiki.test.ui.SuperAdminAuthenticationRule;
import org.xwiki.test.ui.po.ViewPage;

import static org.junit.Assert.*;
import static com.github.tlrx.elasticsearch.test.EsSetup.*;

/**
 * Verify the overall Active Installs feature.
 *
 * @version $Id$
 * @since 5.2M2
 */
public class ActiveInstallsIT extends AbstractTest
{
    @Rule
    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());

    @After
    public void verify()
    {
        // TODO: Fix it
        this.validateConsole.getLogCaptureConfiguration().registerExcludes(
            "Failed to compute the first ping date and the number of elapsed days since the first ping"
        );
    }

    @Test
    public void verifyActiveInstalls() throws Exception
    {
        // Note that we verify that the ES Runner has been initialized as this allows us to more easily debug the test
        // by manually starting an XWiki instance and an ES instance prior to running this test (in this case we don't
        // provision ES).
        if (ElasticSearchRunner.esSetup != null) {
            // When XWiki was started by ElasticSearchRunner from AllITs, a page was checked to verify that the XWiki
            // instance was up. This, in turn, triggered the send of an asynchronous ping to the ES instance
            // (started prior to the XWiki start in ElasticSearchRunner).
            //
            // Since the ping may take some time to be sent to our ES instance, we wait till we have 1 index in ES or
            // till the timeout expires.
            long count = 0;
            long time = System.currentTimeMillis();
            while (count != 1 && (System.currentTimeMillis() - time) < 5000L) {
                count = ElasticSearchRunner.esSetup.countAll();
                Thread.sleep(100L);
            }
            assertEquals("AS ping wasn't sent by the XWiki instance", 1, count);

            // In order to verify backward compatibility with the previous Active Install format, we also add an index
            // in the older format.
            ElasticSearchRunner.esSetup.execute(index("installs", "install", "156231f3-705b-44c6-afe3-e191bcc4b746")
                .withSource("{ \"formatVersion\": \"1.0\", \"distributionVersion\": \"5.2\", "
                    + "\"distributionId\": \"org.xwiki.platform:xwiki-platform-web\", "
                    + "\"date\": \"2013-09-16T20:00:34.277Z\", \"extensions\": [ ] }"));
        }

        // Navigate to the ActiveInstalls app by clicking in the Application Panel.
        // This verifies that the ActiveInstalls application is registered in the Applications Panel.
        // It also verifies that the Translation is registered properly.
        ApplicationsPanel applicationPanel = ApplicationsPanel.gotoPage();
        ViewPage vp = applicationPanel.clickApplication("Active Installs");

        // Verify we're on the right page!<commit_msg>[Misc] Increase timeout to leave more time to receive the ping in case the agent is slow.<commit_after>/*
 * 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.activeinstalls.test.ui;

import org.junit.*;
import org.xwiki.activeinstalls.test.po.ActiveInstallsHomePage;
import org.xwiki.panels.test.po.ApplicationsPanel;
import org.xwiki.test.ui.AbstractTest;
import org.xwiki.test.ui.SuperAdminAuthenticationRule;
import org.xwiki.test.ui.po.ViewPage;

import static org.junit.Assert.*;
import static com.github.tlrx.elasticsearch.test.EsSetup.*;

/**
 * Verify the overall Active Installs feature.
 *
 * @version $Id$
 * @since 5.2M2
 */
public class ActiveInstallsIT extends AbstractTest
{
    @Rule
    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());

    @After
    public void verify()
    {
        // TODO: Fix it
        this.validateConsole.getLogCaptureConfiguration().registerExcludes(
            "Failed to compute the first ping date and the number of elapsed days since the first ping"
        );
    }

    @Test
    public void verifyActiveInstalls() throws Exception
    {
        // Note that we verify that the ES Runner has been initialized as this allows us to more easily debug the test
        // by manually starting an XWiki instance and an ES instance prior to running this test (in this case we don't
        // provision ES).
        if (ElasticSearchRunner.esSetup != null) {
            // When XWiki was started by ElasticSearchRunner from AllITs, a page was checked to verify that the XWiki
            // instance was up. This, in turn, triggered the send of an asynchronous ping to the ES instance
            // (started prior to the XWiki start in ElasticSearchRunner).
            //
            // Since the ping may take some time to be sent to our ES instance, we wait till we have 1 index in ES or
            // till the timeout expires.
            long count = 0;
            long time = System.currentTimeMillis();
            while (count != 1 && (System.currentTimeMillis() - time) < 30000L) {
                count = ElasticSearchRunner.esSetup.countAll();
                Thread.sleep(100L);
            }
            assertEquals("AS ping wasn't sent by the XWiki instance", 1, count);

            // In order to verify backward compatibility with the previous Active Install format, we also add an index
            // in the older format.
            ElasticSearchRunner.esSetup.execute(index("installs", "install", "156231f3-705b-44c6-afe3-e191bcc4b746")
                .withSource("{ \"formatVersion\": \"1.0\", \"distributionVersion\": \"5.2\", "
                    + "\"distributionId\": \"org.xwiki.platform:xwiki-platform-web\", "
                    + "\"date\": \"2013-09-16T20:00:34.277Z\", \"extensions\": [ ] }"));
        }

        // Navigate to the ActiveInstalls app by clicking in the Application Panel.
        // This verifies that the ActiveInstalls application is registered in the Applications Panel.
        // It also verifies that the Translation is registered properly.
        ApplicationsPanel applicationPanel = ApplicationsPanel.gotoPage();
        ViewPage vp = applicationPanel.clickApplication("Active Installs");

        // Verify we're on the right page!
{'fraction_non_alphanumeric': 0.08514514757682497, 'fraction_numerical': 0.016883274626503096, 'mean_word_length': 2.7666971637694417, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1123174', 'n_tokens_mistral': 2205, 'n_tokens_neox': 2065, 'n_words': 871}