io.jenkins.plugins.casc.ConfiguratorRegistry Java Examples
The following examples show how to use
io.jenkins.plugins.casc.ConfiguratorRegistry.
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: UpdateCenterConfiguratorTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@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 #2
Source File: GitToolConfiguratorJenkinsRuleTest.java From git-client-plugin with MIT License | 6 votes |
@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: ProxyConfiguratorTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@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 #4
Source File: ProxyConfiguratorTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@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 #5
Source File: GitLabConnectionConfigAsCodeTest.java From gitlab-plugin with GNU General Public License v2.0 | 6 votes |
@Test @ConfiguredWithCode("global-config.yml") public void export_configuration() throws Exception { GitLabConnectionConfig globalConfiguration = GitLabConnectionConfig.get(); ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); final Configurator c = context.lookupOrFail(GitLabConnectionConfig.class); @SuppressWarnings("unchecked") CNode node = c.describe(globalConfiguration, context); assertNotNull(node); String exported = toYamlString(node); String expected = toStringFromYamlFile(this, "global-config-expected.yml"); assertEquals(expected, exported); }
Example #6
Source File: ProxyConfiguratorTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@Test @ConfiguredWithCode("Proxy.yml") public void describeProxyConfig() throws Exception { ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); final CNode configNode = getProxyNode(context); Secret password = requireNonNull(Secret.decrypt(getProxyNode(context).getScalarValue("secretPassword"))); final String yamlConfig = Util.toYamlString(configNode); assertEquals(String.join("\n", "name: \"proxyhost\"", "noProxyHost: \"externalhost\"", "port: 80", "secretPassword: \"" + password.getEncryptedValue() + "\"", "testUrl: \"http://google.com\"", "userName: \"login\"", "" ), yamlConfig); }
Example #7
Source File: DataBoundConfiguratorTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@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 #8
Source File: ConfigurationAsCodeTest.java From oic-auth-plugin with MIT License | 6 votes |
@Test public void testExport() throws Exception { ConfigurationContext context = new ConfigurationContext(ConfiguratorRegistry.get()); CNode yourAttribute = getJenkinsRoot(context).get("securityRealm").asMapping().get("oic"); String exported = toYamlString(yourAttribute); // secrets are always changing. so, just remove them before there's a better solution String[] lines = exported.split("\n"); List<String> lineList = new ArrayList<>(); for(String line : lines) { if(!line.contains("Secret")) { lineList.add(line); } } String cleanedExported = String.join("\n", lineList); String expected = toStringFromYamlFile(this, "ConfigurationAsCodeExport.yml"); assertThat(cleanedExported, is(expected)); }
Example #9
Source File: DataBoundConfiguratorTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@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 #10
Source File: DataBoundConfiguratorTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@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 #11
Source File: AdminWhitelistRuleConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("Issue #172") @ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_disabled.yml") public void checkA2MAccessControl_disable() throws Exception { final Jenkins jenkins = Jenkins.get(); MasterKillSwitchConfiguration config = jenkins.getDescriptorByType(MasterKillSwitchConfiguration.class); Assert.assertFalse("Agent → Master Access Control should be disabled", config.getMasterToSlaveAccessControl()); AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class); ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); final Configurator c = context.lookupOrFail(AdminWhitelistRule.class); final CNode node = c.describe(rule, context); final Mapping agent = node.asMapping(); assertEquals("false", agent.get("enabled").toString()); }
Example #12
Source File: ProxyConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @ConfiguredWithCode("ProxyMinimal.yml") public void describeMinimalProxyConfig() throws Exception { ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); final CNode configNode = getProxyNode(context); final String yamlConfig = Util.toYamlString(configNode); assertEquals(String.join("\n", "name: \"proxyhost\"", "port: 80", "" ), yamlConfig); }
Example #13
Source File: JenkinsConfiguratorCloudSupportTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @ConfiguredWithCode("JenkinsConfiguratorCloudSupportTest.yml") public void should_export_only_static_nodes() throws Exception { j.jenkins.addNode(new Cloud1PretendSlave()); ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); final CNode configNode = getJenkinsRoot(context).get("nodes"); final String yamlConfig = toYamlString(configNode); assertThat(yamlConfig, containsString("name: \"agent1\"")); assertThat(yamlConfig, containsString("name: \"agent2\"")); assertThat(yamlConfig, not(containsString("name: \"testCloud\""))); }
Example #14
Source File: AdminWhitelistRuleConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("Issue #172") @ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_enabled.yml") public void checkA2MAccessControl_enabled() throws Exception { final Jenkins jenkins = Jenkins.get(); MasterKillSwitchConfiguration config = jenkins.getDescriptorByType(MasterKillSwitchConfiguration.class); Assert.assertTrue("Agent → Master Access Control should be enabled", config.getMasterToSlaveAccessControl()); AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class); ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); final Configurator c = context.lookupOrFail(AdminWhitelistRule.class); final CNode node = c.describe(rule, context); final Mapping agent = node.asMapping(); assertEquals("true", agent.get("enabled").toString()); }
Example #15
Source File: DataBoundConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@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=}]"); }
Example #16
Source File: ConfigurationAsCodeTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void should_support_configuration_export() throws Exception { ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); CNode buildStatusConfigAttribute = getUnclassifiedRoot(context).get("buildStatusConfig"); String exported = toYamlString(buildStatusConfigAttribute); String expected = toStringFromYamlFile(this, "configuration-as-code-expected.yml"); assertThat(exported, is(expected)); }
Example #17
Source File: GitHubAppCredentialsJCasCCompatibilityTest.java From github-branch-source-plugin with MIT License | 5 votes |
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 #18
Source File: ConfigurationAsCodeTest.java From jenkins-build-monitor-plugin with MIT License | 5 votes |
@Test public void should_support_configuration_export() throws Exception { ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); CNode yourAttribute = getJenkinsRoot(context).get("views"); String exported = toYamlString(yourAttribute); String expected = toStringFromYamlFile(this, "configuration-as-code-expected.yml"); assertThat(exported, is(expected)); }
Example #19
Source File: ConfigurationAsCodeTest.java From lockable-resources-plugin with MIT License | 5 votes |
@Test public void should_support_configuration_export() throws Exception { ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); CNode yourAttribute = getUnclassifiedRoot(context).get("lockableResourcesManager"); String exported = toYamlString(yourAttribute); String expected = toStringFromYamlFile(this, "casc_expected_output.yml"); assertThat(exported, is(expected)); }
Example #20
Source File: GitToolConfiguratorJenkinsRuleTest.java From git-client-plugin with MIT License | 5 votes |
@Test public void testDescribeGitTool() 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); List<ToolProperty<ToolInstallation>> gitToolProperties = new ArrayList<>(); List<ToolInstaller> toolInstallers = new ArrayList<>(); ToolInstaller toolInstaller = new ZipExtractionInstaller("tool-label", "tool-url", "tool-subdir"); toolInstallers.add(toolInstaller); InstallSourceProperty installSourceProperty = new InstallSourceProperty(toolInstallers); gitToolProperties.add(installSourceProperty); 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)); // properties: // - installSource: // installers: // - zip: // label: "tool-label" // subdir: "tool-subdir" // url: "tool-url" Sequence propertiesSequence = cNodeMapping.get("properties").asSequence(); // properties: Mapping installSourceMapping = propertiesSequence.get(0).asMapping().get("installSource").asMapping(); // - installSource: Sequence installersSequence = installSourceMapping.get("installers").asSequence(); // installers: Mapping zipMapping = installersSequence.get(0).asMapping().get("zip").asMapping(); // - zip: assertThat(zipMapping.getScalarValue("label"), is("tool-label")); assertThat(zipMapping.getScalarValue("subdir"), is("tool-subdir")); assertThat(zipMapping.getScalarValue("url"), is("tool-url")); }
Example #21
Source File: ConfigurationAsCodeTest.java From folder-auth-plugin with MIT License | 5 votes |
@Test @ConfiguredWithCode("config.yml") public void configurationExportTest() throws Exception { ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); CNode yourAttribute = getJenkinsRoot(context).get("authorizationStrategy").asMapping() .get("folderBased"); String exported = toYamlString(yourAttribute); String expected = toStringFromYamlFile(this, "expected.yml"); assertThat(exported, is(expected)); }
Example #22
Source File: DataBoundConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@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 #23
Source File: DataBoundConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@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 |
@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 |
@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 |
@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 |
@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 |
@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 |
@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 |
@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)); }