<commit_before>package net.nemerosa.ontrack.extension.test;

import com.fasterxml.jackson.databind.JsonNode;
import net.nemerosa.ontrack.acceptance.config.AcceptanceConfig;
import net.nemerosa.ontrack.client.JsonClient;
import net.nemerosa.ontrack.client.JsonClientImpl;
import net.nemerosa.ontrack.client.OTHttpClient;
import net.nemerosa.ontrack.client.OTHttpClientBuilder;
import org.apache.commons.lang3.StringUtils;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class ExtensionAcceptance {

    private static String baseUrl;
    private static String version;

    @BeforeClass
    public static void init() throws InterruptedException, ExecutionException, TimeoutException {
        baseUrl = getEnvironment(
                "ontrack.url",
                "ONTRACK_URL",
                "http://localhost:8080"
        );
        version = getEnvironment(
                "ontrack.version",
                "ONTRACK_VERSION",
                "n/a"
        );
        System.out.println("[extension][test] Starting running acceptance tests...");
        System.out.println("[extension][test] Base URL = " + baseUrl);
        System.out.println("[extension][test] Version = " + version);
        System.out.println("[extension][test] Waiting for Ontrack to be ready...");
        AcceptanceConfig acceptanceConfig = new AcceptanceConfig();
        acceptanceConfig.setUrl(baseUrl);
        acceptanceConfig.check();
    }

    private static String getEnvironment(String systemProperty, String environmentVariable, String defaultValue) {
        String env = System.getenv(environmentVariable);
        String sys = System.getProperty(systemProperty);
        if (StringUtils.isNotBlank(sys)) {
            return sys;
        } else if (StringUtils.isNotBlank(env)) {
            return env;
        } else {
            return defaultValue;
        }
    }

    @Test
    public void information_is_accessible() {
        JsonClient client = getJsonClient();
        JsonNode info = client.get("info");
        String displayVersion = info.path("version").path("display").asText();
        assertTrue(StringUtils.isNotBlank(displayVersion));
    }

    @Test
    public void version_check() {
        JsonClient client = getJsonClient();
        JsonNode info = client.get("info");
        String displayVersion = info.path("version").path("display").asText();
        assertEquals(version, displayVersion);
    }

    private JsonClient getJsonClient() {
        OTHttpClient httpClient = OTHttpClientBuilder.create(baseUrl, true)
                .withLogger(System.out::println)
                .build();
        return new JsonClientImpl(httpClient);
    }

}<commit_msg>#504 Test that the extension is loaded<commit_after>package net.nemerosa.ontrack.extension.test;

import com.fasterxml.jackson.databind.JsonNode;
import net.nemerosa.ontrack.acceptance.config.AcceptanceConfig;
import net.nemerosa.ontrack.client.JsonClient;
import net.nemerosa.ontrack.client.JsonClientImpl;
import net.nemerosa.ontrack.client.OTHttpClient;
import net.nemerosa.ontrack.client.OTHttpClientBuilder;
import org.apache.commons.lang3.StringUtils;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class ExtensionAcceptance {

    private static String baseUrl;
    private static String version;

    @BeforeClass
    public static void init() throws InterruptedException, ExecutionException, TimeoutException {
        baseUrl = getEnvironment(
                "ontrack.url",
                "ONTRACK_URL",
                "http://localhost:8080"
        );
        version = getEnvironment(
                "ontrack.version",
                "ONTRACK_VERSION",
                "n/a"
        );
        System.out.println("[extension][test] Starting running acceptance tests...");
        System.out.println("[extension][test] Base URL = " + baseUrl);
        System.out.println("[extension][test] Version = " + version);
        System.out.println("[extension][test] Waiting for Ontrack to be ready...");
        AcceptanceConfig acceptanceConfig = new AcceptanceConfig();
        acceptanceConfig.setUrl(baseUrl);
        acceptanceConfig.check();
    }

    private static String getEnvironment(String systemProperty, String environmentVariable, String defaultValue) {
        String env = System.getenv(environmentVariable);
        String sys = System.getProperty(systemProperty);
        if (StringUtils.isNotBlank(sys)) {
            return sys;
        } else if (StringUtils.isNotBlank(env)) {
            return env;
        } else {
            return defaultValue;
        }
    }

    @Test
    public void information_is_accessible() {
        JsonClient client = getJsonClient();
        JsonNode info = client.get("info");
        String displayVersion = info.path("version").path("display").asText();
        assertTrue(StringUtils.isNotBlank(displayVersion));
    }

    @Test
    public void version_check() {
        JsonClient client = getJsonClient();
        JsonNode info = client.get("info");
        String displayVersion = info.path("version").path("display").asText();
        assertEquals(version, displayVersion);
    }

    @Test
    public void extension_loaded() {
        JsonClient client = getJsonClient();
        JsonNode extensionList = client.get("extensions");
        boolean found = false;
        for (JsonNode extensionFeatureDescription : extensionList.path("extensions")) {
            if ("test".equals(extensionFeatureDescription.path("id").asText())) {
                assertEquals("Test", extensionFeatureDescription.path("name").asText());
                assertEquals("Test extension", extensionFeatureDescription.path("description").asText());
                found = true;
            }
        }
        assertTrue("Test extension must be present", found);
    }

    private JsonClient getJsonClient() {
        OTHttpClient httpClient = OTHttpClientBuilder.create(baseUrl, true)
                .withLogger(System.out::println)
                .build();
        return new JsonClientImpl(httpClient);
    }

}
{'fraction_non_alphanumeric': 0.10660055779361637, 'fraction_numerical': 0.002014254725751472, 'mean_word_length': 2.916868932038835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4503910', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1652, 'n_words': 344}