Search in sources :

Example 26 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class ProxyConfiguratorTest method describeProxyConfig.

@Test
@ConfiguredWithCode("Proxy.yml")
public void describeProxyConfig() throws Exception {
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    final CNode configNode = getProxyNode(context);
    Secret password = requireNonNull(Secret.decrypt(getProxyNode(context).getScalarValue("secretPassword")));
    final String yamlConfig = Util.toYamlString(configNode);
    assertEquals(String.join("\n", "name: \"proxyhost\"", "noProxyHost: \"externalhost\"", "port: 80", "secretPassword: \"" + password.getEncryptedValue() + "\"", "testUrl: \"http://google.com\"", "userName: \"login\"", ""), yamlConfig);
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) Secret(hudson.util.Secret) ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 27 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class UpdateCenterConfiguratorTest method shouldSetUpdateCenterSites.

@Test
@ConfiguredWithCode("UpdateCenter.yml")
public void shouldSetUpdateCenterSites() throws Exception {
    UpdateCenter updateCenter = j.jenkins.getUpdateCenter();
    List<UpdateSite> sites = updateCenter.getSites();
    assertEquals(2, sites.size());
    UpdateSite siteOne = sites.get(0);
    assertEquals("default", siteOne.getId());
    assertEquals("https://updates.jenkins.io/update-center.json", siteOne.getUrl());
    UpdateSite siteTwo = sites.get(1);
    assertEquals("experimental", siteTwo.getId());
    assertEquals("https://updates.jenkins.io/experimental/update-center.json", siteTwo.getUrl());
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    final Configurator c = context.lookupOrFail(UpdateCenter.class);
    final CNode node = c.describe(updateCenter, context);
    assertNotNull(node);
    Mapping site1 = node.asMapping().get("sites").asSequence().get(1).asMapping();
    assertEquals("experimental", site1.getScalarValue("id"));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) UpdateCenter(hudson.model.UpdateCenter) Configurator(io.jenkins.plugins.casc.Configurator) Mapping(io.jenkins.plugins.casc.model.Mapping) UpdateSite(hudson.model.UpdateSite) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 28 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class JenkinsConfiguratorCloudSupportTest method should_export_only_static_nodes.

@Test
@ConfiguredWithCode("JenkinsConfiguratorCloudSupportTest.yml")
public void should_export_only_static_nodes() throws Exception {
    j.jenkins.addNode(new Cloud1PretendSlave());
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    final CNode configNode = getJenkinsRoot(context).get("nodes");
    final String yamlConfig = toYamlString(configNode);
    assertThat(yamlConfig, containsString("name: \"agent1\""));
    assertThat(yamlConfig, containsString("name: \"agent2\""));
    assertThat(yamlConfig, not(containsString("name: \"testCloud\"")));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Util.toYamlString(io.jenkins.plugins.casc.misc.Util.toYamlString) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 29 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class EssentialsTest method essentialsTest.

@Test
@ConfiguredWithCode("EssentialsTest.yml")
public void essentialsTest() {
    final Jenkins jenkins = Jenkins.get();
    assertEquals("Welcome to Jenkins Essentials!", jenkins.getSystemMessage());
    final ExtensionList<MetricsAccessKey.DescriptorImpl> metricsDescriptors = ExtensionList.lookup(MetricsAccessKey.DescriptorImpl.class);
    assertNotNull(metricsDescriptors);
    assertThat(metricsDescriptors, hasSize(1));
    MetricsAccessKey.DescriptorImpl metricsDescriptor = metricsDescriptors.get(0);
    final List<MetricsAccessKey> accessKeys = metricsDescriptor.getAccessKeys();
    assertThat(accessKeys, hasSize(1));
    MetricsAccessKey accessKey = accessKeys.get(0);
    assertThat(accessKey.getKey(), is("evergreen"));
    assertThat(accessKey.getDescription(), is("Key for evergreen health-check"));
    assertThat(accessKey.isCanHealthCheck(), is(true));
    assertThat(accessKey.isCanPing(), is(false));
    assertThat(accessKey.isCanPing(), is(false));
    assertThat(accessKey.isCanThreadDump(), is(false));
    assertThat(accessKey.isCanMetrics(), is(false));
    assertThat(accessKey.getOrigins(), is("*"));
// metricsDescriptor.g
}
Also used : Jenkins(jenkins.model.Jenkins) MetricsAccessKey(jenkins.metrics.api.MetricsAccessKey) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 30 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class GitTest method checkAssemblaWebIsLoaded.

@Test
@Issue("JENKINS-57604")
@ConfiguredWithCode("GitTest.yml")
public void checkAssemblaWebIsLoaded() {
    final Jenkins jenkins = Jenkins.get();
    final GlobalLibraries libs = jenkins.getExtensionList(GlobalConfiguration.class).get(GlobalLibraries.class);
    LibraryConfiguration lib = libs.getLibraries().get(0);
    SCMRetriever retriever = (SCMRetriever) lib.getRetriever();
    GitSCM scm = (GitSCM) retriever.getScm();
    AssemblaWeb browser = (AssemblaWeb) scm.getBrowser();
    assertEquals("assembla.acmecorp.com", browser.getRepoUrl());
}
Also used : Jenkins(jenkins.model.Jenkins) GlobalConfiguration(jenkins.model.GlobalConfiguration) AssemblaWeb(hudson.plugins.git.browser.AssemblaWeb) GlobalLibraries(org.jenkinsci.plugins.workflow.libs.GlobalLibraries) SCMRetriever(org.jenkinsci.plugins.workflow.libs.SCMRetriever) LibraryConfiguration(org.jenkinsci.plugins.workflow.libs.LibraryConfiguration) GitSCM(hudson.plugins.git.GitSCM) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Aggregations

ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)52 Test (org.junit.Test)51 Issue (org.jvnet.hudson.test.Issue)18 CNode (io.jenkins.plugins.casc.model.CNode)16 Jenkins (jenkins.model.Jenkins)15 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)8 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)8 Util.toYamlString (io.jenkins.plugins.casc.misc.Util.toYamlString)8 Mapping (io.jenkins.plugins.casc.model.Mapping)7 BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)5 Configurator (io.jenkins.plugins.casc.Configurator)5 ProxyConfiguration (hudson.ProxyConfiguration)4 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)3 UsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials)3 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)3 CredentialsRootConfigurator (com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator)2 Role (com.michelin.cio.hudson.plugins.rolestrategy.Role)2 RoleBasedAuthorizationStrategy (com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy)2 FreeStyleProject (hudson.model.FreeStyleProject)2 User (hudson.model.User)2