Skip to content
Permalink
Browse files

JENKINS-43538 API change: remove getTestUrl (#13)

  • Loading branch information...
i386 committed Apr 13, 2017
1 parent e4914ab commit c45806f45c16b51af889e0de40e185710460a0e5
@@ -9,7 +9,7 @@
<relativePath />
</parent>
<artifactId>display-url-api</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<packaging>hpi</packaging>

<properties>
@@ -58,11 +58,6 @@
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
@@ -4,9 +4,6 @@
import hudson.Util;
import hudson.model.Job;
import hudson.model.Run;
import hudson.tasks.junit.TestResult;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.TestObject;

/**
* Display URL Provider for the Classical Jenkins UI
@@ -33,34 +30,4 @@ public String getChangesURL(Run<?, ?> run) {
public String getJobURL(Job<?, ?> job) {
return getRoot() + Util.encode(job.getUrl());
}

@Override
public String getTestUrl(hudson.tasks.test.TestResult result) {
String buildUrl = getRunURL(result.getRun());
AbstractTestResultAction action = result.getTestResultAction();

TestObject parent = result.getParent();
TestResult testResultRoot = null;
while(parent != null) {
if (parent instanceof TestResult) {
testResultRoot = (TestResult) parent;
break;
}
parent = parent.getParent();
}

String testUrl = action.getUrlName()
+ (testResultRoot != null ? testResultRoot.getUrl() : "")
+ result.getUrl();

String[] pathComponents = testUrl.split("/");
StringBuilder buf = new StringBuilder();
for (String c : pathComponents) {
buf.append(Util.rawEncode(c)).append('/');
}
// remove last /
buf.deleteCharAt(buf.length() - 1);

return buildUrl + buf.toString();
}
}
@@ -3,7 +3,6 @@
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.ExtensionPoint;
import hudson.Util;
import hudson.model.Job;
@@ -71,14 +70,6 @@ public String getDisplayName() {
/** Fully qualified URL for a Jobs home */
public abstract String getJobURL(Job<?, ?> job);

/** Fully qualified URL to the test details page for a given test result */
public abstract String getTestUrl(hudson.tasks.test.TestResult result);

/** Fully qualified URL to the test details page for a given test result. Alternate name for consistency. See JENKINS-41802. */
public String getTestURL(hudson.tasks.test.TestResult result) {
return getTestUrl(result);
}

static class DisplayURLProviderImpl extends ClassicDisplayURLProvider {

public static final DisplayURLProvider INSTANCE = new DisplayURLProviderImpl();
@@ -99,13 +90,6 @@ public String getChangesURL(Run<?, ?> run) {
public String getJobURL(Job<?, ?> job) {
return super.getJobURL(job) + DISPLAY_POSTFIX;
}

@Override
@SuppressFBWarnings(value = "NM_VERY_CONFUSING", justification = "getTestURL was introduced for consistency")
public String getTestUrl(hudson.tasks.test.TestResult result) {
Run<?, ?> run = result.getRun();
return super.getRunURL(run) + DISPLAY_POSTFIX + "?page=test&id=" + Util.rawEncode(result.getId());
}
}

private static String findClass() {
@@ -4,8 +4,6 @@
import hudson.Extension;
import hudson.model.Action;
import hudson.model.Run;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.TestResult;
import jenkins.model.TransientActionFactory;
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
import org.kohsuke.stapler.Stapler;
@@ -28,17 +26,6 @@ protected String getRedirectURL(DisplayURLProvider provider) {
String url;
if ("changes".equals(page)) {
url = provider.getChangesURL(run);
} else if ("test".equals(page)) {
String id = req.getParameter("id");
if (id == null) {
throw new IllegalArgumentException("id parameter not specified");
}
AbstractTestResultAction action = run.getAction(AbstractTestResultAction.class);
if (action == null) {
throw new IllegalStateException("No AbstractTestResultAction on this run");
}
TestResult result = action.findCorrespondingResult(id);
url = provider.getTestUrl(result);
} else {
url = provider.getRunURL(run);
}
@@ -3,17 +3,11 @@
import hudson.EnvVars;
import hudson.model.FreeStyleProject;
import hudson.model.Run;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.TestObject;
import hudson.tasks.test.TestResult;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.MockFolder;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class DisplayURLProviderTest {

@@ -37,55 +31,4 @@ public void urls() throws Exception {
assertEquals(DisplayURLProvider.get().getChangesURL(run), environment.get("RUN_CHANGES_DISPLAY_URL"));
assertEquals(DisplayURLProvider.get().getJobURL(project), environment.get("JOB_DISPLAY_URL"));
}

@Test
public void testGetTestURL() throws Exception {

MockFolder folder = rule.createFolder("my folder");
FreeStyleProject project = (FreeStyleProject) folder.createProject(rule.jenkins.getDescriptorByType(FreeStyleProject.DescriptorImpl.class), "my job", false);
Run<?, ?> run = project.scheduleBuild2(0).get();
MockTestResult result = new MockTestResult(run);

AbstractTestResultAction action = mock(AbstractTestResultAction.class);
when(action.getUrlName()).thenReturn("action");
when(action.findCorrespondingResult(anyString())).thenReturn(result);

String testUrl = DisplayURLProvider.get().getTestUrl(result);

assertEquals("http://localhost:" + rule.getLocalPort() + "/jenkins/job/my%20folder/job/my%20job/1/display/redirect?page=test&id=some%20id%20with%20spaces", testUrl);
}

class MockTestResult extends TestResult {

private final Run<?, ?> owner;

public MockTestResult(Run<?, ?> owner) {
this.owner = owner;
}

@Override
public String getName() {
return "some id with spaces";
}

@Override
public Run<?, ?> getRun() {
return owner;
}

@Override
public TestObject getParent() {
return null;
}

@Override
public TestResult findCorrespondingResult(String id) {
return null;
}

@Override
public String getDisplayName() {
return null;
}
}
}
@@ -104,11 +104,6 @@ public String getChangesURL(Run<?, ?> run) {
public String getJobURL(Job<?, ?> project) {
return ELIGIBLE_IN_URL;
}

@Override
public String getTestUrl(hudson.tasks.test.TestResult result) {
return ELIGIBLE_IN_URL;
}
}

@TestExtension
@@ -4,8 +4,6 @@
import com.google.common.collect.Iterables;
import hudson.model.Job;
import hudson.model.Run;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.TestResult;
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
import org.junit.Test;
import org.jvnet.hudson.test.TestExtension;
@@ -14,8 +12,6 @@

import static io.restassured.RestAssured.given;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ActionRedirectExtendedTest extends AbstractActionRedirectTest {
@Test
@@ -57,20 +53,6 @@ public void testUrls() throws Exception {
assertEquals(root + "job/my%20folder/job/my%20job/changesanother", getRedirectedProvider().getChangesURL(run));
}

@Test
public void testGetTestUrl() throws Exception {
TestResult result = mock(TestResult.class);

AbstractTestResultAction action = mock(AbstractTestResultAction.class);
when(action.getUrlName()).thenReturn("action");

when(result.getRun()).thenReturn((Run)run);
when(result.getTestResultAction()).thenReturn(action);
when(result.getUrl()).thenReturn("/some id with spaces");

String testUrl = getRedirectedProvider().getTestUrl(result);
assertEquals("http://localhost:" + rule.getLocalPort() + "/jenkins/job/my%20folder/job/my%20job/1/action/some%20id%20with%20spacesanother", testUrl);
}

@Override
protected DisplayURLProvider getRedirectedProvider() {
@@ -96,10 +78,5 @@ public String getChangesURL(Run<?, ?> run) {
public String getJobURL(Job<?, ?> project) {
return DisplayURLProvider.getDefault().getJobURL(project) + EXTRA_CONTENT_IN_URL;
}

@Override
public String getTestUrl(hudson.tasks.test.TestResult result) {
return DisplayURLProvider.getDefault().getTestUrl(result) + EXTRA_CONTENT_IN_URL;
}
}
}

0 comments on commit c45806f

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