}
/**
- * Creates a new {@link Dashboard}-
+ * Creates a new {@link Dashboard}.
*/
public static Dashboard create(String id, String name) {
return new Dashboard()
/**
* Add a widget with the given parameters, and return the newly created {@link Widget} object if one wants to add parameters to it.
+ *
+ * @param widgetId id of an existing widget
+ * @param columnId column starts with 1. The widget is ignored if the column id does not match the layout.
*/
public Widget addWidget(String widgetId, int columnId) {
if (columnId < 1) {
return id;
}
- /**
- * @param id the id to set
- */
private Dashboard setId(String id) {
if (StringUtils.isBlank(id)) {
throw new IllegalArgumentException("Dashboard id can not be blank");
}
/**
- * Returns the layout of the dashboard.
+ * Returns the layout. Default value is the 2 columns mode with width 50%/50%.
*
* @return the layout
*/
return properties;
}
+ public String getProperty(String key) {
+ return properties.get(key);
+ }
+
/**
* Returns the identifier of this widget.
*
@Test
public void shouldAddSeveralTimesTheSameWidget() {
- // TODO
+ Dashboard dashboard = Dashboard.createByName("Fake");
+ dashboard.addWidget("most_violated_rules", 1);
+ dashboard.addWidget("most_violated_rules", 1).setProperty("foo", "bar");
+
+ assertThat(dashboard.getWidgets().size(), is(2));
+ assertThat(dashboard.getWidgetsOfColumn(1).get(0).getProperties().size(), is(0));
+ assertThat(dashboard.getWidgetsOfColumn(1).get(1).getProperty("foo"), is("bar"));
+ }
+
+ @Test
+ public void shouldSetWidgetProperty() {
+ Dashboard dashboard = Dashboard.createByName("Fake");
+ Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1);
+ widget.setProperty("foo", "bar");
+
+ assertThat(widget.getProperties().get("foo"), is("bar"));
}
}
+++ /dev/null
-/*
- * 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.api.web.dashboard;
-
-import org.junit.Test;
-
-import java.util.Map.Entry;
-import java.util.Set;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class WidgetTest {
-
- @Test
- public void shouldCreateWidget() {
- Dashboard dashboard = Dashboard.createByName("Fake");
- Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1);
- assertThat(widget.getId(), is("fake-widget"));
- }
-
- @Test
- public void shouldSetProperty() {
- Dashboard dashboard = Dashboard.createByName("Fake");
- Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1);
- widget.setProperty("foo", "bar");
-
- assertThat(widget.getProperties().get("foo"), is("bar"));
- }
-
-}
DashboardDto defaultDashboard = null;
for (DashboardTemplate dashboardTemplate : dashboardTemplates) {
Dashboard dashboard = dashboardTemplate.createDashboard();
- if (shouldBeRegistered(dashboard)) {
- DashboardDto dashboardDto = loadDashboard(dashboard);
+ if (shouldRegister(dashboard)) {
+ DashboardDto dashboardDto = registerDashboard(dashboard);
if (DEFAULT_DASHBOARD_ID.equals(dashboard.getId())) {
defaultDashboard = dashboardDto;
} else {
LOG.info("New dashboard '" + dashboardDto.getName() + "' registered");
}
- protected DashboardDto loadDashboard(Dashboard dashboard) {
+ protected DashboardDto registerDashboard(Dashboard dashboard) {
DashboardDto dto = createDtoFromExtension(dashboard);
// save the new dashboard
dashboardDao.insert(dto);
return dashboardDto;
}
- protected boolean shouldBeRegistered(Dashboard dashboard) {
+ protected boolean shouldRegister(Dashboard dashboard) {
return loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.DASHBOARD_TYPE, dashboard.getId()) == 0;
}
@Test
public void testShouldNotBeRegistered() throws Exception {
when(loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.DASHBOARD_TYPE, "fake-dashboard")).thenReturn(1);
- assertThat(registerNewDashboards.shouldBeRegistered(fakeDashboardTemplate.createDashboard()), is(false));
+ assertThat(registerNewDashboards.shouldRegister(fakeDashboardTemplate.createDashboard()), is(false));
}
@Test
public void testShouldBeLoaded() throws Exception {
- assertThat(registerNewDashboards.shouldBeRegistered(fakeDashboardTemplate.createDashboard()), is(true));
+ assertThat(registerNewDashboards.shouldRegister(fakeDashboardTemplate.createDashboard()), is(true));
}
@Test
public void shouldLoadDasboard() throws Exception {
- DashboardDto dashboardDto = registerNewDashboards.loadDashboard(fakeDashboardTemplate.createDashboard());
+ DashboardDto dashboardDto = registerNewDashboards.registerDashboard(fakeDashboardTemplate.createDashboard());
assertNotNull(dashboardDto);
verify(dashboardDao).insert(dashboardDto);
verify(loadedTemplateDao).insert(eq(new LoadedTemplateDto("fake-dashboard", LoadedTemplateDto.DASHBOARD_TYPE)));