aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/testFixtures
diff options
context:
space:
mode:
authorZipeng WU <zipeng.wu@sonarsource.com>2022-05-20 12:15:50 +0200
committersonartech <sonartech@sonarsource.com>2022-05-24 20:10:14 +0000
commitf05edf50468fca40be695a0519fe962a020d26b1 (patch)
treede6cc70eda7eabf94c14ff040177f6d6eb8b4f5b /server/sonar-db-dao/src/testFixtures
parentec85c6ac6c0a29f27eb241dff4445be8ad07e727 (diff)
downloadsonarqube-f05edf50468fca40be695a0519fe962a020d26b1.tar.gz
sonarqube-f05edf50468fca40be695a0519fe962a020d26b1.zip
SONAR-16419 merge rules and rules metadata in single table and DTO
Diffstat (limited to 'server/sonar-db-dao/src/testFixtures')
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java42
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java25
2 files changed, 7 insertions, 60 deletions
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java
index 0c09ee46243..4aadca4f202 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java
@@ -26,7 +26,6 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleType;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbTester;
-import org.sonar.db.user.UserDto;
import static java.util.Arrays.asList;
import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT;
@@ -126,26 +125,6 @@ public class RuleDbTester {
}
@SafeVarargs
- public final RuleMetadataDto insertOrUpdateMetadata(RuleDto rule, Consumer<RuleMetadataDto>... populaters) {
- RuleMetadataDto dto = RuleTesting.newRuleMetadata(rule);
- asList(populaters).forEach(populater -> populater.accept(dto));
- return insertOrUpdateMetadata(dto);
- }
-
- @SafeVarargs
- public final RuleMetadataDto insertOrUpdateMetadata(RuleDto rule, UserDto noteUser, Consumer<RuleMetadataDto>... populaters) {
- RuleMetadataDto dto = RuleTesting.newRuleMetadata(rule, noteUser);
- asList(populaters).forEach(populater -> populater.accept(dto));
- return insertOrUpdateMetadata(dto);
- }
-
- public RuleMetadataDto insertOrUpdateMetadata(RuleMetadataDto metadata) {
- db.getDbClient().ruleDao().insertOrUpdateRuleMetadata(db.getSession(), metadata);
- db.commit();
- return db.getDbClient().ruleDao().selectByUuid(metadata.getRuleUuid(), db.getSession()).get().getMetadata();
- }
-
- @SafeVarargs
public final RuleParamDto insertRuleParam(RuleDto rule, Consumer<RuleParamDto>... populaters) {
RuleParamDto param = RuleTesting.newRuleParam(rule);
asList(populaters).forEach(populater -> populater.accept(param));
@@ -154,18 +133,6 @@ public class RuleDbTester {
return param;
}
- public RuleDto insertRule(RuleDto ruleDto) {
- if (ruleDto.getUuid() == null) {
- ruleDto.setUuid(Uuids.createFast());
- }
-
- insert(ruleDto);
- RuleMetadataDto metadata = ruleDto.getMetadata();
- db.getDbClient().ruleDao().insertOrUpdateRuleMetadata(db.getSession(), metadata.setRuleUuid(ruleDto.getUuid()));
- db.commit();
- return ruleDto;
- }
-
/**
* Create and persist a rule with random values.
*/
@@ -178,7 +145,7 @@ public class RuleDbTester {
public final RuleDto insertRule(Consumer<RuleDto>... populaters) {
RuleDto ruleDto = newRuleDto();
asList(populaters).forEach(populater -> populater.accept(ruleDto));
- return insertRule(ruleDto);
+ return insert(ruleDto);
}
public RuleDto insertRule(Consumer<RuleDto> populateRuleDto) {
@@ -189,7 +156,7 @@ public class RuleDbTester {
ruleDto.setUuid(Uuids.createFast());
}
- return insertRule(ruleDto);
+ return insert(ruleDto);
}
@SafeVarargs
@@ -200,9 +167,4 @@ public class RuleDbTester {
return deprecatedRuleKeyDto;
}
- public RuleDto insertRule(RuleDto ruleDto, RuleMetadataDto ruleMetadata) {
- db.getDbClient().ruleDao().insertOrUpdateRuleMetadata(db.getSession(), ruleMetadata.setRuleUuid(ruleDto.getUuid()));
- db.commit();
- return db.getDbClient().ruleDao().selectOrFailByKey(db.getSession(), ruleDto.getKey());
- }
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
index 982b9e4820a..57bdd634f10 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
@@ -33,7 +33,6 @@ import org.sonar.core.util.UuidFactory;
import org.sonar.core.util.UuidFactoryFast;
import org.sonar.core.util.Uuids;
import org.sonar.db.rule.RuleDto.Scope;
-import org.sonar.db.user.UserDto;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableSet.copyOf;
@@ -96,14 +95,6 @@ public class RuleTesting {
//voluntarily offset the remediation to be able to detect issues
.setDefRemediationGapMultiplier((nextInt(10) + 10) + "h")
.setDefRemediationFunction("LINEAR_OFFSET")
- .setCreatedAt(currentTimeMillis)
- .setUpdatedAt(currentTimeMillis + 5)
- .setScope(Scope.MAIN);
- }
-
- public static RuleMetadataDto newRuleMetadata() {
- return new RuleMetadataDto()
- .setRuleUuid("uuid_" + randomAlphanumeric(5))
.setRemediationBaseEffort(nextInt(10) + "h")
.setRemediationGapMultiplier(nextInt(10) + "h")
.setRemediationFunction("LINEAR_OFFSET")
@@ -115,16 +106,10 @@ public class RuleTesting {
.setAdHocName("adHocName_" + randomAlphanumeric(5))
.setAdHocDescription("adHocDescription_" + randomAlphanumeric(5))
.setAdHocSeverity(Severity.ALL.get(nextInt(Severity.ALL.size())))
- .setAdHocType(RuleType.values()[nextInt(RuleType.values().length - 1)]);
- }
-
- public static RuleMetadataDto newRuleMetadata(RuleDto rule) {
- return newRuleMetadata()
- .setRuleUuid(rule.getUuid());
- }
-
- public static RuleMetadataDto newRuleMetadata(RuleDto rule, UserDto noteUser) {
- return newRuleMetadata(rule).setNoteUserUuid(noteUser.getUuid());
+ .setAdHocType(RuleType.values()[nextInt(RuleType.values().length - 1)])
+ .setCreatedAt(currentTimeMillis)
+ .setUpdatedAt(currentTimeMillis + 5)
+ .setScope(Scope.MAIN);
}
public static RuleParamDto newRuleParam(RuleDto rule) {
@@ -287,7 +272,7 @@ public class RuleTesting {
return rule -> rule.setSystemTags(copyOf(tags));
}
- public static Consumer<RuleMetadataDto> setTags(String... tags) {
+ public static Consumer<RuleDto> setTags(String... tags) {
return rule -> rule.setTags(copyOf(tags));
}