Java Code Examples for io.jenkins.plugins.casc.ConfigurationContext#lookupOrFail()
The following examples show how to use
io.jenkins.plugins.casc.ConfigurationContext#lookupOrFail() .
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: 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 3
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 4
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 5
Source File: GitToolConfigurator.java From git-client-plugin with MIT License | 6 votes |
@NonNull private List<ToolProperty<?>> instantiateProperties(@CheckForNull CNode props, @NonNull ConfigurationContext context) throws ConfiguratorException { List<ToolProperty<?>> toolProperties = new ArrayList<>(); if (props == null) { return toolProperties; } final Configurator<ToolProperty> configurator = context.lookupOrFail(ToolProperty.class); if (props instanceof Sequence) { Sequence s = (Sequence) props; for (CNode cNode : s) { toolProperties.add(configurator.configure(cNode, context)); } } else { toolProperties.add(configurator.configure(props, context)); } return toolProperties; }
Example 6
Source File: GitToolConfigurator.java From git-client-plugin with MIT License | 6 votes |
@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 7
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 8
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()); }