Skip to content

Commit

Permalink
Merge pull request #200 from raul-arabaolaza/JENKINS-38788
Browse files Browse the repository at this point in the history
[JENKINS-37276] Path atributes can change values if reordered
  • Loading branch information
olivergondza committed Oct 20, 2016
2 parents f21bd79 + f1d6c7d commit 59e2288
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
Expand Up @@ -251,7 +251,7 @@ 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.4"));
ArtifactResult resolvedArtifact = resolverUtil.resolve(new DefaultArtifact("org.jenkins-ci.plugins", "form-element-path", "hpi", "1.7-alpha-1"));
return resolvedArtifact.getArtifact().getFile();
}

Expand Down
26 changes: 23 additions & 3 deletions src/main/java/org/jenkinsci/test/acceptance/po/Job.java
Expand Up @@ -128,11 +128,31 @@ public <T extends PostBuildStep> T getPublisher(Class<T> type) {
private <T extends Step> T addStep(Class<T> type, String section) {
ensureConfigPage();

// get @Describable value to use later to retrieve the path
String[] describableValue = null;
if (type.isAnnotationPresent(Describable.class)) {
describableValue = type.getAnnotation(Describable.class).value();
}
control(by.path("/hetero-list-add[%s]", section)).selectDropdownMenu(type);
elasticSleep(1000); // it takes some time until the element is visible
WebElement last = last(by.xpath("//div[@name='%s']", section));
String path = last.getAttribute("path");

String path = null;
// if I have got a Describable use it to get the path
if (describableValue != null && PostBuildStep.class.isAssignableFrom(type)) {
List<WebElement> newSteps = driver.findElements(by.xpath("//div[@name='%s']", section));
outer:
for (WebElement element : newSteps) {
for (String s : describableValue) {
if (element.getText().contains(s)) {
path = element.getAttribute("path");
break outer;
}
}
}
} else {
// on the other case just use the last element
WebElement last = last(by.xpath("//div[@name='%s']", section));
path = last.getAttribute("path");
}
return newInstance(type, this, path);
}

Expand Down
61 changes: 61 additions & 0 deletions src/test/java/core/PublisherOrderTest.java
@@ -0,0 +1,61 @@
package core;

import org.apache.commons.lang.SystemUtils;
import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest;
import org.jenkinsci.test.acceptance.po.AggregateDownstreamTestResults;
import org.jenkinsci.test.acceptance.po.ArtifactArchiver;
import org.jenkinsci.test.acceptance.po.BuildTrigger;
import org.jenkinsci.test.acceptance.po.Fingerprint;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.JUnitPublisher;
import org.junit.Test;

public class PublisherOrderTest extends AbstractJUnitTest {

@Test
public void testOrdered() {
FreeStyleJob upstream = jenkins.jobs.create(FreeStyleJob.class);
upstream.configure();
String command = "echo 'hello' > aggregate.txt";
if(SystemUtils.IS_OS_UNIX) {
upstream.addShellStep(command);
} else {
upstream.addBatchStep(command);
}
AggregateDownstreamTestResults aggregate = upstream.addPublisher(AggregateDownstreamTestResults.class);
aggregate.specify.check();
ArtifactArchiver archiver = upstream.addPublisher(ArtifactArchiver.class);
archiver.includes("aggregate.txt");
BuildTrigger trigger = upstream.addPublisher(BuildTrigger.class);
trigger.childProjects.set("projectName");
Fingerprint fingerprint = upstream.addPublisher(Fingerprint.class);
fingerprint.targets.set("aggregate.txt");
upstream.save();
}

@Test
public void testUnordered() {
FreeStyleJob upstream = jenkins.jobs.create(FreeStyleJob.class);
upstream.configure();
String command = "echo 'hello' > aggregate.txt";
if(SystemUtils.IS_OS_UNIX) {
upstream.addShellStep(command);
} else {
upstream.addBatchStep(command);
}
ArtifactArchiver archiver = upstream.addPublisher(ArtifactArchiver.class);
archiver.includes("aggregate.txt");
BuildTrigger trigger = upstream.addPublisher(BuildTrigger.class);
trigger.childProjects.set("projectName");
Fingerprint fingerprint = upstream.addPublisher(Fingerprint.class);
fingerprint.targets.set("aggregate.txt");
AggregateDownstreamTestResults aggregate = upstream.addPublisher(AggregateDownstreamTestResults.class);
aggregate.specify.check();
fingerprint.targets.set("another.txt");
upstream.save();
upstream.configure();
archiver.includes("another.txt");
JUnitPublisher junit = upstream.addPublisher(JUnitPublisher.class);
fingerprint.targets.set("yetanother");
}
}

0 comments on commit 59e2288

Please sign in to comment.