Skip to content

Commit

Permalink
[JENKINS-28113] Integration test of BuildTrigger with WorkflowJob dow…
Browse files Browse the repository at this point in the history
…nstream.
  • Loading branch information
jglick committed May 5, 2017
1 parent 20546ec commit f4e8795
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -62,8 +62,8 @@
</pluginRepository>
</pluginRepositories>
<properties>
<jenkins-core.version>2.59-20170505.181537-3</jenkins-core.version> <!-- TODO https://github.com/jenkinsci/jenkins/pull/2866 -->
<jenkins-war.version>2.59-20170505.181558-3</jenkins-war.version>
<jenkins-core.version>2.59-20170505.212130-4</jenkins-core.version> <!-- TODO https://github.com/jenkinsci/jenkins/pull/2873 -->
<jenkins-war.version>2.59-20170505.212307-4</jenkins-war.version>
<java.level>8</java.level>
<no-test-jar>false</no-test-jar>
<workflow-support-plugin.version>2.2</workflow-support-plugin.version>
Expand Down
@@ -0,0 +1,68 @@
/*
* The MIT License
*
* Copyright 2017 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 org.jenkinsci.plugins.workflow.job;

import hudson.model.Cause;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.tasks.BuildTrigger;
import hudson.util.FormValidation;
import java.util.Collections;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import static org.junit.Assert.*;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

public class BuildTriggerTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule r = new JenkinsRule();

@Issue("JENKINS-28113")
@Test public void smokes() throws Exception {
BuildTrigger.DescriptorImpl d = r.jenkins.getDescriptorByType(BuildTrigger.DescriptorImpl.class);
FreeStyleProject us = r.createProject(FreeStyleProject.class, "us");
WorkflowJob ds = r.createProject(WorkflowJob.class, "ds");
ds.setDefinition(new CpsFlowDefinition("", true));
assertEquals(Collections.singletonList("ds"), d.doAutoCompleteChildProjects("d", us, r.jenkins).getValues());
FormValidation validation = d.doCheck(us, "ds");
assertEquals(validation.renderHtml(), FormValidation.Kind.OK, validation.kind);
us.getPublishersList().add(new BuildTrigger("ds", Result.SUCCESS));
r.jenkins.setQuietPeriod(0);
FreeStyleBuild us1 = r.buildAndAssertSuccess(us);
r.waitUntilNoActivity();
WorkflowRun ds1 = ds.getLastBuild();
assertNotNull("triggered", ds1);
Cause.UpstreamCause cause = ds1.getCause(Cause.UpstreamCause.class);
assertNotNull(cause);
assertEquals(us1, cause.getUpstreamRun());
}

}
Expand Up @@ -29,12 +29,9 @@
import hudson.model.Result;
import jenkins.triggers.ReverseBuildTrigger;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.BuildWatcher;
Expand All @@ -48,11 +45,11 @@ public class ReverseBuildTriggerTest {
@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();

@Ignore("TODO fails prior to 1.656")
@Issue("JENKINS-33971")
@Test public void upstreamMapRebuilding() throws Exception {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
story.j.jenkins.setQuietPeriod(0);
WorkflowJob us = story.j.jenkins.createProject(WorkflowJob.class, "us");
us.setDefinition(new CpsFlowDefinition(""));
us.addProperty(new SlowToLoad()); // force it to load after ds when we restart
Expand Down

0 comments on commit f4e8795

Please sign in to comment.