Skip to content

Commit

Permalink
[JENKINS-48447] Fixed HTTP 404 error when clicking on newView sidebar…
Browse files Browse the repository at this point in the history
… link from an other view. (#3178)

* [JENKINS-48447] Fixed HTTP 404 error when clicking on newView sidebar link from an other view.

* [JENKINS-48447] Fixed unit tests for NewViewLink

* [JENKINS-48447] Load url name each time object gets initialized and adapted tests.

* [JENKINS-48447] Rewrite tests for url name; fixed indenting.

* [JENKINS-48447] Fixed more identing.

* [JENKINS-48447] Added @restricted to NewViewLink; undo URL_NAME renaming.
  • Loading branch information
Jochen-A-Fuerbacher authored and oleg-nenashev committed Jan 7, 2018
1 parent ac2a1aa commit 6df06fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
7 changes: 6 additions & 1 deletion core/src/main/java/jenkins/model/NewViewLink.java
Expand Up @@ -8,7 +8,11 @@
import java.util.Collections;
import java.util.List;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;

@Extension
@Restricted(DoNotUse.class)
public class NewViewLink extends TransientViewActionFactory {

@VisibleForTesting
Expand Down Expand Up @@ -40,7 +44,8 @@ public String getDisplayName() {

@Override
public String getUrlName() {
return URL_NAME;
String urlName = Jenkins.getInstance().getRootUrl() + URL_NAME;
return urlName;
}

private boolean hasPermission(View view) {
Expand Down
29 changes: 26 additions & 3 deletions core/src/test/java/jenkins/model/NewViewLinkTest.java
Expand Up @@ -9,13 +9,36 @@
import hudson.model.Action;
import hudson.model.View;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest({NewViewLink.class, Jenkins.class})
public class NewViewLinkTest {

@Mock
private Jenkins jenkins;

@Mock
private final String rootUrl = "https://127.0.0.1:8080/";

private NewViewLink newViewLink = new NewViewLink();
private NewViewLink newViewLink;

private View view = mock(View.class);

@Before
public void initTests() throws Exception {
PowerMockito.mockStatic(Jenkins.class);
PowerMockito.when(Jenkins.getInstance()).thenReturn(jenkins);
PowerMockito.when(jenkins.getRootUrl()).thenReturn(rootUrl);
newViewLink = new NewViewLink();
}

@Test
public void getActionsHasPermission() throws Exception {
Expand All @@ -27,7 +50,7 @@ public void getActionsHasPermission() throws Exception {
final Action action = actions.get(0);
assertEquals(Messages.NewViewLink_NewView(), action.getDisplayName());
assertEquals(NewViewLink.ICON_FILE_NAME, action.getIconFileName());
assertEquals(NewViewLink.URL_NAME, action.getUrlName());
assertEquals(rootUrl + NewViewLink.URL_NAME, action.getUrlName());
}

@Test
Expand All @@ -40,7 +63,7 @@ public void getActionsNoPermission() throws Exception {
final Action action = actions.get(0);
assertNull(action.getDisplayName());
assertNull(action.getIconFileName());
assertEquals(NewViewLink.URL_NAME, action.getUrlName());
assertEquals(rootUrl + NewViewLink.URL_NAME, action.getUrlName());
}

}

0 comments on commit 6df06fc

Please sign in to comment.