aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-api
diff options
context:
space:
mode:
authorAurelien <100427063+aurelien-poscia-sonarsource@users.noreply.github.com>2022-05-04 09:28:10 +0200
committersonartech <sonartech@sonarsource.com>2022-05-06 20:02:44 +0000
commit85249a5a2a2de92eb547be3825520a9dd5fd8ddf (patch)
treebb8b49ac3bb5217c28005715f7979319bf69d90c /server/sonar-webserver-api
parent5cea1b86e42b9b71bd289ee35d4b376cb62e51c4 (diff)
downloadsonarqube-85249a5a2a2de92eb547be3825520a9dd5fd8ddf.tar.gz
sonarqube-85249a5a2a2de92eb547be3825520a9dd5fd8ddf.zip
SONAR-16302 remove RuleDefinitionDto and put information in RuleDto
Diffstat (limited to 'server/sonar-webserver-api')
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java4
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java77
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java8
-rw-r--r--server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java91
4 files changed, 90 insertions, 90 deletions
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java
index 1c97688ad39..a0f79856ef1 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java
@@ -25,7 +25,7 @@ import javax.annotation.Nullable;
import org.sonar.api.server.ServerSide;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QProfileDto;
-import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.rule.RuleDto;
import org.sonar.server.rule.index.RuleQuery;
/**
@@ -60,5 +60,5 @@ public interface QProfileRules {
* Delete a rule from all Quality profiles. Db session is not committed. As a
* consequence Elasticsearch indices are NOT updated.
*/
- List<ActiveRuleChange> deleteRule(DbSession dbSession, RuleDefinitionDto rule);
+ List<ActiveRuleChange> deleteRule(DbSession dbSession, RuleDto rule);
}
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
index 43f6fdb03c6..313914a6f96 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
@@ -40,7 +40,7 @@ import org.sonar.api.rules.RuleQuery;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import static java.util.Collections.emptyList;
@@ -53,28 +53,28 @@ import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
*/
public class CachingRuleFinder implements ServerRuleFinder {
- private static final Ordering<Map.Entry<RuleDefinitionDto, Rule>> FIND_BY_QUERY_ORDER = Ordering.natural().reverse().onResultOf(entry -> entry.getKey().getUpdatedAt());
+ private static final Ordering<Map.Entry<RuleDto, Rule>> FIND_BY_QUERY_ORDER = Ordering.natural().reverse().onResultOf(entry -> entry.getKey().getUpdatedAt());
- private final Map<RuleKey, RuleDefinitionDto> ruleDtosByKey;
- private final Map<String, RuleDefinitionDto> ruleDtosByUuid;
- private final Map<RuleDefinitionDto, Rule> rulesByRuleDefinition;
+ private final Map<RuleKey, RuleDto> ruleDtosByKey;
+ private final Map<String, RuleDto> ruleDtosByUuid;
+ private final Map<RuleDto, Rule> ruleByRuleDto;
private final Map<RuleKey, Rule> rulesByKey;
public CachingRuleFinder(DbClient dbClient) {
try (DbSession dbSession = dbClient.openSession(false)) {
- List<RuleDefinitionDto> dtos = dbClient.ruleDao().selectAllDefinitions(dbSession);
- this.ruleDtosByKey = dtos.stream().collect(Collectors.toMap(RuleDefinitionDto::getKey, d -> d));
- this.ruleDtosByUuid = dtos.stream().collect(Collectors.toMap(RuleDefinitionDto::getUuid, d -> d));
- this.rulesByRuleDefinition = buildRulesByRuleDefinitionDto(dbClient, dbSession, dtos);
- this.rulesByKey = this.rulesByRuleDefinition.entrySet().stream()
+ List<RuleDto> dtos = dbClient.ruleDao().selectAll(dbSession);
+ this.ruleDtosByKey = dtos.stream().collect(Collectors.toMap(RuleDto::getKey, d -> d));
+ this.ruleDtosByUuid = dtos.stream().collect(Collectors.toMap(RuleDto::getUuid, d -> d));
+ this.ruleByRuleDto = buildRulesByRuleDefinitionDto(dbClient, dbSession, dtos);
+ this.rulesByKey = this.ruleByRuleDto.entrySet().stream()
.collect(uniqueIndex(entry -> entry.getKey().getKey(), Map.Entry::getValue));
}
}
- private static Map<RuleDefinitionDto, Rule> buildRulesByRuleDefinitionDto(DbClient dbClient, DbSession dbSession, List<RuleDefinitionDto> dtos) {
+ private static Map<RuleDto, Rule> buildRulesByRuleDefinitionDto(DbClient dbClient, DbSession dbSession, List<RuleDto> dtos) {
Map<String, List<RuleParamDto>> ruleParamsByRuleUuid = retrieveRuleParameters(dbClient, dbSession);
- Map<RuleDefinitionDto, Rule> rulesByDefinition = new HashMap<>(dtos.size());
- for (RuleDefinitionDto definition : dtos) {
+ Map<RuleDto, Rule> rulesByDefinition = new HashMap<>(dtos.size());
+ for (RuleDto definition : dtos) {
rulesByDefinition.put(definition, toRule(definition, ruleParamsByRuleUuid.getOrDefault(definition.getUuid(), emptyList())));
}
return unmodifiableMap(rulesByDefinition);
@@ -107,7 +107,7 @@ public class CachingRuleFinder implements ServerRuleFinder {
return null;
}
- return rulesByRuleDefinition.entrySet().stream()
+ return ruleByRuleDto.entrySet().stream()
.filter(entry -> matchQuery(entry.getKey(), query))
.sorted(FIND_BY_QUERY_ORDER)
.map(Map.Entry::getValue)
@@ -120,48 +120,47 @@ public class CachingRuleFinder implements ServerRuleFinder {
if (query == null) {
return Collections.emptyList();
}
- return rulesByRuleDefinition.entrySet().stream()
+ return ruleByRuleDto.entrySet().stream()
.filter(entry -> matchQuery(entry.getKey(), query))
.sorted(FIND_BY_QUERY_ORDER)
.map(Map.Entry::getValue)
.collect(MoreCollectors.toList());
}
- private static boolean matchQuery(RuleDefinitionDto ruleDefinition, RuleQuery ruleQuery) {
- if (RuleStatus.REMOVED.equals(ruleDefinition.getStatus())) {
+ private static boolean matchQuery(RuleDto ruleDto, RuleQuery ruleQuery) {
+ if (RuleStatus.REMOVED.equals(ruleDto.getStatus())) {
return false;
}
String repositoryKey = ruleQuery.getRepositoryKey();
- if (ruleQuery.getRepositoryKey() != null && !repositoryKey.equals(ruleDefinition.getRepositoryKey())) {
+ if (ruleQuery.getRepositoryKey() != null && !repositoryKey.equals(ruleDto.getRepositoryKey())) {
return false;
}
String key = ruleQuery.getKey();
- if (key != null && !key.equals(ruleDefinition.getRuleKey())) {
+ if (key != null && !key.equals(ruleDto.getRuleKey())) {
return false;
}
String configKey = ruleQuery.getConfigKey();
- return configKey == null || configKey.equals(ruleDefinition.getConfigKey());
+ return configKey == null || configKey.equals(ruleDto.getConfigKey());
}
- private static Rule toRule(RuleDefinitionDto ruleDefinition, List<RuleParamDto> params) {
- String severity = ruleDefinition.getSeverityString();
-
- Rule apiRule = new Rule();
- apiRule
- .setName(ruleDefinition.getName())
- .setLanguage(ruleDefinition.getLanguage())
- .setKey(ruleDefinition.getRuleKey())
- .setConfigKey(ruleDefinition.getConfigKey())
- .setIsTemplate(ruleDefinition.isTemplate())
- .setCreatedAt(new Date(ruleDefinition.getCreatedAt()))
- .setUpdatedAt(new Date(ruleDefinition.getUpdatedAt()))
- .setRepositoryKey(ruleDefinition.getRepositoryKey())
+ private static Rule toRule(RuleDto ruleDto, List<RuleParamDto> params) {
+ String severity = ruleDto.getSeverityString();
+
+ Rule apiRule = Rule.create()
+ .setName(ruleDto.getName())
+ .setKey(ruleDto.getRuleKey())
+ .setConfigKey(ruleDto.getConfigKey())
+ .setIsTemplate(ruleDto.isTemplate())
+ .setCreatedAt(new Date(ruleDto.getCreatedAt()))
+ .setUpdatedAt(new Date(ruleDto.getUpdatedAt()))
+ .setRepositoryKey(ruleDto.getRepositoryKey())
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
- .setStatus(ruleDefinition.getStatus().name())
- .setSystemTags(ruleDefinition.getSystemTags().toArray(new String[ruleDefinition.getSystemTags().size()]))
+ .setStatus(ruleDto.getStatus().name())
+ .setSystemTags(ruleDto.getSystemTags().toArray(new String[ruleDto.getSystemTags().size()]))
.setTags(new String[0])
- .setDescription(RuleDescriptionFormatter.getDescriptionAsHtml(ruleDefinition));
+ .setDescription(RuleDescriptionFormatter.getDescriptionAsHtml(ruleDto));
+ Optional.ofNullable(ruleDto.getLanguage()).map(apiRule::setLanguage);
List<org.sonar.api.rules.RuleParam> apiParams = new ArrayList<>();
for (RuleParamDto param : params) {
@@ -174,17 +173,17 @@ public class CachingRuleFinder implements ServerRuleFinder {
}
@Override
- public Optional<RuleDefinitionDto> findDtoByKey(RuleKey key) {
+ public Optional<RuleDto> findDtoByKey(RuleKey key) {
return Optional.ofNullable(this.ruleDtosByKey.get(key));
}
@Override
- public Optional<RuleDefinitionDto> findDtoByUuid(String uuid) {
+ public Optional<RuleDto> findDtoByUuid(String uuid) {
return Optional.ofNullable(this.ruleDtosByUuid.get(uuid));
}
@Override
- public Collection<RuleDefinitionDto> findAll() {
+ public Collection<RuleDto> findAll() {
return ruleDtosByUuid.values();
}
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java
index cc2a98c77a8..1a79d6528a3 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java
@@ -27,7 +27,7 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleQuery;
import org.sonar.db.DbClient;
-import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.rule.RuleDto;
public class WebServerRuleFinderImpl implements WebServerRuleFinder {
private final DbClient dbClient;
@@ -75,17 +75,17 @@ public class WebServerRuleFinderImpl implements WebServerRuleFinder {
}
@Override
- public Optional<RuleDefinitionDto> findDtoByKey(RuleKey key) {
+ public Optional<RuleDto> findDtoByKey(RuleKey key) {
return delegate.findDtoByKey(key);
}
@Override
- public Optional<RuleDefinitionDto> findDtoByUuid(String uuid) {
+ public Optional<RuleDto> findDtoByUuid(String uuid) {
return delegate.findDtoByUuid(uuid);
}
@Override
- public Collection<RuleDefinitionDto> findAll() {
+ public Collection<RuleDto> findAll() {
return delegate.findAll();
}
diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
index da0ca92e525..b7b555a8b94 100644
--- a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
+++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
@@ -34,7 +34,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.rule.RuleDao;
-import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.rule.RuleTesting;
@@ -53,14 +53,14 @@ public class CachingRuleFinderTest {
private final DbClient dbClient = dbTester.getDbClient();
private final AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2();
- private RuleDefinitionDto[] ruleDefinitions;
+ private RuleDto[] ruleDtos;
private RuleParamDto[] ruleParams;
private CachingRuleFinder underTest;
@Before()
public void setUp() {
- Consumer<RuleDefinitionDto> setUpdatedAt = rule -> rule.setUpdatedAt(system2.now());
- this.ruleDefinitions = new RuleDefinitionDto[] {
+ Consumer<RuleDto> setUpdatedAt = rule -> rule.setUpdatedAt(system2.now());
+ this.ruleDtos = new RuleDto[] {
dbTester.rules().insert(setUpdatedAt),
dbTester.rules().insert(setUpdatedAt),
dbTester.rules().insert(setUpdatedAt),
@@ -68,7 +68,7 @@ public class CachingRuleFinderTest {
dbTester.rules().insert(setUpdatedAt),
dbTester.rules().insert(setUpdatedAt)
};
- this.ruleParams = Arrays.stream(ruleDefinitions)
+ this.ruleParams = Arrays.stream(ruleDtos)
.map(rule -> dbTester.rules().insertRuleParam(rule))
.toArray(RuleParamDto[]::new);
@@ -92,7 +92,7 @@ public class CachingRuleFinderTest {
new CachingRuleFinder(dbClient);
verify(dbClient).openSession(anyBoolean());
- verify(ruleDao).selectAllDefinitions(dbSession);
+ verify(ruleDao).selectAll(dbSession);
verify(ruleDao).selectAllRuleParams(dbSession);
verifyNoMoreInteractions(ruleDao);
}
@@ -105,7 +105,7 @@ public class CachingRuleFinderTest {
when(dbClient.openSession(anyBoolean())).thenReturn(dbSession);
when(dbClient.ruleDao()).thenReturn(ruleDao);
List<RuleKey> ruleKeys = Arrays.asList(RuleKey.of("A", "B"), RuleKey.of("C", "D"), RuleKey.of("E", "F"));
- when(ruleDao.selectAllDefinitions(dbSession)).thenReturn(ruleKeys.stream().map(RuleTesting::newRule).collect(toList()));
+ when(ruleDao.selectAll(dbSession)).thenReturn(ruleKeys.stream().map(RuleTesting::newRule).collect(toList()));
new CachingRuleFinder(dbClient);
@@ -114,13 +114,13 @@ public class CachingRuleFinderTest {
@Test
public void findByKey_returns_all_loaded_rules() {
- for (int i = 0; i < ruleDefinitions.length; i++) {
- RuleDefinitionDto ruleDefinition = ruleDefinitions[i];
+ for (int i = 0; i < ruleDtos.length; i++) {
+ RuleDto ruleDto = ruleDtos[i];
RuleParamDto ruleParam = ruleParams[i];
- org.sonar.api.rules.Rule rule = underTest.findByKey(ruleDefinition.getKey());
- verifyRule(rule, ruleDefinition, ruleParam);
- assertThat(underTest.findByKey(ruleDefinition.getRepositoryKey(), ruleDefinition.getRuleKey()))
+ org.sonar.api.rules.Rule rule = underTest.findByKey(ruleDto.getKey());
+ verifyRule(rule, ruleDto, ruleParam);
+ assertThat(underTest.findByKey(ruleDto.getRepositoryKey(), ruleDto.getRuleKey()))
.isSameAs(rule);
}
}
@@ -154,17 +154,17 @@ public class CachingRuleFinderTest {
public void find_returns_most_recent_rule_when_RuleQuery_has_no_non_null_field() {
Rule rule = underTest.find(RuleQuery.create());
- assertThat(toRuleKey(rule)).isEqualTo(ruleDefinitions[5].getKey());
+ assertThat(toRuleKey(rule)).isEqualTo(ruleDtos[5].getKey());
}
@Test
public void find_searches_by_exact_match_of_repository_key_and_returns_most_recent_rule() {
String repoKey = "ABCD";
- RuleDefinitionDto[] sameRepoKey = {
+ RuleDto[] sameRepoKey = {
dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now())),
dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now()))
};
- RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
+ RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
@@ -181,11 +181,11 @@ public class CachingRuleFinderTest {
@Test
public void find_searches_by_exact_match_of_ruleKey_and_returns_most_recent_rule() {
String ruleKey = "ABCD";
- RuleDefinitionDto[] sameRuleKey = {
+ RuleDto[] 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()));
+ RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
@@ -202,11 +202,11 @@ public class CachingRuleFinderTest {
@Test
public void find_searches_by_exact_match_of_configKey_and_returns_most_recent_rule() {
String configKey = "ABCD";
- RuleDefinitionDto[] sameConfigKey = {
+ RuleDto[] 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()));
+ RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
@@ -225,7 +225,7 @@ public class CachingRuleFinderTest {
String repoKey = "ABCD";
String ruleKey = "EFGH";
String configKey = "IJKL";
- RuleDefinitionDto[] rules = {
+ RuleDto[] rules = {
dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())),
dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())),
dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setConfigKey(configKey).setUpdatedAt(system2.now())),
@@ -259,17 +259,18 @@ public class CachingRuleFinderTest {
public void findAll_returns_all_rules_when_RuleQuery_has_no_non_null_field() {
assertThat(underTest.findAll(RuleQuery.create()))
.extracting(CachingRuleFinderTest::toRuleKey)
- .containsOnly(Arrays.stream(ruleDefinitions).map(RuleDefinitionDto::getKey).toArray(RuleKey[]::new));
+ .containsOnly(Arrays.stream(ruleDtos).map(RuleDto::getKey).toArray(RuleKey[]::new));
}
@Test
public void findAll_returns_all_rules_with_exact_same_repository_key_and_order_them_most_recent_first() {
String repoKey = "ABCD";
- RuleDefinitionDto[] sameRepoKey = {
- dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now())),
- dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now()))
+ long currentTimeMillis = System.currentTimeMillis();
+ RuleDto[] sameRepoKey = {
+ dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(currentTimeMillis + system2.now())),
+ dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(currentTimeMillis + system2.now()))
};
- RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
+ RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(currentTimeMillis + system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
@@ -288,11 +289,11 @@ public class CachingRuleFinderTest {
@Test
public void findAll_returns_all_rules_with_exact_same_rulekey_and_order_them_most_recent_first() {
String ruleKey = "ABCD";
- RuleDefinitionDto[] sameRuleKey = {
+ RuleDto[] 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()));
+ RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
@@ -311,11 +312,11 @@ public class CachingRuleFinderTest {
@Test
public void findAll_returns_all_rules_with_exact_same_configkey_and_order_them_most_recent_first() {
String configKey = "ABCD";
- RuleDefinitionDto[] sameConfigKey = {
+ RuleDto[] 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()));
+ RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
@@ -336,7 +337,7 @@ public class CachingRuleFinderTest {
String repoKey = "ABCD";
String ruleKey = "EFGH";
String configKey = "IJKL";
- RuleDefinitionDto[] rules = {
+ RuleDto[] rules = {
dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())),
dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())),
dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setConfigKey(configKey).setUpdatedAt(system2.now())),
@@ -377,14 +378,14 @@ public class CachingRuleFinderTest {
@Test
public void findDtoByKey_finds_rules() {
- for(RuleDefinitionDto dto : ruleDefinitions) {
+ for(RuleDto dto : ruleDtos) {
assertThat(underTest.findDtoByKey(dto.getKey())).contains(dto);
}
}
@Test
public void findDtoByUuid_finds_rules() {
- for(RuleDefinitionDto dto : ruleDefinitions) {
+ for(RuleDto dto : ruleDtos) {
assertThat(underTest.findDtoByUuid(dto.getUuid())).contains(dto);
}
}
@@ -401,28 +402,28 @@ public class CachingRuleFinderTest {
@Test
public void findAll_returns_all_rules() {
- assertThat(underTest.findAll()).containsOnly(ruleDefinitions);
+ assertThat(underTest.findAll()).containsOnly(ruleDtos);
}
private static RuleKey toRuleKey(Rule rule) {
return RuleKey.of(rule.getRepositoryKey(), rule.getKey());
}
- private void verifyRule(@Nullable Rule rule, RuleDefinitionDto ruleDefinition, RuleParamDto ruleParam) {
+ private void verifyRule(@Nullable Rule rule, RuleDto ruleDto, RuleParamDto ruleParam) {
assertThat(rule).isNotNull();
- assertThat(rule.getName()).isEqualTo(ruleDefinition.getName());
- assertThat(rule.getLanguage()).isEqualTo(ruleDefinition.getLanguage());
- assertThat(rule.getKey()).isEqualTo(ruleDefinition.getRuleKey());
- assertThat(rule.getConfigKey()).isEqualTo(ruleDefinition.getConfigKey());
- assertThat(rule.isTemplate()).isEqualTo(ruleDefinition.isTemplate());
- assertThat(rule.getCreatedAt().getTime()).isEqualTo(ruleDefinition.getCreatedAt());
- assertThat(rule.getUpdatedAt().getTime()).isEqualTo(ruleDefinition.getUpdatedAt());
- assertThat(rule.getRepositoryKey()).isEqualTo(ruleDefinition.getRepositoryKey());
- assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString());
- assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().toArray(new String[0]));
+ assertThat(rule.getName()).isEqualTo(ruleDto.getName());
+ assertThat(rule.getLanguage()).isEqualTo(ruleDto.getLanguage());
+ assertThat(rule.getKey()).isEqualTo(ruleDto.getRuleKey());
+ assertThat(rule.getConfigKey()).isEqualTo(ruleDto.getConfigKey());
+ assertThat(rule.isTemplate()).isEqualTo(ruleDto.isTemplate());
+ assertThat(rule.getCreatedAt().getTime()).isEqualTo(ruleDto.getCreatedAt());
+ assertThat(rule.getUpdatedAt().getTime()).isEqualTo(ruleDto.getUpdatedAt());
+ assertThat(rule.getRepositoryKey()).isEqualTo(ruleDto.getRepositoryKey());
+ assertThat(rule.getSeverity().name()).isEqualTo(ruleDto.getSeverityString());
+ assertThat(rule.getSystemTags()).isEqualTo(ruleDto.getSystemTags().toArray(new String[0]));
assertThat(rule.getTags()).isEmpty();
- assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDefaultRuleDescriptionSectionDto().getContent());
+ assertThat(rule.getDescription()).isEqualTo(ruleDto.getDefaultRuleDescriptionSection().getContent());
assertThat(rule.getParams()).hasSize(1);
org.sonar.api.rules.RuleParam param = rule.getParams().iterator().next();