Search in sources :

Example 1 with DeprecatedRuleKeyDto

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));
}
Also used : DbSession(org.sonar.db.DbSession) DeprecatedRuleKeyDto(org.sonar.db.rule.DeprecatedRuleKeyDto) Before(org.junit.Before)

Example 2 with DeprecatedRuleKeyDto

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);
}
Also used : NewRepository(org.sonar.api.server.rule.RulesDefinition.NewRepository) DeprecatedRuleKeyDto(org.sonar.db.rule.DeprecatedRuleKeyDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 3 with DeprecatedRuleKeyDto

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;
    }
}
Also used : DbSession(org.sonar.db.DbSession) DeprecatedRuleKeyDto(org.sonar.db.rule.DeprecatedRuleKeyDto) RuleKey(org.sonar.api.rule.RuleKey) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto)

Example 4 with DeprecatedRuleKeyDto

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()));
}
Also used : DeprecatedRuleKeyDto(org.sonar.db.rule.DeprecatedRuleKeyDto) Test(org.junit.Test)

Example 5 with DeprecatedRuleKeyDto

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());
}
Also used : DeprecatedRuleKeyDto(org.sonar.db.rule.DeprecatedRuleKeyDto) Test(org.junit.Test)

Aggregations

DeprecatedRuleKeyDto (org.sonar.db.rule.DeprecatedRuleKeyDto)9 Test (org.junit.Test)4 DbSession (org.sonar.db.DbSession)3 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)3 RuleKey (org.sonar.api.rule.RuleKey)2 NewRepository (org.sonar.api.server.rule.RulesDefinition.NewRepository)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Sets (com.google.common.collect.Sets)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1