Search in sources :

Example 1 with ConfigurationAsCode

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);
    }
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) StringWriter(java.io.StringWriter) CNode(io.jenkins.plugins.casc.model.CNode) Node(org.yaml.snakeyaml.nodes.Node) ConfigurationAsCode(io.jenkins.plugins.casc.ConfigurationAsCode) YAMLException(org.yaml.snakeyaml.error.YAMLException) IOException(java.io.IOException)

Example 2 with ConfigurationAsCode

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"));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) ConfigurationAsCode(io.jenkins.plugins.casc.ConfigurationAsCode) Mapping(io.jenkins.plugins.casc.model.Mapping) Sequence(io.jenkins.plugins.casc.model.Sequence) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

ConfigurationAsCode (io.jenkins.plugins.casc.ConfigurationAsCode)2 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)2 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)2 CNode (io.jenkins.plugins.casc.model.CNode)2 Mapping (io.jenkins.plugins.casc.model.Mapping)1 Sequence (io.jenkins.plugins.casc.model.Sequence)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Test (org.junit.Test)1 Issue (org.jvnet.hudson.test.Issue)1 YAMLException (org.yaml.snakeyaml.error.YAMLException)1 Node (org.yaml.snakeyaml.nodes.Node)1