diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2022-05-20 12:15:50 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-05-24 20:10:14 +0000 |
commit | f05edf50468fca40be695a0519fe962a020d26b1 (patch) | |
tree | de6cc70eda7eabf94c14ff040177f6d6eb8b4f5b /server/sonar-server-common/src | |
parent | ec85c6ac6c0a29f27eb241dff4445be8ad07e727 (diff) | |
download | sonarqube-f05edf50468fca40be695a0519fe962a020d26b1.tar.gz sonarqube-f05edf50468fca40be695a0519fe962a020d26b1.zip |
SONAR-16419 merge rules and rules metadata in single table and DTO
Diffstat (limited to 'server/sonar-server-common/src')
3 files changed, 29 insertions, 40 deletions
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java index a4286390138..0d9f7680640 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java @@ -19,7 +19,7 @@ */ package org.sonar.server.rule; -import com.google.common.collect.ImmutableSet; +import java.util.Set; import org.junit.Before; import org.junit.Test; import org.sonar.api.rule.RuleKey; @@ -33,6 +33,7 @@ import org.sonar.db.DbTester; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Scope; +import static java.util.Collections.emptySet; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -85,10 +86,10 @@ public class DefaultRuleFinderTest { @Before public void setup() { - dbTester.rules().insertRule(rule1); - dbTester.rules().insertRule(rule2); - dbTester.rules().insertRule(rule3); - dbTester.rules().insertRule(rule4); + dbTester.rules().insert(rule1); + dbTester.rules().insert(rule2); + dbTester.rules().insert(rule3); + dbTester.rules().insert(rule4); session.commit(); } @@ -139,7 +140,7 @@ public class DefaultRuleFinderTest { @Test public void findByKey_populates_system_tags_but_not_tags() { RuleDto ruleDto = dbTester.rules() - .insert(t -> t.setSystemTags(ImmutableSet.of(randomAlphanumeric(5), randomAlphanumeric(6)))); + .insert(t -> t.setSystemTags(Set.of(randomAlphanumeric(5), randomAlphanumeric(6))).setTags(emptySet())); dbTester.rules().insertRule(); Rule rule = underTest.findByKey(ruleDto.getKey()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleDocTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleDocTest.java index af46148f964..9d5dcf92920 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleDocTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleDocTest.java @@ -59,7 +59,10 @@ public class RuleDocTest { assertThat(ruleDoc.status()).isEqualTo(ruleForIndexingDto.getStatus()); assertThat(ruleDoc.type().name()).isEqualTo(ruleForIndexingDto.getTypeAsRuleType().name()); assertThat(ruleDoc.createdAt()).isEqualTo(ruleForIndexingDto.getCreatedAt()); - assertThat(ruleDoc.getTags()).isEqualTo(ruleForIndexingDto.getSystemTags()); + assertThat(ruleDoc.getTags()) + .containsAll(ruleForIndexingDto.getSystemTags()) + .containsAll(ruleForIndexingDto.getTags()) + .hasSize(ruleForIndexingDto.getSystemTags().size() + ruleForIndexingDto.getTags().size()); assertThat(ruleDoc.updatedAt()).isEqualTo(ruleForIndexingDto.getUpdatedAt()); assertThat(ruleDoc.templateKey().repository()).isEqualTo(ruleForIndexingDto.getTemplateRepository()); assertThat(ruleDoc.templateKey().rule()).isEqualTo(ruleForIndexingDto.getTemplateRuleKey()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java index 2b300399360..41b786e2751 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java @@ -38,7 +38,6 @@ import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.rule.RuleDto; -import org.sonar.db.rule.RuleMetadataDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.Facets; import org.sonar.server.es.SearchIdResult; @@ -295,10 +294,8 @@ public class RuleIndexTest { @Test public void filter_by_tags() { - RuleDto rule1 = createRule(setSystemTags("tag1s")); - createRuleMetadata(rule1, setTags("tag1")); - RuleDto rule2 = createRule(setSystemTags("tag2s")); - createRuleMetadata(rule2, setTags("tag2")); + RuleDto rule1 = createRule(setSystemTags("tag1s"), setTags("tag1")); + RuleDto rule2 = createRule(setSystemTags("tag2s"), setTags("tag2")); index(); assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(2); @@ -321,8 +318,7 @@ public class RuleIndexTest { @Test public void tags_facet_supports_selected_value_with_regexp_special_characters() { - RuleDto rule = createRule(); - createRuleMetadata(rule, setTags("misra++")); + createRule(r -> r.setTags(Set.of("misra++"))); index(); RuleQuery query = new RuleQuery() @@ -571,11 +567,6 @@ public class RuleIndexTest { return createRule(r -> r.setLanguage("java"), consumer); } - @SafeVarargs - private final RuleMetadataDto createRuleMetadata(RuleDto rule, Consumer<RuleMetadataDto>... populaters) { - return db.rules().insertOrUpdateMetadata(rule, populaters); - } - @Test public void search_by_any_of_severities() { createRule(setSeverity(BLOCKER)); @@ -762,11 +753,8 @@ public class RuleIndexTest { @Test public void listTags_should_return_tags() { - RuleDto rule1 = createRule(setSystemTags("sys1", "sys2")); - createRuleMetadata(rule1, setTags("tag1")); - - RuleDto rule2 = createRule(setSystemTags()); - createRuleMetadata(rule2, setTags("tag2")); + createRule(setSystemTags("sys1", "sys2"), setTags("tag1")); + createRule(setSystemTags(), setTags("tag2")); index(); @@ -800,11 +788,9 @@ public class RuleIndexTest { @Test public void global_facet_on_repositories_and_tags() { - createRule(setRepositoryKey("php"), setSystemTags("sysTag")); - RuleDto rule1 = createRule(setRepositoryKey("php"), setSystemTags()); - createRuleMetadata(rule1, setTags("tag1")); - RuleDto rule2 = createRule(setRepositoryKey("javascript"), setSystemTags()); - createRuleMetadata(rule2, setTags("tag1", "tag2")); + createRule(setRepositoryKey("php"), setSystemTags("sysTag"), setTags()); + createRule(setRepositoryKey("php"), setSystemTags(), setTags("tag1")); + createRule(setRepositoryKey("javascript"), setSystemTags(), setTags("tag1", "tag2")); index(); // should not have any facet! @@ -834,16 +820,16 @@ public class RuleIndexTest { } private void setupStickyFacets() { - createRule(setRepositoryKey("xoo"), setRuleKey("S001"), setLanguage("java"), setSystemTags(), setType(BUG)); - createRule(setRepositoryKey("xoo"), setRuleKey("S002"), setLanguage("java"), setSystemTags(), setType(CODE_SMELL)); - createRule(setRepositoryKey("xoo"), setRuleKey("S003"), setLanguage("java"), setSystemTags("T1", "T2"), setType(CODE_SMELL)); - createRule(setRepositoryKey("xoo"), setRuleKey("S011"), setLanguage("cobol"), setSystemTags(), setType(CODE_SMELL)); - createRule(setRepositoryKey("xoo"), setRuleKey("S012"), setLanguage("cobol"), setSystemTags(), setType(BUG)); - createRule(setRepositoryKey("foo"), setRuleKey("S013"), setLanguage("cobol"), setSystemTags("T3", "T4"), + createRule(setRepositoryKey("xoo"), setRuleKey("S001"), setLanguage("java"), setTags(), setSystemTags(), setType(BUG)); + createRule(setRepositoryKey("xoo"), setRuleKey("S002"), setLanguage("java"), setTags(), setSystemTags(), setType(CODE_SMELL)); + createRule(setRepositoryKey("xoo"), setRuleKey("S003"), setLanguage("java"), setTags(), setSystemTags("T1", "T2"), setType(CODE_SMELL)); + createRule(setRepositoryKey("xoo"), setRuleKey("S011"), setLanguage("cobol"), setTags(), setSystemTags(), setType(CODE_SMELL)); + createRule(setRepositoryKey("xoo"), setRuleKey("S012"), setLanguage("cobol"), setTags(), setSystemTags(), setType(BUG)); + createRule(setRepositoryKey("foo"), setRuleKey("S013"), setLanguage("cobol"), setTags(), setSystemTags("T3", "T4"), setType(VULNERABILITY)); - createRule(setRepositoryKey("foo"), setRuleKey("S111"), setLanguage("cpp"), setSystemTags(), setType(BUG)); - createRule(setRepositoryKey("foo"), setRuleKey("S112"), setLanguage("cpp"), setSystemTags(), setType(CODE_SMELL)); - createRule(setRepositoryKey("foo"), setRuleKey("S113"), setLanguage("cpp"), setSystemTags("T2", "T3"), setType(CODE_SMELL)); + createRule(setRepositoryKey("foo"), setRuleKey("S111"), setLanguage("cpp"), setTags(), setSystemTags(), setType(BUG)); + createRule(setRepositoryKey("foo"), setRuleKey("S112"), setLanguage("cpp"), setTags(), setSystemTags(), setType(CODE_SMELL)); + createRule(setRepositoryKey("foo"), setRuleKey("S113"), setLanguage("cpp"), setTags(), setSystemTags("T2", "T3"), setType(CODE_SMELL)); index(); } @@ -913,8 +899,7 @@ public class RuleIndexTest { @Test public void tags_facet_should_find_tags() { - RuleDto rule = createRule(setSystemTags()); - createRuleMetadata(rule, setTags("bla")); + createRule(setSystemTags(), setTags("bla")); index(); RuleQuery query = new RuleQuery(); |