Skip to content
Permalink
Browse files
JENKINS-40707
updated constructors, as well as sample pipeline script
  • Loading branch information
prospero238 committed Dec 30, 2016
1 parent 9b66382 commit f87003e755e5b711aa1b099b86941c51f83024f0
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 12 deletions.
@@ -1,11 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.9</version>
<relativePath />
<relativePath/>
</parent>
<artifactId>liquibase-runner</artifactId>
<version>1.2.0-SNAPSHOT</version>
@@ -36,6 +36,7 @@ public class ChangesetEvaluator extends AbstractLiquibaseBuilder {
private boolean dropAll;
protected boolean tagOnSuccessfulBuild;

@DataBoundConstructor
public ChangesetEvaluator() {
super();
}
@@ -89,7 +90,6 @@ public void runPerform(Run<?, ?> build,

}

@DataBoundConstructor
public ChangesetEvaluator(String databaseEngine,
String changeLogFile,
String url,
@@ -39,16 +39,15 @@ public class RollbackBuildStep extends AbstractLiquibaseBuilder {
private String rollbackToTag;
private String rollbackToDate;


private SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN);

public enum RollbackStrategy {
TAG, DATE, RELATIVE, COUNT
}

@DataBoundConstructor
public RollbackBuildStep() {


}

@Override
@@ -95,7 +94,7 @@ public void runPerform(Run<?, ?> build,
action.setRolledbackChangesets(executedChangesetAction.getRolledBackChangesets());
}

@DataBoundConstructor

public RollbackBuildStep(String databaseEngine,
String changeLogFile,
String username,
@@ -0,0 +1,88 @@
package org.jenkinsci.plugins.liquibase.integration;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement;

public class EvaluatorInPipelineTest {
private static final Logger LOG = LoggerFactory.getLogger(EvaluatorInPipelineTest.class);

@Rule
public JenkinsRule jenkinsRule = new JenkinsRule();
protected JenkinsRule.WebClient webClient;
protected String pipelineScript;

@Before
public void setup() throws IOException {
webClient = jenkinsRule.createWebClient();

InputStream resourceAsStream = getClass().getResourceAsStream("/sample-pipline.groovy");
pipelineScript = IOUtils.toString(resourceAsStream);
}

@Ignore("can't get the damn webclient to submit form. Think i'll use selenium instead")
@Test
public void should_allow_pipeline() throws IOException, SAXException {

URL url = jenkinsRule.getURL();

LOG.debug("jenkins url: {} ", url.toString());

HtmlPage newJobPage = webClient.goTo("newJob");
HtmlForm createItem = newJobPage.getFormByName("createItem");
HtmlInput nameInput = createItem.getInputsByName("name").get(0);
String jobName = RandomStringUtils.randomAlphabetic(5);
nameInput.type(jobName);

List<HtmlRadioButtonInput> modes = createItem.getRadioButtonsByName("mode");

LOG.debug("mode buttons size:{}", modes.size());

modes.get(1).setChecked(true);

newJobPage.getElementById("ok-button").click();

HtmlPage configurationPage = webClient.goTo("job/" + jobName + "/configure");


LOG.debug("configuration URL:{}", configurationPage.getUrl().toString());

HtmlElement editor = configurationPage.getFirstByXPath("//div[@id='workflow-editor-1']");

LOG.debug("editor:{}", editor);


List textareas = configurationPage.getByXPath("//textarea");
HtmlTextArea scriptInput = (HtmlTextArea) textareas.get(textareas.size() - 1);
scriptInput.type(pipelineScript);

((HTMLElement) configurationPage.getFirstByXPath("//span[@name='Submit']")).click();






}

}
@@ -1,9 +1,7 @@


node {
stage('build') {
liquibaseUpdate(changeLogFile: "changeset.xml")
}
ws('/home/keith/projects/liquibase-runner-plugin/src/test/resources/example-changesets') {
// liquibaseUpdate()
step([$class: 'ChangesetEvaluator', changeLogFile: 'sunny-day-changeset.xml', testRollbacks: true])
}
}

0 comments on commit f87003e

Please sign in to comment.