Skip to content

Commit

Permalink
Merge pull request #282 from varyvol/JENKINS-42581
Browse files Browse the repository at this point in the history
[JENKINS-42581] Introduce method to trigger a re-index
  • Loading branch information
olivergondza committed Mar 15, 2017
2 parents 73a7bdc + be0ea7f commit cabefea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/main/java/org/jenkinsci/test/acceptance/po/Folder.java
Expand Up @@ -39,8 +39,6 @@
@Describable("com.cloudbees.hudson.plugins.folder.Folder")
public class Folder extends TopLevelItem implements Container {

private static final String ALL_VIEW = "All";

private final JobsMixIn jobs;
private final ViewsMixIn views;
private final Control properties = control("/com-cloudbees-hudson-plugins-folder-properties-EnvVarsFolderProperty/properties");
Expand Down Expand Up @@ -106,25 +104,34 @@ public String getActiveViewName() {

public <T extends View> T selectView(final Class<T> type, final String viewName) {
final List<WebElement> viewTabs = this.getViewTabs();
int i = 0;

for (final WebElement tab : viewTabs) {
if (tab.getText().equals(viewName)) {
tab.click();

if (ALL_VIEW.equals(viewName)) {
if (i == 0) {
// First tab redirects to Folder's home page
return null;
} else {
return newInstance(type, injector, url("view/%s/", viewName));
}
}

i++;
}

throw new NoSuchElementException(String.format("There is no view with name [%s]", viewName));
}

private List<WebElement> getViewTabs() {
final List<WebElement> viewTabs = driver.findElements(viewTab);
viewTabs.remove(viewTabs.size() - 1); // add new view tab

final int lastViewIndex = viewTabs.size() - 1;

if ("+".equals(viewTabs.get(lastViewIndex).getText())) {
viewTabs.remove(lastViewIndex);
}

return viewTabs;
}
Expand Down
Expand Up @@ -2,13 +2,15 @@

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.IOUtils;
import org.jenkinsci.test.acceptance.plugins.workflow_multibranch.BranchSource;

import com.google.inject.Injector;
import org.openqa.selenium.WebElement;

/**
* A pipeline multi-branch job (requires installation of multi-branch-project-plugin).
Expand Down Expand Up @@ -58,4 +60,17 @@ public WorkflowJob getJob(final String name) {
return this.getJobs().get(WorkflowJob.class, name);
}

public void reIndex() {
final List<WebElement> scanRepoNow = driver.findElements(by.xpath("//div[@class=\"task\"]//*[text()=\"Scan Repository Now\"]"));

if (scanRepoNow.size() > 0) {
// JENKINS-41416
scanRepoNow.get(0).click();
} else {
// Previous versions
find(by.xpath("//div[@class=\"task\"]//*[text()=\"Scan Repository\" or text()=\"Branch Indexing\"]")).click();
find(by.xpath("//div[@class=\"subtasks\"]//*[text()=\"Run Now\"]")).click();
}
}

}
9 changes: 8 additions & 1 deletion src/test/java/plugins/WorkflowMultibranchTest.java
Expand Up @@ -46,6 +46,13 @@ public void testMultibranchPipeline() throws IOException, MessagingException {
final WorkflowJob failureJob = multibranchJob.getJob("jenkinsfile_failure");
this.assertExistAndRun(successJob, true);
this.assertExistAndRun(failureJob, false);

multibranchJob.open();
multibranchJob.reIndex();
multibranchJob.waitForBranchIndexingFinished(20);

this.assertExistAndRun(successJob, true);
this.assertExistAndRun(failureJob, false);
}

private void configureJobWithGithubBranchSource(final WorkflowMultiBranchJob job) {
Expand All @@ -55,7 +62,7 @@ private void configureJobWithGithubBranchSource(final WorkflowMultiBranchJob job
}

private void assertBranchIndexing(final WorkflowMultiBranchJob job) {
assertThat(job, anyOf(/* 1.x */hasAction("Branch Indexing"), /* 2.x */hasAction("Scan Repository")));
assertThat(job, anyOf(/* 1.x */hasAction("Branch Indexing"), /* 2.x */hasAction("Scan Repository"), /* 2.1.0 */hasAction("Scan Repository Now")));

final String branchIndexingLog = job.getBranchIndexingLog();

Expand Down

0 comments on commit cabefea

Please sign in to comment.