Skip to content

Commit

Permalink
Merge pull request #186 from mafraba/JENKINS-38058
Browse files Browse the repository at this point in the history
[JENKINS-38058] pass context when creating 'FolderItem' objects
  • Loading branch information
olivergondza committed Sep 13, 2016
2 parents 7d482f4 + b26cce4 commit 002b213
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
Expand Up @@ -39,5 +39,10 @@ public FolderItem(Injector injector, URL url, String name) {
super(injector, url, name);
jobs = new JobsMixIn(this);
}

public FolderItem(PageObject context, URL url, String name) {
super(context, url, name);
jobs = new JobsMixIn(this);
}

}
4 changes: 4 additions & 0 deletions src/main/java/org/jenkinsci/test/acceptance/po/Job.java
Expand Up @@ -65,6 +65,10 @@ public Job(Injector injector, URL url, String name) {
super(injector, url, name);
}

public Job(PageObject context, URL url, String name) {
super(context, url, name);
}

public <T extends Scm> T useScm(Class<T> type) {
ensureConfigPage();

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/jenkinsci/test/acceptance/po/JobsMixIn.java
@@ -1,5 +1,6 @@
package org.jenkinsci.test.acceptance.po;

import java.net.URL;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
Expand Down Expand Up @@ -58,9 +59,25 @@ public Object call() throws Exception {
}

public <T extends TopLevelItem> T get(Class<T> type, String name) {
if (contextAvailable() && typeAcceptsContext(type)) {
return newInstance(type, getContext(), url("job/%s/", name), name);
}
return newInstance(type, injector, url("job/%s/", name), name);
}

private <T extends TopLevelItem> boolean typeAcceptsContext(Class<T> type) {
try {
type.getConstructor(PageObject.class, URL.class, String.class);
return true;
} catch (NoSuchMethodException e) {
return false;
}
}

private boolean contextAvailable() {
return getContext() != null;
}

public FreeStyleJob create() {
return create(FreeStyleJob.class);
}
Expand Down
Expand Up @@ -115,4 +115,8 @@ public Control control(By selector) {
public String toString() {
return String.format("%s(%s)", getClass().getSimpleName(), url);
}

protected PageObject getContext() {
return context;
}
}
Expand Up @@ -28,6 +28,11 @@ public TopLevelItem(Injector injector, URL url, String name) {
this.name = name;
}

public TopLevelItem(PageObject context, URL url, String name) {
super(context, url);
this.name = name;
}

/**
* Renames the job. Opens the configuration section, sets the name and saves the form. Finally the rename is
* confirmed.
Expand Down

0 comments on commit 002b213

Please sign in to comment.