Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-43538 API change: remove getTestUrl (#13)
  • Loading branch information
James William Dumay committed Apr 13, 2017
1 parent e4914ab commit c45806f
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 153 deletions.
7 changes: 1 addition & 6 deletions pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Expand Up @@ -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
Expand All @@ -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();
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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() {
Expand Down
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Expand Up @@ -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 {

Expand All @@ -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;
}
}
}
Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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.