From d88d443bbe5c5dabe45b44760108fa7b506cd7d9 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 18 Feb 2016 20:11:12 +0100 Subject: SONAR-7364 Remove SQALE characteristics from measures and rules --- .../src/test/java/org/sonar/db/DaoModuleTest.java | 2 +- .../org/sonar/db/debt/CharacteristicDaoTest.java | 233 --------------------- .../org/sonar/db/debt/CharacteristicDtoTest.java | 83 -------- .../java/org/sonar/db/measure/MeasureDaoTest.java | 49 ----- .../org/sonar/db/measure/PastMeasureDtoTest.java | 4 - .../test/java/org/sonar/db/rule/RuleDaoTest.java | 2 - .../test/java/org/sonar/db/rule/RuleDtoTest.java | 33 --- .../sonar/db/version/MigrationStepModuleTest.java | 2 +- .../DeleteMeasuresWithCharacteristicIdTest.java | 56 +++++ .../insert_characteristic-result.xml | 7 - .../select_enabled_root_characteristics.xml | 24 --- ...aracteristics_order_by_characteristic_order.xml | 15 -- ...order_when_characteristics_are_all_disabled.xml | 14 -- .../select_sub_characteristics_by_parent_id.xml | 35 ---- .../sonar/db/debt/CharacteristicDaoTest/shared.xml | 26 --- .../update_characteristic-result.xml | 7 - .../update_characteristic.xml | 7 - .../debt/RequirementDaoTest/select_requirement.xml | 10 - .../sonar/db/debt/RequirementDaoTest/shared.xml | 17 -- .../db/measure/MeasureDaoTest/insert-result.xml | 2 +- .../past_measures_with_characteristic_id.xml | 28 --- ...eteWastedMeasuresWhenPurgingSnapshot-result.xml | 4 - ...ouldDeleteWastedMeasuresWhenPurgingSnapshot.xml | 4 - .../before.xml | 7 + .../schema.sql | 25 +++ 25 files changed, 91 insertions(+), 605 deletions(-) delete mode 100644 sonar-db/src/test/java/org/sonar/db/debt/CharacteristicDaoTest.java delete mode 100644 sonar-db/src/test/java/org/sonar/db/debt/CharacteristicDtoTest.java create mode 100644 sonar-db/src/test/java/org/sonar/db/version/v55/DeleteMeasuresWithCharacteristicIdTest.java delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/insert_characteristic-result.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_enabled_root_characteristics.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_enabled_root_characteristics_order_by_characteristic_order.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_max_characteristic_order_when_characteristics_are_all_disabled.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_sub_characteristics_by_parent_id.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/shared.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/update_characteristic-result.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/update_characteristic.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/RequirementDaoTest/select_requirement.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/debt/RequirementDaoTest/shared.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_characteristic_id.xml create mode 100644 sonar-db/src/test/resources/org/sonar/db/version/v55/DeleteMeasuresWithCharacteristicIdTest/before.xml create mode 100644 sonar-db/src/test/resources/org/sonar/db/version/v55/DeleteMeasuresWithCharacteristicIdTest/schema.sql (limited to 'sonar-db/src/test') diff --git a/sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java b/sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java index 7e5f79e1d22..61215aa8b3a 100644 --- a/sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java @@ -29,6 +29,6 @@ public class DaoModuleTest { public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new DaoModule().configure(container); - assertThat(container.size()).isEqualTo(49); + assertThat(container.size()).isEqualTo(48); } } diff --git a/sonar-db/src/test/java/org/sonar/db/debt/CharacteristicDaoTest.java b/sonar-db/src/test/java/org/sonar/db/debt/CharacteristicDaoTest.java deleted file mode 100644 index a8a8e11fa37..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/debt/CharacteristicDaoTest.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.debt; - -import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.sonar.api.utils.DateUtils; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; -import org.sonar.test.DbTests; - -import static com.google.common.collect.Lists.newArrayList; -import static org.assertj.core.api.Assertions.assertThat; - -@Category(DbTests.class) -public class CharacteristicDaoTest { - - private static final String[] EXCLUDED_COLUMNS = new String[] {"id", "root_id", "rule_id", "function_key", "factor_unit", "factor_value", "offset_unit", "offset_value"}; - - @Rule - public DbTester db = DbTester.create(System2.INSTANCE); - - CharacteristicDao dao = db.getDbClient().debtCharacteristicDao(); - - @Test - public void select_enabled_characteristics() { - db.prepareDbUnit(getClass(), "shared.xml"); - - List dtos = dao.selectEnabledCharacteristics(); - - assertThat(dtos).hasSize(2); - - CharacteristicDto rootCharacteristic = dtos.get(0); - assertThat(rootCharacteristic.getId()).isEqualTo(1); - assertThat(rootCharacteristic.getKey()).isEqualTo("PORTABILITY"); - assertThat(rootCharacteristic.getName()).isEqualTo("Portability"); - assertThat(rootCharacteristic.getParentId()).isNull(); - assertThat(rootCharacteristic.getOrder()).isEqualTo(1); - assertThat(rootCharacteristic.isEnabled()).isTrue(); - assertThat(rootCharacteristic.getCreatedAt()).isNotNull(); - assertThat(rootCharacteristic.getUpdatedAt()).isNotNull(); - - CharacteristicDto characteristic = dtos.get(1); - assertThat(characteristic.getId()).isEqualTo(2); - assertThat(characteristic.getKey()).isEqualTo("COMPILER_RELATED_PORTABILITY"); - assertThat(characteristic.getName()).isEqualTo("Compiler related portability"); - assertThat(characteristic.getParentId()).isEqualTo(1); - assertThat(characteristic.getOrder()).isNull(); - assertThat(characteristic.isEnabled()).isTrue(); - assertThat(characteristic.getCreatedAt()).isNotNull(); - assertThat(characteristic.getUpdatedAt()).isNotNull(); - } - - @Test - public void select_characteristics() { - db.prepareDbUnit(getClass(), "shared.xml"); - - assertThat(dao.selectCharacteristics()).hasSize(4); - } - - @Test - public void select_enabled_root_characteristics() { - db.prepareDbUnit(getClass(), "select_enabled_root_characteristics.xml"); - - List dtos = dao.selectEnabledRootCharacteristics(); - - assertThat(dtos).hasSize(1); - - CharacteristicDto rootCharacteristic = dtos.get(0); - assertThat(rootCharacteristic.getId()).isEqualTo(1); - assertThat(rootCharacteristic.getKey()).isEqualTo("PORTABILITY"); - } - - @Test - public void select_enabled_root_characteristics_order_by_characteristic_order() { - db.prepareDbUnit(getClass(), "select_enabled_root_characteristics_order_by_characteristic_order.xml"); - - List dtos = dao.selectEnabledRootCharacteristics(); - - assertThat(dtos).hasSize(3); - assertThat(dtos.get(0).getKey()).isEqualTo("TESTABILITY"); - assertThat(dtos.get(1).getKey()).isEqualTo("PORTABILITY"); - assertThat(dtos.get(2).getKey()).isEqualTo("MAINTAINABILITY"); - } - - @Test - public void select_sub_characteristics_by_parent_id() { - db.prepareDbUnit(getClass(), "select_sub_characteristics_by_parent_id.xml"); - - assertThat(dao.selectCharacteristicsByParentId(1)).hasSize(2); - assertThat(dao.selectCharacteristicsByParentId(55)).isEmpty(); - } - - @Test - public void select_characteristics_by_ids() { - db.prepareDbUnit(getClass(), "shared.xml"); - - assertThat(dao.selectCharacteristicsByIds(newArrayList(1, 2))).hasSize(2); - assertThat(dao.selectCharacteristicsByIds(newArrayList(1))).hasSize(1); - - // Disabled characteristics are not returned - assertThat(dao.selectCharacteristicsByIds(newArrayList(4, 5))).isEmpty(); - } - - @Test - public void select_characteristic_by_key() { - db.prepareDbUnit(getClass(), "shared.xml"); - - CharacteristicDto dto = dao.selectByKey("COMPILER_RELATED_PORTABILITY"); - assertThat(dto).isNotNull(); - assertThat(dto.getId()).isEqualTo(2); - assertThat(dto.getParentId()).isEqualTo(1); - - dto = dao.selectByKey("PORTABILITY"); - assertThat(dto).isNotNull(); - assertThat(dto.getId()).isEqualTo(1); - assertThat(dto.getParentId()).isNull(); - - assertThat(dao.selectByKey("UNKNOWN")).isNull(); - } - - @Test - public void select_characteristic_by_name() { - db.prepareDbUnit(getClass(), "shared.xml"); - - assertThat(dao.selectByName("Portability")).isNotNull(); - assertThat(dao.selectByName("Compiler related portability")).isNotNull(); - assertThat(dao.selectByName("Unknown")).isNull(); - } - - @Test - public void select_characteristic_by_id() { - db.prepareDbUnit(getClass(), "shared.xml"); - - assertThat(dao.selectById(2)).isNotNull(); - assertThat(dao.selectById(1)).isNotNull(); - - assertThat(dao.selectById(10)).isNull(); - } - - @Test - public void select_max_characteristic_order() { - db.prepareDbUnit(getClass(), "shared.xml"); - - assertThat(dao.selectMaxCharacteristicOrder()).isEqualTo(1); - } - - @Test - public void select_max_characteristic_order_when_characteristics_are_all_disabled() { - db.prepareDbUnit(getClass(), "select_max_characteristic_order_when_characteristics_are_all_disabled.xml"); - - assertThat(dao.selectMaxCharacteristicOrder()).isEqualTo(0); - } - - @Test - public void insert_characteristic() { - db.truncateTables(); - - CharacteristicDto dto = new CharacteristicDto() - .setKey("COMPILER_RELATED_PORTABILITY") - .setName("Compiler related portability") - .setOrder(1) - .setEnabled(true) - .setCreatedAt(DateUtils.parseDate("2013-11-20")); - - dao.insert(dto); - db.getSession().commit(); - - db.assertDbUnit(getClass(), "insert_characteristic-result.xml", EXCLUDED_COLUMNS, "characteristics"); - } - - @Test - public void insert_characteristics() { - db.truncateTables(); - - dao.insert(db.getSession(), new CharacteristicDto() - .setKey("COMPILER_RELATED_PORTABILITY") - .setName("Compiler related portability") - .setOrder(1) - .setEnabled(true) - .setCreatedAt(DateUtils.parseDate("2013-11-20")), - new CharacteristicDto() - .setKey("PORTABILITY") - .setName("portability") - .setOrder(2) - .setEnabled(true) - .setCreatedAt(DateUtils.parseDate("2013-11-20"))); - db.getSession().commit(); - - assertThat(db.countRowsOfTable("characteristics")).isEqualTo(2); - } - - @Test - public void update_characteristic() { - db.prepareDbUnit(getClass(), "update_characteristic.xml"); - - CharacteristicDto dto = new CharacteristicDto() - .setId(1) - // The Key should not be changed - .setKey("NEW_KEY") - .setName("New name") - .setOrder(2) - // Created date should not changed - .setCreatedAt(DateUtils.parseDate("2013-11-22")) - .setUpdatedAt(DateUtils.parseDate("2014-03-19")) - .setEnabled(false); - - dao.update(dto); - db.getSession().commit(); - - db.assertDbUnit(getClass(), "update_characteristic-result.xml", EXCLUDED_COLUMNS, "characteristics"); - } - -} diff --git a/sonar-db/src/test/java/org/sonar/db/debt/CharacteristicDtoTest.java b/sonar-db/src/test/java/org/sonar/db/debt/CharacteristicDtoTest.java deleted file mode 100644 index 8c72b0543a5..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/debt/CharacteristicDtoTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.debt; - -import java.util.Date; -import org.junit.Test; -import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CharacteristicDtoTest { - - @Test - public void to_dto_from_characteristic() { - DefaultCharacteristic rootCharacteristic = new DefaultCharacteristic() - .setId(1) - .setKey("MEMORY_EFFICIENCY") - .setName("Memory use"); - - DefaultCharacteristic characteristic = new DefaultCharacteristic() - .setId(2) - .setKey("EFFICIENCY") - .setName("Efficiency") - .setParent(rootCharacteristic) - .setOrder(5) - .setCreatedAt(new Date()) - .setUpdatedAt(new Date()); - - CharacteristicDto dto = CharacteristicDto.toDto(characteristic, 1); - assertThat(dto.getId()).isNull(); - assertThat(dto.getParentId()).isEqualTo(1); - assertThat(dto.getKey()).isEqualTo("EFFICIENCY"); - assertThat(dto.getName()).isEqualTo("Efficiency"); - assertThat(dto.getOrder()).isEqualTo(5); - assertThat(dto.isEnabled()).isTrue(); - assertThat(dto.getCreatedAt()).isNotNull(); - assertThat(dto.getUpdatedAt()).isNotNull(); - } - - @Test - public void to_characteristic() { - DefaultCharacteristic rootCharacteristic = new DefaultCharacteristic() - .setId(1) - .setKey("MEMORY_EFFICIENCY") - .setName("Memory use"); - - CharacteristicDto dto = new CharacteristicDto() - .setId(2) - .setParentId(1) - .setKey("EFFICIENCY") - .setName("Efficiency") - .setOrder(5) - .setEnabled(false) - .setCreatedAt(new Date()) - .setUpdatedAt(new Date()); - - DefaultCharacteristic characteristic = dto.toCharacteristic(rootCharacteristic); - assertThat(characteristic.id()).isEqualTo(2); - assertThat(characteristic.parent()).isEqualTo(rootCharacteristic); - assertThat(characteristic.key()).isEqualTo("EFFICIENCY"); - assertThat(characteristic.name()).isEqualTo("Efficiency"); - assertThat(characteristic.order()).isEqualTo(5); - assertThat(characteristic.createdAt()).isNotNull(); - assertThat(characteristic.updatedAt()).isNotNull(); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java index 75111ceb92c..37c53d4bde0 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java @@ -184,7 +184,6 @@ public class MeasureDaoTest { assertThat(fileMeasure1.getValue()).isEqualTo(5d); assertThat(fileMeasure1.getMetricId()).isEqualTo(1); assertThat(fileMeasure1.getRuleId()).isNull(); - assertThat(fileMeasure1.getCharacteristicId()).isNull(); assertThat(fileMeasure1.getPersonId()).isNull(); PastMeasureDto fileMeasure2 = fileMeasures.get(6L); @@ -221,52 +220,18 @@ public class MeasureDaoTest { assertThat(measure1.getValue()).isEqualTo(60d); assertThat(measure1.getMetricId()).isEqualTo(1); assertThat(measure1.getRuleId()).isNull(); - assertThat(measure1.getCharacteristicId()).isNull(); assertThat(measure1.getPersonId()).isNull(); PastMeasureDto measure2 = pastMeasuresById.get(2L); assertThat(measure2.getValue()).isEqualTo(20d); assertThat(measure2.getMetricId()).isEqualTo(1); assertThat(measure2.getRuleId()).isEqualTo(30); - assertThat(measure2.getCharacteristicId()).isNull(); assertThat(measure2.getPersonId()).isNull(); PastMeasureDto measure3 = pastMeasuresById.get(3L); assertThat(measure3.getValue()).isEqualTo(40d); assertThat(measure3.getMetricId()).isEqualTo(1); assertThat(measure3.getRuleId()).isEqualTo(31); - assertThat(measure3.getCharacteristicId()).isNull(); - assertThat(measure3.getPersonId()).isNull(); - } - - @Test - public void select_past_measures_on_characteristic_by_component_uuid_and_root_snapshot_id_and_metric_keys() { - db.prepareDbUnit(getClass(), "past_measures_with_characteristic_id.xml"); - - List measures = underTest.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(dbSession, "ABCD", 1000L, ImmutableSet.of(1)); - assertThat(measures).hasSize(3); - - Map pastMeasuresById = pastMeasuresById(measures); - - PastMeasureDto measure1 = pastMeasuresById.get(1L); - assertThat(measure1.getValue()).isEqualTo(60d); - assertThat(measure1.getMetricId()).isEqualTo(1); - assertThat(measure1.getRuleId()).isNull(); - assertThat(measure1.getCharacteristicId()).isNull(); - assertThat(measure1.getPersonId()).isNull(); - - PastMeasureDto measure2 = pastMeasuresById.get(2L); - assertThat(measure2.getValue()).isEqualTo(20d); - assertThat(measure2.getMetricId()).isEqualTo(1); - assertThat(measure2.getRuleId()).isNull(); - assertThat(measure2.getCharacteristicId()).isEqualTo(10); - assertThat(measure2.getPersonId()).isNull(); - - PastMeasureDto measure3 = pastMeasuresById.get(3L); - assertThat(measure3.getValue()).isEqualTo(40d); - assertThat(measure3.getMetricId()).isEqualTo(1); - assertThat(measure3.getRuleId()).isNull(); - assertThat(measure3.getCharacteristicId()).isEqualTo(11); assertThat(measure3.getPersonId()).isNull(); } @@ -319,19 +284,6 @@ public class MeasureDaoTest { assertThat(measuresById.get(3L).getRuleId()).isEqualTo(31); } - @Test - public void select_by_snapshot_and_metric_keys_return_measures_with_characteristic_id() throws Exception { - db.prepareDbUnit(getClass(), "select_by_snapshot_and_metric_keys_with_characteristic_id.xml"); - - List results = underTest.selectBySnapshotIdAndMetricKeys(SNAPSHOT_ID, newHashSet("ncloc"), dbSession); - assertThat(results).hasSize(3); - - Map measuresById = measuresById(results); - assertThat(measuresById.get(1L).getCharacteristicId()).isNull(); - assertThat(measuresById.get(2L).getCharacteristicId()).isEqualTo(10); - assertThat(measuresById.get(3L).getCharacteristicId()).isEqualTo(11); - } - @Test public void selectByDeveloperForSnapshotAndMetrics_when_there_is_no_measure_for_developer_returns_empty() { db.prepareDbUnit(getClass(), "shared.xml"); @@ -516,7 +468,6 @@ public class MeasureDaoTest { underTest.insert(dbSession, new MeasureDto() .setSnapshotId(2L) .setMetricId(3) - .setCharacteristicId(4) .setDeveloperId(23L) .setRuleId(5) .setComponentId(6L) diff --git a/sonar-db/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java index cba3b079bc0..4a6325ee390 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java @@ -32,7 +32,6 @@ public class PastMeasureDtoTest { .setValue(1d) .setMetricId(2) .setRuleId(3) - .setCharacteristicId(4) .setPersonId(5); assertThat(dto.getId()).isEqualTo(10L); @@ -40,7 +39,6 @@ public class PastMeasureDtoTest { assertThat(dto.getValue()).isEqualTo(1d); assertThat(dto.getMetricId()).isEqualTo(2); assertThat(dto.getRuleId()).isEqualTo(3); - assertThat(dto.getCharacteristicId()).isEqualTo(4); assertThat(dto.getPersonId()).isEqualTo(5); } @@ -51,7 +49,6 @@ public class PastMeasureDtoTest { .setValue(1d) .setMetricId(2) .setRuleId(3) - .setCharacteristicId(4) .setPersonId(5); assertThat(measureWithValue.hasValue()).isTrue(); @@ -59,7 +56,6 @@ public class PastMeasureDtoTest { .setId(10L) .setMetricId(2) .setRuleId(3) - .setCharacteristicId(4) .setPersonId(5); assertThat(measureWithoutValue.hasValue()).isFalse(); } diff --git a/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java index 4050f3286e7..3d1e2daaeb2 100644 --- a/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java @@ -117,8 +117,6 @@ public class RuleDaoTest { assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.READY); assertThat(ruleDto.getRepositoryKey()).isEqualTo("checkstyle"); assertThat(ruleDto.getNoteData()).isEqualTo("Rule note with accents \u00e9\u00e8\u00e0"); - assertThat(ruleDto.getSubCharacteristicId()).isEqualTo(100); - assertThat(ruleDto.getDefaultSubCharacteristicId()).isEqualTo(101); assertThat(ruleDto.getRemediationFunction()).isEqualTo("LINEAR"); assertThat(ruleDto.getDefaultRemediationFunction()).isEqualTo("LINEAR_OFFSET"); assertThat(ruleDto.getRemediationCoefficient()).isEqualTo("1h"); diff --git a/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java index 37852847722..8c7227c9f9f 100644 --- a/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java @@ -28,45 +28,12 @@ import org.junit.rules.ExpectedException; import static org.apache.commons.lang.StringUtils.repeat; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.db.rule.RuleDto.DISABLED_CHARACTERISTIC_ID; public class RuleDtoTest { - public static final int FAKE_SUB_CHAR_1 = 27; - public static final int FAKE_SUB_CHAR_2 = 42; - @Rule public ExpectedException expectedException = ExpectedException.none(); - @Test - public void effective_sub_characteristic_id() { - RuleDto dto = new RuleDto(); - - // characteristic is not set - dto.setSubCharacteristicId(null).setDefaultSubCharacteristicId(null); - assertThat(dto.getEffectiveSubCharacteristicId()).isNull(); - - // default characteristic is set - dto.setSubCharacteristicId(null).setDefaultSubCharacteristicId(FAKE_SUB_CHAR_2); - assertThat(dto.getEffectiveSubCharacteristicId()).isEqualTo(FAKE_SUB_CHAR_2); - - // default characteristic is set to "none" - dto.setSubCharacteristicId(null).setDefaultSubCharacteristicId(DISABLED_CHARACTERISTIC_ID); - assertThat(dto.getEffectiveSubCharacteristicId()).isNull(); - - // characteristic is overridden - dto.setSubCharacteristicId(FAKE_SUB_CHAR_1).setDefaultSubCharacteristicId(FAKE_SUB_CHAR_2); - assertThat(dto.getEffectiveSubCharacteristicId()).isEqualTo(FAKE_SUB_CHAR_1); - - // characteristic is set, no defaults - dto.setSubCharacteristicId(FAKE_SUB_CHAR_1).setDefaultSubCharacteristicId(null); - assertThat(dto.getEffectiveSubCharacteristicId()).isEqualTo(FAKE_SUB_CHAR_1); - - // characteristic is set to "none" - dto.setSubCharacteristicId(DISABLED_CHARACTERISTIC_ID).setDefaultSubCharacteristicId(FAKE_SUB_CHAR_2); - assertThat(dto.getEffectiveSubCharacteristicId()).isNull(); - } - @Test public void fail_if_key_is_too_long() { expectedException.expect(IllegalArgumentException.class); diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index a3153c66f31..599f12c04a4 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(53); + assertThat(container.size()).isEqualTo(54); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v55/DeleteMeasuresWithCharacteristicIdTest.java b/sonar-db/src/test/java/org/sonar/db/version/v55/DeleteMeasuresWithCharacteristicIdTest.java new file mode 100644 index 00000000000..8ec3c42fd99 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v55/DeleteMeasuresWithCharacteristicIdTest.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.db.version.v55; + +import java.util.List; +import java.util.Map; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; +import org.sonar.db.version.MigrationStep; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DeleteMeasuresWithCharacteristicIdTest { + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, DeleteMeasuresWithCharacteristicIdTest.class, "schema.sql"); + + MigrationStep migration; + + @Before + public void setUp() { + migration = new DeleteMeasuresWithCharacteristicId(db.database()); + } + + @Test + public void delete_measures_with_characteristic_id() throws Exception { + db.prepareDbUnit(getClass(), "before.xml"); + + migration.execute(); + + List> rows = db.select("select id from project_measures"); + assertThat(rows).hasSize(1); + assertThat(rows.get(0).get("ID")).isEqualTo(10L); + } + +} diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/insert_characteristic-result.xml b/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/insert_characteristic-result.xml deleted file mode 100644 index f0ac4524f65..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/insert_characteristic-result.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_enabled_root_characteristics.xml b/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_enabled_root_characteristics.xml deleted file mode 100644 index 8a6e7472bc4..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_enabled_root_characteristics.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_enabled_root_characteristics_order_by_characteristic_order.xml b/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_enabled_root_characteristics_order_by_characteristic_order.xml deleted file mode 100644 index 59f106fe411..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_enabled_root_characteristics_order_by_characteristic_order.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_max_characteristic_order_when_characteristics_are_all_disabled.xml b/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_max_characteristic_order_when_characteristics_are_all_disabled.xml deleted file mode 100644 index d703591428a..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_max_characteristic_order_when_characteristics_are_all_disabled.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_sub_characteristics_by_parent_id.xml b/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_sub_characteristics_by_parent_id.xml deleted file mode 100644 index 60aa6d6fdfb..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/select_sub_characteristics_by_parent_id.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/shared.xml deleted file mode 100644 index 284d01bed45..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/shared.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/update_characteristic-result.xml b/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/update_characteristic-result.xml deleted file mode 100644 index ff12f94cee6..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/update_characteristic-result.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/update_characteristic.xml b/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/update_characteristic.xml deleted file mode 100644 index afa53fb186d..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/CharacteristicDaoTest/update_characteristic.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/RequirementDaoTest/select_requirement.xml b/sonar-db/src/test/resources/org/sonar/db/debt/RequirementDaoTest/select_requirement.xml deleted file mode 100644 index 1a71559a016..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/RequirementDaoTest/select_requirement.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/debt/RequirementDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/debt/RequirementDaoTest/shared.xml deleted file mode 100644 index 0ee097f0869..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/debt/RequirementDaoTest/shared.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml index 26c55c5d3c4..eff8abfd5bd 100644 --- a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml @@ -3,7 +3,7 @@ id="1" snapshot_id="2" metric_id="3" - characteristic_id="4" + characteristic_id="[null]" rule_id="5" project_id="6" person_id="23" diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_characteristic_id.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_characteristic_id.xml deleted file mode 100644 index 7e06f10c94c..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_characteristic_id.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml index c59e34d5c8b..f326322849d 100644 --- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml @@ -10,10 +10,6 @@ worst_value="0" optimized_best_value="[true]" best_value="100" direction="1" hidden="[false]"/> - - - -