@Override
public Dashboard createDashboard() {
Dashboard dashboard = Dashboard.create()
- .setGlobal(true)
- .setLayout(DashboardLayout.TWO_COLUMNS);
+ .setGlobal(true)
+ .setLayout(DashboardLayout.TWO_COLUMNS);
dashboard.addWidget(WelcomeWidget.ID, 1);
+ addMyFavouritesWidget(dashboard);
+ addProjectsWidgets(dashboard);
+ return dashboard;
+ }
+
+ private void addMyFavouritesWidget(Dashboard dashboard) {
MeasureFilterDto filter = findSystemFilter(MyFavouritesFilter.NAME);
if (filter != null) {
dashboard
- .addWidget(MeasureFilterListWidget.ID, 1)
- .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
- .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "50");
+ .addWidget(MeasureFilterListWidget.ID, 1)
+ .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
+ .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "50");
}
+ }
- filter = findSystemFilter(ProjectFilter.NAME);
+ private void addProjectsWidgets(Dashboard dashboard) {
+ MeasureFilterDto filter = findSystemFilter(ProjectFilter.NAME);
if (filter != null) {
dashboard
- .addWidget(MeasureFilterListWidget.ID, 2)
- .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
- .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "20");
+ .addWidget(MeasureFilterListWidget.ID, 2)
+ .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
+ .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "20");
dashboard
- .addWidget(MeasureFilterTreemapWidget.ID, 2)
- .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
- .setProperty(MeasureFilterTreemapWidget.SIZE_METRIC_PROPERTY, "ncloc")
- .setProperty(MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, "violations_density");
+ .addWidget(MeasureFilterTreemapWidget.ID, 2)
+ .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
+ .setProperty(MeasureFilterTreemapWidget.SIZE_METRIC_PROPERTY, "ncloc")
+ .setProperty(MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, "violations_density");
}
-
- return dashboard;
}
@Override
@WidgetCategory({"Action plans", "Reviews"})
public class ActionPlansWidget extends CoreWidget {
public ActionPlansWidget() {
- super("action_plans", "Action plans", "/org/sonar/plugins/core/widgets/actionPlans/action_plans.html.erb");
+ super("action_plans", "Action plans", "/org/sonar/plugins/core/widgets/action_plans.html.erb");
}
}
\ No newline at end of file
public static final String ID = "measure_filter_list";
public MeasureFilterListWidget() {
- super(ID, "Measure Filter as List",
- "/org/sonar/plugins/core/widgets/measure_filter_list.html.erb");
+ super(ID, "Measure Filter as List", "/org/sonar/plugins/core/widgets/measure_filter_list.html.erb");
}
}
+++ /dev/null
-<%
- if has_role?(:user, @project)
- open_action_plans = ActionPlan.find(:all, :conditions => ['status= ? AND project_id=?', ActionPlan::STATUS_OPEN, @project.id],
- :include => 'reviews', :order => 'deadline ASC')
-
- div_id = "action-plan-widget-#{widget.id.to_s}"
-%>
-
-<div class="line-block">
- <% if has_role?(:admin, @project) %>
- <div style="float:right">
- <a href="<%= url_for :controller => 'action_plans', :action => 'index', :id => @project.id -%>">
- <%= message('widgets.more') -%>
- </a>
- </div>
- <% end %>
-
- <h3><%= message('widget.action_plans.title') -%></h3>
-</div>
-
-
-<div id="<%= div_id -%>">
-
-<% if open_action_plans.size ==0 %>
- <span class="empty_widget"><%= message('widget.action_plans.no_action_plan') -%></span>
-<% else %>
- <table class="width100 actionPlans">
- <thead>
- <tr>
- <th colspan="3"></th>
- </tr>
- </thead>
- <tbody>
- <%
- open_action_plans.each do |plan|
- %>
- <tr>
- <td class="nowrap"><%= h(plan.name) -%></td>
- <td class="nowrap small <%= 'over-due' if plan.over_due? -%>" style="text-align: right; padding-left:10px"><%= plan.deadline ? plan.deadline.strftime("%d %b %Y") : ' ' -%></td>
- <% if plan.progress[:total]==0 %>
- <td class="noprogress nowrap"><%= message('action_plans.no_reviews_linked_to_action_plan') -%></td>
- <% else %>
- <td class="progress">
- <%= render :partial => 'action_plans/progress', :locals => {:action_plan => plan} -%>
- </td>
- <% end %>
- </tr>
- <%
- end
- %>
- </tbody>
- </table>
-<% end %>
-
-</div>
-
-<% end %>
--- /dev/null
+<%
+ if has_role?(:user, @project)
+ open_action_plans = ActionPlan.find(:all, :conditions => ['status= ? AND project_id=?', ActionPlan::STATUS_OPEN, @project.id],
+ :include => 'reviews', :order => 'deadline ASC')
+
+ div_id = "action-plan-widget-#{widget.id.to_s}"
+%>
+
+<div class="line-block">
+ <% if has_role?(:admin, @project) %>
+ <div style="float:right">
+ <a href="<%= url_for :controller => 'action_plans', :action => 'index', :id => @project.id -%>">
+ <%= message('widgets.more') -%>
+ </a>
+ </div>
+ <% end %>
+
+ <h3><%= message('widget.action_plans.title') -%></h3>
+</div>
+
+
+<div id="<%= div_id -%>">
+
+<% if open_action_plans.size ==0 %>
+ <span class="empty_widget"><%= message('widget.action_plans.no_action_plan') -%></span>
+<% else %>
+ <table class="width100 actionPlans">
+ <thead>
+ <tr>
+ <th colspan="3"></th>
+ </tr>
+ </thead>
+ <tbody>
+ <%
+ open_action_plans.each do |plan|
+ %>
+ <tr>
+ <td class="nowrap"><%= h(plan.name) -%></td>
+ <td class="nowrap small <%= 'over-due' if plan.over_due? -%>" style="text-align: right; padding-left:10px"><%= plan.deadline ? plan.deadline.strftime("%d %b %Y") : ' ' -%></td>
+ <% if plan.progress[:total]==0 %>
+ <td class="noprogress nowrap"><%= message('action_plans.no_reviews_linked_to_action_plan') -%></td>
+ <% else %>
+ <td class="progress">
+ <%= render :partial => 'action_plans/progress', :locals => {:action_plan => plan} -%>
+ </td>
+ <% end %>
+ </tr>
+ <%
+ end
+ %>
+ </tbody>
+ </table>
+<% end %>
+
+</div>
+
+<% end %>
@Test
public void should_create_global_dashboard_with_four_widgets() {
when(dao.findSystemFilterByName(MyFavouritesFilter.NAME)).thenReturn(
- new MeasureFilterDto().setId(100L)
- );
+ new MeasureFilterDto().setId(100L)
+ );
when(dao.findSystemFilterByName(ProjectFilter.NAME)).thenReturn(
- new MeasureFilterDto().setId(101L)
- );
+ new MeasureFilterDto().setId(101L)
+ );
Dashboard dashboard = template.createDashboard();
List<Widget> firstColumn = dashboard.getWidgetsOfColumn(1);
assertThat(firstColumn).hasSize(2);
assertThat(secondColumn.get(1).getId()).isEqualTo(MeasureFilterTreemapWidget.ID);
assertThat(secondColumn.get(1).getProperty("filter")).isEqualTo("101");
}
+
+ @Test
+ public void should_not_fail_if_filter_widgets_not_found() {
+ when(dao.findSystemFilterByName(MyFavouritesFilter.NAME)).thenReturn(null);
+ when(dao.findSystemFilterByName(ProjectFilter.NAME)).thenReturn(null);
+
+ Dashboard dashboard = template.createDashboard();
+ List<Widget> firstColumn = dashboard.getWidgetsOfColumn(1);
+ assertThat(firstColumn).hasSize(1);
+ assertThat(firstColumn.get(0).getId()).isEqualTo(WelcomeWidget.ID);
+
+ List<Widget> secondColumn = dashboard.getWidgetsOfColumn(2);
+ assertThat(secondColumn).isEmpty();
+ }
}
@Test
public void should_find_templates() {
for (CoreWidget widget : widgets()) {
- assertThat(widget.getClass().getResource(widget.getTemplatePath())).isNotNull();
+ assertThat(widget.getClass().getResource(widget.getTemplatePath()))
+ .as("Template not found: " + widget.getTemplatePath())
+ .isNotNull();
}
}
@Test
public void should_be_registered_as_an_extension() {
for (CoreWidget widget : widgets()) {
- assertThat(new CorePlugin().getExtensions()).contains(widget.getClass());
+ assertThat(new CorePlugin().getExtensions()).as("Widget not registered: " + widget.getClass()).contains(widget.getClass());
}
}
this.sql = sql;
}
- public String getCode() {
- return code;
- }
-
public String getSql() {
return sql;
}
}
throw new IllegalArgumentException("Unknown operator code: " + code);
}
-
- public static Operator fromSql(String sql) {
- for (Operator operator : values()) {
- if (operator.sql.equals(sql)) {
- return operator;
- }
- }
- throw new IllegalArgumentException("Unknown operator sql: " + sql);
- }
}
private final Metric metric;
return "pm.value";
}
- void appendSqlCondition(StringBuilder sql) {
+ StringBuilder appendSqlCondition(StringBuilder sql) {
sql.append(" pm.metric_id=");
sql.append(metric.getId());
sql.append(" AND ").append(valueColumn()).append(operator.getSql()).append(value);
+ return sql;
}
@Override
connection = session.getConnection();
DdlUtils.createSchema(connection, database.getDialect().getId());
} finally {
- try {
- MyBatis.closeQuietly(session);
+ MyBatis.closeQuietly(session);
- // The connection is probably already closed by session.close()
- // but it's not documented in mybatis javadoc.
- if (null != connection) {
- connection.close();
- }
- } catch (Exception e) {
- // ignore
- }
+ // The connection is probably already closed by session.close()
+ // but it's not documented in mybatis javadoc.
+ DatabaseUtils.closeQuietly(connection);
}
return true;
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.measure;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.measures.Metric;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class MeasureFilterConditionTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void create_operator_from_code() {
+ assertThat(MeasureFilterCondition.Operator.fromCode("eq")).isEqualTo(MeasureFilterCondition.Operator.EQUALS);
+ assertThat(MeasureFilterCondition.Operator.fromCode("lte")).isEqualTo(MeasureFilterCondition.Operator.LESS_OR_EQUALS);
+ }
+
+ @Test
+ public void fail_if_operator_code_not_found() {
+ thrown.expect(IllegalArgumentException.class);
+ MeasureFilterCondition.Operator.fromCode("xxx");
+ }
+
+ @Test
+ public void operator_sql() {
+ assertThat(MeasureFilterCondition.Operator.EQUALS.getSql()).isEqualTo("=");
+ assertThat(MeasureFilterCondition.Operator.LESS_OR_EQUALS.getSql()).isEqualTo("<=");
+ assertThat(MeasureFilterCondition.Operator.GREATER.getSql()).isEqualTo(">");
+ }
+
+ @Test
+ public void value_condition() {
+ Metric ncloc = new Metric.Builder("ncloc", "NCLOC", Metric.ValueType.INT).create();
+ ncloc.setId(123);
+ MeasureFilterCondition condition = new MeasureFilterCondition(ncloc, MeasureFilterCondition.Operator.GREATER, 10.0);
+
+ assertThat(condition.metric()).isEqualTo(ncloc);
+ assertThat(condition.operator()).isEqualTo(MeasureFilterCondition.Operator.GREATER);
+ assertThat(condition.period()).isNull();
+ assertThat(condition.value()).isEqualTo(10.0);
+ assertThat(condition.valueColumn()).isEqualTo("pm.value");
+ assertThat(condition.toString()).isNotEmpty();
+ assertThat(condition.appendSqlCondition(new StringBuilder()).toString()).isEqualTo(" pm.metric_id=123 AND pm.value>10.0");
+ }
+
+ @Test
+ public void variation_condition() {
+ Metric ncloc = new Metric.Builder("ncloc", "NCLOC", Metric.ValueType.INT).create();
+ ncloc.setId(123);
+ MeasureFilterCondition condition = new MeasureFilterCondition(ncloc, MeasureFilterCondition.Operator.LESS_OR_EQUALS, 10.0);
+ condition.setPeriod(3);
+
+ assertThat(condition.metric()).isEqualTo(ncloc);
+ assertThat(condition.operator()).isEqualTo(MeasureFilterCondition.Operator.LESS_OR_EQUALS);
+ assertThat(condition.period()).isEqualTo(3);
+ assertThat(condition.value()).isEqualTo(10.0);
+ assertThat(condition.valueColumn()).isEqualTo("pm.variation_value_3");
+ assertThat(condition.toString()).isNotEmpty();
+ assertThat(condition.appendSqlCondition(new StringBuilder()).toString()).isEqualTo(" pm.metric_id=123 AND pm.variation_value_3<=10.0");
+ }
+}
import java.util.Properties;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class OracleSequenceGeneratorTest {
OracleSequenceGenerator generator = new OracleSequenceGenerator();
generator.configure(null, props, new Oracle.Oracle10gWithDecimalDialect());
- assertThat(generator.getSequenceName(), is("MY_TABLE_SEQ"));
+ assertThat(generator.getSequenceName()).isEqualTo("MY_TABLE_SEQ");
}
+ @Test
+ public void should_not_fail_if_table_name_can_not_be_loaded() {
+ Properties props = new Properties();
+ OracleSequenceGenerator generator = new OracleSequenceGenerator();
+ generator.configure(null, props, new Oracle.Oracle10gWithDecimalDialect());
+ assertThat(generator.getSequenceName()).isNotEmpty();
+ }
}
import static org.mockito.Mockito.when;
public class RegisterNewMeasureFiltersTest {
- private RegisterNewMeasureFilters registerMeasure;
+ private RegisterNewMeasureFilters registration;
private MeasureFilterDao filterDao;
private LoadedTemplateDao loadedTemplateDao;
private FilterTemplate filterTemplate;
loadedTemplateDao = mock(LoadedTemplateDao.class);
filterTemplate = mock(FilterTemplate.class);
- registerMeasure = new RegisterNewMeasureFilters(new FilterTemplate[]{filterTemplate}, filterDao, loadedTemplateDao);
+ registration = new RegisterNewMeasureFilters(new FilterTemplate[]{filterTemplate}, filterDao, loadedTemplateDao);
}
@Test
when(loadedTemplateDao.countByTypeAndKey(eq(LoadedTemplateDto.FILTER_TYPE), anyString())).thenReturn(0);
when(filterTemplate.createFilter()).thenReturn(Filter.create());
- registerMeasure.start();
+ registration.start();
verify(filterDao).insert(any(MeasureFilterDto.class));
verify(loadedTemplateDao).insert(any(LoadedTemplateDto.class));
public void should_insert_nothing_if_templates_are_alreday_loaded() {
when(loadedTemplateDao.countByTypeAndKey(eq(LoadedTemplateDto.FILTER_TYPE), anyString())).thenReturn(1);
- registerMeasure.start();
+ registration.start();
verify(filterDao, never()).insert(any(MeasureFilterDto.class));
verify(loadedTemplateDao, never()).insert(any(LoadedTemplateDto.class));
public void should_register_filter() {
when(filterTemplate.createFilter()).thenReturn(Filter.create());
- MeasureFilterDto filterDto = registerMeasure.register("Fake", filterTemplate.createFilter());
+ MeasureFilterDto filterDto = registration.register("Fake", filterTemplate.createFilter());
assertThat(filterDto).isNotNull();
verify(filterDao).insert(filterDto);
public void should_not_recreate_filter() {
when(filterDao.findSystemFilterByName("Fake")).thenReturn(new MeasureFilterDto());
- MeasureFilterDto filterDto = registerMeasure.register("Fake", null);
+ MeasureFilterDto filterDto = registration.register("Fake", null);
assertThat(filterDto).isNull();
verify(filterDao, never()).insert(filterDto);
.add(FilterColumn.create("metric", "distance", "ASC", false))
);
- MeasureFilterDto dto = registerMeasure.createDtoFromExtension("Fake", filterTemplate.createFilter());
+ MeasureFilterDto dto = registration.createDtoFromExtension("Fake", filterTemplate.createFilter());
assertThat(dto.getName()).isEqualTo("Fake");
assertThat(dto.isShared()).isTrue();
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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 org.junit.Test;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.core.properties.PropertiesDao;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+public class RenameDeprecatedPropertyKeysTest {
+ @Test
+ public void should_rename_deprecated_keys() {
+ PropertiesDao dao = mock(PropertiesDao.class);
+ PropertyDefinitions definitions = new PropertyDefinitions(FakeExtension.class);
+ RenameDeprecatedPropertyKeys task = new RenameDeprecatedPropertyKeys(dao, definitions);
+ task.start();
+
+ verify(dao).renamePropertyKey("old_key", "new_key");
+ verifyNoMoreInteractions(dao);
+ }
+
+ @Properties({
+ @Property(key = "new_key", deprecatedKey = "old_key", name = "Name"),
+ @Property(key = "other", name = "Other")
+ })
+ public static class FakeExtension {
+
+ }
+}