<commit_before>package org.jboss.hal.testsuite.test.configuration.elytron;

import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
import static org.jboss.hal.testsuite.util.ConfigChecker.InputType.CHECKBOX;
import static org.jboss.hal.testsuite.util.ConfigChecker.InputType.TEXT;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.jboss.arquillian.graphene.page.Page;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.hal.testsuite.category.Shared;
import org.jboss.hal.testsuite.creaper.ResourceVerifier;
import org.jboss.hal.testsuite.fragment.formeditor.Editor;
import org.jboss.hal.testsuite.fragment.shared.modal.WizardWindowWithOptionalFields;
import org.jboss.hal.testsuite.page.config.elytron.DirContextPage;
import org.jboss.hal.testsuite.util.ConfigChecker;
import org.jboss.hal.testsuite.util.ElytronIntegrationChecker;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.wildfly.extras.creaper.core.online.operations.Address;
import org.wildfly.extras.creaper.core.online.operations.Values;

@RunWith(Arquillian.class)
@Category(Shared.class)
public class DirContextTestCase extends AbstractElytronTestCase {

    private static final String
        DIR_CONTEXT = "dir-context",
        DIR_CONTEXT_LABEL = "Dir Context",
        URL = "url",
        PRINCIPAL = "principal",
        CONNECTION_TIMEOUT = "connection-timeout",
        ENABLE_CONNECTION_POOLING = "enable-connection-pooling",
        CREDENTIAL_REFERENCE_LABEL = "Credential Reference",
        LDAP_URL_BEGINNING = "ldap://127.0.0.1:3",
        PRINCIPAL_BEGINNING = "uid=admin,ou=";

    @Page
    private DirContextPage page;

    /**
     * @tpTestDetails Try to create Elytron Dir Context instance in Web Console's Elytron subsystem
     * configuration.
     * Validate created resource is visible in Dir Context table.
     * Validate created resource is present in model.
     * Validate value of created resource in model.
     */
    @Test
    public void addDirContextTest() throws Exception {
        String
            dirContextName = randomAlphanumeric(5),
            urlValue = LDAP_URL_BEGINNING + randomNumeric(3),
            principalValue = PRINCIPAL_BEGINNING + randomAlphanumeric(5);
        Address dirContextAddress = elyOps.getElytronAddress(DIR_CONTEXT, dirContextName);

        page.navigateToApplication().selectResource(DIR_CONTEXT_LABEL);

        try {
            WizardWindowWithOptionalFields wizard = page.getResourceManager()
                    .addResource(WizardWindowWithOptionalFields.class);
            Editor editor = wizard.getEditor();
            editor.text(NAME, dirContextName);
            editor.text(URL, urlValue);
            wizard.openOptionalFieldsTab();
            editor.text(PRINCIPAL, principalValue);

            assertTrue("Dialog should be closed!", wizard.save());
            assertTrue("Created resource should be present in the table!",
                    page.resourceIsPresentInMainTable(dirContextName));
            new ResourceVerifier(dirContextAddress, client).verifyExists()
                    .verifyAttribute(URL, urlValue)
                    .verifyAttribute(PRINCIPAL, principalValue);
        } finally {
            ops.removeIfExists(dirContextAddress);
            adminOps.reloadIfRequired();
        }
    }

