org.jvnet.hudson.test.RestartableJenkinsRule Java Examples

The following examples show how to use org.jvnet.hudson.test.RestartableJenkinsRule. 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: GitHubBranchSourcesJCasCCompatibilityTest.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Issue("JENKINS-57557")
@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule restartableJenkinsRule, String s) {
    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(ForkPullRequestDiscoveryTrait.TrustPermission.class));
}
 
Example #2
Source File: RoundTripMailerTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule j, String configContent) {
    final Jenkins jenkins = Jenkins.get();
    final Mailer.DescriptorImpl descriptor = (Mailer.DescriptorImpl) jenkins.getDescriptor(Mailer.class);
    assertEquals("4441", descriptor.getSmtpPort());
    assertEquals("[email protected]", descriptor.getReplyToAddress());
}
 
Example #3
Source File: EnvVarCasCTest.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule r, String configContent) {
    KubernetesCloud cloud = r.j.jenkins.clouds.get(KubernetesCloud.class);
    assertNotNull(cloud);
    List<PodTemplate> templates = cloud.getTemplates();
    assertNotNull(templates);
    assertEquals(1, templates.size());
    PodTemplate podTemplate = templates.get(0);
    List<TemplateEnvVar> envVars = podTemplate.getEnvVars();
    assertEquals(1, envVars.size());
    strategy._verify(envVars.get(0));

}
 
Example #4
Source File: VolumeCasCTest.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule r, String configContent) {
    KubernetesCloud cloud = r.j.jenkins.clouds.get(KubernetesCloud.class);
    assertNotNull(cloud);
    List<PodTemplate> templates = cloud.getTemplates();
    assertNotNull(templates);
    assertEquals(1, templates.size());
    PodTemplate podTemplate = templates.get(0);
    List<PodVolume> volumes = podTemplate.getVolumes();
    assertEquals(1, volumes.size());
    strategy.verify(volumes.get(0));

}
 
Example #5
Source File: WorkspaceVolumeCasCTest.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule r, String configContent) {
    KubernetesCloud cloud = r.j.jenkins.clouds.get(KubernetesCloud.class);
    assertNotNull(cloud);
    List<PodTemplate> templates = cloud.getTemplates();
    assertNotNull(templates);
    assertEquals(1, templates.size());
    PodTemplate podTemplate = templates.get(0);
    strategy.verify(podTemplate.getWorkspaceVolume());

}
 
Example #6
Source File: CasCTest.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule r, String configContent) {
    KubernetesCloud cloud = r.j.jenkins.clouds.get(KubernetesCloud.class);
    assertNotNull(cloud);
    assertEquals(10,cloud.getContainerCap());
    assertEquals("http://jenkinshost:8080/jenkins/", cloud.getJenkinsUrl());
    assertEquals(32, cloud.getMaxRequestsPerHost());
    assertEquals("kubernetes", cloud.name);
    List<PodTemplate> templates = cloud.getTemplates();
    assertNotNull(templates);
    assertEquals(3, templates.size());
    PodTemplate podTemplate = templates.get(0);
    assertEquals(false, podTemplate.isHostNetwork());
    assertEquals("java", podTemplate.getLabel());
    assertEquals("default-java", podTemplate.getName());
    assertEquals(10, podTemplate.getInstanceCap());
    assertEquals(123, podTemplate.getSlaveConnectTimeout());
    assertEquals(5, podTemplate.getIdleMinutes());
    assertEquals(66, podTemplate.getActiveDeadlineSeconds());
    assertThat(podTemplate.getYamlMergeStrategy(), isA(Overrides.class));
    podTemplate = templates.get(1);
    assertEquals(false, podTemplate.isHostNetwork());
    assertEquals("dynamic-pvc", podTemplate.getLabel());
    assertEquals("dynamic-pvc", podTemplate.getName());
    assertThat(podTemplate.getYamlMergeStrategy(), isA(Overrides.class));
    WorkspaceVolume workspaceVolume = podTemplate.getWorkspaceVolume();
    assertNotNull(workspaceVolume);
    assertThat(workspaceVolume, isA(DynamicPVCWorkspaceVolume.class));
    DynamicPVCWorkspaceVolume dynamicPVCVolume = (DynamicPVCWorkspaceVolume) workspaceVolume;
    assertEquals("ReadWriteOnce", dynamicPVCVolume.getAccessModes());
    assertEquals("1",dynamicPVCVolume.getRequestsSize());
    assertEquals("hostpath",dynamicPVCVolume.getStorageClassName());
    podTemplate = templates.get(2);
    assertEquals(false, podTemplate.isHostNetwork());
    assertEquals("test", podTemplate.getLabel());
    assertEquals("test", podTemplate.getName());
    assertThat(podTemplate.getYamlMergeStrategy(), isA(Merge.class));
    List<ContainerTemplate> containers = podTemplate.getContainers();
    assertNotNull(containers);
    assertEquals(1, containers.size());
    ContainerTemplate container = containers.get(0);
    assertEquals("cat", container.getArgs());
    assertEquals("/bin/sh -c", container.getCommand());
    assertEquals("maven:3.6.3-jdk-8", container.getImage());
    ContainerLivenessProbe livenessProbe = container.getLivenessProbe();
    assertEquals(1, livenessProbe.getFailureThreshold());
    assertEquals(2, livenessProbe.getInitialDelaySeconds());
    assertEquals(3, livenessProbe.getPeriodSeconds());
    assertEquals(4, livenessProbe.getSuccessThreshold());
    assertEquals(5, livenessProbe.getTimeoutSeconds());
    assertEquals("maven",container.getName());
    assertEquals(true, container.isTtyEnabled());
    assertEquals("/src", container.getWorkingDir());

}
 
