use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.
the class GiteaOrganisationFolderTest method configure_gitea_organisation_folder_seed_job.
@Test
@WithPlugin({ "branch-api.jpi", "cloudbees-folder.jpi", "scm-api.jpi", "structs.jpi" })
@ConfiguredWithCode("SeedJobTest_withGiteaOrganisation.yml")
public void configure_gitea_organisation_folder_seed_job() {
OrganizationFolder folder = (OrganizationFolder) r.jenkins.getItem("Gitea Organization Folder");
assertNotNull(folder);
GiteaSCMNavigator organization = (GiteaSCMNavigator) folder.getNavigators().get(0);
assertNotNull(organization);
assertEquals("gitea-token", organization.getCredentialsId());
assertEquals("https://git.example.com", organization.getServerUrl());
assertEquals("OWN", organization.getRepoOwner());
List<SCMTrait<?>> traits = organization.getTraits();
assertEquals(7, traits.size());
assertEquals(ExcludeArchivedRepositoriesTrait.class, traits.get(0).getClass());
assertEquals(TagDiscoveryTrait.class, traits.get(1).getClass());
SCMTrait<?> trait2 = traits.get(2);
assertEquals(BranchDiscoveryTrait.class, trait2.getClass());
assertEquals(1, ((BranchDiscoveryTrait) trait2).getStrategyId());
SCMTrait<?> trait3 = traits.get(3);
assertEquals(OriginPullRequestDiscoveryTrait.class, trait3.getClass());
assertEquals(2, ((OriginPullRequestDiscoveryTrait) trait3).getStrategyId());
SCMTrait<?> trait4 = traits.get(4);
assertEquals(ForkPullRequestDiscoveryTrait.class, trait4.getClass());
assertEquals(1, ((ForkPullRequestDiscoveryTrait) trait4).getStrategyId());
assertEquals(ForkPullRequestDiscoveryTrait.TrustContributors.class, ((ForkPullRequestDiscoveryTrait) trait4).getTrust().getClass());
SCMTrait<?> trait5 = traits.get(5);
assertEquals(WebhookRegistrationTrait.class, trait5.getClass());
assertEquals("ITEM", ((WebhookRegistrationTrait) trait5).getMode().name());
SCMTrait<?> trait6 = traits.get(6);
assertEquals(SSHCheckoutTrait.class, trait6.getClass());
assertEquals("ssh-gitea", ((SSHCheckoutTrait) trait6).getCredentialsId());
}
use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.
the class CredentialsTest method testExportFileCredentials.
@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="));
}
use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.
the class CustomToolsTest method configure_custom_tools.
@Test
@Issue("#97")
@Ignore
@ConfiguredWithCode(value = "CustomToolsTest.yml")
public void configure_custom_tools() {
DescriptorImpl descriptor = (DescriptorImpl) j.jenkins.getDescriptorOrDie(CustomTool.class);
assertEquals(1, descriptor.getInstallations().length);
final CustomTool customTool = descriptor.getInstallations()[0];
final InstallSourceProperty source = customTool.getProperties().get(InstallSourceProperty.class);
assertNotNull(source);
final CommandInstaller installer = source.installers.get(CommandInstaller.class);
assertNotNull(installer);
assertEquals("/bin/my-tool", installer.getToolHome());
}
use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.
the class GlobalLibrariesTest method configure_global_library_using_github.
@Issue("JENKINS-57557")
@Test
@ConfiguredWithCode("GlobalLibrariesGitHubTest.yml")
public void configure_global_library_using_github() {
assertEquals(1, GlobalLibraries.get().getLibraries().size());
final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
assertEquals("jenkins-pipeline-lib", library.getName());
final SCMSourceRetriever retriever = (SCMSourceRetriever) library.getRetriever();
final GitHubSCMSource scm = (GitHubSCMSource) retriever.getScm();
assertEquals("e43d6600-ba0e-46c5-8eae-3989bf654055", scm.getId());
assertEquals("jenkins-infra", scm.getRepoOwner());
assertEquals("pipeline-library", scm.getRepository());
assertEquals(3, scm.getTraits().size());
final BranchDiscoveryTrait branchDiscovery = (BranchDiscoveryTrait) scm.getTraits().get(0);
assertEquals(1, branchDiscovery.getStrategyId());
final OriginPullRequestDiscoveryTrait prDiscovery = (OriginPullRequestDiscoveryTrait) scm.getTraits().get(1);
assertEquals(2, prDiscovery.getStrategyId());
final ForkPullRequestDiscoveryTrait forkDiscovery = (ForkPullRequestDiscoveryTrait) scm.getTraits().get(2);
assertEquals(3, forkDiscovery.getStrategyId());
assertThat(forkDiscovery.getTrust(), instanceOf(TrustPermission.class));
}
use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.
the class JenkinsDemoTest method configure_demo_yaml.
@Test
@ConfiguredWithCode("jenkins/jenkins.yaml")
public void configure_demo_yaml() {
final Jenkins jenkins = Jenkins.get();
assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
assertEquals(5, jenkins.getNumExecutors());
assertEquals(2, jenkins.getScmCheckoutRetryCount());
assertEquals(Mode.NORMAL, jenkins.getMode());
assertEquals("https://ci.example.com/", jenkins.getRootUrl());
final FullControlOnceLoggedInAuthorizationStrategy strategy = (FullControlOnceLoggedInAuthorizationStrategy) jenkins.getAuthorizationStrategy();
assertFalse(strategy.isAllowAnonymousRead());
final DockerCloud docker = DockerCloud.getCloudByName("docker");
assertNotNull(docker);
assertNotNull(docker.getDockerApi());
assertNotNull(docker.getDockerApi().getDockerHost());
assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
final GitTool.DescriptorImpl gitTool = (GitTool.DescriptorImpl) jenkins.getDescriptor(GitTool.class);
assertEquals(1, gitTool.getInstallations().length);
assertEquals(1, GlobalLibraries.get().getLibraries().size());
final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
assertEquals("awesome-lib", library.getName());
final Mailer.DescriptorImpl descriptor = (Mailer.DescriptorImpl) jenkins.getDescriptor(Mailer.class);
assertEquals("4441", descriptor.getSmtpPort());
assertEquals("do-not-reply@acme.org", descriptor.getReplyToAddress());
assertEquals("smtp.acme.org", descriptor.getSmtpHost());
final ArtifactoryBuilder.DescriptorImpl artifactory = (ArtifactoryBuilder.DescriptorImpl) jenkins.getDescriptor(ArtifactoryBuilder.class);
assertTrue(artifactory.getUseCredentialsPlugin());
final List<JFrogPlatformInstance> jfrogInstances = artifactory.getJfrogInstances();
assertThat(jfrogInstances, hasSize(1));
assertThat(jfrogInstances.get(0).getId(), is(equalTo("artifactory")));
assertThat(jfrogInstances.get(0).getUrl(), is(equalTo("http://acme.com/artifactory")));
assertThat(jfrogInstances.get(0).getResolverCredentialsConfig().getUsername(), is(equalTo("artifactory_user")));
assertThat(jfrogInstances.get(0).getResolverCredentialsConfig().getPassword().getPlainText(), is(equalTo("password123")));
}
Aggregations