From 3710ea959f659b72d283fa3f14fe14b067f312b4 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 22 Mar 2013 15:19:43 +0100 Subject: [PATCH] SONAR-4173 Add the possibility for a plugin to add a configuration page --- .../org/sonar/api/web/NavigationSection.java | 2 + .../webapp/WEB-INF/app/models/navigation.rb | 1 + .../layouts/_menu_resource_settings.html.erb | 5 + .../java/org/sonar/server/ui/ViewsTest.java | 124 +++++++++--------- 4 files changed, 70 insertions(+), 62 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/NavigationSection.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/NavigationSection.java index 58dca1b105e..b065f7fd1b1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/NavigationSection.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/NavigationSection.java @@ -37,6 +37,8 @@ public @interface NavigationSection { String RESOURCE = "resource"; String RESOURCE_TAB = "resource_tab"; String CONFIGURATION = "configuration"; + // @since 3.6 + String PROJECT_CONFIGURATION = "project_configuration"; String[] value() default { HOME }; diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/navigation.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/navigation.rb index 94e8f3fe4f2..cea364c906c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/navigation.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/navigation.rb @@ -22,6 +22,7 @@ class Navigation SECTION_HOME = 'home' SECTION_RESOURCE = 'resource' SECTION_CONFIGURATION = 'configuration' + SECTION_PROJECT_CONFIGURATION = 'project_configuration' SECTION_SESSION = 'session' end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_menu_resource_settings.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_menu_resource_settings.html.erb index abf7434fe19..653596c0c31 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_menu_resource_settings.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_menu_resource_settings.html.erb @@ -34,6 +34,11 @@ <% if controller.java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'deletable') %>
  • <%= message('resource_deletion.page', :params => message('qualifier.' + @project.qualifier)) -%>
  • <% end %> + <% controller.java_facade.getPages(Navigation::SECTION_PROJECT_CONFIGURATION, @project.scope, @project.qualifier, @project.language, nil).each do |page| + page_url = (page.isController() ? "#{page.getId()}?id=#{@project.id}" : "/plugins/project_configuration/#{@project.id}?page=#{page.getId()}") + %> +
  • <%= message(page.getId() + '.page', :default => page.getTitle()) -%>
  • + <% end %> diff --git a/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java b/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java index 2f509e1ffca..d682ea6dc1f 100644 --- a/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java @@ -19,14 +19,6 @@ */ package org.sonar.server.ui; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsNull.nullValue; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.List; - import org.junit.Test; import org.sonar.api.resources.Java; import org.sonar.api.resources.Qualifiers; @@ -36,6 +28,12 @@ import org.sonar.api.web.Page; import org.sonar.api.web.View; import org.sonar.api.web.Widget; +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class ViewsTest { private static FakeResourceViewer FAKE_TAB = new FakeResourceViewer(); @@ -44,127 +42,129 @@ public class ViewsTest { private static final View[] VIEWS = {FAKE_PAGE, FAKE_TAB, FAKE_WIDGET}; @Test - public void getPageById() { + public void should_get_page_by_id() { final Views views = new Views(VIEWS); - assertThat(views.getPage("fake-page").getTarget(), is(FakePage.class)); - assertThat(views.getPage("fake-widget"), nullValue()); - assertThat(views.getPage("foo"), nullValue()); - assertThat(views.getPage("fake-resourceviewer").getTarget(), is(FakeResourceViewer.class)); + assertThat(views.getPage("fake-page").getTarget().getClass()).isEqualTo(FakePage.class); + assertThat(views.getPage("fake-widget")).isNull(); + assertThat(views.getPage("foo")).isNull(); + assertThat(views.getPage("fake-resourceviewer").getTarget().getClass()).isEqualTo(FakeResourceViewer.class); } @Test - public void getPagesBySection() { + public void should_get_pages_by_section() { final Views views = new Views(VIEWS); List> pages = views.getPages(NavigationSection.RESOURCE); - assertThat(pages.size(), is(1)); - assertThat(pages.get(0).getTarget(), is(FakePage.class)); + assertThat(pages.size()).isEqualTo(1); + assertThat(pages.get(0).getTarget().getClass()).isEqualTo(FakePage.class); pages = views.getPages(NavigationSection.CONFIGURATION); - assertThat(pages.size(), is(0)); + assertThat(pages.size()).isEqualTo(0); } @Test - public void getResourceViewers() { + public void should_get_resource_viewers() { final Views views = new Views(VIEWS); List resourceViewers = views.getPages(NavigationSection.RESOURCE_TAB); - assertThat(resourceViewers.size(), is(1 + 4 /* default */)); - assertThat(resourceViewers.contains(new ViewProxy(FAKE_TAB)), is(true)); + assertThat(resourceViewers.size()).isEqualTo(1 + 4 /* default */); + assertThat(resourceViewers.contains(new ViewProxy(FAKE_TAB))).isEqualTo(true); } @Test - public void getWidgets() { + public void should_get_widgets() { final Views views = new Views(VIEWS); List> widgets = views.getWidgets(null, null, null, null); - assertThat(widgets.size(), is(1)); - assertThat(widgets.get(0).getTarget(), is(FakeWidget.class)); + assertThat(widgets.size()).isEqualTo(1); + assertThat(widgets.get(0).getTarget().getClass()).isEqualTo(FakeWidget.class); } @Test - public void sortViewsByTitle() { + public void should_sort_views_by_title() { final Views views = new Views(new View[] {new FakeWidget("ccc", "ccc"), new FakeWidget("aaa", "aaa"), new FakeWidget("bbb", "bbb")}); List> widgets = views.getWidgets(null, null, null, null); - assertThat(widgets.size(), is(3)); - assertThat(widgets.get(0).getId(), is("aaa")); - assertThat(widgets.get(1).getId(), is("bbb")); - assertThat(widgets.get(2).getId(), is("ccc")); + assertThat(widgets.size()).isEqualTo(3); + assertThat(widgets.get(0).getId()).isEqualTo("aaa"); + assertThat(widgets.get(1).getId()).isEqualTo("bbb"); + assertThat(widgets.get(2).getId()).isEqualTo("ccc"); } @Test - public void prefixTitleByNumberToDisplayFirst() { + public void should_prefix_title_by_number_to_display_first() { final Views views = new Views(new View[] {new FakeWidget("other", "Other"), new FakeWidget("1id", "1widget"), new FakeWidget("2id", "2widget")}); List> widgets = views.getWidgets(null, null, null, null); - assertThat(widgets.size(), is(3)); - assertThat(widgets.get(0).getId(), is("1id")); - assertThat(widgets.get(1).getId(), is("2id")); - assertThat(widgets.get(2).getId(), is("other")); + assertThat(widgets.size()).isEqualTo(3); + assertThat(widgets.get(0).getId()).isEqualTo("1id"); + assertThat(widgets.get(1).getId()).isEqualTo("2id"); + assertThat(widgets.get(2).getId()).isEqualTo("other"); } @Test - public void acceptNavigationSection() { + public void should_accept_navigation_section() { ViewProxy proxy = mock(ViewProxy.class); when(proxy.getSections()).thenReturn(new String[] {NavigationSection.RESOURCE}); when(proxy.isWidget()).thenReturn(false); - assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE), is(true)); - assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME), is(false)); - assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION), is(false)); - assertThat(Views.acceptNavigationSection(proxy, null), is(true)); + assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE)).isEqualTo(true); + assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME)).isEqualTo(false); + assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION)).isEqualTo(false); + assertThat(Views.acceptNavigationSection(proxy, NavigationSection.PROJECT_CONFIGURATION)).isEqualTo(false); + assertThat(Views.acceptNavigationSection(proxy, null)).isEqualTo(true); } @Test - public void acceptAvailableMeasures() { + public void should_accept_available_measures() { ViewProxy proxy = mock(ViewProxy.class); when(proxy.acceptsAvailableMeasures(new String[] {"lines"})).thenReturn(true); when(proxy.acceptsAvailableMeasures(new String[] {"ncloc"})).thenReturn(false); - assertThat(Views.acceptAvailableMeasures(proxy, null), is(true)); - assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"lines"}), is(true)); - assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"ncloc"}), is(false)); + assertThat(Views.acceptAvailableMeasures(proxy, null)).isEqualTo(true); + assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"lines"})).isEqualTo(true); + assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"ncloc"})).isEqualTo(false); - assertThat(Views.accept(proxy, null, null, null, null, null), is(true)); - assertThat(Views.accept(proxy, null, null, null, null, new String[] {"lines"}), is(true)); - assertThat(Views.accept(proxy, null, null, null, null, new String[] {"ncloc"}), is(false)); + assertThat(Views.accept(proxy, null, null, null, null, null)).isEqualTo(true); + assertThat(Views.accept(proxy, null, null, null, null, new String[] {"lines"})).isEqualTo(true); + assertThat(Views.accept(proxy, null, null, null, null, new String[] {"ncloc"})).isEqualTo(false); } @Test - public void doNotCheckNavigationSectionOnWidgets() { + public void should_not_check_navigation_section_on_widgets() { ViewProxy proxy = mock(ViewProxy.class); when(proxy.isWidget()).thenReturn(true); - assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE), is(true)); - assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME), is(true)); - assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION), is(true)); - assertThat(Views.acceptNavigationSection(proxy, null), is(true)); + assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE)).isEqualTo(true); + assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME)).isEqualTo(true); + assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION)).isEqualTo(true); + assertThat(Views.acceptNavigationSection(proxy, NavigationSection.PROJECT_CONFIGURATION)).isEqualTo(true); + assertThat(Views.acceptNavigationSection(proxy, null)).isEqualTo(true); } @Test - public void checkResourceLanguage() { + public void should_check_resource_language() { ViewProxy proxy = mock(ViewProxy.class); - assertThat(Views.acceptResourceLanguage(proxy, Java.KEY), is(true)); + assertThat(Views.acceptResourceLanguage(proxy, Java.KEY)).isEqualTo(true); when(proxy.getResourceLanguages()).thenReturn(new String[] {"foo"}); - assertThat(Views.acceptResourceLanguage(proxy, Java.KEY), is(false)); - assertThat(Views.acceptResourceLanguage(proxy, "foo"), is(true)); + assertThat(Views.acceptResourceLanguage(proxy, Java.KEY)).isEqualTo(false); + assertThat(Views.acceptResourceLanguage(proxy, "foo")).isEqualTo(true); } @Test - public void checkResourceScope() { + public void should_check_resource_scope() { ViewProxy proxy = mock(ViewProxy.class); - assertThat(Views.acceptResourceScope(proxy, Scopes.FILE), is(true)); + assertThat(Views.acceptResourceScope(proxy, Scopes.FILE)).isEqualTo(true); when(proxy.getResourceScopes()).thenReturn(new String[] {Scopes.PROJECT, Scopes.FILE}); - assertThat(Views.acceptResourceScope(proxy, Scopes.FILE), is(true)); - assertThat(Views.acceptResourceScope(proxy, Scopes.DIRECTORY), is(false)); + assertThat(Views.acceptResourceScope(proxy, Scopes.FILE)).isEqualTo(true); + assertThat(Views.acceptResourceScope(proxy, Scopes.DIRECTORY)).isEqualTo(false); } @Test - public void checkResourceQualifier() { + public void should_check_resource_qualifier() { ViewProxy proxy = mock(ViewProxy.class); - assertThat(Views.acceptResourceQualifier(proxy, Scopes.FILE), is(true)); + assertThat(Views.acceptResourceQualifier(proxy, Scopes.FILE)).isEqualTo(true); when(proxy.getResourceQualifiers()).thenReturn(new String[] {Qualifiers.CLASS, Qualifiers.FILE}); - assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.FILE), is(true)); - assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.PACKAGE), is(false)); + assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.FILE)).isEqualTo(true); + assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.PACKAGE)).isEqualTo(false); } } -- 2.39.5