Search in sources :

Example 16 with Configurator

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

the class PrimitiveConfiguratorTest method _string_env_default.

@Test
public void _string_env_default() throws Exception {
    environment.set("NOT_THERE", "abc");
    Configurator c = registry.lookupOrFail(String.class);
    final Object value = c.configure(new Scalar("${ENV_FOR_TEST:-unsecured-token}"), context);
    assertEquals("unsecured-token", value);
}
Also used : Configurator(io.jenkins.plugins.casc.Configurator) Scalar(io.jenkins.plugins.casc.model.Scalar) Test(org.junit.Test)

Example 17 with Configurator

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

the class PrimitiveConfiguratorTest method _int.

@Test
public void _int() throws Exception {
    Configurator c = registry.lookupOrFail(int.class);
    final Object value = c.configure(new Scalar("123"), context);
    assertEquals(123, (int) value);
}
Also used : Configurator(io.jenkins.plugins.casc.Configurator) Scalar(io.jenkins.plugins.casc.model.Scalar) Test(org.junit.Test)

Example 18 with Configurator

use of io.jenkins.plugins.casc.Configurator 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 19 with Configurator

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

Aggregations

Configurator (io.jenkins.plugins.casc.Configurator)19 Test (org.junit.Test)16 CNode (io.jenkins.plugins.casc.model.CNode)10 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)9 Mapping (io.jenkins.plugins.casc.model.Mapping)9 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)8 Scalar (io.jenkins.plugins.casc.model.Scalar)8 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)5 Jenkins (jenkins.model.Jenkins)4 ProxyConfiguration (hudson.ProxyConfiguration)2 BaseConfigurator (io.jenkins.plugins.casc.BaseConfigurator)2 DescriptorConfigurator (io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)2 MasterKillSwitchConfiguration (jenkins.security.s2m.MasterKillSwitchConfiguration)2 Issue (org.jvnet.hudson.test.Issue)2 CheckForNull (edu.umd.cs.findbugs.annotations.CheckForNull)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Extension (hudson.Extension)1