Search in sources :

Example 21 with ConfiguratorRegistry

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

the class DataBoundConfiguratorTest method shouldExportArray.

@Test
public void shouldExportArray() throws Exception {
    ArrayConstructor obj = new ArrayConstructor(new Foo[] { new Foo("", false, 0) });
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final Configurator c = registry.lookupOrFail(ArrayConstructor.class);
    final ConfigurationContext context = new ConfigurationContext(registry);
    CNode node = c.describe(obj, context);
    assertNotNull(node);
    assertTrue(node instanceof Mapping);
    Mapping map = (Mapping) node;
    assertEquals(map.get("anArray").toString(), "[{qix=0, bar=false, 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) Test(org.junit.Test)

Example 22 with ConfiguratorRegistry

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

the class DataBoundConfiguratorTest method configureWithEmptySet.

@Test
public void configureWithEmptySet() throws Exception {
    Mapping config = new Mapping();
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final Bar configured = (Bar) registry.lookupOrFail(Bar.class).configure(config, new ConfigurationContext(registry));
    Set<String> strings = configured.getStrings();
    assertEquals(0, strings.size());
}
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 23 with ConfiguratorRegistry

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

the class DataBoundConfiguratorTest method classParametersAreNonnullByDefault.

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

Example 24 with ConfiguratorRegistry

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

the class DataBoundConfiguratorTest method configure_databound.

@Test
public void configure_databound() throws Exception {
    Mapping config = new Mapping();
    config.put("foo", "foo");
    config.put("bar", "true");
    config.put("qix", "123");
    config.put("zot", "DataBoundSetter");
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final Foo configured = (Foo) registry.lookupOrFail(Foo.class).configure(config, new ConfigurationContext(registry));
    assertEquals("foo", configured.foo);
    assertTrue(configured.bar);
    assertEquals(123, configured.qix);
    assertEquals("DataBoundSetter", configured.zot);
    assertThat(configured.initialized, is(true));
}
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 25 with ConfiguratorRegistry

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

the class DuplicateKeyDescribableConfiguratorTest method implementors_shouldNotThrowException.

@Test
public void implementors_shouldNotThrowException() {
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    HeteroDescribableConfigurator configurator = Objects.requireNonNull((HeteroDescribableConfigurator) registry.lookup(FooBar.class));
    assertThat(configurator.getImplementors().size(), equalTo(1));
}
Also used : ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) 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