Search in sources :

Example 6 with Scalar

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

the class PrimitiveConfiguratorTest method _string.

@Test
public void _string() throws Exception {
    Configurator c = registry.lookupOrFail(String.class);
    final Object value = c.configure(new Scalar("abc"), context);
    assertEquals("abc", value);
}
Also used : Configurator(io.jenkins.plugins.casc.Configurator) Scalar(io.jenkins.plugins.casc.model.Scalar) Test(org.junit.Test)

Example 7 with Scalar

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

the class PrimitiveConfiguratorTest method _boolean.

@Test
public void _boolean() throws Exception {
    Configurator c = registry.lookupOrFail(boolean.class);
    final Object value = c.configure(new Scalar("true"), context);
    assertTrue((Boolean) value);
}
Also used : Configurator(io.jenkins.plugins.casc.Configurator) Scalar(io.jenkins.plugins.casc.model.Scalar) Test(org.junit.Test)

Example 8 with Scalar

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

the class PrimitiveConfiguratorTest method _enum2.

@Test
public void _enum2() throws Exception {
    // No explicit converter set by jenkins
    Configurator<TimeUnit> c = registry.lookupOrFail(TimeUnit.class);
    final TimeUnit value = c.configure(new Scalar("DAYS"), context);
    assertEquals(TimeUnit.DAYS, value);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Scalar(io.jenkins.plugins.casc.model.Scalar) Test(org.junit.Test)

Example 9 with Scalar

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

the class PrimitiveConfiguratorTest method _int_env_default.

@Test
public void _int_env_default() throws Exception {
    Configurator c = registry.lookupOrFail(Integer.class);
    final Object value = c.configure(new Scalar("${ENV_FOR_TEST:-123}"), context);
    assertEquals(123, value);
}
Also used : Configurator(io.jenkins.plugins.casc.Configurator) Scalar(io.jenkins.plugins.casc.model.Scalar) Test(org.junit.Test)

Example 10 with Scalar

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

Scalar (io.jenkins.plugins.casc.model.Scalar)15 Test (org.junit.Test)11 Configurator (io.jenkins.plugins.casc.Configurator)8 Sequence (io.jenkins.plugins.casc.model.Sequence)4 Mapping (io.jenkins.plugins.casc.model.Mapping)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CheckForNull (edu.umd.cs.findbugs.annotations.CheckForNull)1 Node (hudson.model.Node)1 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)1 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)1 CNode (io.jenkins.plugins.casc.model.CNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 AbstractMapDecorator (org.apache.commons.collections.map.AbstractMapDecorator)1 Restricted (org.kohsuke.accmod.Restricted)1 DumperOptions (org.yaml.snakeyaml.DumperOptions)1 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)1 Node (org.yaml.snakeyaml.nodes.Node)1