use of com.gargoylesoftware.htmlunit.html.HtmlTextArea in project workflow-cps-plugin by jenkinsci.
the class ReplayActionTest method editSimpleDefinition.
@Test
public void editSimpleDefinition() throws Exception {
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'first script'", false));
// Start off with a simple run of the first script.
WorkflowRun b1 = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("first script", b1);
// Now will replay with a second script.
WorkflowRun b2;
{
// First time around, verify that UI elements are present and functional.
ReplayAction a = b1.getAction(ReplayAction.class);
assertNotNull(a);
assertTrue(a.isEnabled());
HtmlPage page = story.j.createWebClient().getPage(b1, a.getUrlName());
HtmlForm form = page.getFormByName("config");
HtmlTextArea text = form.getTextAreaByName("_.mainScript");
assertEquals("echo 'first script'", text.getText());
text.setText("echo 'second script'");
// TODO loaded scripts
HtmlPage redirect = story.j.submit(form);
assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString());
story.j.waitUntilNoActivity();
b2 = p.getBuildByNumber(2);
assertNotNull(b2);
}
// Subsequently can use the faster whitebox method.
story.j.assertLogContains("second script", story.j.assertBuildStatusSuccess(b2));
ReplayCause cause = b2.getCause(ReplayCause.class);
assertNotNull(cause);
assertEquals(1, cause.getOriginalNumber());
assertEquals(b1, cause.getOriginal());
assertEquals(b2, cause.getRun());
// Replay #2 as #3. Note that the diff is going to be from #1 → #3, not #2 → #3.
WorkflowRun b3 = (WorkflowRun) b2.getAction(ReplayAction.class).run("echo 'third script'", Collections.<String, String>emptyMap()).get();
story.j.assertLogContains("third script", story.j.assertBuildStatusSuccess(b3));
String diff = b3.getAction(ReplayAction.class).getDiff();
assertThat(diff, containsString("-echo 'first script'"));
assertThat(diff, containsString("+echo 'third script'"));
System.out.println(diff);
// Make a persistent edit to the script and run, just to make sure there is no lingering effect.
p.setDefinition(new CpsFlowDefinition("echo 'fourth script'", false));
story.j.assertLogContains("fourth script", story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
});
}
Aggregations