diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-03 17:52:05 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-03 17:52:32 +0200 |
commit | fcb07c6af06f952f5c241470ffaef47b6d5df8ed (patch) | |
tree | 73fe1861970e4ff015b20d8e9039e05cb4041251 /sonar-batch/src/test/java | |
parent | ac849445803cfb26d9a7bf298fc4320ae941bd2f (diff) | |
download | sonarqube-fcb07c6af06f952f5c241470ffaef47b6d5df8ed.tar.gz sonarqube-fcb07c6af06f952f5c241470ffaef47b6d5df8ed.zip |
Create a new DebtModel API on batch side
Diffstat (limited to 'sonar-batch/src/test/java')
3 files changed, 50 insertions, 49 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelProviderTest.java index 66bf2768902..a61e4e18063 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelProviderTest.java @@ -25,8 +25,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; -import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel; +import org.sonar.api.batch.debt.DebtCharacteristic; +import org.sonar.api.batch.debt.DebtModel; import org.sonar.core.technicaldebt.db.CharacteristicDao; import org.sonar.core.technicaldebt.db.CharacteristicDto; @@ -42,18 +42,18 @@ public class DebtModelProviderTest { DebtModelProvider provider; - @Before public void before() { provider = new DebtModelProvider(); } @Test - public void find_all() throws Exception { + public void provide_model() throws Exception { CharacteristicDto rootCharacteristicDto = new CharacteristicDto() .setId(1) .setKey("MEMORY_EFFICIENCY") - .setName("Memory use"); + .setName("Memory use") + .setOrder(1); CharacteristicDto characteristicDto = new CharacteristicDto() .setId(2) @@ -63,21 +63,19 @@ public class DebtModelProviderTest { when(dao.selectEnabledCharacteristics()).thenReturn(newArrayList(rootCharacteristicDto, characteristicDto)); - DefaultTechnicalDebtModel result = (DefaultTechnicalDebtModel) provider.provide(dao); - assertThat(result.rootCharacteristics()).hasSize(1); + DebtModel result = provider.provide(dao); + assertThat(result.characteristics()).hasSize(1); - DefaultCharacteristic rootCharacteristic = result.characteristicByKey("MEMORY_EFFICIENCY"); - assertThat(rootCharacteristic.key()).isEqualTo("MEMORY_EFFICIENCY"); - assertThat(rootCharacteristic.name()).isEqualTo("Memory use"); - assertThat(rootCharacteristic.parent()).isNull(); - assertThat(rootCharacteristic.children()).hasSize(1); - assertThat(rootCharacteristic.children().get(0).key()).isEqualTo("EFFICIENCY"); + DebtCharacteristic characteristic = result.characteristicByKey("MEMORY_EFFICIENCY"); + assertThat(characteristic.key()).isEqualTo("MEMORY_EFFICIENCY"); + assertThat(characteristic.name()).isEqualTo("Memory use"); + assertThat(characteristic.isSub()).isFalse(); + assertThat(characteristic.order()).isEqualTo(1); - DefaultCharacteristic characteristic = result.characteristicByKey("EFFICIENCY"); - assertThat(characteristic.key()).isEqualTo("EFFICIENCY"); - assertThat(characteristic.name()).isEqualTo("Efficiency"); - assertThat(characteristic.parent().key()).isEqualTo("MEMORY_EFFICIENCY"); - assertThat(characteristic.children()).isEmpty(); + DebtCharacteristic subCharacteristic = result.characteristicByKey("EFFICIENCY"); + assertThat(subCharacteristic.key()).isEqualTo("EFFICIENCY"); + assertThat(subCharacteristic.name()).isEqualTo("Efficiency"); + assertThat(subCharacteristic.isSub()).isTrue(); + assertThat(subCharacteristic.order()).isNull(); } - } diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java index 5a5f8ef282d..6be76b5d95d 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java @@ -47,9 +47,7 @@ import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) public class ModuleIssuesTest { @@ -252,7 +250,7 @@ public class ModuleIssuesTest { public void set_debt_with_linear_function() throws Exception { ruleBuilder.add(SQUID_RULE_KEY) .setName(SQUID_RULE_NAME) - .setDebtCharacteristic("COMPILER_RELATED_PORTABILITY") + .setDebtSubCharacteristic("COMPILER_RELATED_PORTABILITY") .setDebtRemediationFunction(DebtRemediationFunction.createLinear(Duration.create(10L))); activeRulesBuilder.activate(SQUID_RULE_KEY).setSeverity(Severity.INFO); initModuleIssues(); @@ -278,7 +276,7 @@ public class ModuleIssuesTest { public void set_debt_with_linear_with_offset_function() throws Exception { ruleBuilder.add(SQUID_RULE_KEY) .setName(SQUID_RULE_NAME) - .setDebtCharacteristic("COMPILER_RELATED_PORTABILITY") + .setDebtSubCharacteristic("COMPILER_RELATED_PORTABILITY") .setDebtRemediationFunction(DebtRemediationFunction.createLinearWithOffset(Duration.create(10L), Duration.create(25L))); activeRulesBuilder.activate(SQUID_RULE_KEY).setSeverity(Severity.INFO); initModuleIssues(); @@ -304,7 +302,7 @@ public class ModuleIssuesTest { public void set_debt_with_constant_issue_function() throws Exception { ruleBuilder.add(SQUID_RULE_KEY) .setName(SQUID_RULE_NAME) - .setDebtCharacteristic("COMPILER_RELATED_PORTABILITY") + .setDebtSubCharacteristic("COMPILER_RELATED_PORTABILITY") .setDebtRemediationFunction(DebtRemediationFunction.createConstantPerIssue(Duration.create(10L))); activeRulesBuilder.activate(SQUID_RULE_KEY).setSeverity(Severity.INFO); initModuleIssues(); @@ -330,7 +328,7 @@ public class ModuleIssuesTest { public void fail_to_set_debt_with_constant_issue_function_when_effort_to_fix_is_set() throws Exception { ruleBuilder.add(SQUID_RULE_KEY) .setName(SQUID_RULE_NAME) - .setDebtCharacteristic("COMPILER_RELATED_PORTABILITY") + .setDebtSubCharacteristic("COMPILER_RELATED_PORTABILITY") .setDebtRemediationFunction(DebtRemediationFunction.createConstantPerIssue(Duration.create(25L))); activeRulesBuilder.activate(SQUID_RULE_KEY).setSeverity(Severity.INFO); initModuleIssues(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java index ffcab662476..5ec693d2bc1 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java @@ -25,6 +25,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.sonar.api.batch.debt.internal.DefaultDebtCharacteristic; +import org.sonar.api.batch.debt.internal.DefaultDebtModel; import org.sonar.api.batch.rule.DebtRemediationFunction; import org.sonar.api.batch.rule.Rule; import org.sonar.api.batch.rule.RuleParam; @@ -32,12 +34,10 @@ import org.sonar.api.batch.rule.Rules; import org.sonar.api.config.Settings; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; -import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.api.utils.Duration; import org.sonar.api.utils.Durations; import org.sonar.core.persistence.AbstractDaoTestCase; import org.sonar.core.rule.RuleDao; -import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; @@ -50,29 +50,34 @@ public class RulesProviderTest extends AbstractDaoTestCase { RuleDao ruleDao; - DefaultTechnicalDebtModel debtModel; + DefaultDebtModel debtModel; RulesProvider provider; @Before public void setUp() throws Exception { - debtModel = new DefaultTechnicalDebtModel(); - debtModel.addRootCharacteristic(new DefaultCharacteristic() - .setId(101) - .setKey("EFFICIENCY") - .setName("Efficiency") - .setParent(new DefaultCharacteristic() + debtModel = new DefaultDebtModel() + .addCharacteristic(new DefaultDebtCharacteristic() .setId(100) .setKey("MEMORY_EFFICIENCY") - .setName("Memory use"))); - debtModel.addRootCharacteristic(new DefaultCharacteristic() - .setId(103) - .setKey("PORTABILITY") - .setName("Portability") - .setParent(new DefaultCharacteristic() + .setName("Memory use") + .setOrder(1)) + .addCharacteristic(new DefaultDebtCharacteristic() + .setId(101) + .setKey("EFFICIENCY") + .setName("Efficiency") + .setParentId(100)); + debtModel + .addCharacteristic(new DefaultDebtCharacteristic() .setId(102) .setKey("COMPILER_RELATED_PORTABILITY") - .setName("Compiler"))); + .setName("Compiler") + .setOrder(1)) + .addCharacteristic(new DefaultDebtCharacteristic() + .setId(103) + .setKey("PORTABILITY") + .setName("Portability") + .setParentId(102)); durations = new Durations(new Settings().setProperty("sonar.technicalDebt.hoursInDay", 8), null); ruleDao = new RuleDao(getMyBatis()); @@ -111,7 +116,7 @@ public class RulesProviderTest extends AbstractDaoTestCase { Rules rules = provider.provide(ruleDao, debtModel, durations); Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull")); - assertThat(rule.debtCharacteristic()).isEqualTo("EFFICIENCY"); + assertThat(rule.debtSubCharacteristic()).isEqualTo("EFFICIENCY"); assertThat(rule.debtRemediationFunction()).isEqualTo(DebtRemediationFunction.createLinearWithOffset(Duration.decode("5d", 8), Duration.decode("10h", 8))); } @@ -122,7 +127,7 @@ public class RulesProviderTest extends AbstractDaoTestCase { Rules rules = provider.provide(ruleDao, debtModel, durations); Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull")); - assertThat(rule.debtCharacteristic()).isEqualTo("PORTABILITY"); + assertThat(rule.debtSubCharacteristic()).isEqualTo("PORTABILITY"); assertThat(rule.debtRemediationFunction()).isEqualTo(DebtRemediationFunction.createLinear(Duration.decode("2h", 8))); } @@ -134,7 +139,7 @@ public class RulesProviderTest extends AbstractDaoTestCase { // As both default columns and user columns on debt are set, user debt columns should be used Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull")); - assertThat(rule.debtCharacteristic()).isEqualTo("PORTABILITY"); + assertThat(rule.debtSubCharacteristic()).isEqualTo("PORTABILITY"); assertThat(rule.debtRemediationFunction()).isEqualTo(DebtRemediationFunction.createLinear(Duration.decode("2h", 8))); } @@ -146,7 +151,7 @@ public class RulesProviderTest extends AbstractDaoTestCase { // As both default columns and user columns on debt are set, user debt columns should be used Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull")); - assertThat(rule.debtCharacteristic()).isEqualTo("PORTABILITY"); + assertThat(rule.debtSubCharacteristic()).isEqualTo("PORTABILITY"); assertThat(rule.debtRemediationFunction()).isEqualTo(DebtRemediationFunction.createLinear(Duration.decode("2h", 8))); } @@ -158,7 +163,7 @@ public class RulesProviderTest extends AbstractDaoTestCase { // As both default columns and user columns on debt are set, user debt columns should be used Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull")); - assertThat(rule.debtCharacteristic()).isEqualTo("PORTABILITY"); + assertThat(rule.debtSubCharacteristic()).isEqualTo("PORTABILITY"); assertThat(rule.debtRemediationFunction()).isEqualTo(DebtRemediationFunction.createLinear(Duration.decode("2h", 8))); } @@ -169,7 +174,7 @@ public class RulesProviderTest extends AbstractDaoTestCase { Rules rules = provider.provide(ruleDao, debtModel, durations); Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull")); - assertThat(rule.debtCharacteristic()).isNull(); + assertThat(rule.debtSubCharacteristic()).isNull(); assertThat(rule.debtRemediationFunction()).isNull(); } @@ -180,7 +185,7 @@ public class RulesProviderTest extends AbstractDaoTestCase { Rules rules = provider.provide(ruleDao, debtModel, durations); Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull")); - assertThat(rule.debtCharacteristic()).isNull(); + assertThat(rule.debtSubCharacteristic()).isNull(); assertThat(rule.debtRemediationFunction()).isNull(); } |