aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-21 10:49:24 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-21 10:49:24 +0200
commitd1015259b51a4bfb21325e1823c4a2c1637c0ff4 (patch)
tree769a4703f25b2a0a25af5072faa031c66fd7b098
parent64bd8932d2dd5844937f2e1b506f967a9f3b1a52 (diff)
downloadsonarqube-d1015259b51a4bfb21325e1823c4a2c1637c0ff4.tar.gz
sonarqube-d1015259b51a4bfb21325e1823c4a2c1637c0ff4.zip
SONAR-5320 Property "sonar.technicalDebt.hoursInDay" were not been taking into account when migrating issues and measures from hours to minutes
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java6
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java10
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueMigration.java10
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java6
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java16
-rw-r--r--sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationTest.java14
-rw-r--r--sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java11
-rw-r--r--sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueMigrationTest.java11
-rw-r--r--sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationTest.java14
-rw-r--r--sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java (renamed from sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DebtMigrationExecutorTest.java)18
10 files changed, 65 insertions, 51 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java
index 06d39511ceb..0bb8d3cb7cf 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java
@@ -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
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java
index 6133183688d..ee2dff668a9 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java
@@ -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;
}
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueMigration.java
index 539e1e9d393..c34e0c419eb 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueMigration.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueMigration.java
@@ -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;
}
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java
index 022d5863238..85fe5a192b1 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java
@@ -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
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java
index cf1df726ea2..b31ec9e2614 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java
@@ -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/DevelopmentCostMeasuresMigrationTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationTest.java
index dddfcf7487e..5faeeba177f 100644
--- a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationTest.java
@@ -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
diff --git a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java
index 0ce7c54c1de..9808acbc3ee 100644
--- a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java
@@ -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
diff --git a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueMigrationTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueMigrationTest.java
index 601540c77ac..3b4eacebd02 100644
--- a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueMigrationTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueMigrationTest.java
@@ -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
diff --git a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationTest.java
index 99ecd0dee0e..5372118b0df 100644
--- a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationTest.java
@@ -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/DebtMigrationExecutorTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java
index 17b253323f9..eb64d80f1f9 100644
--- 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/WorkDurationConvertorTest.java
@@ -21,24 +21,28 @@
package org.sonar.server.db.migrations.v43;
import org.junit.Test;
-import org.sonar.api.config.Settings;
+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 DebtMigrationExecutorTest {
+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;
- Settings settings = new Settings();
- WorkDurationConvertor convertor = new WorkDurationConvertor(settings);
+ PropertiesDao propertiesDao = mock(PropertiesDao.class);
+
+ WorkDurationConvertor convertor = new WorkDurationConvertor(propertiesDao);
@Test
public void convert_from_long() throws Exception {
- settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, HOURS_IN_DAY);
+ 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);
@@ -54,7 +58,7 @@ public class DebtMigrationExecutorTest {
@Test
public void fail_convert_from_long_on_bad_hours_in_day_property() throws Exception {
try {
- settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, -2);
+ when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("-2"));
convertor.createFromLong(1);
fail();
} catch (Exception e) {
@@ -64,7 +68,7 @@ public class DebtMigrationExecutorTest {
@Test
public void convert_from_days() throws Exception {
- settings.setProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY, HOURS_IN_DAY);
+ 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);