Search in sources :

Example 91 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class DefaultRuleFinderTest method findByKey_populates_system_tags_but_not_tags.

@Test
public void findByKey_populates_system_tags_but_not_tags() {
    RuleDefinitionDto ruleDefinition = dbTester.rules().insert(t -> t.setSystemTags(ImmutableSet.of(randomAlphanumeric(5), randomAlphanumeric(6))));
    dbTester.rules().insertRule();
    Rule rule = underTest.findByKey(ruleDefinition.getKey());
    assertThat(rule.getSystemTags()).containsOnlyElementsOf(ruleDefinition.getSystemTags());
    assertThat(rule.getTags()).isEmpty();
    rule = underTest.findByKey(ruleDefinition.getRepositoryKey(), ruleDefinition.getRuleKey());
    assertThat(rule.getSystemTags()).containsOnlyElementsOf(ruleDefinition.getSystemTags());
    assertThat(rule.getTags()).isEmpty();
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Rule(org.sonar.api.rules.Rule) Test(org.junit.Test)

Example 92 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class RuleDescriptionFormatterTest method handleNullDescription.

@Test
public void handleNullDescription() {
    RuleDefinitionDto rule = new RuleDefinitionDto().setDescription(null).setDescriptionFormat(RuleDto.Format.HTML);
    String result = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
    assertThat(result).isNull();
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 93 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class RuleDescriptionFormatterTest method handleNullDescriptionFormat.

@Test
public void handleNullDescriptionFormat() {
    RuleDefinitionDto rule = new RuleDefinitionDto().setDescription("whatever").setDescriptionFormat(null);
    String result = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
    assertThat(result).isNull();
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 94 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class CachingRuleFinderTest method find_searches_by_exact_match_of_ruleKey_and_returns_most_recent_rule.

@Test
public void find_searches_by_exact_match_of_ruleKey_and_returns_most_recent_rule() {
    String ruleKey = "ABCD";
    RuleDefinitionDto[] sameRuleKey = { dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())) };
    RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
    assertThat(toRuleKey(underTest.find(RuleQuery.create().withKey(ruleKey)))).isEqualTo(sameRuleKey[1].getKey());
    assertThat(toRuleKey(underTest.find(RuleQuery.create().withKey(otherRule.getRuleKey())))).isEqualTo(otherRule.getKey());
    assertThat(underTest.find(RuleQuery.create().withKey(ruleKey.toLowerCase()))).isNull();
    assertThat(underTest.find(RuleQuery.create().withKey(randomAlphabetic(3)))).isNull();
}
Also used : Rule(org.sonar.api.rules.Rule) Arrays(java.util.Arrays) RuleQuery(org.sonar.api.rules.RuleQuery) RuleDao(org.sonar.db.rule.RuleDao) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) DbSession(org.sonar.db.DbSession) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Nullable(javax.annotation.Nullable) Before(org.junit.Before) DbTester(org.sonar.db.DbTester) RuleTesting(org.sonar.db.rule.RuleTesting) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) AlwaysIncreasingSystem2(org.sonar.api.impl.utils.AlwaysIncreasingSystem2) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) DbClient(org.sonar.db.DbClient) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RuleParamDto(org.sonar.db.rule.RuleParamDto) RuleKey(org.sonar.api.rule.RuleKey) Mockito.mock(org.mockito.Mockito.mock) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 95 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class CachingRuleFinderTest method find_searches_by_exact_match_of_configKey_and_returns_most_recent_rule.

@Test
public void find_searches_by_exact_match_of_configKey_and_returns_most_recent_rule() {
    String configKey = "ABCD";
    RuleDefinitionDto[] sameConfigKey = { dbTester.rules().insert(rule -> rule.setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setConfigKey(configKey).setUpdatedAt(system2.now())) };
    RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
    assertThat(toRuleKey(underTest.find(RuleQuery.create().withConfigKey(configKey)))).isEqualTo(sameConfigKey[1].getKey());
    assertThat(toRuleKey(underTest.find(RuleQuery.create().withConfigKey(otherRule.getConfigKey())))).isEqualTo(otherRule.getKey());
    assertThat(underTest.find(RuleQuery.create().withConfigKey(configKey.toLowerCase()))).isNull();
    assertThat(underTest.find(RuleQuery.create().withConfigKey(randomAlphabetic(3)))).isNull();
}
Also used : Rule(org.sonar.api.rules.Rule) Arrays(java.util.Arrays) RuleQuery(org.sonar.api.rules.RuleQuery) RuleDao(org.sonar.db.rule.RuleDao) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) DbSession(org.sonar.db.DbSession) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Nullable(javax.annotation.Nullable) Before(org.junit.Before) DbTester(org.sonar.db.DbTester) RuleTesting(org.sonar.db.rule.RuleTesting) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) AlwaysIncreasingSystem2(org.sonar.api.impl.utils.AlwaysIncreasingSystem2) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) DbClient(org.sonar.db.DbClient) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RuleParamDto(org.sonar.db.rule.RuleParamDto) RuleKey(org.sonar.api.rule.RuleKey) Mockito.mock(org.mockito.Mockito.mock) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Aggregations

RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)654 Test (org.junit.Test)583 ComponentDto (org.sonar.db.component.ComponentDto)305 IssueDto (org.sonar.db.issue.IssueDto)219 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)144 UserDto (org.sonar.db.user.UserDto)96 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)93 DbTester (org.sonar.db.DbTester)93 System2 (org.sonar.api.utils.System2)91 UserSessionRule (org.sonar.server.tester.UserSessionRule)84 List (java.util.List)80 Rule (org.junit.Rule)77 DbClient (org.sonar.db.DbClient)68 RuleParamDto (org.sonar.db.rule.RuleParamDto)67 Mockito.mock (org.mockito.Mockito.mock)65 TestRequest (org.sonar.server.ws.TestRequest)64 Consumer (java.util.function.Consumer)63 EsTester (org.sonar.server.es.EsTester)61 Random (java.util.Random)60 RuleType (org.sonar.api.rules.RuleType)60