Search in sources :

Example 11 with Mapping

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

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

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

use of io.jenkins.plugins.casc.model.Mapping 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)

Example 15 with Mapping

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

the class DataBoundConfiguratorTest method configureWithSets.

@Test
public void configureWithSets() throws Exception {
    Mapping config = new Mapping();
    Sequence sequence = new Sequence();
    sequence.add(new Scalar("bar"));
    sequence.add(new Scalar("foo"));
    config.put("strings", sequence);
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final Bar configured = (Bar) registry.lookupOrFail(Bar.class).configure(config, new ConfigurationContext(registry));
    Set<String> strings = configured.getStrings();
    assertTrue(strings.contains("foo"));
    assertTrue(strings.contains("bar"));
    assertFalse(strings.contains("baz"));
}
Also used : ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Mapping(io.jenkins.plugins.casc.model.Mapping) Sequence(io.jenkins.plugins.casc.model.Sequence) Scalar(io.jenkins.plugins.casc.model.Scalar) Test(org.junit.Test)

Aggregations

Mapping (io.jenkins.plugins.casc.model.Mapping)29 Test (org.junit.Test)21 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)19 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)19 CNode (io.jenkins.plugins.casc.model.CNode)12 Configurator (io.jenkins.plugins.casc.Configurator)8 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)7 Issue (org.jvnet.hudson.test.Issue)5 Scalar (io.jenkins.plugins.casc.model.Scalar)3 Sequence (io.jenkins.plugins.casc.model.Sequence)3 CredentialsRootConfigurator (com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator)2 CheckForNull (edu.umd.cs.findbugs.annotations.CheckForNull)2 ProxyConfiguration (hudson.ProxyConfiguration)2 ConfiguratorException (io.jenkins.plugins.casc.ConfiguratorException)2 HashSet (java.util.HashSet)2 Jenkins (jenkins.model.Jenkins)2 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)2 MasterKillSwitchConfiguration (jenkins.security.s2m.MasterKillSwitchConfiguration)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 BulkChange (hudson.BulkChange)1