Skip to content
Permalink
Browse files

[FIXED JENKINS-46082] API will include culprits again.

(cherry picked from commit a975f72)
  • Loading branch information
abayer authored and olivergondza committed Sep 4, 2017
1 parent 69828cd commit 69d8fe47ff9d60cd885aaeb3e0b91b4fcfe6ba6e
@@ -324,6 +324,12 @@ public final FilePath getModuleRoot() {
return culprits;
}

@Override
@Exported
@Nonnull public Set<User> getCulprits() {
return RunWithSCM.super.getCulprits();
}

@Override
public boolean shouldCalculateCulprits() {
return getCulpritIds() == null;
@@ -24,6 +24,7 @@
package hudson.model;

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebResponse;
import hudson.EnvVars;
import hudson.Launcher;
import hudson.model.queue.QueueTaskFuture;
@@ -43,6 +44,8 @@
import hudson.tasks.LogRotatorTest;
import hudson.tasks.Recorder;
import hudson.util.OneShotEvent;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.CaptureEnvironmentBuilder;
@@ -53,6 +56,7 @@
import org.jvnet.hudson.test.TestBuilder;
import org.jvnet.hudson.test.TestExtension;
import org.jvnet.hudson.test.UnstableBuilder;
import org.xml.sax.SAXException;

/**
* Unit tests of {@link AbstractBuild}.
@@ -125,12 +129,31 @@ public void rawConsoleOutput() throws Exception {
assertThat(rsp.getWebResponse().getContentAsString(), containsString(out));
}

private void assertCulprits(AbstractBuild<?,?> b, String... expectedIds) {
private void assertCulprits(AbstractBuild<?,?> b, String... expectedIds) throws IOException, SAXException {
Set<String> actual = new TreeSet<>();
for (User u : b.getCulprits()) {
actual.add(u.getId());
}
assertEquals(actual, new TreeSet<>(Arrays.asList(expectedIds)));

if (expectedIds.length > 0) {
JenkinsRule.WebClient wc = j.createWebClient();
WebResponse response = wc.goTo(b.getUrl() + "api/json?tree=culprits[id]", "application/json").getWebResponse();
JSONObject json = JSONObject.fromObject(response.getContentAsString());

Object culpritsArray = json.get("culprits");
assertNotNull(culpritsArray);
assertTrue(culpritsArray instanceof JSONArray);
Set<String> fromApi = new TreeSet<>();
for (Object o : ((JSONArray)culpritsArray).toArray()) {
assertTrue(o instanceof JSONObject);
Object id = ((JSONObject)o).get("id");
if (id instanceof String) {
fromApi.add((String)id);
}
}
assertEquals(fromApi, new TreeSet<>(Arrays.asList(expectedIds)));
}
}

@Test

0 comments on commit 69d8fe4

Please sign in to comment.
You can’t perform that action at this time.