io.jenkins.plugins.casc.model.Mapping Java Examples

The following examples show how to use io.jenkins.plugins.casc.model.Mapping. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitToolConfigurator.java    From git-client-plugin with MIT License 6 votes vote down vote up
@CheckForNull
@Override
public CNode describe(GitTool instance, ConfigurationContext context) throws Exception {
    Mapping mapping = new Mapping();
    if (instance instanceof JGitTool) {
        mapping.put("name", JGitTool.MAGIC_EXENAME);
    } else if (instance instanceof JGitApacheTool) {
        mapping.put("name", JGitApacheTool.MAGIC_EXENAME);
    } else if (instance != null) {
        mapping.put("name", instance.getName());
        mapping.put("home", instance.getHome());
    }
    if (context != null && instance != null && instance.getProperties() != null && !instance.getProperties().isEmpty()) {
        final Configurator<ToolProperty> configurator = context.lookupOrFail(ToolProperty.class);
        Sequence s = new Sequence(instance.getProperties().size());
        for (ToolProperty<?> property : instance.getProperties()) {
            s.add(configurator.describe(property, context));
        }
        mapping.put("properties", s);
    }
    return mapping;
}
 
Example #2
Source File: GitToolConfiguratorJenkinsRuleTest.java    From git-client-plugin with MIT License 6 votes vote down vote up
@Test
public void testDescribeGitToolEmptyProperties() throws Exception {
    String gitName = "git-2.19.1-name";
    String gitHome = "/opt/git-2.19.1/bin/git";

    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);

    // Intentionally empty properties passed to GitTool constructor
    List<ToolProperty<ToolInstallation>> gitToolProperties = new ArrayList<>();

    GitTool gitTool = new GitTool(gitName, gitHome, gitToolProperties);

    CNode cNode = gitToolConfigurator.describe(gitTool, context);

    assertThat(cNode, is(notNullValue()));
    assertThat(cNode.getType(), is(CNode.Type.MAPPING));
    Mapping cNodeMapping = cNode.asMapping();
    assertThat(cNodeMapping.getScalarValue("name"), is(gitName));
    assertThat(cNodeMapping.getScalarValue("home"), is(gitHome));
}
 
Example #3
Source File: HeteroDescribableConfigurator.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@CheckForNull
@Override
public CNode describe(T instance, ConfigurationContext context) {
    Predicate<CNode> isScalar = node -> node.getType().equals(MAPPING)
        && unchecked(node::asMapping).apply().size() == 0;
    return lookupConfigurator(context, instance.getClass())
            .map(configurator -> convertToNode(context, configurator, instance))
            .filter(Objects::nonNull)
            .map(node -> {
                if (isScalar.test(node)) {
                    return new Scalar(preferredSymbol(instance.getDescriptor()));
                } else {
                    final Mapping mapping = new Mapping();
                    mapping.put(preferredSymbol(instance.getDescriptor()), node);
                    return mapping;
                }
            }).getOrNull();
}
 
Example #4
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@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"));
}
 
Example #5
Source File: ConfigurationAsCode.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
private void configureWith(Mapping entries,
    ConfigurationContext context) throws ConfiguratorException {
    // Initialize secret sources
    SecretSource.all().forEach(SecretSource::init);

    // Check input before actually applying changes,
    // so we don't let master in a weird state after some ConfiguratorException has been thrown
    final Mapping clone = entries.clone();
    checkWith(clone, context);

    final ObsoleteConfigurationMonitor monitor = ObsoleteConfigurationMonitor.get();
    monitor.reset();
    context.clearListeners();
    context.addListener(monitor::record);
    try (ACLContext acl = ACL.as(ACL.SYSTEM)) {
        invokeWith(entries, (configurator, config) -> configurator.configure(config, context));
    }
}
 
Example #6
Source File: ProxyConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@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"));
}
 
Example #7
Source File: ProxyConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("Proxy.yml")
public void shouldSetProxyWithAllFields() throws Exception {
    ProxyConfiguration proxy = j.jenkins.proxy;
    assertEquals(proxy.name, "proxyhost");
    assertEquals(proxy.port, 80);

    assertEquals(proxy.getUserName(), "login");
    assertThat(proxy.getSecretPassword(), hasPlainText("password"));
    assertEquals(proxy.noProxyHost, "externalhost");
    assertEquals(proxy.getTestUrl(), "http://google.com");

    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(6, mapping.size());
    assertEquals("proxyhost", mapping.getScalarValue("name"));
}
 
