Search in sources :

Example 21 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project promoted-builds-plugin by jenkinsci.

the class PromotedBuildRebuildParameterProviderTest method testRebuild.

@Test
public void testRebuild() throws Exception {
    // job with promotion process
    FreeStyleProject p1 = j.createFreeStyleProject("promojob");
    // setup promotion process
    JobPropertyImpl promotion = new JobPropertyImpl(p1);
    p1.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new SelfPromotionCondition(false));
    // build it
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p1.scheduleBuild2(0));
    j.waitUntilNoActivity();
    // verify that promotion happened
    Assert.assertSame(proc.getBuilds().getLastBuild().getTargetBuildOrFail(), b1);
    // job with parameter
    FreeStyleProject p2 = j.createFreeStyleProject("paramjob");
    // add promoted build param
    p2.addProperty(new ParametersDefinitionProperty(new PromotedBuildParameterDefinition("var", "promojob", "promo", "promoted build param to test rebuild")));
    // build with parameter
    FreeStyleBuild b2 = j.assertBuildStatusSuccess(p2.scheduleBuild2(0));
    // validate presence of parameter
    ParametersAction a1 = b2.getAction(ParametersAction.class);
    Assert.assertNotNull(a1);
    Assert.assertFalse(a1.getParameters().isEmpty());
    ParameterValue v1 = a1.getParameter("var");
    Assert.assertTrue(v1 instanceof PromotedBuildParameterValue);
    PromotedBuildParameterValue pbpv1 = (PromotedBuildParameterValue) v1;
    Assert.assertEquals(b1.getNumber(), pbpv1.getRun().getNumber());
    // rebuild it
    JenkinsRule.WebClient wc = j.createWebClient();
    HtmlPage page = wc.getPage(b2, "rebuild");
    HtmlForm form = page.getFormByName("config");
    j.submit(form);
    j.waitUntilNoActivity();
    // validate presence of parameter
    FreeStyleBuild rebuild = p2.getLastBuild();
    j.assertBuildStatusSuccess(rebuild);
    Assert.assertNotEquals(b2.getNumber(), rebuild.getNumber());
    ParametersAction a2 = rebuild.getAction(ParametersAction.class);
    Assert.assertNotNull(a2);
    Assert.assertFalse(a2.getParameters().isEmpty());
    ParameterValue v2 = a2.getParameter("var");
    Assert.assertTrue(v2 instanceof PromotedBuildParameterValue);
    PromotedBuildParameterValue pbpv2 = (PromotedBuildParameterValue) v2;
    Assert.assertEquals(b1.getNumber(), pbpv2.getRun().getNumber());
}
Also used : PromotedBuildParameterValue(hudson.plugins.promoted_builds.parameters.PromotedBuildParameterValue) PromotedBuildParameterValue(hudson.plugins.promoted_builds.parameters.PromotedBuildParameterValue) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) PromotedBuildParameterDefinition(hudson.plugins.promoted_builds.parameters.PromotedBuildParameterDefinition) Test(org.junit.Test)

Aggregations

HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)21 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)20 Test (org.junit.Test)14 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)7 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)5 WebClient (com.gargoylesoftware.htmlunit.WebClient)4 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)4 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)4 Page (com.gargoylesoftware.htmlunit.Page)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)3 Descriptor (hudson.model.Descriptor)3 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)3 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)3 Issue (org.jvnet.hudson.test.Issue)3 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)3 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)2 WebClientOptions (com.gargoylesoftware.htmlunit.WebClientOptions)2 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)2 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)2 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)2