提交 6df06fc1 编写于 作者: J Jochen A. Fürbacher 提交者: Oleg Nenashev

[JENKINS-48447] Fixed HTTP 404 error when clicking on newView sidebar link...

[JENKINS-48447] Fixed HTTP 404 error when clicking on newView sidebar 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.
上级 ac2a1aaf
......@@ -8,7 +8,11 @@ import hudson.model.View;
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
......@@ -40,7 +44,8 @@ public class NewViewLink extends TransientViewActionFactory {
@Override
public String getUrlName() {
return URL_NAME;
String urlName = Jenkins.getInstance().getRootUrl() + URL_NAME;
return urlName;
}
private boolean hasPermission(View view) {
......
......@@ -9,13 +9,36 @@ import static org.mockito.Mockito.when;
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 {
......@@ -27,7 +50,7 @@ public class NewViewLinkTest {
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
......@@ -40,7 +63,7 @@ public class NewViewLinkTest {
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());
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册