]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 6 Dec 2012 22:56:22 +0000 (23:56 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 6 Dec 2012 22:56:22 +0000 (23:56 +0100)
13 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboard.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ActionPlansWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/actionPlans/action_plans.html.erb [deleted file]
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/action_plans.html.erb [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboardTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoreWidgetsTest.java
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterCondition.java
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseMigrator.java
sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterConditionTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleSequenceGeneratorTest.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterNewMeasureFiltersTest.java
sonar-server/src/test/java/org/sonar/server/startup/RenameDeprecatedPropertyKeysTest.java [new file with mode: 0644]

index d58987ec998b2ae31511c382509fece168b8576e..c0719a2c8983e84d9bda1d025318951e2291e4c9 100644 (file)
@@ -46,34 +46,40 @@ public final class GlobalDefaultDashboard extends DashboardTemplate {
   @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
index 6964ec72987c956f489a7f571210dc88a21c5821..f64f68ad1a1db92fce5aeebce6599ddde8616312 100644 (file)
@@ -24,6 +24,6 @@ import org.sonar.api.web.WidgetCategory;
 @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
index a5f4e4612c5ee54434304cb4e02edf8c66cbf343..a551f35d74e0d9b700736a93a53728717999f2a4 100644 (file)
@@ -39,7 +39,6 @@ public class MeasureFilterListWidget extends CoreWidget {
   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");
   }
 }
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/actionPlans/action_plans.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/actionPlans/action_plans.html.erb
deleted file mode 100644 (file)
index 208641d..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<%
-   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 %>
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/action_plans.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/action_plans.html.erb
new file mode 100644 (file)
index 0000000..208641d
--- /dev/null
@@ -0,0 +1,57 @@
+<%
+   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 %>
index 2081d92c49986a994da5304152605263489c7d20..83772b25ac03939209868defb78164272078c6e5 100644 (file)
@@ -61,11 +61,11 @@ public class GlobalDefaultDashboardTest {
   @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);
@@ -80,4 +80,18 @@ public class GlobalDefaultDashboardTest {
     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();
+  }
 }
index 19393c20e11a9274941303976df02807fbd2a293..831c922268fc4cede735d730af04b3388088f75f 100644 (file)
@@ -72,14 +72,16 @@ public class CoreWidgetsTest {
   @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());
     }
   }
 
index 2485c905583e7f80e7899961263c5cda8bfb45c9..746902aff2515770e9109b9105cd0a4430a218f9 100644 (file)
@@ -35,10 +35,6 @@ public class MeasureFilterCondition {
       this.sql = sql;
     }
 
-    public String getCode() {
-      return code;
-    }
-
     public String getSql() {
       return sql;
     }
@@ -51,15 +47,6 @@ public class MeasureFilterCondition {
       }
       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;
@@ -101,10 +88,11 @@ public class MeasureFilterCondition {
     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
index dba97bb0a700272b0ba09ccf81e5c84bd463c3e6..3211cc55c39ec5dea906d3159b7ca9e382ec82e8 100644 (file)
@@ -57,17 +57,11 @@ public class DatabaseMigrator implements ServerComponent {
       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;
   }
diff --git a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterConditionTest.java b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterConditionTest.java
new file mode 100644 (file)
index 0000000..112975f
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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");
+  }
+}
index 9333cb0dd53a007d5e9a5f02322aa5009801f7a6..e50efdac84469b0d23f7ca20f72e80d8ea3e34b8 100644 (file)
@@ -24,8 +24,7 @@ import org.junit.Test;
 
 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 {
 
@@ -37,7 +36,14 @@ 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();
+  }
 }
index 69c881273bc9416c7cd083c3c1e1e7500a959818..efe5a492a1fe0387a6326fbdefc2913771934594 100644 (file)
@@ -40,7 +40,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 public class RegisterNewMeasureFiltersTest {
-  private RegisterNewMeasureFilters registerMeasure;
+  private RegisterNewMeasureFilters registration;
   private MeasureFilterDao filterDao;
   private LoadedTemplateDao loadedTemplateDao;
   private FilterTemplate filterTemplate;
@@ -51,7 +51,7 @@ public class RegisterNewMeasureFiltersTest {
     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
@@ -59,7 +59,7 @@ public class RegisterNewMeasureFiltersTest {
     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));
@@ -69,7 +69,7 @@ public class RegisterNewMeasureFiltersTest {
   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));
@@ -79,7 +79,7 @@ public class RegisterNewMeasureFiltersTest {
   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);
@@ -90,7 +90,7 @@ public class RegisterNewMeasureFiltersTest {
   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);
@@ -107,7 +107,7 @@ public class RegisterNewMeasureFiltersTest {
       .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();
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RenameDeprecatedPropertyKeysTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RenameDeprecatedPropertyKeysTest.java
new file mode 100644 (file)
index 0000000..06ba9b9
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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 {
+
+  }
+}