Skip to content

Commit

Permalink
[JENKINS-38058] pass context when creating 'FolderItem' objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Franco committed Sep 8, 2016
1 parent 19aca5e commit 7454e77
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
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
Expand Up @@ -58,7 +58,14 @@ public Object call() throws Exception {
}

public <T extends TopLevelItem> T get(Class<T> type, String name) {
return newInstance(type, injector, url("job/%s/", name), name);
try {
assert getContext() != null;
return newInstance(type, getContext(), url("job/%s/", name), name);
} catch (AssertionError e) {
// will get here either if the contructor with 'context' parameter
// was not found or if we have no context
return newInstance(type, injector, url("job/%s/", name), name);
}
}

public FreeStyleJob create() {
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 7454e77

Please sign in to comment.