Search in sources :

Example 1 with Bug

use of org.jvnet.hudson.test.Bug in project promoted-builds-plugin by jenkinsci.

the class SelfPromotionInheritanceTest method testPromotionEnvironmentShouldIncludeTargetParameters.

@Test
@Bug(22679)
public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception {
    String paramName = "param";
    InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase());
    inheritanceProjectPair.getBase().addProperty(promotion);
    // TODO review this property asignment after https://issues.jenkins-ci.org/browse/JENKINS-34831 is fixed
    inheritanceProjectPair.getBase().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
    inheritanceProjectPair.getDerived().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
    fireItemListeners();
    String paramValue = "someString";
    j.assertBuildStatusSuccess(inheritanceProjectPair.getDerived().scheduleBuild2(0, new Cause.UserCause(), new ParametersAction(new StringParameterValue(paramName, paramValue))));
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    j.waitUntilNoActivity();
    // rebind
    promotion = inheritanceProjectPair.getDerived().getProperty(JobPropertyImpl.class, /*Forcing inheritance as temporary hack for inheritance plugin 1.53 
                because that version of the plugin uses inheritance only for certain predefined cases: 
                -specific methods on the call stack
                -url paths.
                This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40
               */
    IMode.INHERIT_FORCED);
    promo1 = promotion.getItem("promo1");
    // verify that the promotion's environment contains the parameter from the target build.
    Promotion pb = promo1.getBuildByNumber(1);
    assertEquals(paramValue, pb.getEnvironment(TaskListener.NULL).get(paramName, null));
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) StringParameterValue(hudson.model.StringParameterValue) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test) Bug(org.jvnet.hudson.test.Bug)

Example 2 with Bug

use of org.jvnet.hudson.test.Bug in project promoted-builds-plugin by jenkinsci.

the class DownstreamPassConditionTest method shouldEvaluateUpstreamRecursively.

@Test
@Bug(7739)
public void shouldEvaluateUpstreamRecursively() throws Exception {
    final FreeStyleProject job1 = j.createFreeStyleProject("job1");
    final FreeStyleProject job2 = j.createFreeStyleProject("job2");
    final FreeStyleProject job3 = j.createFreeStyleProject("job3");
    final JobPropertyImpl property = new JobPropertyImpl(job1);
    job1.addProperty(property);
    final PromotionProcess process = property.addProcess("promotion");
    process.conditions.add(new DownstreamPassCondition(job3.getFullName()));
    job1.getPublishersList().add(new BuildTrigger(job2.getFullName(), Result.SUCCESS));
    job2.getPublishersList().add(new BuildTrigger(job3.getFullName(), Result.SUCCESS));
    j.jenkins.rebuildDependencyGraph();
    final FreeStyleBuild run1 = j.buildAndAssertSuccess(job1);
    j.waitUntilNoActivity();
    j.assertBuildStatusSuccess(job2.getLastBuild());
    j.waitUntilNoActivity();
    final FreeStyleBuild run3 = j.assertBuildStatusSuccess(job3.getLastBuild());
    j.waitUntilNoActivity();
    assertEquals("fingerprint relation", run3.getUpstreamRelationship(job1), -1);
    assertFalse("no promotion process", process.getBuilds().isEmpty());
    final PromotedBuildAction action = run1.getAction(PromotedBuildAction.class);
    assertNotNull("no promoted action", action);
    final Status promotion = action.getPromotion("promotion");
    assertNotNull("promotion not found", promotion);
    assertTrue("promotion not successful", promotion.isPromotionSuccessful());
}
Also used : Status(hudson.plugins.promoted_builds.Status) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) BuildTrigger(hudson.tasks.BuildTrigger) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Test(org.junit.Test) Bug(org.jvnet.hudson.test.Bug)

Example 3 with Bug

use of org.jvnet.hudson.test.Bug in project promoted-builds-plugin by jenkinsci.

the class DownstreamPassConditionInheritanceTest method shouldEvaluateUpstreamRecursively.

