Search in sources :

Example 6 with ConfiguratorRegistry

use of io.jenkins.plugins.casc.ConfiguratorRegistry 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 7 with ConfiguratorRegistry

use of io.jenkins.plugins.casc.ConfiguratorRegistry 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 8 with ConfiguratorRegistry

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

the class DataBoundConfiguratorTest method exportWithSets.

@Test
@SuppressWarnings("unchecked")
public void exportWithSets() throws Exception {
    HashSet<String> set = new HashSet<>();
    set.add("foo");
    Bar bar = new Bar(set);
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final Configurator c = registry.lookupOrFail(Bar.class);
    final ConfigurationContext context = new ConfigurationContext(registry);
    CNode node = c.describe(bar, context);
    assertNotNull(node);
    assertTrue(node instanceof Mapping);
    Mapping map = (Mapping) node;
    assertEquals(map.get("strings").toString(), "[foo]");
    assertEquals(Util.toYamlString(map.get("strings")).trim(), "- \"foo\"");
    assertFalse(map.containsKey("other"));
    // now with two elements
    set.add("bar");
    node = c.describe(bar, context);
    assertNotNull(node);
    assertTrue(node instanceof Mapping);
    map = (Mapping) node;
    assertEquals(map.get("strings").toString(), "[bar, foo]");
    assertEquals(Util.toYamlString(map.get("strings")).trim(), "- \"bar\"\n- \"foo\"");
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Configurator(io.jenkins.plugins.casc.Configurator) Mapping(io.jenkins.plugins.casc.model.Mapping) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with ConfiguratorRegistry

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

the class DataBoundConfiguratorTest method shouldNotLogSecrets.

@Test
public void shouldNotLogSecrets() throws Exception {
    Mapping config = new Mapping();
    config.put("secret", "mySecretValue");
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    registry.lookupOrFail(SecretHolder.class).configure(config, new ConfigurationContext(registry));
    assertLogContains(logging, "secret");
    assertNotInLog(logging, "mySecretValue");
}
Also used : ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Mapping(io.jenkins.plugins.casc.model.Mapping) Test(org.junit.Test)

Example 10 with ConfiguratorRegistry

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

the class DataBoundConfiguratorTest method nonnullConstructorParameter.

@Test
public void nonnullConstructorParameter() throws Exception {
    Mapping config = new Mapping();
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final NonnullParameterConstructor configured = (NonnullParameterConstructor) registry.lookupOrFail(NonnullParameterConstructor.class).configure(config, new ConfigurationContext(registry));
    assertEquals(0, configured.getStrings().size());
}
Also used : ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) NonnullParameterConstructor(io.jenkins.plugins.casc.impl.configurators.nonnull.NonnullParameterConstructor) Mapping(io.jenkins.plugins.casc.model.Mapping) Test(org.junit.Test)

Aggregations

ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)25 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)24 Test (org.junit.Test)23 Mapping (io.jenkins.plugins.casc.model.Mapping)19 CNode (io.jenkins.plugins.casc.model.CNode)13 Configurator (io.jenkins.plugins.casc.Configurator)8 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)8 Issue (org.jvnet.hudson.test.Issue)5 ProxyConfiguration (hudson.ProxyConfiguration)2 ConfigurationAsCode (io.jenkins.plugins.casc.ConfigurationAsCode)2 ConfiguratorException (io.jenkins.plugins.casc.ConfiguratorException)2 Sequence (io.jenkins.plugins.casc.model.Sequence)2 Jenkins (jenkins.model.Jenkins)2 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)2 MasterKillSwitchConfiguration (jenkins.security.s2m.MasterKillSwitchConfiguration)2 UpdateCenter (hudson.model.UpdateCenter)1 UpdateSite (hudson.model.UpdateSite)1 Secret (hudson.util.Secret)1 ClassParametersAreNonnullByDefault (io.jenkins.plugins.casc.impl.configurators.nonnull.ClassParametersAreNonnullByDefault)1 NonnullParameterConstructor (io.jenkins.plugins.casc.impl.configurators.nonnull.NonnullParameterConstructor)1