Search in sources :

Example 11 with ConfigurationContext

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

Example 12 with ConfigurationContext

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

the class DataBoundConfiguratorTest method packageParametersAreNonnullByDefault.

@Test
public void packageParametersAreNonnullByDefault() {
    Mapping config = new Mapping();
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    String expectedMessage = "string is required to configure class io.jenkins.plugins.casc.impl.configurators.nonnull.nonnullparampackage.PackageParametersAreNonnullByDefault";
    ConfiguratorException exception = assertThrows(ConfiguratorException.class, () -> registry.lookupOrFail(PackageParametersAreNonnullByDefault.class).configure(config, new ConfigurationContext(registry)));
    assertThat(exception.getMessage(), is(expectedMessage));
}
Also used : ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Mapping(io.jenkins.plugins.casc.model.Mapping) ConfiguratorException(io.jenkins.plugins.casc.ConfiguratorException) Test(org.junit.Test)

Example 13 with ConfigurationContext

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

the class DataBoundConfiguratorTest method exportYaml.

@Test
public void exportYaml() throws Exception {
    Foo foo = new Foo("foo", true, 42);
    foo.setZot("zot");
    foo.setDbl(12.34);
    // whole numbers are exported as "<number>.0"
    foo.setFlt(1f);
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final Configurator c = registry.lookupOrFail(Foo.class);
    final ConfigurationContext context = new ConfigurationContext(registry);
    final CNode node = c.describe(foo, context);
    assertNotNull(node);
    assertTrue(node instanceof Mapping);
    Mapping map = (Mapping) node;
    assertEquals(map.get("foo").toString(), "foo");
    assertEquals(map.get("bar").toString(), "true");
    assertEquals(map.get("qix").toString(), "42");
    assertEquals(map.get("zot").toString(), "zot");
    assertEquals(map.get("dbl").toString(), "12.34");
    assertEquals(map.get("flt").toString(), "1.0");
    assertEquals(Util.toYamlString(map.get("foo")).trim(), "\"foo\"");
    assertEquals(Util.toYamlString(map.get("bar")).trim(), "true");
    assertEquals(Util.toYamlString(map.get("qix")).trim(), "42");
    assertEquals(Util.toYamlString(map.get("zot")).trim(), "\"zot\"");
    assertEquals(Util.toYamlString(map.get("dbl")).trim(), "\"12.34\"");
    assertEquals(Util.toYamlString(map.get("flt")).trim(), "\"1.0\"");
    assertFalse(map.containsKey("other"));
}
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) Test(org.junit.Test)

Example 14 with ConfigurationContext

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

the class OverrideMergeStrategyTest method setUp.

@BeforeClass
public static void setUp() {
    environment.set("CASC_MERGE_STRATEGY", "override");
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    context = new ConfigurationContext(registry);
}
Also used : ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) BeforeClass(org.junit.BeforeClass)

Example 15 with ConfigurationContext

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

the class PrimitiveConfiguratorTest method setUp.

@BeforeClass
public static void setUp() {
    registry = ConfiguratorRegistry.get();
    context = new ConfigurationContext(registry);
}
Also used : ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) BeforeClass(org.junit.BeforeClass)

Aggregations

ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)25 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)24 Test (org.junit.Test)22 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 BeforeClass (org.junit.BeforeClass)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