Example #8
Source File: UpdateCenterConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("UpdateCenter.yml")
public void shouldSetUpdateCenterSites() throws Exception {
    UpdateCenter updateCenter = j.jenkins.getUpdateCenter();
    List<UpdateSite> sites = updateCenter.getSites();
    assertEquals(2, sites.size());
    UpdateSite siteOne = sites.get(0);
    assertEquals("default", siteOne.getId());
    assertEquals("https://updates.jenkins.io/update-center.json", siteOne.getUrl());
    UpdateSite siteTwo = sites.get(1);
    assertEquals("experimental", siteTwo.getId());
    assertEquals("https://updates.jenkins.io/experimental/update-center.json", siteTwo.getUrl());

    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    final Configurator c = context.lookupOrFail(UpdateCenter.class);
    final CNode node = c.describe(updateCenter, context);
    assertNotNull(node);
    Mapping site1 = node.asMapping().get("sites").asSequence().get(1).asMapping();
    assertEquals("experimental", site1.getScalarValue("id"));

}
 
Example #9
Source File: BaseConfigurator.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
protected final void handleUnknown(Mapping config, ConfigurationContext context) throws ConfiguratorException {
    if (!config.isEmpty()) {
        final String invalid = StringUtils.join(config.keySet(), ',');
        final String message = "Invalid configuration elements for type " + getTarget() + " : " + invalid + ".\n"
                + "Available attributes : " + StringUtils.join(getAttributes().stream().map(Attribute::getName).collect(Collectors.toList()), ", ");
        context.warning(config, message);
        switch (context.getUnknown()) {
            case reject:
                throw new ConfiguratorException(message);

            case warn:
                LOGGER.warning(message);
                break;
            default: // All cases in the ENUM is covered
        }
    }
}
 
Example #10
Source File: GitToolConfigurator.java    From git-client-plugin with MIT License 6 votes vote down vote up
@Override
protected GitTool instance(Mapping mapping, @NonNull ConfigurationContext context) throws ConfiguratorException {
    if (mapping == null) {
        return new GitTool("Default", "", instantiateProperties(null, context));
    }
    final CNode mproperties = mapping.remove("properties");
    final String name = mapping.getScalarValue("name");
    if (JGitTool.MAGIC_EXENAME.equals(name)) {
        if (mapping.remove("home") != null) { //Ignored but could be added, so removing to not fail handleUnknown
            logger.warning("property `home` is ignored for `" + JGitTool.MAGIC_EXENAME + "`");
        }
        return new JGitTool(instantiateProperties(mproperties, context));
    } else if (JGitApacheTool.MAGIC_EXENAME.equals(name)) {
        if (mapping.remove("home") != null) { //Ignored but could be added, so removing to not fail handleUnknown
            logger.warning("property `home` is ignored for `" + JGitApacheTool.MAGIC_EXENAME + "`");
        }
        return new JGitApacheTool(instantiateProperties(mproperties, context));
    } else {
        if (mapping.get("home") == null) {
            throw new ConfiguratorException(this, "Home required for cli git configuration.");
        }
        String home = mapping.getScalarValue("home");
        return new GitTool(name, home, instantiateProperties(mproperties, context));
    }
}
 
Example #11
Source File: BaseConfigurator.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@NonNull
@Override
public T configure(CNode c, ConfigurationContext context) throws ConfiguratorException {
    final Mapping mapping = (c != null ? c.asMapping() : Mapping.EMPTY);
    final T instance = instance(mapping, context);
    if (instance instanceof Saveable) {
        try (BulkChange bc = new BulkChange((Saveable) instance) ){
            configure(mapping, instance, false, context);
            bc.commit();
        } catch (IOException e) {
            throw new ConfiguratorException("Failed to save "+instance, e);
        }
    } else {
        configure(mapping, instance, false, context);
    }

    return instance;
}
 
Example #12
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@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"));
    }
}
 
Example #13
Source File: Configurator.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
/**
 * Describe Structure of the attributes, as required by the schema.
 * @param instance
 * @param context
 * @since 1.35
 * @return CNode describing the attributes.
 */