    /**
     * @tpTestDetails Create Elytron Dir Context instance in model
     * and try to remove it in Web Console's Elytron subsystem configuration.
     * Validate the resource is not any more visible in Dir Context table.
     * Validate created resource is not any more present in the model.
     */
    @Test
    public void removeDirContextTest() throws Exception {<commit_msg>Fixed DirContextTestCase<commit_after>package org.jboss.hal.testsuite.test.configuration.elytron;

import org.apache.commons.lang3.RandomStringUtils;
import org.jboss.arquillian.graphene.page.Page;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.hal.testsuite.category.Shared;
import org.jboss.hal.testsuite.creaper.ResourceVerifier;
import org.jboss.hal.testsuite.dmr.ModelNodeGenerator;
import org.jboss.hal.testsuite.fragment.formeditor.Editor;
import org.jboss.hal.testsuite.fragment.shared.modal.WizardWindowWithOptionalFields;
import org.jboss.hal.testsuite.page.config.elytron.DirContextPage;
import org.jboss.hal.testsuite.util.ConfigChecker;
import org.jboss.hal.testsuite.util.ElytronIntegrationChecker;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.wildfly.extras.creaper.core.online.operations.Address;
import org.wildfly.extras.creaper.core.online.operations.Values;

import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
import static org.jboss.hal.testsuite.util.ConfigChecker.InputType.CHECKBOX;
import static org.jboss.hal.testsuite.util.ConfigChecker.InputType.TEXT;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith(Arquillian.class)
@Category(Shared.class)
public class DirContextTestCase extends AbstractElytronTestCase {

    private static final String
        DIR_CONTEXT = "dir-context",
        DIR_CONTEXT_LABEL = "Dir Context",
        URL = "url",
        PRINCIPAL = "principal",
        CONNECTION_TIMEOUT = "connection-timeout",
        ENABLE_CONNECTION_POOLING = "enable-connection-pooling",
        CREDENTIAL_REFERENCE_LABEL = "Credential Reference",
        CREDENTIAL_REFERENCE = "credential-reference",
        CLEAR_TEXT = "clear-text",
        CREDENTIAL_REFERENCE_CLEAR_TEXT = "credential-reference-clear-text",
        LDAP_URL_BEGINNING = "ldap://127.0.0.1:3",
        PRINCIPAL_BEGINNING = "uid=admin,ou=";

    @Page
    private DirContextPage page;

    /**
     * @tpTestDetails Try to create Elytron Dir Context instance in Web Console's Elytron subsystem
     * configuration.
     * Validate created resource is visible in Dir Context table.
     * Validate created resource is present in model.
     * Validate value of created resource in model.
     */
    @Test
    public void addDirContextTest() throws Exception {
        String
            dirContextName = randomAlphanumeric(5),
            urlValue = LDAP_URL_BEGINNING + randomNumeric(3),
            principalValue = PRINCIPAL_BEGINNING + randomAlphanumeric(5),
            credentitialStoreClearTextValue = RandomStringUtils.randomAlphanumeric(7);
        Address dirContextAddress = elyOps.getElytronAddress(DIR_CONTEXT, dirContextName);

        page.navigateToApplication().selectResource(DIR_CONTEXT_LABEL);

        try {
            WizardWindowWithOptionalFields wizard = page.getResourceManager()
                    .addResource(WizardWindowWithOptionalFields.class);
            Editor editor = wizard.getEditor();
            editor.text(NAME, dirContextName);
            editor.text(URL, urlValue);
            wizard.openOptionalFieldsTab();
            editor.text(CREDENTIAL_REFERENCE_CLEAR_TEXT, credentitialStoreClearTextValue);
            editor.text(PRINCIPAL, principalValue);

            wizard.saveWithState().assertWindowClosed();
            assertTrue("Created resource should be present in the table!",
                    page.resourceIsPresentInMainTable(dirContextName));
            new ResourceVerifier(dirContextAddress, client).verifyExists()
                    .verifyAttribute(URL, urlValue)
                    .verifyAttribute(PRINCIPAL, principalValue)
                    .verifyAttribute(CREDENTIAL_REFERENCE, new ModelNodeGenerator.ModelNodePropertiesBuilder()
                        .addProperty(CLEAR_TEXT, credentitialStoreClearTextValue)
                        .build());
        } finally {
            ops.removeIfExists(dirContextAddress);
            adminOps.reloadIfRequired();
        }
    }

    /**
     * @tpTestDetails Create Elytron Dir Context instance in model
     * and try to remove it in Web Console's Elytron subsystem configuration.
     * Validate the resource is not any more visible in Dir Context table.
     * Validate created resource is not any more present in the model.
     */
    @Test
    public void removeDirContextTest() throws Exception {
{'fraction_non_alphanumeric': 0.08594396500768413, 'fraction_numerical': 0.003073649367537534, 'mean_word_length': 3.385692068429238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7325871', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2342, 'n_words': 471}