Skip to content

Commit

Permalink
Merge pull request #210 from Vlatombe/JENKINS-38928
Browse files Browse the repository at this point in the history
[JENKINS-38928] Add a test doing apply then save in a job
  • Loading branch information
Vlatombe committed Nov 4, 2016
2 parents fdd33e1 + 057ae2f commit 5f4c2b8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
20 changes: 20 additions & 0 deletions pom.xml
Expand Up @@ -743,6 +743,26 @@
</plugins>
</build>
</profile>
<profile>
<id>FORM_ELEMENT_PATH_VERSION</id>
<activation>
<property>
<name>FORM_ELEMENT_PATH_VERSION</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<environmentVariables>
<FORM_ELEMENT_PATH_VERSION>${FORM_ELEMENT_PATH_VERSION}</FORM_ELEMENT_PATH_VERSION>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- TODO could be laboriously repeated for $TYPE, etc. (seems Maven provides no generic way to do this) -->

<profile>
Expand Down
Expand Up @@ -251,7 +251,9 @@ public Jenkins createJenkins(Injector injector, JenkinsController controller) {
@Named("form-element-path.hpi") @Provides
public File getFormElementsPathFile(RepositorySystem repositorySystem, RepositorySystemSession repositorySystemSession) {
ArtifactResolverUtil resolverUtil = new ArtifactResolverUtil(repositorySystem, repositorySystemSession);
ArtifactResult resolvedArtifact = resolverUtil.resolve(new DefaultArtifact("org.jenkins-ci.plugins", "form-element-path", "hpi", "1.7"));
String version = System.getenv("FORM_ELEMENT_PATH_VERSION");
version = version == null ? "1.8" : version;
ArtifactResult resolvedArtifact = resolverUtil.resolve(new DefaultArtifact("org.jenkins-ci.plugins", "form-element-path", "hpi", version));
return resolvedArtifact.getArtifact().getFile();
}

Expand Down
Expand Up @@ -23,11 +23,14 @@
*/
package org.jenkinsci.test.acceptance.po;

import com.google.common.base.Predicate;
import com.google.inject.Injector;
import groovy.lang.Closure;
import org.openqa.selenium.WebDriver;

import java.net.URL;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
Expand Down Expand Up @@ -95,4 +98,9 @@ public void save() {
clickButton("Save");
assertThat(driver, not(hasContent("This page expects a form submission")));
}

public void apply() {
clickButton("Apply");
waitFor(driver, hasContent("Saved"), 5);
}
}
32 changes: 32 additions & 0 deletions src/test/java/core/FreestyleJobTest.java
@@ -0,0 +1,32 @@
package core;

import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.ShellBuildStep;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

import static org.jenkinsci.test.acceptance.Matchers.pageObjectExists;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class FreestyleJobTest extends AbstractJUnitTest {

@Test
@Issue("JENKINS-38928")
public void apply_then_save() {
FreeStyleJob j = jenkins.jobs.create(FreeStyleJob.class, "simple-job");
assertThat(j, pageObjectExists());

j.configure();
ShellBuildStep shell = j.addBuildStep(ShellBuildStep.class);
shell.command("echo 1");

j.apply();
j.save();

j.visit("config.xml");

assertTrue("job config.xml should contain the step \"echo 1\"",driver.getPageSource().contains("echo 1"));
}
}

0 comments on commit 5f4c2b8

Please sign in to comment.