@Test
@Bug(7739)
public void shouldEvaluateUpstreamRecursively() throws Exception {
    final InheritanceProjectsPair pair1 = j.createInheritanceProjectDerivedWithBase();
    final InheritanceProjectsPair pair2 = j.createInheritanceProjectDerivedWithBase();
    final InheritanceProjectsPair pair3 = j.createInheritanceProjectDerivedWithBase();
    final JobPropertyImpl property = new JobPropertyImpl(pair1.getBase());
    pair1.getBase().addProperty(property);
    final PromotionProcess process = property.addProcess("promotion");
    process.conditions.add(new DownstreamPassCondition(pair3.getDerived().getFullName()));
    pair1.getDerived().getPublishersList().add(new BuildTrigger(pair2.getDerived().getFullName(), Result.SUCCESS));
    pair2.getDerived().getPublishersList().add(new BuildTrigger(pair3.getDerived().getFullName(), Result.SUCCESS));
    j.jenkins.rebuildDependencyGraph();
    final InheritanceBuild run1 = j.buildAndAssertSuccess(pair1.getDerived());
    j.assertBuildStatusSuccess(run1);
    j.waitUntilNoActivity();
    j.assertBuildStatusSuccess(pair2.getDerived().getLastBuild());
    j.waitUntilNoActivity();
    final InheritanceBuild run3 = j.assertBuildStatusSuccess(pair3.getDerived().getLastBuild());
    j.waitUntilNoActivity();
    //We cannot assume that the process will contain builds because the process added to base project is different to the one in derived. 
    JobPropertyImpl jobProperty = pair1.getDerived().getProperty(JobPropertyImpl.class, /*Forcing inheritance as temporary hack for inheritance plugin 1.53 
                because that version of the plugin uses inheritance only for certain predefined cases: 
                -specific methods on the call stack
                -url paths.
                This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40
               */
    IMode.INHERIT_FORCED);
    assertNotNull("derived jobProperty is null", jobProperty);
    PromotionProcess processDerived = jobProperty.getItem("promotion");
    assertEquals("fingerprint relation", run3.getUpstreamRelationship(pair1.getDerived()), -1);
    assertFalse("no promotion process", processDerived.getBuilds().isEmpty());
    final PromotedBuildAction action = run1.getAction(PromotedBuildAction.class);
    assertNotNull("no promoted action", action);
    final Status promotion = action.getPromotion("promotion");
    assertNotNull("promotion not found", promotion);
    assertTrue("promotion not successful", promotion.isPromotionSuccessful());
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) Status(hudson.plugins.promoted_builds.Status) InheritanceBuild(hudson.plugins.project_inheritance.projects.InheritanceBuild) DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) BuildTrigger(hudson.tasks.BuildTrigger) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Test(org.junit.Test) Bug(org.jvnet.hudson.test.Bug)

Example 4 with Bug

use of org.jvnet.hudson.test.Bug in project promoted-builds-plugin by jenkinsci.

the class ConfigurationDoCheckTest method testCheckProcessNameRequired.

@Bug(7972)
public void testCheckProcessNameRequired() throws Exception {
    FreeStyleProject down = createFreeStyleProject();
    FreeStyleProject p = createFreeStyleProject();
    JobPropertyImpl pp = new JobPropertyImpl(p);
    p.addProperty(pp);
    PromotionProcess proc = pp.addProcess("");
    assertEquals(1, pp.getItems().size());
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
    proc.icon = "star-blue";
    WebClient client = new WebClient();
    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = submit(client.getPage(p, "configure").getFormByName("config"));
    assertTrue(page.asText().contains("No name is specified"));
}
Also used : DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JavadocArchiver(hudson.tasks.JavadocArchiver) FreeStyleProject(hudson.model.FreeStyleProject) Bug(org.jvnet.hudson.test.Bug)

Example 5 with Bug

use of org.jvnet.hudson.test.Bug in project promoted-builds-plugin by jenkinsci.

the class ConfigurationDoCheckTest method testCheckInvalidProcessName.

@Bug(7972)
public void testCheckInvalidProcessName() throws Exception {
    FreeStyleProject down = createFreeStyleProject();
    FreeStyleProject p = createFreeStyleProject();
    JobPropertyImpl pp = new JobPropertyImpl(p);
    p.addProperty(pp);
    PromotionProcess proc = pp.addProcess("test/");
    assertEquals(1, pp.getItems().size());
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
    proc.icon = "star-blue";
    WebClient client = new WebClient();
    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = submit(client.getPage(p, "configure").getFormByName("config"));
    assertTrue(page.asText().contains("unsafe character"));
}
Also used : DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JavadocArchiver(hudson.tasks.JavadocArchiver) FreeStyleProject(hudson.model.FreeStyleProject) Bug(org.jvnet.hudson.test.Bug)

Aggregations

Bug (org.jvnet.hudson.test.Bug)8 FreeStyleProject (hudson.model.FreeStyleProject)5 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)4 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)4 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)3 Test (org.junit.Test)3 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 FreeStyleBuild (hudson.model.FreeStyleBuild)2 ParametersAction (hudson.model.ParametersAction)2 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)2 StringParameterDefinition (hudson.model.StringParameterDefinition)2 StringParameterValue (hudson.model.StringParameterValue)2 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)2 Promotion (hudson.plugins.promoted_builds.Promotion)2 Status (hudson.plugins.promoted_builds.Status)2 InheritanceProjectsPair (hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair)2 BuildTrigger (hudson.tasks.BuildTrigger)2 JavadocArchiver (hudson.tasks.JavadocArchiver)2 InheritanceBuild (hudson.plugins.project_inheritance.projects.InheritanceBuild)1 SelfPromotionCondition (hudson.plugins.promoted_builds.conditions.SelfPromotionCondition)1