Browse Source

SONAR-7330 Rename activeRuleDao to deprecatedActiveRuleDao in DbClient

tags/5.5-M6
Julien Lancelot 8 years ago
parent
commit
41d87615d2
21 changed files with 135 additions and 125 deletions
  1. 1
    1
      server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java
  2. 1
    1
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
  3. 1
    1
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java
  4. 7
    7
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
  5. 4
    5
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java
  6. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleNormalizer.java
  7. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
  8. 5
    5
      server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java
  9. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java
  10. 34
    31
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleTest.java
  11. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
  12. 5
    5
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java
  13. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java
  14. 11
    11
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
  15. 14
    15
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java
  16. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java
  17. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java
  18. 28
    28
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
  19. 2
    0
      sonar-db/src/main/java/org/sonar/db/DaoModule.java
  20. 7
    0
      sonar-db/src/main/java/org/sonar/db/DbClient.java
  21. 1
    1
      sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java

+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java View File

@@ -47,7 +47,7 @@ public class DbClient extends org.sonar.db.DbClient {
this.ruleDao = (RuleDao) daoByClass.get(RuleDao.class);
}

public ActiveRuleDao activeRuleDao() {
public ActiveRuleDao deprecatedActiveRuleDao() {
return activeRuleDao;
}


+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java View File

@@ -116,7 +116,7 @@ public class QProfileFactory {

private void doDelete(DbSession session, QualityProfileDto profile) {
db.qualityProfileDao().deleteAllProjectProfileAssociation(profile.getKey(), session);
db.activeRuleDao().deleteByProfileKey(session, profile.getKey());
db.deprecatedActiveRuleDao().deleteByProfileKey(session, profile.getKey());
db.qualityProfileDao().delete(session, profile);
}


+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java View File

@@ -128,7 +128,7 @@ public class QProfileReset {
BulkChangeResult result = new BulkChangeResult(profile);
Set<RuleKey> ruleToBeDeactivated = Sets.newHashSet();
// Keep reference to all the activated rules before backup restore
for (ActiveRuleDto activeRuleDto : db.activeRuleDao().selectByProfileKey(dbSession, profile.getKee())) {
for (ActiveRuleDto activeRuleDto : db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, profile.getKee())) {
if (activeRuleDto.getInheritance() == null) {
// inherited rules can't be deactivated
ruleToBeDeactivated.add(activeRuleDto.getKey().ruleKey());

+ 7
- 7
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java View File

@@ -235,7 +235,7 @@ public class RuleActivator {
activeRule = doInsert(change, context, dbSession);

} else if (change.getType() == ActiveRuleChange.Type.DEACTIVATED) {
ActiveRuleDao dao = db.activeRuleDao();
ActiveRuleDao dao = db.deprecatedActiveRuleDao();
dao.deleteByKey(dbSession, change.getKey());

} else if (change.getType() == ActiveRuleChange.Type.UPDATED) {
@@ -247,7 +247,7 @@ public class RuleActivator {

private ActiveRuleDto doInsert(ActiveRuleChange change, RuleActivatorContext context, DbSession dbSession) {
ActiveRuleDto activeRule;
ActiveRuleDao dao = db.activeRuleDao();
ActiveRuleDao dao = db.deprecatedActiveRuleDao();
activeRule = ActiveRuleDto.createFor(context.profile(), context.rule());
String severity = change.getSeverity();
if (severity != null) {
@@ -269,7 +269,7 @@ public class RuleActivator {
}

private ActiveRuleDto doUpdate(ActiveRuleChange change, RuleActivatorContext context, DbSession dbSession) {
ActiveRuleDao dao = db.activeRuleDao();
ActiveRuleDao dao = db.deprecatedActiveRuleDao();
ActiveRuleDto activeRule = context.activeRule();
if (activeRule != null) {
String severity = change.getSeverity();
@@ -331,7 +331,7 @@ public class RuleActivator {
*/
public List<ActiveRuleChange> deactivate(DbSession dbSession, RuleDto ruleDto) {
List<ActiveRuleChange> changes = Lists.newArrayList();
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRule(dbSession, ruleDto);
List<ActiveRuleDto> activeRules = db.deprecatedActiveRuleDao().selectByRule(dbSession, ruleDto);
for (ActiveRuleDto activeRule : activeRules) {
changes.addAll(deactivate(dbSession, activeRule.getKey(), true));
}
@@ -478,7 +478,7 @@ public class RuleActivator {
// set new parent
profile.setParentKee(parentKey);
db.qualityProfileDao().update(dbSession, profile);
for (ActiveRuleDto parentActiveRule : db.activeRuleDao().selectByProfileKey(dbSession, parentKey)) {
for (ActiveRuleDto parentActiveRule : db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, parentKey)) {
try {
RuleActivation activation = new RuleActivation(parentActiveRule.getKey().ruleKey());
activate(dbSession, activation, profileKey);
@@ -497,12 +497,12 @@ public class RuleActivator {
if (profileDto.getParentKee() != null) {
profileDto.setParentKee(null);
db.qualityProfileDao().update(dbSession, profileDto);
for (ActiveRuleDto activeRule : db.activeRuleDao().selectByProfileKey(dbSession, profileDto.getKey())) {
for (ActiveRuleDto activeRule : db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, profileDto.getKey())) {
if (ActiveRuleDto.INHERITED.equals(activeRule.getInheritance())) {
deactivate(dbSession, activeRule.getKey(), true);
} else if (ActiveRuleDto.OVERRIDES.equals(activeRule.getInheritance())) {
activeRule.setInheritance(null);
db.activeRuleDao().update(dbSession, activeRule);
db.deprecatedActiveRuleDao().update(dbSession, activeRule);
}
}
}

+ 4
- 5
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java View File

@@ -19,8 +19,9 @@
*/
package org.sonar.server.qualityprofile;

import org.sonar.api.server.ServerSide;
import java.util.Collection;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.ServerSide;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
@@ -30,8 +31,6 @@ import org.sonar.db.rule.RuleDto;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;

import java.util.Collection;

@ServerSide
public class RuleActivatorContextFactory {

@@ -87,10 +86,10 @@ public class RuleActivatorContextFactory {

private void initActiveRules(String profileKey, RuleKey ruleKey, RuleActivatorContext context, DbSession session, boolean parent) {
ActiveRuleKey key = ActiveRuleKey.of(profileKey, ruleKey);
ActiveRuleDto activeRule = db.activeRuleDao().getNullableByKey(session, key);
ActiveRuleDto activeRule = db.deprecatedActiveRuleDao().getNullableByKey(session, key);
Collection<ActiveRuleParamDto> activeRuleParams = null;
if (activeRule != null) {
activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleKey(session, key);
activeRuleParams = db.deprecatedActiveRuleDao().selectParamsByActiveRuleKey(session, key);
}
if (parent) {
context.setParentActiveRule(activeRule);

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleNormalizer.java View File

@@ -104,7 +104,7 @@ public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRu
String parentKey = null;
Integer parentId = activeRuleDto.getParentId();
if (parentId != null) {
ActiveRuleDto parentDto = db.activeRuleDao().selectById(session, parentId);
ActiveRuleDto parentDto = db.deprecatedActiveRuleDao().selectById(session, parentId);
if (parentDto != null) {
parentKey = parentDto.getKey().toString();
}
@@ -119,7 +119,7 @@ public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRu
.upsert(getUpsertFor(ActiveRuleField.ALL_FIELDS, newRule)));

// Get the RuleParameters
for (ActiveRuleParamDto param : db.activeRuleDao().selectParamsByActiveRuleKey(session, key)) {
for (ActiveRuleParamDto param : db.deprecatedActiveRuleDao().selectParamsByActiveRuleKey(session, key)) {
requests.addAll(normalizeNested(param, key));
}


+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java View File

@@ -284,7 +284,7 @@ public class RegisterRules implements Startable {
for (RuleParamDto paramDto : paramDtos) {
RulesDefinition.Param paramDef = ruleDef.param(paramDto.getName());
if (paramDef == null) {
dbClient.activeRuleDao().deleteParamsByRuleParam(session, rule, paramDto.getName());
dbClient.deprecatedActiveRuleDao().deleteParamsByRuleParam(session, rule, paramDto.getName());
dbClient.ruleDao().deleteRuleParam(session, paramDto.getId());
} else {
if (mergeParam(paramDto, paramDef)) {
@@ -306,9 +306,9 @@ public class RegisterRules implements Startable {
dbClient.ruleDao().insertRuleParam(session, rule, paramDto);
if (!StringUtils.isEmpty(param.defaultValue())) {
// Propagate the default value to existing active rules
for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRule(session, rule)) {
for (ActiveRuleDto activeRule : dbClient.deprecatedActiveRuleDao().selectByRule(session, rule)) {
ActiveRuleParamDto activeParam = ActiveRuleParamDto.createFor(paramDto).setValue(param.defaultValue());
dbClient.activeRuleDao().insertParam(session, activeRule, activeParam);
dbClient.deprecatedActiveRuleDao().insertParam(session, activeRule, activeParam);
}
}
}

+ 5
- 5
server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java View File

@@ -251,9 +251,9 @@ public class RuleUpdater {
// Load active rules and its parameters in cache
Multimap<RuleDto, ActiveRuleDto> activeRules = ArrayListMultimap.create();
Multimap<ActiveRuleDto, ActiveRuleParamDto> activeRuleParams = ArrayListMultimap.create();
for (ActiveRuleDto activeRuleDto : dbClient.activeRuleDao().selectByRule(dbSession, customRule)) {
for (ActiveRuleDto activeRuleDto : dbClient.deprecatedActiveRuleDao().selectByRule(dbSession, customRule)) {
activeRules.put(customRule, activeRuleDto);
for (ActiveRuleParamDto activeRuleParamDto : dbClient.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey())) {
for (ActiveRuleParamDto activeRuleParamDto : dbClient.deprecatedActiveRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey())) {
activeRuleParams.put(activeRuleDto, activeRuleParamDto);
}
}
@@ -278,9 +278,9 @@ public class RuleUpdater {
for (ActiveRuleDto activeRuleDto : activeRules.get(customRule)) {
for (ActiveRuleParamDto activeRuleParamDto : activeRuleParams.get(activeRuleDto)) {
if (activeRuleParamDto.getKey().equals(key)) {
dbClient.activeRuleDao().updateParam(dbSession, activeRuleDto, activeRuleParamDto.setValue(value));
dbClient.deprecatedActiveRuleDao().updateParam(dbSession, activeRuleDto, activeRuleParamDto.setValue(value));
} else {
dbClient.activeRuleDao().insertParam(dbSession, activeRuleDto, ActiveRuleParamDto.createFor(ruleParamDto).setValue(value));
dbClient.deprecatedActiveRuleDao().insertParam(dbSession, activeRuleDto, ActiveRuleParamDto.createFor(ruleParamDto).setValue(value));
}
}
}
@@ -289,7 +289,7 @@ public class RuleUpdater {
for (ActiveRuleDto activeRuleDto : activeRules.get(customRule)) {
for (ActiveRuleParamDto activeRuleParamDto : activeRuleParams.get(activeRuleDto)) {
if (activeRuleParamDto.getKey().equals(key)) {
dbClient.activeRuleDao().deleteParam(dbSession, activeRuleDto, activeRuleParamDto);
dbClient.deprecatedActiveRuleDao().deleteParam(dbSession, activeRuleDto, activeRuleParamDto);
}
}
}

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java View File

@@ -56,7 +56,7 @@ public class DbClientTest {

// DAO
assertThat(client.qualityProfileDao()).isSameAs(qualityProfileDao);
assertThat(client.activeRuleDao()).isSameAs(activeRuleDao);
assertThat(client.deprecatedActiveRuleDao()).isSameAs(activeRuleDao);
assertThat(client.deprecatedRuleDao()).isSameAs(ruleDao);
}
}

+ 34
- 31
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleTest.java View File

@@ -31,6 +31,7 @@ import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
@@ -57,6 +58,8 @@ import org.sonar.server.tester.UserSessionRule;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;

// TODO To be removed when dao v2 is removed
@Ignore
public class ActiveRuleTest {

@ClassRule
@@ -97,20 +100,20 @@ public class ActiveRuleTest {
db.deprecatedRuleDao().insert(dbSession, rule1);

ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile1, rule1).setSeverity("BLOCKER");
db.activeRuleDao().insert(dbSession, activeRule);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule);
dbSession.commit();

// 1. Synchronize since 0
tester.clearIndexes();
assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNull();
db.activeRuleDao().synchronizeAfter(dbSession, new Date(0L));
db.deprecatedActiveRuleDao().synchronizeAfter(dbSession, new Date(0L));
dbSession.commit();
assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNotNull();

// 2. Synchronize since beginning
tester.clearIndexes();
assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNull();
db.activeRuleDao().synchronizeAfter(dbSession, beginning);
db.deprecatedActiveRuleDao().synchronizeAfter(dbSession, beginning);
dbSession.commit();
assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNotNull();

@@ -134,7 +137,7 @@ public class ActiveRuleTest {
db.deprecatedRuleDao().insert(dbSession, rule);

ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER");
db.activeRuleDao().insert(dbSession, activeRule);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule);
dbSession.commit();

// Remove rule -> Active rule is now linked to a not existing rule
@@ -143,7 +146,7 @@ public class ActiveRuleTest {

// Synchronize index from start
tester.clearIndexes();
db.activeRuleDao().synchronizeAfter(dbSession, new Date(0L));
db.deprecatedActiveRuleDao().synchronizeAfter(dbSession, new Date(0L));
dbSession.commit();

// Active does not exist in the index
@@ -162,7 +165,7 @@ public class ActiveRuleTest {
db.deprecatedRuleDao().insert(dbSession, rule);

ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER");
db.activeRuleDao().insert(dbSession, activeRule);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule);
dbSession.commit();

// Remove quality profile -> active rule is now linked to a not existing quality profile
@@ -171,7 +174,7 @@ public class ActiveRuleTest {

// Synchronize index from start
tester.clearIndexes();
db.activeRuleDao().synchronizeAfter(dbSession, new Date(0L));
db.deprecatedActiveRuleDao().synchronizeAfter(dbSession, new Date(0L));
dbSession.commit();

// Active does not exist in the index
@@ -189,12 +192,12 @@ public class ActiveRuleTest {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto)
.setInheritance(ActiveRule.Inheritance.INHERITED.name())
.setSeverity(Severity.BLOCKER);
db.activeRuleDao().insert(dbSession, activeRule);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule);
dbSession.commit();

// verify db
assertThat(db.activeRuleDao().getByKey(dbSession, activeRule.getKey())).isNotNull();
List<ActiveRuleDto> persistedDtos = db.activeRuleDao().selectByRule(dbSession, ruleDto);
assertThat(db.deprecatedActiveRuleDao().getByKey(dbSession, activeRule.getKey())).isNotNull();
List<ActiveRuleDto> persistedDtos = db.deprecatedActiveRuleDao().selectByRule(dbSession, ruleDto);
assertThat(persistedDtos).hasSize(1);

// verify es
@@ -228,20 +231,20 @@ public class ActiveRuleTest {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto)
.setInheritance(ActiveRule.Inheritance.INHERITED.name())
.setSeverity(Severity.BLOCKER);
db.activeRuleDao().insert(dbSession, activeRule);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule);

ActiveRuleParamDto activeRuleMinParam = ActiveRuleParamDto.createFor(minParam)
.setValue("minimum");
db.activeRuleDao().insertParam(dbSession, activeRule, activeRuleMinParam);
db.deprecatedActiveRuleDao().insertParam(dbSession, activeRule, activeRuleMinParam);

ActiveRuleParamDto activeRuleMaxParam = ActiveRuleParamDto.createFor(maxParam)
.setValue("maximum");
db.activeRuleDao().insertParam(dbSession, activeRule, activeRuleMaxParam);
db.deprecatedActiveRuleDao().insertParam(dbSession, activeRule, activeRuleMaxParam);

dbSession.commit();

// verify db
List<ActiveRuleParamDto> persistedDtos = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRule.getKey());
List<ActiveRuleParamDto> persistedDtos = db.deprecatedActiveRuleDao().selectParamsByActiveRuleKey(dbSession, activeRule.getKey());
assertThat(persistedDtos).hasSize(2);

// verify es
@@ -264,21 +267,21 @@ public class ActiveRuleTest {
RuleDto removedRule = RuleTesting.newDto(RuleKey.of("xoo", "removed")).setSeverity(Severity.MAJOR).setStatus(RuleStatus.REMOVED);
db.deprecatedRuleDao().insert(dbSession, rule1, rule2, removedRule);

db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule1).setSeverity(Severity.MINOR));
db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule2).setSeverity(Severity.BLOCKER));
db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, rule2).setSeverity(Severity.CRITICAL));
db.deprecatedActiveRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule1).setSeverity(Severity.MINOR));
db.deprecatedActiveRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule2).setSeverity(Severity.BLOCKER));
db.deprecatedActiveRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, rule2).setSeverity(Severity.CRITICAL));
// Removed rule can still be activated for instance when removing the checkstyle plugin, active rules related on checkstyle are not
// removed
// because if the plugin is re-install, quality profiles using these rule are not changed.
db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, removedRule).setSeverity(Severity.MAJOR));
db.deprecatedActiveRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, removedRule).setSeverity(Severity.MAJOR));
dbSession.commit();

// 1. find by rule key

// in db
dbSession.clearCache();
assertThat(db.activeRuleDao().selectByRule(dbSession, rule1)).hasSize(1);
assertThat(db.activeRuleDao().selectByRule(dbSession, rule2)).hasSize(2);
assertThat(db.deprecatedActiveRuleDao().selectByRule(dbSession, rule1)).hasSize(1);
assertThat(db.deprecatedActiveRuleDao().selectByRule(dbSession, rule2)).hasSize(2);

// in es
List<ActiveRule> activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X1);
@@ -317,7 +320,7 @@ public class ActiveRuleTest {
db.deprecatedRuleDao().insert(dbSession, rule);

ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, rule).setSeverity(Severity.MAJOR);
db.activeRuleDao().insert(dbSession, activeRule);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule);
}
dbSession.commit();
dbSession.clearCache();
@@ -339,7 +342,7 @@ public class ActiveRuleTest {

ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(profileDto1, ruleDto).setSeverity(Severity.MAJOR);
ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(profileDto2, ruleDto).setSeverity(Severity.MAJOR);
db.activeRuleDao().insert(dbSession, activeRule1, activeRule2);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule1, activeRule2);
dbSession.commit();

// 0. Test base case
@@ -367,7 +370,7 @@ public class ActiveRuleTest {

ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(profileDto1, ruleDto).setSeverity(Severity.MAJOR);
ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(profileDto2, ruleDto).setSeverity(Severity.MAJOR);
db.activeRuleDao().insert(dbSession, activeRule1, activeRule2);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule1, activeRule2);
dbSession.commit();

// 0. Test base case
@@ -390,7 +393,7 @@ public class ActiveRuleTest {
RuleDto ruleDto2 = newRuleDto(RuleTesting.XOO_X2);
db.deprecatedRuleDao().insert(dbSession, ruleDto1, ruleDto2);

db.activeRuleDao().insert(dbSession,
db.deprecatedActiveRuleDao().insert(dbSession,
ActiveRuleDto.createFor(profileDto1, ruleDto1)
.setInheritance(ActiveRule.Inheritance.INHERITED.name())
.setSeverity(Severity.BLOCKER),
@@ -432,7 +435,7 @@ public class ActiveRuleTest {
profileKeys.add(profileDto.getKey());
db.qualityProfileDao().insert(dbSession, profileDto);

db.activeRuleDao().insert(dbSession,
db.deprecatedActiveRuleDao().insert(dbSession,
ActiveRuleDto.createFor(profileDto, ruleDto1)
.setSeverity(Severity.BLOCKER),
ActiveRuleDto.createFor(profileDto, ruleDto2)
@@ -454,10 +457,10 @@ public class ActiveRuleTest {
db.deprecatedRuleDao().insert(dbSession, rule);

ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER");
db.activeRuleDao().insert(dbSession, activeRule);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule);
dbSession.commit();

assertThat(db.activeRuleDao().selectById(dbSession, activeRule.getId()).getId()).isEqualTo(activeRule.getId());
assertThat(db.deprecatedActiveRuleDao().selectById(dbSession, activeRule.getId()).getId()).isEqualTo(activeRule.getId());
}

@Test
@@ -469,14 +472,14 @@ public class ActiveRuleTest {
db.deprecatedRuleDao().insert(dbSession, rule);

ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER");
db.activeRuleDao().insert(dbSession, activeRule);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule);
dbSession.commit();

// Remove rule -> Active rule is now linked to a not existing rule
executeSql(String.format("DELETE FROM rules WHERE id=%s", rule.getId()));
dbSession.commit();

assertThat(db.activeRuleDao().selectById(dbSession, activeRule.getId())).isNull();
assertThat(db.deprecatedActiveRuleDao().selectById(dbSession, activeRule.getId())).isNull();
}

@Test
@@ -488,14 +491,14 @@ public class ActiveRuleTest {
db.deprecatedRuleDao().insert(dbSession, rule);

ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER");
db.activeRuleDao().insert(dbSession, activeRule);
db.deprecatedActiveRuleDao().insert(dbSession, activeRule);
dbSession.commit();

// Remove quality profile -> active rule is now linked to a not existing quality profile
executeSql(String.format("DELETE FROM rules_profiles WHERE id=%s", profile.getId()));
dbSession.commit();

assertThat(db.activeRuleDao().selectById(dbSession, activeRule.getId())).isNull();
assertThat(db.deprecatedActiveRuleDao().selectById(dbSession, activeRule.getId())).isNull();
}

private RuleDto newRuleDto(RuleKey ruleKey) {

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java View File

@@ -318,7 +318,7 @@ public class QProfileBackuperMediumTest {
null);

dbSession.clearCache();
assertThat(db.activeRuleDao().selectAll(dbSession)).hasSize(0);
assertThat(db.deprecatedActiveRuleDao().selectAll(dbSession)).hasSize(0);
List<QualityProfileDto> profiles = db.qualityProfileDao().selectAll(dbSession);
assertThat(profiles).hasSize(1);
assertThat(profiles.get(0).getName()).isEqualTo("P1");

+ 5
- 5
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java View File

@@ -212,8 +212,8 @@ public class QProfileFactoryMediumTest {

dbSession.clearCache();
assertThat(db.qualityProfileDao().selectAll(dbSession)).isEmpty();
assertThat(db.activeRuleDao().selectAll(dbSession)).isEmpty();
assertThat(db.activeRuleDao().selectAllParams(dbSession)).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectAll(dbSession)).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectAllParams(dbSession)).isEmpty();
assertThat(index.get(ActiveRuleIndex.class).findByProfile(XOO_P1_KEY)).isEmpty();
}

@@ -229,14 +229,14 @@ public class QProfileFactoryMediumTest {
dbSession.commit();
dbSession.clearCache();
assertThat(db.qualityProfileDao().selectAll(dbSession)).hasSize(3);
assertThat(db.activeRuleDao().selectAll(dbSession)).hasSize(3);
assertThat(db.deprecatedActiveRuleDao().selectAll(dbSession)).hasSize(3);

factory.delete(XOO_P1_KEY);

dbSession.clearCache();
assertThat(db.qualityProfileDao().selectAll(dbSession)).isEmpty();
assertThat(db.activeRuleDao().selectAll(dbSession)).isEmpty();
assertThat(db.activeRuleDao().selectAllParams(dbSession)).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectAll(dbSession)).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectAllParams(dbSession)).isEmpty();
assertThat(index.get(ActiveRuleIndex.class).findByProfile(XOO_P1_KEY)).isEmpty();
assertThat(index.get(ActiveRuleIndex.class).findByProfile(XOO_P2_KEY)).isEmpty();
assertThat(index.get(ActiveRuleIndex.class).findByProfile(XOO_P3_KEY)).isEmpty();

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java View File

@@ -33,12 +33,12 @@ import org.sonar.api.server.rule.RuleParamType;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.db.DbSession;
import org.sonar.db.loadedtemplate.LoadedTemplateDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.loadedtemplate.LoadedTemplateDto;
import org.sonar.server.db.DbClient;
import org.sonar.server.platform.Platform;
import org.sonar.server.qualityprofile.db.ActiveRuleDao;
@@ -76,7 +76,7 @@ public class RegisterQualityProfilesMediumTest {
assertThat(profile).isNotNull();

// Check ActiveRules in DB
ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
ActiveRuleDao activeRuleDao = dbClient().deprecatedActiveRuleDao();
assertThat(activeRuleDao.selectByProfileKey(dbSession, profile.getKey())).hasSize(2);
RuleKey ruleKey = RuleKey.of("xoo", "x1");
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), ruleKey);
@@ -122,7 +122,7 @@ public class RegisterQualityProfilesMediumTest {
verifyDefaultProfile("xoo", "Basic");

// Check ActiveRules in DB
ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
ActiveRuleDao activeRuleDao = dbClient().deprecatedActiveRuleDao();
assertThat(activeRuleDao.selectByProfileKey(dbSession, profile.getKey())).hasSize(2);
RuleKey ruleKey = RuleKey.of("xoo", "x1");


+ 11
- 11
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java View File

@@ -42,11 +42,11 @@ import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.Message;
import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.search.QueryContext;
@@ -264,10 +264,10 @@ public class RuleActivatorMediumTest {
activation.setSeverity(Severity.BLOCKER);
activate(activation, XOO_P1_KEY);

assertThat(db.activeRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNotNull();
db.activeRuleDao().deleteParamByKeyAndName(dbSession, activeRuleKey, "max");
assertThat(db.deprecatedActiveRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNotNull();
db.deprecatedActiveRuleDao().deleteParamByKeyAndName(dbSession, activeRuleKey, "max");
dbSession.commit();
assertThat(db.activeRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNull();
assertThat(db.deprecatedActiveRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNull();
dbSession.clearCache();

// update
@@ -853,7 +853,7 @@ public class RuleActivatorMediumTest {

// 2. assert that all activation has been commit to DB and ES
dbSession.clearCache();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(bulkSize);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(bulkSize);
assertThat(index.findByProfile(XOO_P1_KEY)).hasSize(bulkSize);
assertThat(result.countSucceeded()).isEqualTo(bulkSize);
assertThat(result.countFailed()).isEqualTo(0);
@@ -867,7 +867,7 @@ public class RuleActivatorMediumTest {
// 2. assert that all activations have been commit to DB and ES
// -> xoo rules x1, x2 and custom1
dbSession.clearCache();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(3);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(3);
assertThat(index.findByProfile(XOO_P1_KEY)).hasSize(3);
assertThat(result.countSucceeded()).isEqualTo(3);
assertThat(result.countFailed()).isGreaterThan(0);
@@ -1035,7 +1035,7 @@ public class RuleActivatorMediumTest {
}

private int countActiveRules(String profileKey) {
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, profileKey);
List<ActiveRuleDto> activeRuleDtos = db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, profileKey);
List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(profileKey));
assertThat(activeRuleDtos.size()).as("Not same active rules between db and index").isEqualTo(activeRules.size());
return activeRuleDtos.size();
@@ -1056,7 +1056,7 @@ public class RuleActivatorMediumTest {
@Nullable String expectedInheritance, Map<String, String> expectedParams) {
// verify db
boolean found = false;
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, activeRuleKey.qProfile());
List<ActiveRuleDto> activeRuleDtos = db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, activeRuleKey.qProfile());
for (ActiveRuleDto activeRuleDto : activeRuleDtos) {
if (activeRuleDto.getKey().equals(activeRuleKey)) {
found = true;
@@ -1066,10 +1066,10 @@ public class RuleActivatorMediumTest {
assertThat(activeRuleDto.getCreatedAt()).isNotNull();
assertThat(activeRuleDto.getUpdatedAt()).isNotNull();

List<ActiveRuleParamDto> paramDtos = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey());
List<ActiveRuleParamDto> paramDtos = db.deprecatedActiveRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey());
assertThat(paramDtos).hasSize(expectedParams.size());
for (Map.Entry<String, String> entry : expectedParams.entrySet()) {
ActiveRuleParamDto paramDto = db.activeRuleDao().selectParamByKeyAndName(activeRuleDto.getKey(), entry.getKey(), dbSession);
ActiveRuleParamDto paramDto = db.deprecatedActiveRuleDao().selectParamByKeyAndName(activeRuleDto.getKey(), entry.getKey(), dbSession);
assertThat(paramDto).isNotNull();
assertThat(paramDto.getValue()).isEqualTo(entry.getValue());
}
@@ -1117,7 +1117,7 @@ public class RuleActivatorMediumTest {
private void verifyZeroActiveRules(String key) {
// verify db
dbSession.clearCache();
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, key);
List<ActiveRuleDto> activeRuleDtos = db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, key);
assertThat(activeRuleDtos).isEmpty();

// verify es

+ 14
- 15
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java View File

@@ -19,6 +19,7 @@
*/
package org.sonar.server.qualityprofile.ws;

import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -42,8 +43,6 @@ import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class ChangeParentActionMediumTest {
@@ -83,7 +82,7 @@ public class ChangeParentActionMediumTest {
createActiveRule(rule1, parent1);
session.commit();

assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();

// Set parent
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
@@ -93,7 +92,7 @@ public class ChangeParentActionMediumTest {
session.clearCache();

// Check rule 1 enabled
List<ActiveRuleDto> activeRules1 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
List<ActiveRuleDto> activeRules1 = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().ruleKey().rule()).isEqualTo("rule1");
}
@@ -122,7 +121,7 @@ public class ChangeParentActionMediumTest {
session.clearCache();

// Check rule 2 enabled
List<ActiveRuleDto> activeRules2 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
List<ActiveRuleDto> activeRules2 = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().ruleKey().rule()).isEqualTo("rule2");
}
@@ -147,7 +146,7 @@ public class ChangeParentActionMediumTest {
session.clearCache();

// Check no rule enabled
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(session, child.getKey());
List<ActiveRuleDto> activeRules = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules).isEmpty();
}

@@ -163,7 +162,7 @@ public class ChangeParentActionMediumTest {
createActiveRule(rule2, parent2);
session.commit();

assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();

// 1. Set parent 1
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
@@ -174,7 +173,7 @@ public class ChangeParentActionMediumTest {
session.clearCache();

// 1. check rule 1 enabled
List<ActiveRuleDto> activeRules1 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
List<ActiveRuleDto> activeRules1 = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().ruleKey().rule()).isEqualTo("rule1");

@@ -187,7 +186,7 @@ public class ChangeParentActionMediumTest {
session.clearCache();

// 2. check rule 2 enabled
List<ActiveRuleDto> activeRules2 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
List<ActiveRuleDto> activeRules2 = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().ruleKey().rule()).isEqualTo("rule2");

@@ -200,7 +199,7 @@ public class ChangeParentActionMediumTest {
session.clearCache();

// 3. check no rule enabled
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(session, child.getKey());
List<ActiveRuleDto> activeRules = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules).isEmpty();
}

@@ -213,7 +212,7 @@ public class ChangeParentActionMediumTest {
createActiveRule(rule1, parent);
session.commit();

assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();

// Set parent
tester.get(RuleActivator.class).setParent(child.getKey(), parent.getKey());
@@ -227,7 +226,7 @@ public class ChangeParentActionMediumTest {
session.clearCache();

// Check no rule enabled
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(session, child.getKey());
List<ActiveRuleDto> activeRules = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules).isEmpty();
}

@@ -236,7 +235,7 @@ public class ChangeParentActionMediumTest {
QualityProfileDto child = createProfile("xoo", "Child");
session.commit();

assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();

wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileIdentificationParamUtils.PARAM_PROFILE_KEY, child.getKee())
@@ -250,7 +249,7 @@ public class ChangeParentActionMediumTest {
QualityProfileDto child = createProfile("xoo", "Child");
session.commit();

assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();

wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileIdentificationParamUtils.PARAM_PROFILE_KEY, child.getKee())
@@ -286,7 +285,7 @@ public class ChangeParentActionMediumTest {
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
db.activeRuleDao().insert(session, activeRule);
db.deprecatedActiveRuleDao().insert(session, activeRule);
return activeRule;
}
}

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java View File

@@ -216,7 +216,7 @@ public class CompareActionMediumTest {
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
db.activeRuleDao().insert(session, activeRule);
db.deprecatedActiveRuleDao().insert(session, activeRule);
return activeRule;
}

@@ -224,14 +224,14 @@ public class CompareActionMediumTest {
ActiveRuleDto activeRule = createActiveRule(rule, profile);
RuleParamDto paramDto = db.deprecatedRuleDao().selectRuleParamsByRuleKey(session, rule.getKey()).get(0);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(paramDto).setValue(value);
db.activeRuleDao().insertParam(session, activeRule, activeRuleParam);
db.deprecatedActiveRuleDao().insertParam(session, activeRule, activeRuleParam);
return activeRule;
}

private ActiveRuleDto createActiveRuleWithSeverity(RuleDto rule, QualityProfileDto profile, String severity) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(severity);
db.activeRuleDao().insert(session, activeRule);
db.deprecatedActiveRuleDao().insert(session, activeRule);
return activeRule;
}
}

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java View File

@@ -137,7 +137,7 @@ public class InheritanceActionMediumTest {
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
db.activeRuleDao().insert(session, activeRule);
db.deprecatedActiveRuleDao().insert(session, activeRule);
return activeRule;
}


+ 28
- 28
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java View File

@@ -29,9 +29,9 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.component.ComponentDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.QualityProfileDto;
@@ -89,7 +89,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);

// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.DEACTIVATE_ACTION);
@@ -99,7 +99,7 @@ public class QProfilesWsMediumTest {
session.clearCache();

// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
}

@Test
@@ -116,7 +116,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(4);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(4);

// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
@@ -125,7 +125,7 @@ public class QProfilesWsMediumTest {
session.clearCache();

// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
}

@Test
@@ -141,7 +141,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);

// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
@@ -150,8 +150,8 @@ public class QProfilesWsMediumTest {
session.clearCache();

// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
}

@Test
@@ -164,7 +164,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);

// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
@@ -174,7 +174,7 @@ public class QProfilesWsMediumTest {
session.clearCache();

// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
}

@Test
@@ -184,7 +184,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();

// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
@@ -194,7 +194,7 @@ public class QProfilesWsMediumTest {
session.clearCache();

// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
}

@Test
@@ -204,7 +204,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();

try {
// 1. Activate Rule
@@ -226,7 +226,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();

// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
@@ -239,7 +239,7 @@ public class QProfilesWsMediumTest {
// 2. Assert ActiveRule in DAO
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), rule.getKey());

assertThat(db.activeRuleDao().getNullableByKey(session, activeRuleKey).getSeverityString())
assertThat(db.deprecatedActiveRuleDao().getNullableByKey(session, activeRuleKey).getSeverityString())
.isEqualTo("MINOR");
}

@@ -253,7 +253,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();

// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
@@ -263,7 +263,7 @@ public class QProfilesWsMediumTest {
session.clearCache();

// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(4);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(4);
}

@Test
@@ -277,7 +277,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, php.getKey())).isEmpty();

// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
@@ -287,7 +287,7 @@ public class QProfilesWsMediumTest {
session.clearCache();

// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
}

@Test
@@ -300,7 +300,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();

// 1. Activate Rule with query returning 0 hits
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
@@ -310,7 +310,7 @@ public class QProfilesWsMediumTest {
session.clearCache();

// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);

// 1. Activate Rule with query returning 1 hits
request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
@@ -320,7 +320,7 @@ public class QProfilesWsMediumTest {
session.commit();

// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
}

@Test
@@ -331,8 +331,8 @@ public class QProfilesWsMediumTest {
session.commit();

// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);

// 2. Assert ActiveRule with BLOCKER severity
assertThat(tester.get(RuleIndex.class).search(
@@ -362,12 +362,12 @@ public class QProfilesWsMediumTest {
.setSeverity(rule.getSeverityString());
ActiveRuleDto active2 = ActiveRuleDto.createFor(subProfile, rule)
.setSeverity("MINOR");
db.activeRuleDao().insert(session, active1, active2);
db.deprecatedActiveRuleDao().insert(session, active1, active2);

session.commit();

// 0. assert rule child rule is minor
assertThat(db.activeRuleDao().getByKey(session, active2.getKey()).getSeverityString()).isEqualTo("MINOR");
assertThat(db.deprecatedActiveRuleDao().getByKey(session, active2.getKey()).getSeverityString()).isEqualTo("MINOR");

// 1. reset child rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
@@ -378,7 +378,7 @@ public class QProfilesWsMediumTest {
session.clearCache();

// 2. assert rule child rule is NOT minor
assertThat(db.activeRuleDao().getByKey(session, active2.getKey()).getSeverityString()).isNotEqualTo("MINOR");
assertThat(db.deprecatedActiveRuleDao().getByKey(session, active2.getKey()).getSeverityString()).isNotEqualTo("MINOR");
}

@Test
@@ -566,7 +566,7 @@ public class QProfilesWsMediumTest {
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
db.activeRuleDao().insert(session, activeRule);
db.deprecatedActiveRuleDao().insert(session, activeRule);
return activeRule;
}
}

+ 2
- 0
sonar-db/src/main/java/org/sonar/db/DaoModule.java View File

@@ -57,6 +57,7 @@ import org.sonar.db.purge.PurgeDao;
import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
import org.sonar.db.qualitygate.QualityGateConditionDao;
import org.sonar.db.qualitygate.QualityGateDao;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.rule.RuleDao;
import org.sonar.db.source.FileSourceDao;
@@ -107,6 +108,7 @@ public class DaoModule extends Module {
QualityProfileDao.class,
PurgeDao.class,
RuleDao.class,
ActiveRuleDao.class,
ResourceIndexDao.class,
ResourceDao.class,
ResourceKeyUpdaterDao.class,

+ 7
- 0
sonar-db/src/main/java/org/sonar/db/DbClient.java View File

@@ -57,6 +57,7 @@ import org.sonar.db.purge.PurgeDao;
import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
import org.sonar.db.qualitygate.QualityGateConditionDao;
import org.sonar.db.qualitygate.QualityGateDao;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.rule.RuleDao;
import org.sonar.db.source.FileSourceDao;
@@ -119,6 +120,7 @@ public class DbClient {
private final MetricDao metricDao;
private final GroupDao groupDao;
private final RuleDao ruleDao;
private final ActiveRuleDao activeRuleDao;

public DbClient(Database database, MyBatis myBatis, Dao... daos) {
this.database = database;
@@ -174,6 +176,7 @@ public class DbClient {
metricDao = getDao(map, MetricDao.class);
groupDao = getDao(map, GroupDao.class);
ruleDao = getDao(map, RuleDao.class);
activeRuleDao = getDao(map, ActiveRuleDao.class);
doOnLoad(map);
}

@@ -378,6 +381,10 @@ public class DbClient {
return ruleDao;
}

public ActiveRuleDao activeRuleDao() {
return activeRuleDao;
}

protected <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) {
return (K) map.get(clazz);
}

+ 1
- 1
sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java View File

@@ -29,6 +29,6 @@ public class DaoModuleTest {
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new DaoModule().configure(container);
assertThat(container.size()).isEqualTo(48);
assertThat(container.size()).isEqualTo(49);
}
}

Loading…
Cancel
Save