@CheckForNull
default CNode describeStructure(T instance, ConfigurationContext context)
    throws Exception {
    Mapping mapping = new Mapping();
    for (Attribute attribute : getAttributes()) {
        if (context.getMode().equals("JSONSchema")) {
            attribute.setJsonSchema(true);
        }
        CNode value = attribute.describeForSchema(instance, context);
        if (value != null) {
            mapping.put(attribute.getName(), attribute.getType().getSimpleName());
        }
    }
    return mapping;
}
 
Example #14
Source File: CredentialsTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("GlobalCredentials.yml")
public void testExportFileCredentials() throws Exception {
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    CredentialsRootConfigurator root = ExtensionList.lookupSingleton(CredentialsRootConfigurator.class);

    CNode node = root.describe(root.getTargetComponent(context), context);
    assertNotNull(node);
    final Mapping mapping = node.asMapping();

    Mapping fileCredential = mapping.get("system")
        .asMapping()
        .get("domainCredentials")
        .asSequence().get(0)
        .asMapping().get("credentials")
        .asSequence().get(2)
        .asMapping().get("file").asMapping();

    assertThat(fileCredential.getScalarValue("scope"), is("GLOBAL"));
    assertThat(fileCredential.getScalarValue("id"), is("secret-file"));
    assertThat(fileCredential.getScalarValue("fileName"), is("mysecretfile.txt"));
    assertThat(fileCredential.getScalarValue("secretBytes"), not("WJjZAo="));
}
 
Example #15
Source File: ModelConstructor.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
/**
 * Enforce Map keys are only Scalars and can be used as {@link String} keys in {@link Mapping}
 */
@Override
protected void constructMapping2ndStep(MappingNode node, final Map mapping) {
    ((Mapping) mapping).setSource(getSource(node));
    super.constructMapping2ndStep(node,
            new AbstractMapDecorator(mapping) {
        @Override
        public Object put(Object key, Object value) {
            if (!(key instanceof Scalar)) throw new IllegalStateException("We only support scalar map keys");
            Object scalar = ObjectUtils.clone(value);
            if (scalar instanceof Number) scalar = new Scalar(scalar.toString());
            else if (scalar instanceof Boolean) scalar = new Scalar(scalar.toString());

            return mapping.put(key.toString(), scalar);
        }
    });
}
 
Example #16
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
public void exportYaml() throws Exception {
    Foo foo = new Foo("foo", true, 42);
    foo.setZot("zot");
    foo.setDbl(12.34);
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final Configurator c = registry.lookupOrFail(Foo.class);
    final ConfigurationContext context = new ConfigurationContext(registry);
    final CNode node = c.describe(foo, context);
    assertNotNull(node);
    assertTrue(node instanceof Mapping);
    Mapping map = (Mapping) node;
    assertEquals(map.get("foo").toString(), "foo");
    assertEquals(map.get("bar").toString(), "true");
    assertEquals(map.get("qix").toString(), "42");
    assertEquals(map.get("zot").toString(), "zot");
    assertEquals(map.get("dbl").toString(), "12.34");
    assertEquals(Util.toYamlString(map.get("foo")).trim(), "\"foo\"");
    assertEquals(Util.toYamlString(map.get("bar")).trim(), "true");
    assertEquals(Util.toYamlString(map.get("qix")).trim(), "42");
    assertEquals(Util.toYamlString(map.get("zot")).trim(), "\"zot\"");
    assertEquals(Util.toYamlString(map.get("dbl")).trim(), "12.34");
    assertFalse(map.containsKey("other"));
}
 
Example #17
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@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");
}
 
Example #18
Source File: GitToolConfiguratorTest.java    From git-client-plugin with MIT License 5 votes vote down vote up
@Test
public void testInstance() throws Exception {
    Mapping mapping = null;
    ConfigurationContext context = new ConfigurationContext(null);
    GitTool gitTool = gitToolConfigurator.instance(mapping, context);
    assertThat(gitTool, is(instanceOf(GitTool.class)));
    assertThat(gitTool.getName(), is("Default"));
    assertThat(gitTool.getHome(), is(""));
}
 
