aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-12-15 17:00:18 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2011-12-15 17:00:18 +0100
commitb84f33030464fcc3e6e70affb1680381516a19e6 (patch)
tree46dcb237e52cd36760f8e1435cb220af10b56fb6 /sonar-server
parentf149f41b21b5d630bdaf98eaa80f15e47ef990e9 (diff)
downloadsonarqube-b84f33030464fcc3e6e70affb1680381516a19e6.tar.gz
sonarqube-b84f33030464fcc3e6e70affb1680381516a19e6.zip
SONAR-1929 refactoring of the extension point Dashboard
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java2
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java160
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedDashboards.java170
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/236_add_key_to_dashboards.rb12
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java (renamed from sonar-server/src/test/java/org/sonar/server/startup/RegisterProvidedDashboardsTest.java)120
5 files changed, 220 insertions, 244 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 3cdb47b9e21..8b42b3add9e 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -233,7 +233,7 @@ public final class Platform {
startupContainer.addSingleton(RegisterQualityModels.class);
startupContainer.addSingleton(DeleteDeprecatedMeasures.class);
startupContainer.addSingleton(GeneratePluginIndex.class);
- startupContainer.addSingleton(RegisterProvidedDashboards.class);
+ startupContainer.addSingleton(RegisterNewDashboards.class);
startupContainer.startComponents();
startupContainer.getComponentByType(ServerLifecycleNotifier.class).notifyStart();
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java
new file mode 100644
index 00000000000..462cc0899e1
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java
@@ -0,0 +1,160 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.server.startup;
+
+import com.google.common.collect.Lists;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.web.dashboard.Dashboard;
+import org.sonar.api.web.dashboard.DashboardTemplate;
+import org.sonar.api.web.dashboard.Widget;
+import org.sonar.persistence.dashboard.*;
+import org.sonar.persistence.template.LoadedTemplateDao;
+import org.sonar.persistence.template.LoadedTemplateDto;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.Map.Entry;
+
+/**
+ * @since 2.13
+ */
+public final class RegisterNewDashboards {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RegisterNewDashboards.class);
+ private static final String MAIN_DASHBOARD_ID = "main";
+
+ private List<DashboardTemplate> dashboardTemplates;
+ private DashboardDao dashboardDao;
+ private ActiveDashboardDao activeDashboardDao;
+ private LoadedTemplateDao loadedTemplateDao;
+
+ public RegisterNewDashboards(DashboardDao dashboardDao, ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao) {
+ this(new DashboardTemplate[]{}, dashboardDao, activeDashboardDao, loadedTemplateDao);
+ }
+
+ public RegisterNewDashboards(DashboardTemplate[] dashboardTemplatesArray, DashboardDao dashboardDao,
+ ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao) {
+ this.dashboardTemplates = Lists.newArrayList(dashboardTemplatesArray);
+ this.dashboardDao = dashboardDao;
+ this.activeDashboardDao = activeDashboardDao;
+ this.loadedTemplateDao = loadedTemplateDao;
+ }
+
+ public void start() {
+ TimeProfiler profiler = new TimeProfiler().start("Register dashboards");
+
+ // load the dashboards that need to be loaded
+ List<DashboardDto> loadedDashboards = Lists.newArrayList();
+ DashboardDto mainDashboard = null;
+ for (DashboardTemplate dashboardTemplate : dashboardTemplates) {
+ Dashboard dashboard = dashboardTemplate.createDashboard();
+ if (shouldBeRegistered(dashboard)) {
+ DashboardDto dashboardDto = loadDashboard(dashboard);
+ if (MAIN_DASHBOARD_ID.equals(dashboard.getId())) {
+ mainDashboard = dashboardDto;
+ } else {
+ loadedDashboards.add(dashboardDto);
+ }
+ }
+ }
+ // and activate them
+ activateDashboards(loadedDashboards, mainDashboard);
+
+ profiler.stop();
+ }
+
+ protected void activateDashboards(List<DashboardDto> loadedDashboards, DashboardDto mainDashboard) {
+ int nextOrderIndex;
+ if (mainDashboard != null) {
+ activateDashboard(mainDashboard, 1);
+ nextOrderIndex = 2;
+ } else {
+ nextOrderIndex = activeDashboardDao.selectMaxOrderIndexForNullUser() + 1;
+ }
+ Collections.sort(loadedDashboards, new DashboardComparator());
+ for (DashboardDto dashboardDto : loadedDashboards) {
+ activateDashboard(dashboardDto, nextOrderIndex++);
+ }
+ }
+
+ private void activateDashboard(DashboardDto dashboardDto, int index) {
+ ActiveDashboardDto activeDashboardDto = new ActiveDashboardDto();
+ activeDashboardDto.setDashboardId(dashboardDto.getId());
+ activeDashboardDto.setOrderIndex(index);
+ activeDashboardDao.insert(activeDashboardDto);
+ LOG.info("New dashboard '" + dashboardDto.getName() + "' registered");
+ }
+
+ protected DashboardDto loadDashboard(Dashboard dashboard) {
+ DashboardDto dto = createDtoFromExtension(dashboard);
+ // save the new dashboard
+ dashboardDao.insert(dto);
+ // and save the fact that is has now already been loaded
+ loadedTemplateDao.insert(new LoadedTemplateDto(dashboard.getId(), LoadedTemplateDto.DASHBOARD_TYPE));
+ return dto;
+ }
+
+ protected DashboardDto createDtoFromExtension(Dashboard dashboard) {
+ Date now = new Date();
+ DashboardDto dashboardDto = new DashboardDto();
+ dashboardDto.setKey(dashboard.getId());
+ dashboardDto.setName(dashboard.getName());
+ dashboardDto.setDescription(dashboard.getDescription());
+ dashboardDto.setColumnLayout(dashboard.getLayout().toString());
+ dashboardDto.setShared(true);
+ dashboardDto.setCreatedAt(now);
+ dashboardDto.setUpdatedAt(now);
+
+ for (Widget widget : dashboard.getWidgets()) {
+ WidgetDto widgetDto = new WidgetDto();
+ widgetDto.setKey(widget.getId());
+ widgetDto.setColumnIndex(widget.getColumnIndex());
+ widgetDto.setRowIndex(widget.getRowIndex());
+ widgetDto.setConfigured(true);
+ widgetDto.setCreatedAt(now);
+ widgetDto.setUpdatedAt(now);
+ dashboardDto.addWidget(widgetDto);
+
+ for (Entry<String, String> property : widget.getProperties().entrySet()) {
+ WidgetPropertyDto propDto = new WidgetPropertyDto();
+ propDto.setKey(property.getKey());
+ propDto.setValue(property.getValue());
+ widgetDto.addWidgetProperty(propDto);
+ }
+ }
+
+ return dashboardDto;
+ }
+
+ protected boolean shouldBeRegistered(Dashboard dashboard) {
+ return loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.DASHBOARD_TYPE, dashboard.getId()) == 0;
+ }
+
+ protected static class DashboardComparator implements Comparator<DashboardDto> {
+ public int compare(DashboardDto d1, DashboardDto d2) {
+ return d1.getName().compareTo(d2.getName());
+ }
+ }
+
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedDashboards.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedDashboards.java
deleted file mode 100644
index afe2d447b45..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedDashboards.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.server.startup;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map.Entry;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.utils.TimeProfiler;
-import org.sonar.api.web.dashboard.Dashboard;
-import org.sonar.api.web.dashboard.DashboardTemplate;
-import org.sonar.api.web.dashboard.Widget;
-import org.sonar.core.i18n.I18nManager;
-import org.sonar.persistence.dashboard.ActiveDashboardDao;
-import org.sonar.persistence.dashboard.ActiveDashboardDto;
-import org.sonar.persistence.dashboard.DashboardDao;
-import org.sonar.persistence.template.LoadedTemplateDao;
-import org.sonar.persistence.template.LoadedTemplateDto;
-
-import com.google.common.collect.Lists;
-
-public final class RegisterProvidedDashboards {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(RegisterProvidedDashboards.class);
- private static final String MAIN_DASHBOARD_ID = "sonar-main";
-
- private List<DashboardTemplate> dashboardTemplates;
- private DashboardDao dashboardDao;
- private ActiveDashboardDao activeDashboardDao;
- private LoadedTemplateDao loadedTemplateDao;
- private I18nManager i18nManager;
-
- public RegisterProvidedDashboards(DashboardDao dashboardDao, ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao,
- I18nManager i18nManager) {
- this(new DashboardTemplate[] {}, dashboardDao, activeDashboardDao, loadedTemplateDao, i18nManager);
- }
-
- public RegisterProvidedDashboards(DashboardTemplate[] dashboardTemplatesArray, DashboardDao dashboardDao,
- ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao, I18nManager i18nManager) {
- this.dashboardTemplates = Lists.newArrayList(dashboardTemplatesArray);
- this.dashboardDao = dashboardDao;
- this.activeDashboardDao = activeDashboardDao;
- this.loadedTemplateDao = loadedTemplateDao;
- this.i18nManager = i18nManager;
- }
-
- public void start() {
- TimeProfiler profiler = new TimeProfiler().start("Load provided dashboards");
-
- // load the dashboards that need to be loaded
- ArrayList<org.sonar.persistence.dashboard.DashboardDto> loadedDashboards = Lists.newArrayList();
- org.sonar.persistence.dashboard.DashboardDto mainDashboard = null;
- for (DashboardTemplate dashboardTemplate : dashboardTemplates) {
- Dashboard dashboard = dashboardTemplate.createDashboard();
- if (shouldBeLoaded(dashboard)) {
- org.sonar.persistence.dashboard.DashboardDto dashboardDataModel = loadDashboard(dashboard);
- if (MAIN_DASHBOARD_ID.equals(dashboard.getId())) {
- mainDashboard = dashboardDataModel;
- } else {
- loadedDashboards.add(dashboardDataModel);
- }
- }
- }
- // and activate them
- activateDashboards(loadedDashboards, mainDashboard);
-
- profiler.stop();
- }
-
- protected void activateDashboards(List<org.sonar.persistence.dashboard.DashboardDto> loadedDashboards,
- org.sonar.persistence.dashboard.DashboardDto mainDashboard) {
- int nextOrderIndex = 0;
- if (mainDashboard != null) {
- activateDashboard(mainDashboard, 1);
- nextOrderIndex = 2;
- } else {
- nextOrderIndex = activeDashboardDao.selectMaxOrderIndexForNullUser() + 1;
- }
- Collections.sort(loadedDashboards, new DashboardComparator());
- for (org.sonar.persistence.dashboard.DashboardDto dashboardDto : loadedDashboards) {
- activateDashboard(dashboardDto, nextOrderIndex++);
- }
- }
-
- private void activateDashboard(org.sonar.persistence.dashboard.DashboardDto dashboardDto, int index) {
- ActiveDashboardDto activeDashboardDto = new ActiveDashboardDto();
- activeDashboardDto.setDashboardId(dashboardDto.getId());
- activeDashboardDto.setOrderIndex(index);
- activeDashboardDao.insert(activeDashboardDto);
- LOGGER.info("New dashboard '" + dashboardDto.getName() + "' registered and activated.");
- }
-
- protected org.sonar.persistence.dashboard.DashboardDto loadDashboard(Dashboard dashboard) {
- org.sonar.persistence.dashboard.DashboardDto dashboardDataModel = createDataModelFromExtension(dashboard);
- // save the new dashboard
- dashboardDao.insert(dashboardDataModel);
- // and save the fact that is has now already been loaded
- loadedTemplateDao.insert(new LoadedTemplateDto(dashboard.getId(), LoadedTemplateDto.DASHBOARD_TYPE));
- return dashboardDataModel;
- }
-
- protected org.sonar.persistence.dashboard.DashboardDto createDataModelFromExtension(Dashboard dashboard) {
- Date now = new Date();
- org.sonar.persistence.dashboard.DashboardDto dashboardDataModel = new org.sonar.persistence.dashboard.DashboardDto();
- dashboardDataModel.setKey(dashboard.getId());
- dashboardDataModel.setName(i18nManager.message(Locale.ENGLISH, "dashboard." + dashboard.getId() + ".name", dashboard.getName()));
- dashboardDataModel.setDescription(dashboard.getDescription());
- dashboardDataModel.setColumnLayout(dashboard.getLayout().toString());
- dashboardDataModel.setShared(true);
- dashboardDataModel.setCreatedAt(now);
- dashboardDataModel.setUpdatedAt(now);
-
- for (Widget widget : dashboard.getWidgets()) {
- org.sonar.persistence.dashboard.WidgetDto widgetDataModel = new org.sonar.persistence.dashboard.WidgetDto();
- widgetDataModel.setKey(widget.getId());
- widgetDataModel.setName(i18nManager.message(Locale.ENGLISH, "widget." + widget.getId() + ".name", ""));
- widgetDataModel.setColumnIndex(widget.getColumnIndex());
- widgetDataModel.setRowIndex(widget.getRowIndex());
- widgetDataModel.setConfigured(true);
- widgetDataModel.setCreatedAt(now);
- widgetDataModel.setUpdatedAt(now);
- dashboardDataModel.addWidget(widgetDataModel);
-
- for (Entry<String, String> property : widget.getProperties().entrySet()) {
- org.sonar.persistence.dashboard.WidgetPropertyDto widgetPropertyDataModel = new org.sonar.persistence.dashboard.WidgetPropertyDto();
- widgetPropertyDataModel.setKey(property.getKey());
- widgetPropertyDataModel.setValue(property.getValue());
- widgetDataModel.addWidgetProperty(widgetPropertyDataModel);
- }
- }
-
- return dashboardDataModel;
- }
-
- protected boolean shouldBeLoaded(Dashboard dashboard) {
- return loadedTemplateDao.selectByKeyAndType(dashboard.getId(), LoadedTemplateDto.DASHBOARD_TYPE) == null;
- }
-
- protected static class DashboardComparator implements Comparator<org.sonar.persistence.dashboard.DashboardDto> {
-
- public int compare(org.sonar.persistence.dashboard.DashboardDto d1, org.sonar.persistence.dashboard.DashboardDto d2) {
- return d1.getName().compareTo(d2.getName());
- }
-
- }
-
-}
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/236_add_key_to_dashboards.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/236_add_key_to_dashboards.rb
index 04c287e98b0..77edc445efa 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/236_add_key_to_dashboards.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/236_add_key_to_dashboards.rb
@@ -24,20 +24,20 @@
class AddKeyToDashboards < ActiveRecord::Migration
def self.up
- add_column 'dashboards', 'kee', :string, :limit => 200
+ add_column 'dashboards', 'kee', :string, :limit => 200, :null => true
Dashboard.reset_column_information
-
+
Dashboard.find(:all).each do |d|
key = d.name(false).strip.downcase.sub(/\s+/, '_')
Dashboard.update_all "kee = '#{key}'", ["id = ?", d.id]
end
-
+
main_dashboard = Dashboard.find(:first, :conditions => {:name => 'Dashboard'})
if main_dashboard
- Dashboard.update_all "kee = 'sonar-main'", ["id = ?", main_dashboard.id]
+ Dashboard.update_all "kee = 'main'", ["id = ?", main_dashboard.id]
end
-
- change_column 'dashboards', 'kee', :string, :limit => 200, :null => false
+
+ change_column 'dashboards', 'kee', :string, :limit => 200, :null => false
Dashboard.reset_column_information
end
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterProvidedDashboardsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java
index a7815f16e51..42088666274 100644
--- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterProvidedDashboardsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java
@@ -19,43 +19,35 @@
*/
package org.sonar.server.startup;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-
+import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.web.dashboard.Dashboard;
import org.sonar.api.web.dashboard.DashboardLayout;
import org.sonar.api.web.dashboard.DashboardTemplate;
-import org.sonar.core.i18n.I18nManager;
-import org.sonar.persistence.dashboard.ActiveDashboardDao;
-import org.sonar.persistence.dashboard.ActiveDashboardDto;
-import org.sonar.persistence.dashboard.DashboardDao;
-import org.sonar.persistence.dashboard.WidgetDto;
+import org.sonar.api.web.dashboard.Widget;
+import org.sonar.persistence.dashboard.*;
import org.sonar.persistence.template.LoadedTemplateDao;
import org.sonar.persistence.template.LoadedTemplateDto;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
-public class RegisterProvidedDashboardsTest {
+public class RegisterNewDashboardsTest {
- private RegisterProvidedDashboards registerProvidedDashboards;
+ private RegisterNewDashboards registerNewDashboards;
private DashboardDao dashboardDao;
private ActiveDashboardDao activeDashboardDao;
private LoadedTemplateDao loadedTemplateDao;
- private I18nManager i18nManager;
private DashboardTemplate fakeDashboardTemplate;
@Before
@@ -63,60 +55,53 @@ public class RegisterProvidedDashboardsTest {
dashboardDao = mock(DashboardDao.class);
activeDashboardDao = mock(ActiveDashboardDao.class);
loadedTemplateDao = mock(LoadedTemplateDao.class);
- i18nManager = mock(I18nManager.class);
- when(i18nManager.message(Locale.ENGLISH, "widget.fake-widget.name", "")).thenReturn("Fake Widget");
- when(i18nManager.message(Locale.ENGLISH, "dashboard.fake-dashboard.name", "Fake")).thenReturn("Fake Dashboard");
fakeDashboardTemplate = new FakeDashboard();
- registerProvidedDashboards = new RegisterProvidedDashboards(new DashboardTemplate[] { fakeDashboardTemplate }, dashboardDao,
- activeDashboardDao, loadedTemplateDao, i18nManager);
+ registerNewDashboards = new RegisterNewDashboards(new DashboardTemplate[]{fakeDashboardTemplate}, dashboardDao,
+ activeDashboardDao, loadedTemplateDao);
}
@Test
public void testStart() throws Exception {
- registerProvidedDashboards.start();
+ registerNewDashboards.start();
verify(dashboardDao).insert(any(org.sonar.persistence.dashboard.DashboardDto.class));
verify(loadedTemplateDao).insert(any(LoadedTemplateDto.class));
verify(activeDashboardDao).insert(any(ActiveDashboardDto.class));
}
@Test
- public void testShouldNotBeLoaded() throws Exception {
- when(loadedTemplateDao.selectByKeyAndType("fake-dashboard", LoadedTemplateDto.DASHBOARD_TYPE)).thenReturn(new LoadedTemplateDto());
- assertThat(registerProvidedDashboards.shouldBeLoaded(fakeDashboardTemplate.createDashboard()), is(false));
+ public void testShouldNotBeRegistered() throws Exception {
+ when(loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.DASHBOARD_TYPE, "fake-dashboard")).thenReturn(1);
+ assertThat(registerNewDashboards.shouldBeRegistered(fakeDashboardTemplate.createDashboard()), is(false));
}
@Test
public void testShouldBeLoaded() throws Exception {
- assertThat(registerProvidedDashboards.shouldBeLoaded(fakeDashboardTemplate.createDashboard()), is(true));
+ assertThat(registerNewDashboards.shouldBeRegistered(fakeDashboardTemplate.createDashboard()), is(true));
}
@Test
public void shouldLoadDasboard() throws Exception {
- org.sonar.persistence.dashboard.DashboardDto dataModelDashboard = registerProvidedDashboards.loadDashboard(fakeDashboardTemplate
- .createDashboard());
- assertNotNull(dataModelDashboard);
- verify(dashboardDao).insert(dataModelDashboard);
+ DashboardDto dashboardDto = registerNewDashboards.loadDashboard(fakeDashboardTemplate.createDashboard());
+ assertNotNull(dashboardDto);
+ verify(dashboardDao).insert(dashboardDto);
verify(loadedTemplateDao).insert(eq(new LoadedTemplateDto("fake-dashboard", LoadedTemplateDto.DASHBOARD_TYPE)));
}
@Test
- public void shouldCreateDataModelFromExtension() {
- org.sonar.persistence.dashboard.DashboardDto dataModelDashboard = registerProvidedDashboards
- .createDataModelFromExtension(fakeDashboardTemplate.createDashboard());
- assertThat(dataModelDashboard.getUserId(), is(nullValue()));
- assertThat(dataModelDashboard.getKey(), is("fake-dashboard"));
- assertThat(dataModelDashboard.getName(), is("Fake Dashboard"));
- assertThat(dataModelDashboard.getDescription(), is(""));
- assertThat(dataModelDashboard.getColumnLayout(), is("30%-70%"));
- assertThat(dataModelDashboard.getShared(), is(true));
- assertNotNull(dataModelDashboard.getCreatedAt());
- assertNotNull(dataModelDashboard.getUpdatedAt());
-
- WidgetDto widgetDto = dataModelDashboard.getWidgets().iterator().next();
+ public void shouldCreateDtoFromExtension() {
+ DashboardDto dto = registerNewDashboards.createDtoFromExtension(fakeDashboardTemplate.createDashboard());
+ assertThat(dto.getUserId(), is(nullValue()));
+ assertThat(dto.getKey(), is("fake-dashboard"));
+ assertThat(dto.getDescription(), nullValue());
+ assertThat(dto.getColumnLayout(), is("30%-70%"));
+ assertThat(dto.getShared(), is(true));
+ assertNotNull(dto.getCreatedAt());
+ assertNotNull(dto.getUpdatedAt());
+
+ WidgetDto widgetDto = dto.getWidgets().iterator().next();
assertThat(widgetDto.getKey(), is("fake-widget"));
- assertThat(widgetDto.getName(), is("Fake Widget"));
assertThat(widgetDto.getDescription(), is(nullValue()));
assertThat(widgetDto.getColumnIndex(), is(12));
assertThat(widgetDto.getRowIndex(), is(13));
@@ -124,36 +109,36 @@ public class RegisterProvidedDashboardsTest {
assertNotNull(widgetDto.getCreatedAt());
assertNotNull(widgetDto.getUpdatedAt());
- org.sonar.persistence.dashboard.WidgetPropertyDto widgetPropertyDto = widgetDto.getWidgetProperties().iterator().next();
+ WidgetPropertyDto widgetPropertyDto = widgetDto.getWidgetProperties().iterator().next();
assertThat(widgetPropertyDto.getKey(), is("fake-property"));
assertThat(widgetPropertyDto.getValue(), is("fake_metric"));
}
@Test
public void shouldCompareDashboardForSorting() throws Exception {
- org.sonar.persistence.dashboard.DashboardDto d1 = mock(org.sonar.persistence.dashboard.DashboardDto.class);
+ DashboardDto d1 = mock(DashboardDto.class);
when(d1.getName()).thenReturn("Foo");
- org.sonar.persistence.dashboard.DashboardDto d2 = mock(org.sonar.persistence.dashboard.DashboardDto.class);
+ DashboardDto d2 = mock(DashboardDto.class);
when(d2.getName()).thenReturn("Bar");
- List<org.sonar.persistence.dashboard.DashboardDto> dashboardDtos = Lists.newArrayList(d1, d2);
- Collections.sort(dashboardDtos, new RegisterProvidedDashboards.DashboardComparator());
+ List<DashboardDto> dashboardDtos = Lists.newArrayList(d1, d2);
+ Collections.sort(dashboardDtos, new RegisterNewDashboards.DashboardComparator());
assertThat(dashboardDtos.get(0).getName(), is("Bar"));
}
@Test
public void shouldActivateAllDashboards() throws Exception {
- org.sonar.persistence.dashboard.DashboardDto d1 = mock(org.sonar.persistence.dashboard.DashboardDto.class);
+ DashboardDto d1 = mock(DashboardDto.class);
when(d1.getName()).thenReturn("Foo");
when(d1.getId()).thenReturn(14L);
- org.sonar.persistence.dashboard.DashboardDto d2 = mock(org.sonar.persistence.dashboard.DashboardDto.class);
+ DashboardDto d2 = mock(DashboardDto.class);
when(d2.getName()).thenReturn("Bar");
when(d2.getId()).thenReturn(16L);
- ArrayList<org.sonar.persistence.dashboard.DashboardDto> loadedDashboards = Lists.newArrayList(d1, d2);
+ ArrayList<DashboardDto> loadedDashboards = Lists.newArrayList(d1, d2);
when(activeDashboardDao.selectMaxOrderIndexForNullUser()).thenReturn(4);
- registerProvidedDashboards.activateDashboards(loadedDashboards, null);
+ registerNewDashboards.activateDashboards(loadedDashboards, null);
ActiveDashboardDto ad1 = new ActiveDashboardDto();
ad1.setDashboardId(16L);
@@ -167,15 +152,15 @@ public class RegisterProvidedDashboardsTest {
@Test
public void shouldActivateMainDashboard() throws Exception {
- org.sonar.persistence.dashboard.DashboardDto mainDashboard = mock(org.sonar.persistence.dashboard.DashboardDto.class);
+ DashboardDto mainDashboard = mock(DashboardDto.class);
when(mainDashboard.getName()).thenReturn("Main");
when(mainDashboard.getId()).thenReturn(1L);
- org.sonar.persistence.dashboard.DashboardDto d1 = mock(org.sonar.persistence.dashboard.DashboardDto.class);
+ DashboardDto d1 = mock(DashboardDto.class);
when(d1.getName()).thenReturn("Bar");
when(d1.getId()).thenReturn(16L);
- ArrayList<org.sonar.persistence.dashboard.DashboardDto> loadedDashboards = Lists.newArrayList(d1);
+ List<DashboardDto> loadedDashboards = Lists.newArrayList(d1);
- registerProvidedDashboards.activateDashboards(loadedDashboards, mainDashboard);
+ registerNewDashboards.activateDashboards(loadedDashboards, mainDashboard);
ActiveDashboardDto ad1 = new ActiveDashboardDto();
ad1.setDashboardId(1L);
@@ -191,8 +176,9 @@ public class RegisterProvidedDashboardsTest {
@Override
public Dashboard createDashboard() {
- Dashboard dashboard = Dashboard.createDashboard("fake-dashboard", "Fake", DashboardLayout.TWO_COLUMNS_30_70);
- org.sonar.api.web.dashboard.Widget widget = dashboard.addWidget("fake-widget", 12, 13);
+ Dashboard dashboard = Dashboard.create("fake-dashboard", "Fake");
+ dashboard.setLayout(DashboardLayout.TWO_COLUMNS_30_70);
+ Widget widget = dashboard.addWidget("fake-widget", 12, 13);
widget.addProperty("fake-property", "fake_metric");
return dashboard;
}