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;
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
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;
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;
}
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;
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;
}
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;
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
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 {
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) {
}
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;
}
+++ /dev/null
-/*
- * 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);
- }
-
-}
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 {
@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
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;
@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
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;
@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
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 {
@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
--- /dev/null
+/*
+ * 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);
+ }
+
+}