]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5320 Property "sonar.technicalDebt.hoursInDay" were not been taking into accoun...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 21 May 2014 08:49:24 +0000 (10:49 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 21 May 2014 08:49:24 +0000 (10:49 +0200)
sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java
sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java
sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueMigration.java
sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java
sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java
sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DebtMigrationExecutorTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationTest.java
sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java
sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueMigrationTest.java
sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationTest.java
sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java [new file with mode: 0644]

index 06d39511ceb0e0629fbe1cf37222efb932a9d395..0bb8d3cb7cff3d5ea2d342c8415f905fa394e7a6 100644 (file)
@@ -20,8 +20,8 @@
 
 package org.sonar.server.db.migrations.v43;
 
-import org.sonar.api.config.Settings;
 import org.sonar.core.persistence.Database;
+import org.sonar.core.properties.PropertiesDao;
 import org.sonar.server.db.migrations.DatabaseMigration;
 import org.sonar.server.db.migrations.MassUpdater;
 import org.sonar.server.db.migrations.SqlUtil;
@@ -41,9 +41,9 @@ public class DevelopmentCostMeasuresMigration implements DatabaseMigration {
   private final WorkDurationConvertor workDurationConvertor;
   private final Database db;
 
-  public DevelopmentCostMeasuresMigration(Database database, Settings settings) {
+  public DevelopmentCostMeasuresMigration(Database database, PropertiesDao propertiesDao) {
     this.db = database;
-    this.workDurationConvertor = new WorkDurationConvertor(settings);
+    this.workDurationConvertor = new WorkDurationConvertor(propertiesDao);
   }
 
   @Override
index 6133183688d654a951bc658d4624e2a3f9ce049f..ee2dff668a9aa7b1a875b5d884861cb67b57177d 100644 (file)
@@ -22,9 +22,9 @@ package org.sonar.server.db.migrations.v43;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
-import org.sonar.api.config.Settings;
 import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.Database;
+import org.sonar.core.properties.PropertiesDao;
 import org.sonar.server.db.migrations.DatabaseMigration;
 import org.sonar.server.db.migrations.MassUpdater;
 import org.sonar.server.db.migrations.SqlUtil;
@@ -46,14 +46,14 @@ public class IssueChangelogMigration implements DatabaseMigration {
   private final System2 system2;
   private final Database db;
 
-  public IssueChangelogMigration(Database database, Settings settings) {
-    this(database, settings, System2.INSTANCE);
+  public IssueChangelogMigration(Database database, PropertiesDao propertiesDao) {
+    this(database, propertiesDao, System2.INSTANCE);
   }
 
   @VisibleForTesting
-  IssueChangelogMigration(Database database, Settings settings, System2 system2) {
+  IssueChangelogMigration(Database database, PropertiesDao propertiesDao, System2 system2) {
     this.db = database;
-    this.workDurationConvertor = new WorkDurationConvertor(settings);
+    this.workDurationConvertor = new WorkDurationConvertor(propertiesDao);
     this.system2 = system2;
   }
 
index 539e1e9d39315ce119b3b67e50eeab605c6cfb48..c34e0c419eb9ce75b3e6296d153f2e356cdb2407 100644 (file)
@@ -21,9 +21,9 @@
 package org.sonar.server.db.migrations.v43;
 
 import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.config.Settings;
 import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.Database;
+import org.sonar.core.properties.PropertiesDao;
 import org.sonar.server.db.migrations.DatabaseMigration;
 import org.sonar.server.db.migrations.MassUpdater;
 import org.sonar.server.db.migrations.SqlUtil;
@@ -43,14 +43,14 @@ public class IssueMigration implements DatabaseMigration {
   private final System2 system2;
   private final Database db;
 
-  public IssueMigration(Database database, Settings settings) {
-    this(database, settings, System2.INSTANCE);
+  public IssueMigration(Database database, PropertiesDao propertiesDao) {
+    this(database, propertiesDao, System2.INSTANCE);
   }
 
   @VisibleForTesting
-  IssueMigration(Database database, Settings settings, System2 system2) {
+  IssueMigration(Database database, PropertiesDao propertiesDao, System2 system2) {
     this.db = database;
-    this.workDurationConvertor = new WorkDurationConvertor(settings);
+    this.workDurationConvertor = new WorkDurationConvertor(propertiesDao);
     this.system2 = system2;
   }
 
index 022d58632382f4fac7d9285dd48a9ac4b4421f39..85fe5a192b1b15e4446615b705884dee6ce8d7a0 100644 (file)
@@ -20,8 +20,8 @@
 
 package org.sonar.server.db.migrations.v43;
 
-import org.sonar.api.config.Settings;
 import org.sonar.core.persistence.Database;
+import org.sonar.core.properties.PropertiesDao;
 import org.sonar.server.db.migrations.DatabaseMigration;
 import org.sonar.server.db.migrations.MassUpdater;
 import org.sonar.server.db.migrations.SqlUtil;
@@ -54,9 +54,9 @@ public class TechnicalDebtMeasuresMigration implements DatabaseMigration {
   private final WorkDurationConvertor workDurationConvertor;
   private final Database db;
 
-  public TechnicalDebtMeasuresMigration(Database database, Settings settings) {
+  public TechnicalDebtMeasuresMigration(Database database, PropertiesDao propertiesDao) {
     this.db = database;
-    this.workDurationConvertor = new WorkDurationConvertor(settings);
+    this.workDurationConvertor = new WorkDurationConvertor(propertiesDao);
   }
 
   @Override
index cf1df726ea2ebbabc61273e0339ab83e725e4a98..b31ec9e26146becf28bed4d223c58117eefdcd08 100644 (file)
@@ -20,7 +20,8 @@
 
 package org.sonar.server.db.migrations.v43;
 
-import org.sonar.api.config.Settings;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
 
 class WorkDurationConvertor {
 
@@ -28,10 +29,10 @@ class WorkDurationConvertor {
 
   static final String HOURS_IN_DAY_PROPERTY = "sonar.technicalDebt.hoursInDay";
 
-  private final Settings settings;
+  private final PropertiesDao propertiesDao;
 
-  WorkDurationConvertor(Settings settings) {
-    this.settings = settings;
+  WorkDurationConvertor(PropertiesDao propertiesDao) {
+    this.propertiesDao = propertiesDao;
   }
 
   long createFromLong(long durationInLong) {
@@ -65,13 +66,12 @@ class WorkDurationConvertor {
   }
 
   private int hoursInDay() {
-    int hoursInDay = settings.getInt(HOURS_IN_DAY_PROPERTY);
+    PropertyDto propertyDto = propertiesDao.selectGlobalProperty(HOURS_IN_DAY_PROPERTY);
+    String value = propertyDto != null ? propertyDto.getValue() : "8";
+    int hoursInDay = Integer.valueOf(value);
     if (hoursInDay < 0) {
       throw new IllegalArgumentException(String.format("Bad value of %s: %d", HOURS_IN_DAY_PROPERTY, hoursInDay));
     }
-    if (hoursInDay == 0) {
-      hoursInDay = 8;
-    }
     return hoursInDay;
   }
 
diff --git a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DebtMigrationExecutorTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DebtMigrationExecutorTest.java
deleted file mode 100644 (file)
index 17b2533..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.db.migrations.v43;
-
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class DebtMigrationExecutorTest {
-
-  static final int HOURS_IN_DAY = 8;
-  static final Long ONE_MINUTE = 1L;
-  static final Long ONE_HOUR_IN_MINUTES = ONE_MINUTE * 60;
-  static final Long ONE_DAY_IN_MINUTES = ONE_HOUR_IN_MINUTES * HOURS_IN_DAY;
-
-  Settings settings = new Settings();
-  WorkDurationConvertor convertor = new WorkDurationConvertor(settings);
-
-  @Test
-  public void convert_from_long() throws Exception {
-    settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, HOURS_IN_DAY);
-
-    assertThat(convertor.createFromLong(1)).isEqualTo(ONE_MINUTE);
-    assertThat(convertor.createFromLong(100)).isEqualTo(ONE_HOUR_IN_MINUTES);
-    assertThat(convertor.createFromLong(10000)).isEqualTo(ONE_DAY_IN_MINUTES);
-    assertThat(convertor.createFromLong(10101)).isEqualTo(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE);
-  }
-
-  @Test
-  public void convert_from_long_use_default_value_for_hours_in_day_when_no_property() throws Exception {
-    assertThat(convertor.createFromLong(1)).isEqualTo(ONE_MINUTE);
-  }
-
-  @Test
-  public void fail_convert_from_long_on_bad_hours_in_day_property() throws Exception {
-    try {
-      settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, -2);
-      convertor.createFromLong(1);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalArgumentException.class);
-    }
-  }
-
-  @Test
-  public void convert_from_days() throws Exception {
-    settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, HOURS_IN_DAY);
-
-    assertThat(convertor.createFromDays(1.0)).isEqualTo(ONE_DAY_IN_MINUTES);
-    assertThat(convertor.createFromDays(0.1)).isEqualTo(48L);
-
-    // Should be 4.8 but as it's a long it's truncated after comma
-    assertThat(convertor.createFromDays(0.01)).isEqualTo(4L);
-  }
-
-}
index dddfcf7487eec1fbee36c813f3d6b7928b87ec53..5faeeba177f82561d16c4c9bb3f7963c89f0569e 100644 (file)
@@ -24,9 +24,13 @@ import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.config.Settings;
 import org.sonar.core.persistence.TestDatabase;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
+
+import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
 public class DevelopmentCostMeasuresMigrationTest {
@@ -34,16 +38,16 @@ public class DevelopmentCostMeasuresMigrationTest {
   @ClassRule
   public static TestDatabase db = new TestDatabase().schema(DevelopmentCostMeasuresMigrationTest.class, "schema.sql");
 
-  Settings settings;
+  @Mock
+  PropertiesDao propertiesDao;
 
   DevelopmentCostMeasuresMigration migration;
 
   @Before
   public void setUp() throws Exception {
-    settings = new Settings();
-    settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, 8);
+    when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("8"));
 
-    migration = new DevelopmentCostMeasuresMigration(db.database(), settings);
+    migration = new DevelopmentCostMeasuresMigration(db.database(), propertiesDao);
   }
 
   @Test
index 0ce7c54c1de5acc11a6c1487cfbdafef5d1af5c5..9808acbc3ee3e8a1c0949d0949d9df2d3d3379a3 100644 (file)
@@ -26,10 +26,11 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.config.Settings;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.TestDatabase;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.when;
@@ -43,17 +44,17 @@ public class IssueChangelogMigrationTest {
   @Mock
   System2 system2;
 
-  Settings settings;
+  @Mock
+  PropertiesDao propertiesDao;
 
   IssueChangelogMigration migration;
 
   @Before
   public void setUp() throws Exception {
     when(system2.now()).thenReturn(DateUtils.parseDateTime("2014-02-19T19:10:03+0100").getTime());
-    settings = new Settings();
-    settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, 8);
+    when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("8"));
 
-    migration = new IssueChangelogMigration(db.database(), settings, system2);
+    migration = new IssueChangelogMigration(db.database(), propertiesDao, system2);
   }
 
   @Test
index 601540c77ac00b76a655bacb392300a8e49171ba..3b4eacebd02ac43920e6112e8d6ec800393bbda5 100644 (file)
@@ -26,10 +26,11 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.config.Settings;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.TestDatabase;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
 
 import static org.mockito.Mockito.when;
 
@@ -42,17 +43,17 @@ public class IssueMigrationTest {
   @Mock
   System2 system2;
 
-  Settings settings;
+  @Mock
+  PropertiesDao propertiesDao;
 
   IssueMigration migration;
 
   @Before
   public void setUp() throws Exception {
     when(system2.now()).thenReturn(DateUtils.parseDateTime("2014-02-19T19:10:03+0100").getTime());
-    settings = new Settings();
-    settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, 8);
+    when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("8"));
 
-    migration = new IssueMigration(db.database(), settings, system2);
+    migration = new IssueMigration(db.database(), propertiesDao, system2);
   }
 
   @Test
index 99ecd0dee0ee55959145b6b7b1fdc44f3576246d..5372118b0df45f7368c08f4767bf50618c7b63af 100644 (file)
@@ -24,9 +24,13 @@ import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.config.Settings;
 import org.sonar.core.persistence.TestDatabase;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
+
+import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
 public class TechnicalDebtMeasuresMigrationTest {
@@ -34,16 +38,16 @@ public class TechnicalDebtMeasuresMigrationTest {
   @ClassRule
   public static TestDatabase db = new TestDatabase().schema(TechnicalDebtMeasuresMigrationTest.class, "schema.sql");
 
-  Settings settings;
+  @Mock
+  PropertiesDao propertiesDao;
 
   TechnicalDebtMeasuresMigration migration;
 
   @Before
   public void setUp() throws Exception {
-    settings = new Settings();
-    settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, 8);
+    when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("8"));
 
-    migration = new TechnicalDebtMeasuresMigration(db.database(), settings);
+    migration = new TechnicalDebtMeasuresMigration(db.database(), propertiesDao);
   }
 
   @Test
diff --git a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java
new file mode 100644 (file)
index 0000000..eb64d80
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.db.migrations.v43;
+
+import org.junit.Test;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class WorkDurationConvertorTest {
+
+  static final int HOURS_IN_DAY = 8;
+  static final Long ONE_MINUTE = 1L;
+  static final Long ONE_HOUR_IN_MINUTES = ONE_MINUTE * 60;
+  static final Long ONE_DAY_IN_MINUTES = ONE_HOUR_IN_MINUTES * HOURS_IN_DAY;
+
+  PropertiesDao propertiesDao = mock(PropertiesDao.class);
+
+  WorkDurationConvertor convertor = new WorkDurationConvertor(propertiesDao);
+
+  @Test
+  public void convert_from_long() throws Exception {
+    when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue(Integer.toString(HOURS_IN_DAY)));
+
+    assertThat(convertor.createFromLong(1)).isEqualTo(ONE_MINUTE);
+    assertThat(convertor.createFromLong(100)).isEqualTo(ONE_HOUR_IN_MINUTES);
+    assertThat(convertor.createFromLong(10000)).isEqualTo(ONE_DAY_IN_MINUTES);
+    assertThat(convertor.createFromLong(10101)).isEqualTo(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE);
+  }
+
+  @Test
+  public void convert_from_long_use_default_value_for_hours_in_day_when_no_property() throws Exception {
+    assertThat(convertor.createFromLong(1)).isEqualTo(ONE_MINUTE);
+  }
+
+  @Test
+  public void fail_convert_from_long_on_bad_hours_in_day_property() throws Exception {
+    try {
+      when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("-2"));
+      convertor.createFromLong(1);
+      fail();
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(IllegalArgumentException.class);
+    }
+  }
+
+  @Test
+  public void convert_from_days() throws Exception {
+    when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue(Integer.toString(HOURS_IN_DAY)));
+
+    assertThat(convertor.createFromDays(1.0)).isEqualTo(ONE_DAY_IN_MINUTES);
+    assertThat(convertor.createFromDays(0.1)).isEqualTo(48L);
+
+    // Should be 4.8 but as it's a long it's truncated after comma
+    assertThat(convertor.createFromDays(0.01)).isEqualTo(4L);
+  }
+
+}