<commit_before>package com.cloudbees.plugins.credentials;

import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.domains.DomainSpecification;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import com.gargoylesoftware.htmlunit.WebResponse;
import hudson.ExtensionList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import jenkins.model.Jenkins;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class ViewCredentialsActionTest {
    @Rule
    public JenkinsRule j = new JenkinsRule();

    @Test
    public void smokes() throws Exception {
        SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(
                SystemCredentialsProvider.ProviderImpl.class);

        CredentialsStore systemStore = system.getStore(j.getInstance());

        List<Domain> domainList = new ArrayList<Domain>(systemStore.getDomains());
        domainList.remove(Domain.global());
        for (Domain d: domainList) {
            systemStore.removeDomain(d);
        }

        List<Credentials> credentialsList = new ArrayList<Credentials>(systemStore.getCredentials(Domain.global()));
        for (Credentials c: credentialsList) {
            systemStore.removeCredentials(Domain.global(), c);
        }

        JenkinsRule.WebClient wc = j.createWebClient();
        WebResponse response = wc.goTo("credentials/api/xml?depth=5", "application/xml").getWebResponse();
        assertThat(response.getContentAsString(), is("<rootActionImpl>"
                + "<stores>"
                + "<system>"
                + "<domains>"
                + "<_>"
                + "<description>"
                + "Credentials that should be available irrespective of domain specification to requirements "
                + "matching."
                + "</description>"
                + "<displayName>Global credentials (unrestricted)</displayName>"
                + "<fullDisplayName>System » Global credentials (unrestricted)</fullDisplayName>"
                + "<fullName>system/_</fullName>"
                + "<global>true</global>"
                + "<urlName>_</urlName>"
                + "</_>"
                + "</domains>"
                + "</system>"
                + "</stores>"
                + "</rootActionImpl>"));

        Random entropy = new Random();
        String domainName = "test"+entropy.nextInt();
        String domainDescription = "test description " + entropy.nextLong();
        String credentialId = "test-id-" + entropy.nextInt();
        String credentialDescription = "test-account-" + entropy.nextInt();
        String credentialUsername = "test-user-" + entropy.nextInt();
        systemStore.addDomain(new Domain(domainName, domainDescription, Collections.<DomainSpecification>emptyList()),
                new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credentialId,
                        credentialDescription, credentialUsername, "test-secret"));
        response = wc.goTo("credentials/api/xml?depth=5", "application/xml").getWebResponse();
        assertThat(response.getContentAsString(), is("<rootActionImpl>"
                + "<stores>"
                + "<system>"
                + "<domains>"
                + "<_>"
                + "<description>"
                + "Credentials that should be available irrespective of domain specification to requirements "
                + "matching."
                + "</description>"
                + "<displayName>Global credentials (unrestricted)</displayName>"
                + "<fullDisplayName>System » Global credentials (unrestricted)</fullDisplayName>"<commit_msg>[JENKINS-37801] Use the new Matcher in ViewCredentialsActionTest<commit_after>package com.cloudbees.plugins.credentials;

import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.domains.DomainSpecification;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import com.gargoylesoftware.htmlunit.WebResponse;
import hudson.ExtensionList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static com.cloudbees.plugins.credentials.XmlMatchers.isSimilarToIgnoringPrivateAttrs;
import static org.junit.Assert.assertThat;

public class ViewCredentialsActionTest {
    @Rule
    public JenkinsRule j = new JenkinsRule();

    @Test
    public void smokes() throws Exception {
        SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(
                SystemCredentialsProvider.ProviderImpl.class);

        CredentialsStore systemStore = system.getStore(j.getInstance());

        List<Domain> domainList = new ArrayList<Domain>(systemStore.getDomains());
        domainList.remove(Domain.global());
        for (Domain d: domainList) {
            systemStore.removeDomain(d);
        }

        List<Credentials> credentialsList = new ArrayList<Credentials>(systemStore.getCredentials(Domain.global()));
        for (Credentials c: credentialsList) {
            systemStore.removeCredentials(Domain.global(), c);
        }

        JenkinsRule.WebClient wc = j.createWebClient();
        WebResponse response = wc.goTo("credentials/api/xml?depth=5", "application/xml").getWebResponse();
        assertThat(response.getContentAsString(), isSimilarToIgnoringPrivateAttrs("<rootActionImpl>"
                + "<stores>"
                + "<system>"
                + "<domains>"
                + "<_>"
                + "<description>"
                + "Credentials that should be available irrespective of domain specification to requirements "
                + "matching."
                + "</description>"
                + "<displayName>Global credentials (unrestricted)</displayName>"
                + "<fullDisplayName>System » Global credentials (unrestricted)</fullDisplayName>"
                + "<fullName>system/_</fullName>"
                + "<global>true</global>"
                + "<urlName>_</urlName>"
                + "</_>"
                + "</domains>"
                + "</system>"
                + "</stores>"
                + "</rootActionImpl>"));

        Random entropy = new Random();
        String domainName = "test"+entropy.nextInt();
        String domainDescription = "test description " + entropy.nextLong();
        String credentialId = "test-id-" + entropy.nextInt();
        String credentialDescription = "test-account-" + entropy.nextInt();
        String credentialUsername = "test-user-" + entropy.nextInt();
        systemStore.addDomain(new Domain(domainName, domainDescription, Collections.<DomainSpecification>emptyList()),
                new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credentialId,
                        credentialDescription, credentialUsername, "test-secret"));
        response = wc.goTo("credentials/api/xml?depth=5", "application/xml").getWebResponse();
        assertThat(response.getContentAsString(), isSimilarToIgnoringPrivateAttrs("<rootActionImpl>"
                + "<stores>"
                + "<system>"
                + "<domains>"
                + "<_>"
                + "<description>"
                + "Credentials that should be available irrespective of domain specification to requirements "
                + "matching."
                + "</description>"
                + "<displayName>Global credentials (unrestricted)</displayName>"
                + "<fullDisplayName>System » Global credentials (unrestricted)</fullDisplayName>"
{'fraction_non_alphanumeric': 0.11694722187064928, 'fraction_numerical': 0.0011390963169219087, 'mean_word_length': 2.6907986921999067, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '6819317', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1919, 'n_words': 365}