Java Code Examples for io.jenkins.plugins.casc.ConfiguratorRegistry#get()
The following examples show how to use
io.jenkins.plugins.casc.ConfiguratorRegistry#get() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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)); }
Example 17
Source File: ExportTest.java From configuration-as-code-plugin with MIT License | 5 votes |
public <T> String export(DataBoundConfigurator<T> configurator, T object) throws Exception { ConfigurationAsCode casc = ConfigurationAsCode.get(); ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); final CNode config = configurator.describe(object, context); final Node valueNode = casc.toYaml(config); try (StringWriter writer = new StringWriter()) { ConfigurationAsCode.serializeYamlNode(valueNode, writer); return writer.toString(); } catch (IOException e) { throw new YAMLException(e); } }
Example 18
Source File: ConfigurationAsCodeTest.java From gitlab-branch-source-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 gitLabServers = getUnclassifiedRoot(context).get("gitLabServers"); String exported = toYamlString(gitLabServers); String expected = toStringFromYamlFile(this, "expected_output.yml"); assertThat(exported, matchesPattern(expected)); }
Example 19
Source File: ConfigurationAsCodeTest.java From folder-auth-plugin with MIT License | 5 votes |
@Test @ConfiguredWithCode("config3.yml") public void configurationExportWithHumanReadableTest() 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, "expected3.yml"); assertThat(exported, is(expected)); }
Example 20
Source File: PrimitiveConfiguratorTest.java From configuration-as-code-plugin with MIT License | 4 votes |
@BeforeClass public static void setUp() { registry = ConfiguratorRegistry.get(); context = new ConfigurationContext(registry); }