Skip to content
Permalink
Browse files
Merge pull request #186 from mafraba/JENKINS-38058
[JENKINS-38058] pass context when creating 'FolderItem' objects
  • Loading branch information
olivergondza committed Sep 13, 2016
2 parents 7d482f4 + b26cce4 commit 002b21349a9cad8e478e7d44f665517db12a370c
@@ -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);
}

}
@@ -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();

@@ -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;
@@ -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);
}
@@ -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;
}
}
@@ -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.

0 comments on commit 002b213

Please sign in to comment.