use of io.jenkins.plugins.casc.ConfigurationAsCode in project configuration-as-code-plugin by jenkinsci.
the class ExportTest method export.
public <T> String export(DataBoundConfigurator<T> configurator, T object) throws Exception {
ConfigurationAsCode casc = ConfigurationAsCode.get();
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
final CNode config = configurator.describe(object, context);
final Node valueNode = casc.toYaml(config);
try (StringWriter writer = new StringWriter()) {
ConfigurationAsCode.serializeYamlNode(valueNode, writer);
return writer.toString();
} catch (IOException e) {
throw new YAMLException(e);
}
}
use of io.jenkins.plugins.casc.ConfigurationAsCode 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"));
}
Aggregations