use of io.jenkins.plugins.casc.model.Mapping in project configuration-as-code-plugin by jenkinsci.
the class UpdateCenterConfiguratorTest method shouldSetUpdateCenterSites.
@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"));
}
use of io.jenkins.plugins.casc.model.Mapping in project configuration-as-code-plugin by jenkinsci.
the class DataBoundConfiguratorTest method exportWithSets.
@Test
@SuppressWarnings("unchecked")
public void exportWithSets() throws Exception {
HashSet<String> set = new HashSet<>();
set.add("foo");
Bar bar = new Bar(set);
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
final Configurator c = registry.lookupOrFail(Bar.class);
final ConfigurationContext context = new ConfigurationContext(registry);
CNode node = c.describe(bar, context);
assertNotNull(node);
assertTrue(node instanceof Mapping);
Mapping map = (Mapping) node;
assertEquals(map.get("strings").toString(), "[foo]");
assertEquals(Util.toYamlString(map.get("strings")).trim(), "- \"foo\"");
assertFalse(map.containsKey("other"));
// now with two elements
set.add("bar");
node = c.describe(bar, context);
assertNotNull(node);
assertTrue(node instanceof Mapping);
map = (Mapping) node;
assertEquals(map.get("strings").toString(), "[bar, foo]");
assertEquals(Util.toYamlString(map.get("strings")).trim(), "- \"bar\"\n- \"foo\"");
}
use of io.jenkins.plugins.casc.model.Mapping in project configuration-as-code-plugin by jenkinsci.
the class DataBoundConfiguratorTest method shouldNotLogSecrets.
@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");
}
use of io.jenkins.plugins.casc.model.Mapping in project configuration-as-code-plugin by jenkinsci.
the class DataBoundConfiguratorTest method nonnullConstructorParameter.
@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());
}
use of io.jenkins.plugins.casc.model.Mapping in project configuration-as-code-plugin by jenkinsci.
the class DataBoundConfiguratorTest method configureWithSets.
@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"));
}
Aggregations