use of io.jenkins.plugins.casc.ConfiguratorRegistry 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"));
}
use of io.jenkins.plugins.casc.ConfiguratorRegistry 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));
}
use of io.jenkins.plugins.casc.ConfiguratorRegistry 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"));
}
use of io.jenkins.plugins.casc.ConfiguratorRegistry 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);
}
use of io.jenkins.plugins.casc.ConfiguratorRegistry in project configuration-as-code-plugin by jenkinsci.
the class ProxyConfiguratorTest method shouldSetProxyWithMinimumFields.
@Test
@ConfiguredWithCode("ProxyMinimal.yml")
public void shouldSetProxyWithMinimumFields() throws Exception {
ProxyConfiguration proxy = j.jenkins.proxy;
assertEquals(proxy.name, "proxyhost");
assertEquals(proxy.port, 80);
assertNull(proxy.getUserName());
assertNull(proxy.getTestUrl());
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
final Configurator c = context.lookupOrFail(ProxyConfiguration.class);
final CNode node = c.describe(proxy, context);
assertNotNull(node);
Mapping mapping = node.asMapping();
assertEquals(2, node.asMapping().size());
assertEquals("proxyhost", mapping.getScalarValue("name"));
assertEquals("80", mapping.getScalarValue("port"));
}
Aggregations