Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tests that depend on MavenModuleSet and MavenModuleSetBuild from Jenkins core to Maven Integration #155

Merged
merged 2 commits into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions src/test/java/hudson/bugs/seasar/Operation2174Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.bugs.seasar;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import hudson.maven.MavenModuleSet;
import hudson.model.FreeStyleProject;
import hudson.model.Item;
import hudson.tasks.BuildTrigger;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.Collections;

/**
* See http://ml.seasar.org/archives/operation/2008-November/004003.html
*
* @author Kohsuke Kawaguchi
*/
public class Operation2174Test {

@Rule public JenkinsRule j = new JenkinsRule();

/** Tests that configuring a dependency from a freestyle to a maven project actually works. */
@Test
public void testBuildChains() throws Exception {
FreeStyleProject up = j.createFreeStyleProject("up");
MavenModuleSet dp = j.createProject(MavenModuleSet.class, "dp");

// designate 'dp' as the downstream in 'up'
JenkinsRule.WebClient webClient = j.createWebClient();
webClient.getPage(up, "configure");

// configure downstream build
up.getPublishersList().add(new BuildTrigger("dp", false));
j.configRoundtrip((Item) up);

// verify that the relationship is set up
BuildTrigger trigger = up.getPublishersList().get(BuildTrigger.class);
assertEquals(trigger.getChildJobs(up), Collections.singletonList(dp));

// now go ahead and edit the downstream
j.configRoundtrip((Item) dp);

// verify that the relationship is set up
trigger = up.getPublishersList().get(BuildTrigger.class);
assertNotNull(trigger);
assertEquals(trigger.getChildJobs(up), Collections.singletonList(dp));
}
}
66 changes: 66 additions & 0 deletions src/test/java/hudson/cli/ListJobsCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* The MIT License
*
* Copyright 2018 Victor Martinez.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.cli;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;

import hudson.maven.MavenModuleSet;
import hudson.model.FreeStyleProject;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;

public class ListJobsCommandTest {

@Rule public JenkinsRule j = new JenkinsRule();
private CLICommandInvoker command;

@Before
public void setUp() {
CLICommand listJobsCommand = new ListJobsCommand();
command = new CLICommandInvoker(j, listJobsCommand);
}

@Issue("JENKINS-18393")
@Test
public void getAllJobsFromFolderWithMavenModuleSet() throws Exception {
MockFolder folder = j.createFolder("Folder");

folder.createProject(FreeStyleProject.class, "job1");
folder.createProject(FreeStyleProject.class, "job2");
folder.createProject(MavenModuleSet.class, "mvn");

CLICommandInvoker.Result result = command.invokeWithArgs("Folder");
assertThat(result, CLICommandInvoker.Matcher.succeeded());
assertThat(result.stdout(), containsString("job1"));
assertThat(result.stdout(), containsString("job2"));
assertThat(result.stdout(), containsString("mvn"));
}
}
82 changes: 82 additions & 0 deletions src/test/java/hudson/model/JobPropertyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model;

import com.gargoylesoftware.htmlunit.WebAssert;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import hudson.maven.MavenModuleSet;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.TestExtension;

public class JobPropertyTest {

@Rule public JenkinsRule j = new JenkinsRule();

@Rule public LoggerRule logs = new LoggerRule();

@Test
@Issue("JENKINS-2398")
public void jobPropertySummaryIsShownInMavenModuleSetIndexPage() throws Exception {
assertJobPropertySummaryIsShownInIndexPage(MavenModuleSet.class);
}

private void assertJobPropertySummaryIsShownInIndexPage(Class<? extends TopLevelItem> type)
throws Exception {
JobPropertyImpl jp = new JobPropertyImpl("NeedleInPage");
Job<?, ?> project = (Job<?, ?>) j.jenkins.createProject(type, "job-test-case");
project.addProperty(jp);
project.save();

HtmlPage page = j.createWebClient().goTo("job/job-test-case");
WebAssert.assertTextPresent(page, "NeedleInPage");
}

public static class JobPropertyImpl extends JobProperty<Job<?, ?>> {
private final String propertyString;

public JobPropertyImpl(String propertyString) {
this.propertyString = propertyString;
}

public String getPropertyString() {
return propertyString;
}

@TestExtension
public static class DescriptorImpl extends JobPropertyDescriptor {
@SuppressWarnings("rawtypes")
@Override
public boolean isApplicable(Class<? extends Job> jobType) {
return false;
}
}
}
}
118 changes: 118 additions & 0 deletions src/test/java/hudson/model/NodeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* The MIT License
*
* Copyright 2013 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model;

import static org.junit.Assert.assertEquals;

import hudson.maven.MavenModuleSet;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RunLoadCounter;

import java.util.concurrent.Callable;

/**
* @author Lucie Votypkova
*/
public class NodeTest {

@Rule public JenkinsRule j = new JenkinsRule();

@Before
public void before() {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
}

/** Verify that the Label#getTiedJobCount does not perform a lazy loading operation. */
@Issue("JENKINS-26391")
@Test
public void testGetAssignedLabelWithJobs() throws Exception {
final Node node = j.createOnlineSlave();
node.setLabelString("label1 label2");
MavenModuleSet mavenProject = j.jenkins.createProject(MavenModuleSet.class, "p");
mavenProject.setAssignedLabel(j.jenkins.getLabel("label1"));
RunLoadCounter.prepare(mavenProject);
j.assertBuildStatus(Result.FAILURE, mavenProject.scheduleBuild2(0).get());
Integer labelCount = RunLoadCounter.assertMaxLoads(mavenProject, 0, new Callable<Integer>() {
@Override
public Integer call() throws Exception {
final Label label = j.jenkins.getLabel("label1");
label.reset(); // Make sure cached value is not used
return label.getTiedJobCount();
}
});

assertEquals("Should have only one job tied to label.", 1, labelCount.intValue());
}

/**
* Create two projects which have the same label and verify that both are accounted for when
* getting a count of the jobs tied to the current label.
*/
@Issue("JENKINS-26391")
@Test
public void testGetAssignedLabelMultipleSlaves() throws Exception {
final Node node1 = j.createOnlineSlave();
node1.setLabelString("label1");
final Node node2 = j.createOnlineSlave();
node1.setLabelString("label1");

MavenModuleSet project = j.jenkins.createProject(MavenModuleSet.class, "p1");
final Label label = j.jenkins.getLabel("label1");
project.setAssignedLabel(label);
j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get());

MavenModuleSet project2 = j.jenkins.createProject(MavenModuleSet.class, "p2");
project2.setAssignedLabel(label);
j.assertBuildStatus(Result.FAILURE, project2.scheduleBuild2(0).get());

label.reset(); // Make sure cached value is not used
assertEquals("Two jobs should be tied to this label.", 2, label.getTiedJobCount());
}

/**
* Verify that when a label is removed from a job that the tied job count does not include the
* removed job.
*/
@Issue("JENKINS-26391")
@Test
public void testGetAssignedLabelWhenLabelRemoveFromProject() throws Exception {
final Node node = j.createOnlineSlave();
node.setLabelString("label1");

MavenModuleSet project = j.jenkins.createProject(MavenModuleSet.class, "p");
final Label label = j.jenkins.getLabel("label1");
project.setAssignedLabel(label);
j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get());

project.setAssignedLabel(null);
label.reset(); // Make sure cached value is not used
assertEquals("Label1 should have no tied jobs after the job label was removed.", 0, label.getTiedJobCount());
}
}
Loading