Example #19
Source File: GitToolConfiguratorTest.java    From git-client-plugin with MIT License 5 votes vote down vote up
@Test
public void testInstanceJGitTool() throws Exception {
    Mapping mapping = new Mapping();
    mapping.put("name", JGitTool.MAGIC_EXENAME);
    ConfigurationContext context = new ConfigurationContext(null);
    GitTool gitTool = gitToolConfigurator.instance(mapping, context);
    assertThat(gitTool, is(instanceOf(JGitTool.class)));
    assertThat(gitTool, is(not(instanceOf(JGitApacheTool.class))));
}
 
Example #20
Source File: GitToolConfiguratorTest.java    From git-client-plugin with MIT License 5 votes vote down vote up
@Test
public void testInstanceJGitToolWithHome() throws Exception {
    Mapping mapping = new Mapping();
    mapping.put("name", JGitTool.MAGIC_EXENAME);
    mapping.put("home", "unused-value-for-home"); // Will log a message
    ConfigurationContext context = new ConfigurationContext(null);
    GitTool gitTool = gitToolConfigurator.instance(mapping, context);
    assertThat(gitTool, is(instanceOf(JGitTool.class)));
    assertThat(gitTool, is(not(instanceOf(JGitApacheTool.class))));
}
 
Example #21
Source File: GitToolConfiguratorTest.java    From git-client-plugin with MIT License 5 votes vote down vote up
@Test
public void testInstanceJGitApacheTool() throws Exception {
    Mapping mapping = new Mapping();
    mapping.put("name", JGitApacheTool.MAGIC_EXENAME);
    ConfigurationContext context = new ConfigurationContext(null);
    GitTool gitTool = gitToolConfigurator.instance(mapping, context);
    assertThat(gitTool, is(instanceOf(JGitApacheTool.class)));
    assertThat(gitTool, is(not(instanceOf(JGitTool.class))));
}
 
Example #22
Source File: GitHubAppCredentialsJCasCCompatibilityTest.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
private Sequence getCredentials() throws Exception {
    CredentialsRootConfigurator root = Jenkins.get()
            .getExtensionList(CredentialsRootConfigurator.class).get(0);

    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    Mapping configNode = Objects
            .requireNonNull(root.describe(root.getTargetComponent(context), context)).asMapping();
    Mapping domainCredentials = configNode
            .get("system").asMapping().get("domainCredentials")
            .asSequence()
            .get(0).asMapping();
    return domainCredentials.get("credentials").asSequence();
}
 
Example #23
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
public void shouldNotLogSecrets() throws Exception {
    Mapping config = new Mapping();
    config.put("secret", "mySecretValue");
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    registry.lookupOrFail(SecretHolder.class).configure(config, new ConfigurationContext(registry));
    assertLogContains(logging, "secret");
    assertNotInLog(logging, "mySecretValue");
}
 
Example #24
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@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());
}
 
Example #25
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
public void packageParametersAreNonnullByDefault() {
    Mapping config = new Mapping();
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();

    String expectedMessage = "string is required to configure class io.jenkins.plugins.casc.impl.configurators.nonnull.nonnullparampackage.PackageParametersAreNonnullByDefault";

    ConfiguratorException exception = assertThrows(ConfiguratorException.class, () -> registry
        .lookupOrFail(PackageParametersAreNonnullByDefault.class)
        .configure(config, new ConfigurationContext(registry)));

   assertThat(exception.getMessage(), is(expectedMessage));
}
 
Example #26
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@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());
}
 
Example #27
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
public void nonnullConstructorParameter() throws Exception {
    Mapping config = new Mapping();
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final NonnullParameterConstructor configured = (NonnullParameterConstructor) registry
                                                    .lookupOrFail(NonnullParameterConstructor.class)
                                                    .configure(config, new ConfigurationContext(registry));
    assertEquals(0, configured.getStrings().size());
}
 
Example #28
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@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());
}
 
Example #29
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
public void configureWithSets() throws Exception {
    Mapping config = new Mapping();
    Sequence sequence = new Sequence();
    sequence.add(new Scalar("bar"));
    sequence.add(new Scalar("foo"));
    config.put("strings", sequence);
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final Bar configured = (Bar) registry.lookupOrFail(Bar.class).configure(config, new ConfigurationContext(registry));
    Set<String> strings = configured.getStrings();
    assertTrue(strings.contains("foo"));
    assertTrue(strings.contains("bar"));
    assertFalse(strings.contains("baz"));
}
 
Example #30
Source File: DataBoundConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@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));
}