use of io.jenkins.plugins.casc.Configurator 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"));
}
use of io.jenkins.plugins.casc.Configurator 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\"");
}
use of io.jenkins.plugins.casc.Configurator 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.Configurator in project configuration-as-code-plugin by jenkinsci.
the class MavenConfigurator method describe.
@NonNull
@Override
public Set<Attribute<GlobalMavenConfig, ?>> describe() {
final Set<Attribute<GlobalMavenConfig, ?>> attributes = super.describe();
final Descriptor descriptor = Jenkins.get().getDescriptorOrDie(Maven.class);
final Configurator<Descriptor> task = new DescriptorConfigurator(descriptor);
for (Attribute attribute : task.describe()) {
attributes.add(new Attribute<GlobalMavenConfig, Object>(attribute.getName(), attribute.getType()).multiple(attribute.isMultiple()).getter(g -> attribute.getValue(descriptor)).setter((g, v) -> attribute.setValue(descriptor, v)));
}
return attributes;
}
use of io.jenkins.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.
the class PrimitiveConfiguratorTest method _Integer.
@Test
public void _Integer() throws Exception {
Configurator c = registry.lookupOrFail(Integer.class);
final Object value = c.configure(new Scalar("123"), context);
assertEquals(123, (int) value);
}
Aggregations