use of org.sonar.db.rule.DeprecatedRuleKeyDto in project sonarqube by SonarSource.
the class RuleRepositoryImplTest method setUp.
@Before
public void setUp() {
when(dbClient.openSession(anyBoolean())).thenReturn(dbSession);
when(dbClient.ruleDao()).thenReturn(ruleDao);
when(ruleDao.selectAll(any(DbSession.class))).thenReturn(ImmutableList.of(AB_RULE));
DeprecatedRuleKeyDto abDeprecatedRuleKey1 = deprecatedRuleKeyOf(AB_RULE, AB_RULE_DEPRECATED_KEY_1);
DeprecatedRuleKeyDto abDeprecatedRuleKey2 = deprecatedRuleKeyOf(AB_RULE, AB_RULE_DEPRECATED_KEY_2);
DeprecatedRuleKeyDto deprecatedRuleOfNonExistingRule = deprecatedRuleKeyOf("unknown-rule-uuid", DEPRECATED_KEY_OF_NON_EXITING_RULE);
when(ruleDao.selectAllDeprecatedRuleKeys(any(DbSession.class))).thenReturn(ImmutableSet.of(abDeprecatedRuleKey1, abDeprecatedRuleKey2, deprecatedRuleOfNonExistingRule));
}
use of org.sonar.db.rule.DeprecatedRuleKeyDto in project sonarqube by SonarSource.
the class RegisterRulesTest method rules_that_deprecate_previous_rule_must_be_recorded.
@Test
public void rules_that_deprecate_previous_rule_must_be_recorded() {
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
createRule(repo, "rule1");
repo.done();
});
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
createRule(repo, "newKey").addDeprecatedRuleKey("fake", "rule1").addDeprecatedRuleKey("fake", "rule2");
repo.done();
});
List<RuleDefinitionDto> rules = dbClient.ruleDao().selectAllDefinitions(db.getSession());
Set<DeprecatedRuleKeyDto> deprecatedRuleKeys = dbClient.ruleDao().selectAllDeprecatedRuleKeys(db.getSession());
assertThat(rules).hasSize(1);
assertThat(deprecatedRuleKeys).hasSize(2);
}
use of org.sonar.db.rule.DeprecatedRuleKeyDto in project sonarqube by SonarSource.
the class BuiltInQProfileRepositoryImpl method loadRuleDefinitionsByRuleKey.
private Map<RuleKey, RuleDefinitionDto> loadRuleDefinitionsByRuleKey() {
try (DbSession dbSession = dbClient.openSession(false)) {
Collection<RuleDefinitionDto> ruleDefinitions = ruleFinder.findAll();
Multimap<String, DeprecatedRuleKeyDto> deprecatedRuleKeysByRuleId = dbClient.ruleDao().selectAllDeprecatedRuleKeys(dbSession).stream().collect(MoreCollectors.index(DeprecatedRuleKeyDto::getRuleUuid));
Map<RuleKey, RuleDefinitionDto> rulesByRuleKey = new HashMap<>();
for (RuleDefinitionDto ruleDefinition : ruleDefinitions) {
rulesByRuleKey.put(ruleDefinition.getKey(), ruleDefinition);
deprecatedRuleKeysByRuleId.get(ruleDefinition.getUuid()).forEach(t -> rulesByRuleKey.put(RuleKey.of(t.getOldRepositoryKey(), t.getOldRuleKey()), ruleDefinition));
}
return rulesByRuleKey;
}
}
use of org.sonar.db.rule.DeprecatedRuleKeyDto in project sonarqube by SonarSource.
the class SingleDeprecatedRuleKeyTest method test_creation_from_DeprecatedRuleKeyDto.
@Test
public void test_creation_from_DeprecatedRuleKeyDto() {
// Creation from DeprecatedRuleKeyDto
DeprecatedRuleKeyDto deprecatedRuleKeyDto = new DeprecatedRuleKeyDto().setOldRuleKey(randomAlphanumeric(50)).setOldRepositoryKey(randomAlphanumeric(50)).setRuleUuid(randomAlphanumeric(50)).setUuid(randomAlphanumeric(40));
SingleDeprecatedRuleKey singleDeprecatedRuleKey = SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto);
assertThat(singleDeprecatedRuleKey.getOldRepositoryKey()).isEqualTo(deprecatedRuleKeyDto.getOldRepositoryKey());
assertThat(singleDeprecatedRuleKey.getOldRuleKey()).isEqualTo(deprecatedRuleKeyDto.getOldRuleKey());
assertThat(singleDeprecatedRuleKey.getNewRepositoryKey()).isEqualTo(deprecatedRuleKeyDto.getNewRepositoryKey());
assertThat(singleDeprecatedRuleKey.getNewRuleKey()).isEqualTo(deprecatedRuleKeyDto.getNewRuleKey());
assertThat(singleDeprecatedRuleKey.getUuid()).isEqualTo(deprecatedRuleKeyDto.getUuid());
assertThat(singleDeprecatedRuleKey.getRuleUuid()).isEqualTo(deprecatedRuleKeyDto.getRuleUuid());
assertThat(singleDeprecatedRuleKey.getOldRuleKeyAsRuleKey()).isEqualTo(RuleKey.of(deprecatedRuleKeyDto.getOldRepositoryKey(), deprecatedRuleKeyDto.getOldRuleKey()));
}
use of org.sonar.db.rule.DeprecatedRuleKeyDto in project sonarqube by SonarSource.
the class SingleDeprecatedRuleKeyTest method test_equality.
@Test
public void test_equality() {
DeprecatedRuleKeyDto deprecatedRuleKeyDto1 = new DeprecatedRuleKeyDto().setOldRuleKey(randomAlphanumeric(50)).setOldRepositoryKey(randomAlphanumeric(50)).setUuid(randomAlphanumeric(40)).setRuleUuid("some-uuid");
DeprecatedRuleKeyDto deprecatedRuleKeyDto1WithoutUuid = new DeprecatedRuleKeyDto().setOldRuleKey(deprecatedRuleKeyDto1.getOldRuleKey()).setOldRepositoryKey(deprecatedRuleKeyDto1.getOldRepositoryKey());
DeprecatedRuleKeyDto deprecatedRuleKeyDto2 = new DeprecatedRuleKeyDto().setOldRuleKey(randomAlphanumeric(50)).setOldRepositoryKey(randomAlphanumeric(50)).setUuid(randomAlphanumeric(40));
SingleDeprecatedRuleKey singleDeprecatedRuleKey1 = SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1);
SingleDeprecatedRuleKey singleDeprecatedRuleKey2 = SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2);
assertThat(singleDeprecatedRuleKey1).isEqualTo(singleDeprecatedRuleKey1).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1)).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid));
assertThat(singleDeprecatedRuleKey2).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2));
assertThat(singleDeprecatedRuleKey1).hasSameHashCodeAs(singleDeprecatedRuleKey1).hasSameHashCodeAs(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1)).hasSameHashCodeAs(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid));
assertThat(singleDeprecatedRuleKey2).hasSameHashCodeAs(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2));
assertThat(singleDeprecatedRuleKey1).isNotNull().isNotEqualTo("").isNotEqualTo(singleDeprecatedRuleKey2);
assertThat(singleDeprecatedRuleKey2).isNotEqualTo(singleDeprecatedRuleKey1);
assertThat(singleDeprecatedRuleKey1.hashCode()).isNotEqualTo(singleDeprecatedRuleKey2.hashCode());
assertThat(singleDeprecatedRuleKey2.hashCode()).isNotEqualTo(singleDeprecatedRuleKey1.hashCode());
}
Aggregations