<commit_before><commit_msg>Adds a test to check current set of conferences in jvb. Not enabled by default.<commit_after>/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jitsi.meet.test;

import junit.framework.*;
import org.apache.http.*;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.*;
import org.apache.http.protocol.*;
import org.apache.http.util.*;
import org.json.*;

import java.net.*;
import java.util.*;

/**
 * Test that connects to JVB instance and saves a list of conferences on the
 * first run. On the second run of the test it will check whether the new list
 * has new conferences created or fail otherwise.
 * This test can be used to test whether a meet instance is alive.
 * The JVB instance can be on the same machine as meet or on a specified by
 * the property jitsi-meet.jvb.address.
 * @author <NAME>
 */
public class JVBConferencesCheck
    extends TestCase
{
    /**
     * List used to save the list of available conferences on the first run
     * of the test.
     */
    private static List<String> firstRunConferences = null;

    /**
     * Just gets the url to connect to the jvb instance and saves
     * the current allocated conferences on first run. On second compare current
     * with first run list.
     */
    public void testJVBConferences()
    {
        String jvbAddress = System.getProperty("jitsi-meet.jvb.address");

        HttpHost targetHost = null;

        if(jvbAddress == null)
        {
            String meetAddress =
                System.getProperty(ConferenceFixture.JITSI_MEET_URL_PROP);
            try
            {
                String host = new URL(meetAddress).getHost();

                targetHost = new HttpHost(host, 8080, "http");
            }
            catch(Throwable t)
            {
                t.printStackTrace();
            }
        }
        else
        {
            try
            {
                URL url = new URL(jvbAddress);
                targetHost = new HttpHost(
                    url.getHost(), url.getPort(), url.getProtocol());
            }
            catch(Throwable t)
            {
                t.printStackTrace();
            }
        }

        CloseableHttpClient httpClient = HttpClientBuilder.create().build();

        HttpGet httpget = new HttpGet("/colibri/conferences");

        CloseableHttpResponse response = null;

        ArrayList<String> conferencesList = new ArrayList<String>();
        try
        {
            response = httpClient.execute(
                targetHost, httpget, (HttpContext)null);

            HttpEntity entity = response.getEntity();
            String value = EntityUtils.toString(entity);

            JSONArray jsonArray = new JSONArray(value);
            for(int i = 0; i < jsonArray.length(); i++)
            {
                conferencesList.add(
                    (String)((JSONObject)jsonArray.get(i)).get("id"));
            }
        }
        catch(Throwable t)
        {
            t.printStackTrace();
        }
        finally
        {
            if(response != null)
            {
                try
                {
                    response.close();
                }
                catch(Throwable t){}
            }
        }

        if(firstRunConferences == null)
        {
            firstRunConferences = conferencesList;
        }
        else
        {
            conferencesList.removeAll(firstRunConferences);

            System.out.println("NEW_CONFERENCES=" + conferencesList);

            assertFalse("The list of conferences must not be empty",
                conferencesList.isEmpty());
        }
    }
}
{'fraction_non_alphanumeric': 0.09093326243020473, 'fraction_numerical': 0.0013294336612603031, 'mean_word_length': 1.7340116279069768, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3394152', 'n_tokens_mistral': 995, 'n_tokens_neox': 950, 'n_words': 285}