Example #7
Source File: JcascTest.java    From git-client-plugin with MIT License 4 votes vote down vote up
@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule restartableJenkinsRule, String s) {
    final ToolDescriptor descriptor = (ToolDescriptor) restartableJenkinsRule.j.jenkins.getDescriptor(GitTool.class);
    final ToolInstallation[] installations = descriptor.getInstallations();
    assertThat(installations, arrayWithSize(4));
    assertThat(installations, arrayContainingInAnyOrder(
            allOf(
                    instanceOf(JGitTool.class),
                    hasProperty("name", equalTo(JGitTool.MAGIC_EXENAME))
            ),
            allOf(
                    instanceOf(JGitApacheTool.class),
                    hasProperty("name", equalTo(JGitApacheTool.MAGIC_EXENAME))
            ),
            allOf(
                    instanceOf(GitTool.class),
                    not(instanceOf(JGitTool.class)),
                    not(instanceOf(JGitApacheTool.class)),
                    hasProperty("name", equalTo("Default")),
                    hasProperty("home", equalTo("git"))
            ),
            allOf(
                    instanceOf(GitTool.class),
                    not(instanceOf(JGitTool.class)),
                    not(instanceOf(JGitApacheTool.class)),
                    hasProperty("name", equalTo("optional")),
                    hasProperty("home", equalTo("/opt/git/git"))
            ))
    );
    final DescribableList<ToolProperty<?>, ToolPropertyDescriptor> properties = Arrays.stream(installations).filter(t -> t.getName().equals("optional")).findFirst().get().getProperties();
    assertThat(properties, iterableWithSize(1));
    final ToolProperty<?> property = properties.get(0);
    assertThat(property, instanceOf(InstallSourceProperty.class));
    assertThat(((InstallSourceProperty)property).installers,
            containsInAnyOrder(
                    allOf(
                            instanceOf(BatchCommandInstaller.class),
                            hasProperty("command", equalTo("echo \"got git\""))
                    ),
                    allOf(
                            instanceOf(ZipExtractionInstaller.class),
                            hasProperty("url", equalTo("file://some/path.zip"))
                    )
            )
    );
}
 
Example #8
Source File: RoundTripAbstractTest.java    From configuration-as-code-plugin with MIT License 2 votes vote down vote up
/**
 * A method to assert if the configuration was correctly loaded. The Jenkins rule and the content of the config
 * supposedly loaded are passed.
 * @param j a RestartableJenkinsRule instance.
 * @param configContent expected configuration.
 */
protected abstract void assertConfiguredAsExpected(RestartableJenkinsRule j, String configContent);