Search in sources :

Example 21 with Mapping

use of io.jenkins.plugins.casc.model.Mapping 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"));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) ProxyConfiguration(hudson.ProxyConfiguration) Configurator(io.jenkins.plugins.casc.Configurator) Mapping(io.jenkins.plugins.casc.model.Mapping) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 22 with Mapping

use of io.jenkins.plugins.casc.model.Mapping in project configuration-as-code-plugin by jenkinsci.

the class DataBoundConfiguratorTest method packageParametersAreNonnullByDefaultButCanBeNullable.

@Test
@Issue("#1025")
public void packageParametersAreNonnullByDefaultButCanBeNullable() throws Exception {
    Mapping config = new Mapping();
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final PackageParametersNonNullCheckForNull configured = (PackageParametersNonNullCheckForNull) registry.lookupOrFail(PackageParametersNonNullCheckForNull.class).configure(config, new ConfigurationContext(registry));
    assertNull(configured.getSecret());
}
Also used : ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Mapping(io.jenkins.plugins.casc.model.Mapping) PackageParametersNonNullCheckForNull(io.jenkins.plugins.casc.impl.configurators.nonnull.nonnullparampackage.PackageParametersNonNullCheckForNull) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 23 with Mapping

use of io.jenkins.plugins.casc.model.Mapping in project configuration-as-code-plugin by jenkinsci.

the class DataBoundConfiguratorTest method shouldThrowConfiguratorException.

@Test
public void shouldThrowConfiguratorException() {
    Mapping config = new Mapping();
    config.put("foo", "foo");
    config.put("bar", "abcd");
    config.put("qix", "99");
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    try {
        registry.lookupOrFail(Foo.class).configure(config, new ConfigurationContext(registry));
        fail("above action is excepted to throw ConfiguratorException!");
    } catch (ConfiguratorException e) {
        assertThat(e.getMessage(), is("foo: Failed to construct instance of class io.jenkins.plugins.casc.impl.configurators.DataBoundConfiguratorTest$Foo.\n" + " Constructor: public io.jenkins.plugins.casc.impl.configurators.DataBoundConfiguratorTest$Foo(java.lang.String,boolean,int).\n" + " Arguments: [java.lang.String, java.lang.Boolean, java.lang.Integer].\n" + " Expected Parameters: foo java.lang.String, bar boolean, qix int"));
    }
}
Also used : ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Mapping(io.jenkins.plugins.casc.model.Mapping) ConfiguratorException(io.jenkins.plugins.casc.ConfiguratorException) Test(org.junit.Test)

Example 24 with Mapping

use of io.jenkins.plugins.casc.model.Mapping in project configuration-as-code-plugin by jenkinsci.

the class DataBoundConfiguratorTest method shouldNotLogSecretsForUndefinedConstructors.

@Test
@Issue("SECURITY-1497")
public void shouldNotLogSecretsForUndefinedConstructors() throws Exception {
    Mapping config = new Mapping();
    config.put("secret", "mySecretValue");
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    registry.lookupOrFail(SecretHolderWithString.class).configure(config, new ConfigurationContext(registry));
    assertLogContains(logging, "secret");
    assertNotInLog(logging, "mySecretValue");
}
Also used : ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Mapping(io.jenkins.plugins.casc.model.Mapping) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 25 with Mapping

use of io.jenkins.plugins.casc.model.Mapping 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

Mapping (io.jenkins.plugins.casc.model.Mapping)29 Test (org.junit.Test)21 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)19 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)19 CNode (io.jenkins.plugins.casc.model.CNode)12 Configurator (io.jenkins.plugins.casc.Configurator)8 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)7 Issue (org.jvnet.hudson.test.Issue)5 Scalar (io.jenkins.plugins.casc.model.Scalar)3 Sequence (io.jenkins.plugins.casc.model.Sequence)3 CredentialsRootConfigurator (com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator)2 CheckForNull (edu.umd.cs.findbugs.annotations.CheckForNull)2 ProxyConfiguration (hudson.ProxyConfiguration)2 ConfiguratorException (io.jenkins.plugins.casc.ConfiguratorException)2 HashSet (java.util.HashSet)2 Jenkins (jenkins.model.Jenkins)2 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)2 MasterKillSwitchConfiguration (jenkins.security.s2m.MasterKillSwitchConfiguration)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 BulkChange (hudson.BulkChange)1