use of io.jenkins.plugins.casc.ConfigurationContext in project configuration-as-code-plugin by jenkinsci.
the class DataBoundConfiguratorTest method export_mapping_should_not_be_null.
@Test
@Issue("PR #838, Issue #222")
public void export_mapping_should_not_be_null() throws Exception {
j.createFreeStyleProject("testJob1");
ConfigurationAsCode casc = ConfigurationAsCode.get();
casc.configure(this.getClass().getResource("DataBoundDescriptorNonNull.yml").toString());
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
final Mapping configNode = getJenkinsRoot(context);
final CNode viewsNode = configNode.get("views");
Mapping listView = viewsNode.asSequence().get(1).asMapping().get("list").asMapping();
Mapping otherListView = viewsNode.asSequence().get(2).asMapping().get("list").asMapping();
Sequence listViewColumns = listView.get("columns").asSequence();
Sequence otherListViewColumns = otherListView.get("columns").asSequence();
assertNotNull(listViewColumns);
assertEquals(6, listViewColumns.size());
assertNotNull(otherListViewColumns);
assertEquals(7, otherListViewColumns.size());
assertEquals("loggedInUsersCanDoAnything", configNode.getScalarValue("authorizationStrategy"));
assertEquals("plainText", configNode.getScalarValue("markupFormatter"));
}
use of io.jenkins.plugins.casc.ConfigurationContext 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=}]");
}
use of io.jenkins.plugins.casc.ConfigurationContext 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());
}
use of io.jenkins.plugins.casc.ConfigurationContext 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());
}
use of io.jenkins.plugins.casc.ConfigurationContext 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));
}
Aggregations