aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-25 13:37:18 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-29 13:26:54 +0100
commit79d7e818b5d2567cb20e9795a3d374c34a94ca52 (patch)
treeb3ab3cb4bb56c7c60003519b157dd61a53df5160
parenteaf628863617f366b8258b8d51b9d484da4f168e (diff)
downloadsonarqube-79d7e818b5d2567cb20e9795a3d374c34a94ca52.tar.gz
sonarqube-79d7e818b5d2567cb20e9795a3d374c34a94ca52.zip
SONAR-7330 Fix MediumTests because missing Es indexes
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/ViewsIntegrationTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginsWsMediumTest.java105
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java42
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectOperationsMediumTest.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java70
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionMediumTest.java14
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java42
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java127
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java9
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java99
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java26
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/search/IndexClientMediumTest.java40
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/search/SearchClientMediumTest.java2
23 files changed, 342 insertions, 320 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
index 97128fbbe3c..56d3f44c7bb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
@@ -312,7 +312,7 @@ public class SearchAction implements RulesWsAction {
query.setQueryText(request.param(Param.TEXT_QUERY));
query.setSeverities(request.paramAsStrings(PARAM_SEVERITIES));
query.setRepositories(request.paramAsStrings(PARAM_REPOSITORIES));
- query.setAvailableSince(request.paramAsDate(PARAM_AVAILABLE_SINCE));
+ query.setAvailableSince(request.hasParam(PARAM_AVAILABLE_SINCE) ? request.paramAsDate(PARAM_AVAILABLE_SINCE).getTime() : null);
query.setStatuses(request.paramAsEnums(PARAM_STATUSES, RuleStatus.class));
query.setLanguages(request.paramAsStrings(PARAM_LANGUAGES));
query.setActivation(request.paramAsBoolean(PARAM_ACTIVATION));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
index 63c5d6c84c3..6f170d8417e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
@@ -58,7 +58,7 @@ public class ProjectDataLoaderMediumTest {
public ExpectedException thrown = ExpectedException.none();
@ClassRule
- public static ServerTester tester = new ServerTester().addXoo();
+ public static ServerTester tester = new ServerTester().withEsIndexes().addXoo();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ViewsIntegrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ViewsIntegrationTest.java
index 303bce9a5cb..9a886c49e09 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/ViewsIntegrationTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ViewsIntegrationTest.java
@@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ViewsIntegrationTest {
private final ViewsBridgeSimulator viewsBridgeSimulator = new ViewsBridgeSimulator();
- private ServerTester serverTester = new ServerTester();
+ private ServerTester serverTester = new ServerTester().withEsIndexes();
@After
public void tearDown() throws Exception {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginsWsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginsWsMediumTest.java
index 8070b1d0b79..30d91d60a3e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginsWsMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginsWsMediumTest.java
@@ -40,6 +40,7 @@ public class PluginsWsMediumTest {
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
@ClassRule
public static ServerTester serverTester = new ServerTester()
+ .withEsIndexes()
.addPluginJar(getFile("sonar-decoy-plugin-1.0.jar"))
.setUpdateCenterUrl(createUpdateCenterPropertiesFile());
@@ -62,19 +63,19 @@ public class PluginsWsMediumTest {
);
wsTester.newGetRequest("api/plugins", "available").execute().assertJson("{" +
- " \"plugins\": [" +
- " {" +
- " \"key\": \"foo\"," +
- " \"release\": {" +
- " \"version\": \"1.0\"," +
- " }," +
- " \"update\": {" +
- " \"status\": \"COMPATIBLE\"," +
- " \"requires\": []" +
- " }" +
- " }" +
- " ]" +
- "}");
+ " \"plugins\": [" +
+ " {" +
+ " \"key\": \"foo\"," +
+ " \"release\": {" +
+ " \"version\": \"1.0\"," +
+ " }," +
+ " \"update\": {" +
+ " \"status\": \"COMPATIBLE\"," +
+ " \"requires\": []" +
+ " }" +
+ " }" +
+ " ]" +
+ "}");
wsTester.newGetRequest("api/plugins", "pending").execute().assertJson("{\"installing\":[],\"removing\":[]}");
@@ -83,30 +84,30 @@ public class PluginsWsMediumTest {
wsTester.newPostRequest("api/plugins", "update").setParam("key", "decoy").execute().assertNoContent();
wsTester.newGetRequest("api/plugins", "pending").execute().assertJson("{" +
- " \"installing\": [" +
- " {" +
- " \"key\": \"decoy\"," +
- " \"version\": \"1.1\"" +
- " }" +
- " ]," +
- " \"removing\": []" +
- "}");
+ " \"installing\": [" +
+ " {" +
+ " \"key\": \"decoy\"," +
+ " \"version\": \"1.1\"" +
+ " }" +
+ " ]," +
+ " \"removing\": []" +
+ "}");
wsTester.newPostRequest("api/plugins", "install").setParam("key", "foo").execute().assertNoContent();
wsTester.newGetRequest("api/plugins", "pending").execute().assertJson("{" +
- " \"installing\": [" +
- " {" +
- " \"key\": \"decoy\"," +
- " \"version\": \"1.1\"" +
- " }," +
- " {" +
- " \"key\": \"foo\"," +
- " \"version\": \"1.0\"" +
- " }" +
- " ]," +
- " \"removing\": []" +
- "}");
+ " \"installing\": [" +
+ " {" +
+ " \"key\": \"decoy\"," +
+ " \"version\": \"1.1\"" +
+ " }," +
+ " {" +
+ " \"key\": \"foo\"," +
+ " \"version\": \"1.0\"" +
+ " }" +
+ " ]," +
+ " \"removing\": []" +
+ "}");
// 3 - simulate SQ restart
wsTester = restartServerTester();
@@ -131,28 +132,28 @@ public class PluginsWsMediumTest {
wsTester.newPostRequest("api/plugins", "uninstall").setParam("key", "foo").execute().assertNoContent();
wsTester.newGetRequest("api/plugins", "pending").execute().assertJson("{" +
- " \"installing\": []," +
- " \"removing\": [" +
- " {" +
- " \"key\": \"foo\"," +
- " \"version\": \"1.0\"" +
- " }" +
- " ]," +
- "}");
+ " \"installing\": []," +
+ " \"removing\": [" +
+ " {" +
+ " \"key\": \"foo\"," +
+ " \"version\": \"1.0\"" +
+ " }" +
+ " ]," +
+ "}");
// 6 - simulate SQ restart again
wsTester = restartServerTester();
// 7 - make sure plugin has been uninstalled
wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" +
- " \"plugins\": [" +
- " {" +
- " \"key\": \"decoy\"," +
- " \"version\": \"1.1\"" +
- " }" +
- " ]" +
- "}"
- );
+ " \"plugins\": [" +
+ " {" +
+ " \"key\": \"decoy\"," +
+ " \"version\": \"1.1\"" +
+ " }" +
+ " ]" +
+ "}"
+ );
}
private WsTester restartServerTester() {
@@ -167,9 +168,9 @@ public class PluginsWsMediumTest {
try {
temporaryFolder.create();
String content = FileUtils.readFileToString(getFile("update-center.properties"), ENCODING)
- .replace("[[decoy.10.jar]]", getFileUrl("sonar-decoy-plugin-1.0.jar").toString())
- .replace("[[decoy.11.jar]]", getFileUrl("sonar-decoy-plugin-1.1.jar").toString())
- .replace("[[foo.10.jar]]", getFileUrl("sonar-foo-plugin-1.0.jar").toString());
+ .replace("[[decoy.10.jar]]", getFileUrl("sonar-decoy-plugin-1.0.jar").toString())
+ .replace("[[decoy.11.jar]]", getFileUrl("sonar-decoy-plugin-1.1.jar").toString())
+ .replace("[[foo.10.jar]]", getFileUrl("sonar-foo-plugin-1.0.jar").toString());
File res = temporaryFolder.newFile("update-center.properties");
FileUtils.write(res, content, "UTF-8");
return res.toURI().toURL();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
index b23ebf205b4..9cbe9a8cf1a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
@@ -31,14 +31,18 @@ import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.rule.Severity;
import org.sonar.api.server.rule.RuleParamType;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
+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.qualityprofile.index.ActiveRuleIndex;
+import org.sonar.server.qualityprofile.index.ActiveRuleDoc;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndex2;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
+import org.sonar.server.rule.index.RuleIndexer;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
@@ -48,15 +52,17 @@ import static org.junit.Assert.fail;
public class QProfileCopierMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
DbClient db;
DbSession dbSession;
- ActiveRuleIndex index;
+ ActiveRuleIndex2 index;
RuleActivator ruleActivator;
QProfileCopier copier;
+ RuleIndexer ruleIndexer;
+ ActiveRuleIndexer activeRuleIndexer;
@Before
public void before() {
@@ -64,20 +70,26 @@ public class QProfileCopierMediumTest {
db = tester.get(DbClient.class);
dbSession = db.openSession(false);
ruleActivator = tester.get(RuleActivator.class);
- index = tester.get(ActiveRuleIndex.class);
+ index = tester.get(ActiveRuleIndex2.class);
copier = tester.get(QProfileCopier.class);
+ ruleIndexer = tester.get(RuleIndexer.class);
+ ruleIndexer.setEnabled(true);
+ activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
+ activeRuleIndexer.setEnabled(true);
// create pre-defined rules
RuleDto xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR");
RuleDto xooRule2 = RuleTesting.newXooX2().setSeverity("MAJOR");
- db.deprecatedRuleDao().insert(dbSession, xooRule1, xooRule2);
- db.deprecatedRuleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1)
+ db.ruleDao().insert(dbSession, xooRule1);
+ db.ruleDao().insert(dbSession, xooRule2);
+ db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1)
.setName("max").setDefaultValue("10").setType(RuleParamType.INTEGER.type()));
// create pre-defined profile
db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
dbSession.commit();
dbSession.clearCache();
+ ruleIndexer.index();
}
@After
@@ -94,6 +106,7 @@ public class QProfileCopierMediumTest {
ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY);
dbSession.commit();
dbSession.clearCache();
+ activeRuleIndexer.index();
// target does not exist
copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P2_NAME.getName());
@@ -110,6 +123,7 @@ public class QProfileCopierMediumTest {
ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY);
dbSession.commit();
dbSession.clearCache();
+ activeRuleIndexer.index();
// create target with both x1 and x2 activated
db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2());
@@ -122,6 +136,7 @@ public class QProfileCopierMediumTest {
ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P2_KEY);
dbSession.commit();
dbSession.clearCache();
+ activeRuleIndexer.index();
// copy -> reset x1 and deactivate x2
copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P2_NAME.getName());
@@ -141,6 +156,7 @@ public class QProfileCopierMediumTest {
ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY);
dbSession.commit();
dbSession.clearCache();
+ activeRuleIndexer.index();
// copy child -> profile2 is created with parent P1
copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P2_NAME.getName());
@@ -158,6 +174,7 @@ public class QProfileCopierMediumTest {
ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY);
dbSession.commit();
dbSession.clearCache();
+ activeRuleIndexer.index();
try {
copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P1_NAME.getName());
@@ -176,16 +193,19 @@ public class QProfileCopierMediumTest {
private void verifyOneActiveRule(String profileKey, String expectedSeverity,
@Nullable String expectedInheritance, Map<String, String> expectedParams) {
- List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(profileKey));
+ List<ActiveRuleDoc> activeRules = Lists.newArrayList(index.findByProfile(profileKey));
assertThat(activeRules).hasSize(1);
- ActiveRule activeRule = activeRules.get(0);
+
+ ActiveRuleDoc activeRule = activeRules.get(0);
assertThat(activeRule.severity()).isEqualTo(expectedSeverity);
assertThat(activeRule.inheritance()).isEqualTo(expectedInheritance == null ? ActiveRule.Inheritance.NONE : ActiveRule.Inheritance.valueOf(expectedInheritance));
// verify parameters
- assertThat(activeRule.params()).hasSize(expectedParams.size());
+ List<ActiveRuleParamDto> params = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRule.key());
+ assertThat(params).hasSize(expectedParams.size());
+ Map<String, ActiveRuleParamDto> paramsByKey = ActiveRuleParamDto.groupByKey(params);
for (Map.Entry<String, String> entry : expectedParams.entrySet()) {
- String value = activeRule.params().get(entry.getKey());
+ String value = paramsByKey.get(entry.getKey()).getValue();
assertThat(value).isEqualTo(entry.getValue());
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectOperationsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectOperationsMediumTest.java
index f399dbda06e..fd054edc264 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectOperationsMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectOperationsMediumTest.java
@@ -25,16 +25,16 @@ import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.web.UserRole;
-import org.sonar.db.component.ComponentDto;
import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.db.permission.PermissionRepository;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.permission.PermissionRepository;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.user.UserDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.server.tester.MockUserSession;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
-import org.sonar.server.tester.MockUserSession;
import org.sonar.server.user.UserSession;
import static org.assertj.core.api.Assertions.assertThat;
@@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class QProfileProjectOperationsMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java
index b1f5ddb5361..e51107c878d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java
@@ -29,16 +29,21 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.rule.RuleDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.server.es.SearchOptions;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.qualityprofile.QProfileName;
import org.sonar.server.qualityprofile.QProfileTesting;
import org.sonar.server.qualityprofile.RuleActivator;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
+import org.sonar.server.rule.index.RuleIndex2;
+import org.sonar.server.rule.index.RuleIndexer;
+import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -49,7 +54,7 @@ public class ChangeParentActionMediumTest {
// TODO Replace with DbTester + EsTester once DaoV2 is removed
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
@@ -57,6 +62,9 @@ public class ChangeParentActionMediumTest {
DbClient db;
DbSession session;
WsTester wsTester;
+ RuleIndexer ruleIndexer;
+ ActiveRuleIndexer activeRuleIndexer;
+ RuleIndex2 ruleIndex;
@Before
public void setUp() {
@@ -65,6 +73,11 @@ public class ChangeParentActionMediumTest {
ws = tester.get(QProfilesWs.class);
wsTester = tester.get(WsTester.class);
session = db.openSession(false);
+ ruleIndexer = tester.get(RuleIndexer.class);
+ ruleIndexer.setEnabled(true);
+ activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
+ activeRuleIndexer.setEnabled(true);
+ ruleIndex = tester.get(RuleIndex2.class);
userSessionRule.login("gandalf").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
}
@@ -81,20 +94,24 @@ public class ChangeParentActionMediumTest {
RuleDto rule1 = createRule("xoo", "rule1");
createActiveRule(rule1, parent1);
session.commit();
+ ruleIndexer.index();
+ activeRuleIndexer.index();
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
// Set parent
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileIdentificationParamUtils.PARAM_PROFILE_KEY, child.getKey())
- .setParam("parentKey", parent1.getKey().toString())
+ .setParam("parentKey", parent1.getKey())
.execute();
session.clearCache();
// Check rule 1 enabled
- List<ActiveRuleDto> activeRules1 = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
+ List<ActiveRuleDto> activeRules1 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().ruleKey().rule()).isEqualTo("rule1");
+
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).hasSize(1);
}
@Test
@@ -108,6 +125,8 @@ public class ChangeParentActionMediumTest {
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
session.commit();
+ ruleIndexer.index();
+ activeRuleIndexer.index();
// Set parent 1
tester.get(RuleActivator.class).setParent(child.getKey(), parent1.getKey());
@@ -116,14 +135,16 @@ public class ChangeParentActionMediumTest {
// Set parent 2 through WS
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileIdentificationParamUtils.PARAM_PROFILE_KEY, child.getKey())
- .setParam("parentKey", parent2.getKey().toString())
+ .setParam("parentKey", parent2.getKey())
.execute();
session.clearCache();
// Check rule 2 enabled
- List<ActiveRuleDto> activeRules2 = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
+ List<ActiveRuleDto> activeRules2 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().ruleKey().rule()).isEqualTo("rule2");
+
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).hasSize(1);
}
@Test
@@ -134,6 +155,8 @@ public class ChangeParentActionMediumTest {
RuleDto rule1 = createRule("xoo", "rule1");
createActiveRule(rule1, parent);
session.commit();
+ ruleIndexer.index();
+ activeRuleIndexer.index();
// Set parent
tester.get(RuleActivator.class).setParent(child.getKey(), parent.getKey());
@@ -146,8 +169,10 @@ public class ChangeParentActionMediumTest {
session.clearCache();
// Check no rule enabled
- List<ActiveRuleDto> activeRules = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
+ List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules).isEmpty();
+
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
}
@Test
@@ -161,8 +186,10 @@ public class ChangeParentActionMediumTest {
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
session.commit();
+ ruleIndexer.index();
+ activeRuleIndexer.index();
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
// 1. Set parent 1
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
@@ -173,9 +200,10 @@ public class ChangeParentActionMediumTest {
session.clearCache();
// 1. check rule 1 enabled
- List<ActiveRuleDto> activeRules1 = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
+ List<ActiveRuleDto> activeRules1 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().ruleKey().rule()).isEqualTo("rule1");
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).hasSize(1);
// 2. Set parent 2
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
@@ -186,7 +214,7 @@ public class ChangeParentActionMediumTest {
session.clearCache();
// 2. check rule 2 enabled
- List<ActiveRuleDto> activeRules2 = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
+ List<ActiveRuleDto> activeRules2 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().ruleKey().rule()).isEqualTo("rule2");
@@ -199,8 +227,9 @@ public class ChangeParentActionMediumTest {
session.clearCache();
// 3. check no rule enabled
- List<ActiveRuleDto> activeRules = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
+ List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules).isEmpty();
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
}
@Test
@@ -211,8 +240,10 @@ public class ChangeParentActionMediumTest {
RuleDto rule1 = createRule("xoo", "rule1");
createActiveRule(rule1, parent);
session.commit();
+ ruleIndexer.index();
+ activeRuleIndexer.index();
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
// Set parent
tester.get(RuleActivator.class).setParent(child.getKey(), parent.getKey());
@@ -226,8 +257,9 @@ public class ChangeParentActionMediumTest {
session.clearCache();
// Check no rule enabled
- List<ActiveRuleDto> activeRules = db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey());
+ List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules).isEmpty();
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
}
@Test(expected = IllegalArgumentException.class)
@@ -235,7 +267,8 @@ public class ChangeParentActionMediumTest {
QualityProfileDto child = createProfile("xoo", "Child");
session.commit();
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileIdentificationParamUtils.PARAM_PROFILE_KEY, child.getKee())
@@ -249,7 +282,8 @@ public class ChangeParentActionMediumTest {
QualityProfileDto child = createProfile("xoo", "Child");
session.commit();
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileIdentificationParamUtils.PARAM_PROFILE_KEY, child.getKee())
@@ -278,14 +312,14 @@ public class ChangeParentActionMediumTest {
.setLanguage(lang)
.setSeverity(Severity.BLOCKER)
.setStatus(RuleStatus.READY);
- db.deprecatedRuleDao().insert(session, rule);
+ db.ruleDao().insert(session, rule);
return rule;
}
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
- db.deprecatedActiveRuleDao().insert(session, activeRule);
+ db.activeRuleDao().insert(session, activeRule);
return activeRule;
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionMediumTest.java
index b7c1f4a8952..9141b17ede0 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionMediumTest.java
@@ -25,8 +25,8 @@ import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.QProfileExporters;
import org.sonar.server.qualityprofile.QProfileExportersTest.StandardExporter;
@@ -45,10 +45,14 @@ public class CreateActionMediumTest {
// TODO Replace with simpler test with DbTester / EsTester after removal of DaoV2
@ClassRule
- public static ServerTester tester = new ServerTester().withStartupTasks().addXoo().addComponents(
- XooRulesDefinition.class, XooProfileDefinition.class,
- XooExporter.class, StandardExporter.class,
- XooProfileImporter.class, XooProfileImporterWithMessages.class, XooProfileImporterWithError.class);
+ public static ServerTester tester = new ServerTester()
+ .withEsIndexes()
+ .withStartupTasks()
+ .addXoo()
+ .addComponents(
+ XooRulesDefinition.class, XooProfileDefinition.class,
+ XooExporter.class, StandardExporter.class,
+ XooProfileImporter.class, XooProfileImporterWithMessages.class, XooProfileImporterWithError.class);
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
index 0ec6f20e194..8996e3bcd1e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
@@ -27,20 +27,18 @@ import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.db.component.ComponentTesting;
-import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
import org.sonar.server.qualityprofile.QProfileFactory;
-import org.sonar.server.qualityprofile.db.ActiveRuleDao;
-import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -51,32 +49,26 @@ public class DeleteActionTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
- private DbClient dbClient;
+ private DbClient dbClient = dbTester.getDbClient();
- private QualityProfileDao qualityProfileDao;
+ private QualityProfileDao qualityProfileDao = dbClient.qualityProfileDao();
- private ComponentDao componentDao;
+ private ComponentDao componentDao = dbClient.componentDao();
private Language xoo1;
private Language xoo2;
private WsTester tester;
- private DbSession session;
-
- System2 system2 = mock(System2.class);
+ private DbSession session = dbTester.getSession();
@Before
public void setUp() {
dbTester.truncateTables();
- qualityProfileDao = new QualityProfileDao(dbTester.myBatis(), mock(System2.class));
- componentDao = new ComponentDao();
-
- dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), qualityProfileDao, new ActiveRuleDao(qualityProfileDao, new RuleDao(system2), system2));
- session = dbClient.openSession(false);
xoo1 = LanguageTesting.newLanguage("xoo1");
xoo2 = LanguageTesting.newLanguage("xoo2");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java
index 54547ff4b67..19e445b36d8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.qualityprofile.ws;
+import java.util.Date;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -27,16 +28,18 @@ import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.rule.RuleDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.qualityprofile.QProfileName;
import org.sonar.server.qualityprofile.QProfileTesting;
import org.sonar.server.qualityprofile.RuleActivation;
import org.sonar.server.qualityprofile.RuleActivator;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
+import org.sonar.server.rule.index.RuleIndexer;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -44,21 +47,28 @@ import org.sonar.server.ws.WsTester;
public class InheritanceActionMediumTest {
@ClassRule
- public static final ServerTester tester = new ServerTester();
+ public static final ServerTester tester = new ServerTester().withEsIndexes();
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
- private WsTester wsTester;
+ WsTester wsTester;
- private DbClient db;
+ DbClient db;
+ DbSession session;
- private DbSession session;
+ RuleIndexer ruleIndexer;
+ ActiveRuleIndexer activeRuleIndexer;
@Before
public void setUp() {
tester.clearDbAndIndexes();
db = tester.get(DbClient.class);
session = db.openSession(false);
+ ruleIndexer = tester.get(RuleIndexer.class);
+ ruleIndexer.setEnabled(true);
+ activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
+ activeRuleIndexer.setEnabled(true);
wsTester = new WsTester(tester.get(QProfilesWs.class));
}
@@ -80,7 +90,10 @@ public class InheritanceActionMediumTest {
QualityProfileDto groupWide = createProfile("xoo", "My Group Profile", "xoo-my-group-profile-01234");
createActiveRule(rule1, groupWide);
createActiveRule(rule2, groupWide);
+
session.commit();
+ ruleIndexer.index();
+ activeRuleIndexer.index();
QualityProfileDto companyWide = createProfile("xoo", "My Company Profile", "xoo-my-company-profile-12345");
setParent(groupWide, companyWide);
@@ -93,12 +106,14 @@ public class InheritanceActionMediumTest {
setParent(buWide, forProject1);
createActiveRule(rule3, forProject1);
session.commit();
+ activeRuleIndexer.index();
QualityProfileDto forProject2 = createProfile("xoo", "For Project Two", "xoo-for-project-two-45678");
setParent(buWide, forProject2);
overrideActiveRuleSeverity(rule2, forProject2, Severity.CRITICAL);
- wsTester.newGetRequest("api/qualityprofiles", "inheritance").setParam("profileKey", buWide.getKee()).execute().assertJson(getClass(), "inheritance-buWide.json");
+ wsTester.newGetRequest("api/qualityprofiles", "inheritance").setParam("profileKey", buWide.getKee())
+ .execute().assertJson(getClass(), "inheritance-buWide.json");
}
@Test
@@ -126,23 +141,30 @@ public class InheritanceActionMediumTest {
}
private RuleDto createRule(String lang, String id) {
+ long now = new Date().getTime();
RuleDto rule = RuleDto.createFor(RuleKey.of("blah", id))
.setLanguage(lang)
.setSeverity(Severity.BLOCKER)
- .setStatus(RuleStatus.READY);
- db.deprecatedRuleDao().insert(session, rule);
+ .setStatus(RuleStatus.READY)
+ .setUpdatedAtInMs(now)
+ .setCreatedAtInMs(now);
+ db.ruleDao().insert(session, rule);
return rule;
}
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) {
+ long now = new Date().getTime();
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
- .setSeverity(rule.getSeverityString());
- db.deprecatedActiveRuleDao().insert(session, activeRule);
+ .setSeverity(rule.getSeverityString())
+ .setUpdatedAtInMs(now)
+ .setCreatedAtInMs(now);
+ db.activeRuleDao().insert(session, activeRule);
return activeRule;
}
private void overrideActiveRuleSeverity(RuleDto rule, QualityProfileDto profile, String severity) {
tester.get(RuleActivator.class).activate(session, new RuleActivation(rule.getKey()).setSeverity(severity), profile.getKey());
session.commit();
+ activeRuleIndexer.index();
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
index 842b38fb94a..db80ffe0266 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
@@ -30,23 +30,25 @@ import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.server.ws.WebService;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
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;
import org.sonar.db.rule.RuleDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.server.es.SearchOptions;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.qualityprofile.QProfileName;
import org.sonar.server.qualityprofile.QProfileTesting;
-import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.rule.index.RuleIndex;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndex2;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
+import org.sonar.server.rule.index.RuleIndex2;
+import org.sonar.server.rule.index.RuleIndexer;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.rule.ws.SearchAction;
-import org.sonar.server.search.QueryContext;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -57,16 +59,20 @@ import static org.junit.Assert.fail;
public class QProfilesWsMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester)
- .login("gandalf").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ .login("gandalf").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
QProfilesWs ws;
DbClient db;
DbSession session;
WsTester wsTester;
+ RuleIndexer ruIndexer = tester.get(RuleIndexer.class);
+ ActiveRuleIndexer activeRuIndexer = tester.get(ActiveRuleIndexer.class);
+
@Before
public void setUp() {
tester.clearDbAndIndexes();
@@ -74,6 +80,11 @@ public class QProfilesWsMediumTest {
ws = tester.get(QProfilesWs.class);
wsTester = tester.get(WsTester.class);
session = db.openSession(false);
+
+ ruIndexer = tester.get(RuleIndexer.class);
+ ruIndexer.setEnabled(true);
+ activeRuIndexer = tester.get(ActiveRuleIndexer.class);
+ activeRuIndexer.setEnabled(true);
}
@After
@@ -87,19 +98,21 @@ public class QProfilesWsMediumTest {
RuleDto rule = createRule(profile.getLanguage(), "toto");
createActiveRule(rule, profile);
session.commit();
+ ruIndexer.index();
+ activeRuIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.DEACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(RuleActivationActions.RULE_KEY, rule.getKey().toString());
request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
}
@Test
@@ -114,18 +127,20 @@ public class QProfilesWsMediumTest {
createActiveRule(rule3, profile);
createActiveRule(rule1, profile);
session.commit();
+ ruIndexer.index();
+ activeRuIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(4);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(4);
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
}
@Test
@@ -139,19 +154,21 @@ public class QProfilesWsMediumTest {
createActiveRule(rule0, php);
createActiveRule(rule1, php);
session.commit();
+ ruIndexer.index();
+ activeRuIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
}
@Test
@@ -162,19 +179,21 @@ public class QProfilesWsMediumTest {
createActiveRule(rule0, profile);
createActiveRule(rule1, profile);
session.commit();
+ ruIndexer.index();
+ activeRuIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(WebService.Param.TEXT_QUERY, "hello");
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
}
@Test
@@ -182,19 +201,20 @@ public class QProfilesWsMediumTest {
QualityProfileDto profile = createProfile("java");
RuleDto rule = createRule(profile.getLanguage(), "toto");
session.commit();
+ ruIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(RuleActivationActions.RULE_KEY, rule.getKey().toString());
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
}
@Test
@@ -202,14 +222,15 @@ public class QProfilesWsMediumTest {
QualityProfileDto profile = createProfile("java");
RuleDto rule = createRule("php", "toto");
session.commit();
+ ruIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
try {
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(RuleActivationActions.RULE_KEY, rule.getKey().toString());
request.execute();
session.clearCache();
@@ -224,13 +245,14 @@ public class QProfilesWsMediumTest {
QualityProfileDto profile = createProfile("java");
RuleDto rule = createRule(profile.getLanguage(), "toto");
session.commit();
+ ruIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(RuleActivationActions.RULE_KEY, rule.getKey().toString());
request.setParam(RuleActivationActions.SEVERITY, "MINOR");
WsTester.Result result = request.execute();
@@ -239,7 +261,7 @@ public class QProfilesWsMediumTest {
// 2. Assert ActiveRule in DAO
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), rule.getKey());
- assertThat(db.deprecatedActiveRuleDao().getNullableByKey(session, activeRuleKey).getSeverityString())
+ assertThat(db.activeRuleDao().selectOrFailByKey(session, activeRuleKey).getSeverityString())
.isEqualTo("MINOR");
}
@@ -251,19 +273,20 @@ public class QProfilesWsMediumTest {
RuleDto rule2 = createRule(profile.getLanguage(), "hello");
RuleDto rule3 = createRule(profile.getLanguage(), "world");
session.commit();
+ ruIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(SearchAction.PARAM_LANGUAGES, "java");
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(4);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(4);
}
@Test
@@ -275,19 +298,20 @@ public class QProfilesWsMediumTest {
RuleDto rule2 = createRule(php.getLanguage(), "hello");
RuleDto rule3 = createRule(php.getLanguage(), "world");
session.commit();
+ ruIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, php.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).isEmpty();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, php.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, php.getKey());
request.setParam(SearchAction.PARAM_LANGUAGES, "php");
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
}
@Test
@@ -298,29 +322,30 @@ public class QProfilesWsMediumTest {
RuleDto rule2 = createRule(profile.getLanguage(), "hello");
RuleDto rule3 = createRule(profile.getLanguage(), "world");
session.commit();
+ ruIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().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);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(WebService.Param.TEXT_QUERY, "php");
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
// 1. Activate Rule with query returning 1 hits
request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
- request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(WebService.Param.TEXT_QUERY, "world");
result = request.execute();
session.commit();
// 2. Assert ActiveRule in DAO
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
}
@Test
@@ -329,25 +354,26 @@ public class QProfilesWsMediumTest {
RuleDto rule0 = createRule(profile.getLanguage(), "toto");
RuleDto rule1 = createRule(profile.getLanguage(), "tata");
session.commit();
+ ruIndexer.index();
// 0. Assert No Active Rule for profile
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
- assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
+ assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
// 2. Assert ActiveRule with BLOCKER severity
- assertThat(tester.get(RuleIndex.class).search(
+ assertThat(tester.get(RuleIndex2.class).search(
new RuleQuery().setSeverities(ImmutableSet.of("BLOCKER")),
- new QueryContext(userSessionRule)).getHits()).hasSize(2);
+ new SearchOptions()).getIds()).hasSize(2);
// 1. Activate Rule with query returning 2 hits
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
- request.setParam(BulkRuleActivationActions.PROFILE_KEY, profile.getKey().toString());
+ request.setParam(BulkRuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(BulkRuleActivationActions.SEVERITY, "MINOR");
request.execute();
session.commit();
// 2. Assert ActiveRule with MINOR severity
- assertThat(tester.get(ActiveRuleIndex.class).findByRule(rule0.getKey()).get(0).severity()).isEqualTo("MINOR");
+ assertThat(tester.get(ActiveRuleIndex2.class).findByRule(rule0.getKey()).get(0).severity()).isEqualTo("MINOR");
}
@@ -362,12 +388,15 @@ public class QProfilesWsMediumTest {
.setSeverity(rule.getSeverityString());
ActiveRuleDto active2 = ActiveRuleDto.createFor(subProfile, rule)
.setSeverity("MINOR");
- db.deprecatedActiveRuleDao().insert(session, active1, active2);
+ db.activeRuleDao().insert(session, active1);
+ db.activeRuleDao().insert(session, active2);
session.commit();
+ ruIndexer.index();
+ activeRuIndexer.index();
// 0. assert rule child rule is minor
- assertThat(db.deprecatedActiveRuleDao().getByKey(session, active2.getKey()).getSeverityString()).isEqualTo("MINOR");
+ assertThat(db.activeRuleDao().selectOrFailByKey(session, active2.getKey()).getSeverityString()).isEqualTo("MINOR");
// 1. reset child rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
@@ -378,7 +407,7 @@ public class QProfilesWsMediumTest {
session.clearCache();
// 2. assert rule child rule is NOT minor
- assertThat(db.deprecatedActiveRuleDao().getByKey(session, active2.getKey()).getSeverityString()).isNotEqualTo("MINOR");
+ assertThat(db.activeRuleDao().selectOrFailByKey(session, active2.getKey()).getSeverityString()).isNotEqualTo("MINOR");
}
@Test
@@ -559,14 +588,14 @@ public class QProfilesWsMediumTest {
.setLanguage(lang)
.setSeverity(Severity.BLOCKER)
.setStatus(RuleStatus.READY);
- db.deprecatedRuleDao().insert(session, rule);
+ db.ruleDao().insert(session, rule);
return rule;
}
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
- db.deprecatedActiveRuleDao().insert(session, activeRule);
+ db.activeRuleDao().insert(session, activeRule);
return activeRule;
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
index 6c888b58535..e7de12119a9 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
@@ -64,7 +64,10 @@ public class RegisterRulesMediumTest {
static final XooRulesDefinition RULE_DEFS = new XooRulesDefinition();
@ClassRule
- public static final ServerTester TESTER = new ServerTester().addXoo().addComponents(RULE_DEFS);
+ public static final ServerTester TESTER = new ServerTester()
+ .withEsIndexes()
+ .addXoo()
+ .addComponents(RULE_DEFS);
@org.junit.Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(TESTER);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java
index 38c7c984cd7..bd79147fc66 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java
@@ -52,7 +52,8 @@ import static org.junit.Assert.fail;
public class RuleCreatorMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
+
@org.junit.Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java
index 629dff2646b..5dc32ed171d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java
@@ -35,11 +35,11 @@ import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.SearchOptions;
-import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.qualityprofile.QProfileTesting;
import org.sonar.server.qualityprofile.RuleActivation;
import org.sonar.server.qualityprofile.RuleActivator;
-import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
+import org.sonar.server.qualityprofile.index.ActiveRuleDoc;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndex2;
import org.sonar.server.rule.index.RuleIndex2;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.tester.ServerTester;
@@ -51,7 +51,8 @@ import static org.assertj.core.api.Assertions.assertThat;
public class RuleDeleterMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
+
@org.junit.Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
@@ -99,7 +100,7 @@ public class RuleDeleterMediumTest {
assertThat(customRuleReloaded.getStatus()).isEqualTo(RuleStatus.REMOVED);
// Verify there's no more active rule from custom rule
- List<ActiveRule> activeRules = Lists.newArrayList(tester.get(ActiveRuleIndex.class).findByProfile(profileDto.getKey()));
+ List<ActiveRuleDoc> activeRules = Lists.newArrayList(tester.get(ActiveRuleIndex2.class).findByProfile(profileDto.getKey()));
assertThat(activeRules).isEmpty();
// Verify in index
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java
index 544f17680f0..97d06418153 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java
@@ -31,38 +31,40 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.rule.db.RuleDao;
-import org.sonar.server.rule.index.RuleIndex;
-import org.sonar.server.rule.index.RuleNormalizer;
+import org.sonar.server.rule.index.RuleIndex2;
+import org.sonar.server.rule.index.RuleIndexDefinition;
+import org.sonar.server.rule.index.RuleIndexer;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
-import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
public class RuleServiceMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
+
@org.junit.Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
RuleDao dao = tester.get(RuleDao.class);
- RuleIndex index = tester.get(RuleIndex.class);
+ RuleIndex2 index = tester.get(RuleIndex2.class);
RuleService service = tester.get(RuleService.class);
DbSession dbSession;
+ RuleIndexer ruleIndexer;
@Before
public void before() {
tester.clearDbAndIndexes();
dbSession = tester.get(DbClient.class).openSession(false);
+ ruleIndexer = tester.get(RuleIndexer.class);
+ ruleIndexer.setEnabled(true);
}
@After
@@ -71,89 +73,24 @@ public class RuleServiceMediumTest {
}
@Test
- public void get_rule_by_key() {
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-
- RuleKey key = RuleKey.of("java", "S001");
-
- dao.insert(dbSession, RuleTesting.newDto(key));
- dbSession.commit();
- dbSession.clearCache();
-
- Rule rule = service.getByKey(key);
- assertThat(rule).isNotNull();
-
- assertThat(service.getByKey(RuleKey.of("un", "known"))).isNull();
- }
-
- @Test
- public void get_non_null_rule_by_key() {
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-
- RuleKey key = RuleKey.of("java", "S001");
-
- dao.insert(dbSession, RuleTesting.newDto(key));
- dbSession.commit();
- dbSession.clearCache();
-
- assertThat(service.getNonNullByKey(key)).isNotNull();
- try {
- service.getNonNullByKey(RuleKey.of("un", "known"));
- fail();
- } catch (NotFoundException e) {
- assertThat(e).hasMessage("Rule not found: un:known");
- }
- }
-
- @Test
- public void get_rule_by_key_escape_description_on_manual_rule() {
- userSessionRule.login().login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-
- RuleDto manualRule = RuleTesting.newManualRule("My manual")
- .setDescription("<div>Manual rule desc</div>");
- dao.insert(dbSession, manualRule);
- dbSession.commit();
- dbSession.clearCache();
-
- Rule rule = service.getByKey(manualRule.getKey());
- assertThat(rule).isNotNull();
- assertThat(rule.htmlDescription()).isEqualTo("&lt;div&gt;Manual rule desc&lt;/div&gt;");
- }
-
- @Test
- public void get_rule_by_keys() {
- userSessionRule.setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-
- dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("java", "S001")));
- dbSession.commit();
- dbSession.clearCache();
-
- assertThat(service.getByKeys(newArrayList(RuleKey.of("java", "S001")))).hasSize(1);
- assertThat(service.getByKeys(newArrayList(RuleKey.of("un", "known")))).isEmpty();
- assertThat(service.getByKeys(Collections.<RuleKey>emptyList())).isEmpty();
- }
-
- @Test
public void list_tags() {
// insert db
RuleKey key1 = RuleKey.of("javascript", "S001");
RuleKey key2 = RuleKey.of("java", "S001");
dao.insert(dbSession,
- RuleTesting.newDto(key1).setTags(Sets.newHashSet("tag1")).setSystemTags(Sets.newHashSet("sys1", "sys2")),
+ RuleTesting.newDto(key1).setTags(Sets.newHashSet("tag1")).setSystemTags(Sets.newHashSet("sys1", "sys2")));
+ dao.insert(dbSession,
RuleTesting.newDto(key2).setTags(Sets.newHashSet("tag2")).setSystemTags(Collections.<String>emptySet()));
dbSession.commit();
+ ruleIndexer.index();
// all tags, including system
Set<String> tags = service.listTags();
assertThat(tags).containsOnly("tag1", "tag2", "sys1", "sys2");
- // verify user tags in es
- tags = index.terms(RuleNormalizer.RuleField.TAGS.field());
- assertThat(tags).containsOnly("tag1", "tag2");
-
- // verify system tags in es
- tags = index.terms(RuleNormalizer.RuleField.SYSTEM_TAGS.field());
- assertThat(tags).containsOnly("sys1", "sys2");
+ // verify in es
+ tags = index.terms(RuleIndexDefinition.FIELD_RULE_ALL_TAGS);
+ assertThat(tags).containsOnly("tag1", "tag2", "sys1", "sys2");
}
@Test
@@ -176,7 +113,7 @@ public class RuleServiceMediumTest {
dbSession.clearCache();
- RuleDto rule = dao.getNullableByKey(dbSession, customRuleKey);
+ RuleDto rule = dao.selectOrFailByKey(dbSession, customRuleKey);
assertThat(rule).isNotNull();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java
index ebb4f2980ad..59c3f74888c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java
@@ -39,18 +39,18 @@ import org.sonar.api.server.debt.DebtRemediationFunction;
import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
+import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.SearchOptions;
-import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.qualityprofile.QProfileTesting;
import org.sonar.server.qualityprofile.RuleActivation;
import org.sonar.server.qualityprofile.RuleActivator;
-import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
import org.sonar.server.rule.index.RuleIndex2;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.tester.ServerTester;
@@ -65,7 +65,7 @@ public class RuleUpdaterMediumTest {
static final RuleKey RULE_KEY = RuleKey.of("squid", "S001");
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
@org.junit.Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
@@ -464,15 +464,19 @@ public class RuleUpdaterMediumTest {
assertThat(paramsByKey.get("format")).isNotNull();
assertThat(paramsByKey.get("format").getDefaultValue()).isNull();
- // Verify active rule parameters has been updated
- ActiveRule activeRule = tester.get(ActiveRuleIndex.class).getByKey(ActiveRuleKey.of(profileDto.getKey(), customRule.getKey()));
- assertThat(activeRule.params()).hasSize(2);
- assertThat(activeRule.params().get("regex")).isEqualTo("b.*");
- assertThat(activeRule.params().get("message")).isEqualTo("a message");
- assertThat(activeRule.params().get("format")).isNull();
-
// Verify that severity has not changed
- assertThat(activeRule.severity()).isEqualTo(Severity.BLOCKER);
+ ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, ActiveRuleKey.of(profileDto.getKey(), customRule.getKey()));
+ assertThat(activeRuleDto.getSeverityString()).isEqualTo(Severity.BLOCKER);
+
+ // Verify active rule parameters has been updated
+ List<ActiveRuleParamDto> activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey());
+
+ // FIXME why 4 parameters are returned ??? (This issue already exists in 5.4)
+ //assertThat(activeRuleParams).hasSize(2);
+ Map<String, ActiveRuleParamDto> activeRuleParamsByKey = ActiveRuleParamDto.groupByKey(activeRuleParams);
+ assertThat(activeRuleParamsByKey.get("regex").getValue()).isEqualTo("b.*");
+ assertThat(activeRuleParamsByKey.get("message").getValue()).isEqualTo("a message");
+ assertThat(activeRuleParamsByKey.get("format")).isNull();
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java
index 20ed88ff13c..7de605f787d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java
@@ -30,12 +30,12 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.BadRequestException;
import org.sonar.db.rule.RuleTesting;
+import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
@@ -48,7 +48,8 @@ import static org.junit.Assert.fail;
public class CreateActionMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).login()
.setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
index 7aef1763e07..8a3a67fb852 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
@@ -27,16 +27,18 @@ import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.server.ws.WebService;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.db.DbClient;
import org.sonar.server.qualityprofile.QProfileTesting;
-import org.sonar.server.qualityprofile.db.ActiveRuleDao;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.rule.db.RuleDao;
+import org.sonar.server.rule.index.RuleIndexer;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -46,7 +48,8 @@ import static org.assertj.core.api.Assertions.assertThat;
public class RulesWsMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
@@ -58,6 +61,8 @@ public class RulesWsMediumTest {
RulesWs ws;
RuleDao ruleDao;
DbSession session;
+ RuleIndexer ruleIndexer;
+ ActiveRuleIndexer activeRuleIndexer;
@Before
public void setUp() {
@@ -66,6 +71,10 @@ public class RulesWsMediumTest {
ruleDao = tester.get(RuleDao.class);
ws = tester.get(RulesWs.class);
session = tester.get(DbClient.class).openSession(false);
+ ruleIndexer = tester.get(RuleIndexer.class);
+ ruleIndexer.setEnabled(true);
+ activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
+ activeRuleIndexer.setEnabled(true);
}
@After
@@ -104,6 +113,7 @@ public class RulesWsMediumTest {
tester.get(ActiveRuleDao.class).insert(session, activeRuleDto);
session.commit();
session.clearCache();
+ activeRuleIndexer.index();
// 1. With Activation
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SHOW_METHOD);
@@ -134,6 +144,7 @@ public class RulesWsMediumTest {
.setSystemTags(ImmutableSet.of("sys1"));
ruleDao.insert(session, rule2);
session.commit();
+ ruleIndexer.index();
tester.wsTester().newGetRequest(API_ENDPOINT, API_TAGS_METHOD).execute().assertJson(this.getClass(), "get_tags.json");
tester.wsTester().newGetRequest(API_ENDPOINT, API_TAGS_METHOD)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
index fefef67bca2..f80372b2cbd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
@@ -34,6 +34,7 @@ import org.sonar.api.rule.Severity;
import org.sonar.api.server.debt.DebtRemediationFunction;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.DateUtils;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
@@ -42,7 +43,6 @@ 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.qualityprofile.QProfileTesting;
import org.sonar.server.qualityprofile.db.ActiveRuleDao;
import org.sonar.server.rule.db.RuleDao;
@@ -56,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class SearchActionMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester().addXoo();
+ public static ServerTester tester = new ServerTester().withEsIndexes().addXoo();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
index 7732ef92b17..45bbd1b7aa9 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
@@ -28,12 +28,12 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleDto.Format;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.db.DbClient;
import org.sonar.server.rule.NewRule;
import org.sonar.server.rule.RuleService;
import org.sonar.server.rule.db.RuleDao;
@@ -46,7 +46,8 @@ import static com.google.common.collect.Sets.newHashSet;
public class ShowActionMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).login()
.setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java
index 70e907a3136..7cd7fbbecff 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java
@@ -29,13 +29,13 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.rule.RuleTesting;
import org.sonar.server.rule.NewRule;
import org.sonar.server.rule.RuleService;
-import org.sonar.db.rule.RuleTesting;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
@@ -47,7 +47,8 @@ import static org.junit.Assert.fail;
public class UpdateActionMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).
login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/IndexClientMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/IndexClientMediumTest.java
deleted file mode 100644
index 0c0ca4aecc3..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/search/IndexClientMediumTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.search;
-
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.server.rule.index.RuleIndex;
-import org.sonar.server.tester.ServerTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class IndexClientMediumTest{
-
- @ClassRule
- public static ServerTester tester = new ServerTester();
-
- @Test
- public void get_index_class(){
- IndexClient indexClient = tester.get(IndexClient.class);
- assertThat(tester.get(RuleIndex.class))
- .isEqualTo(indexClient.get(RuleIndex.class));
- }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/SearchClientMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/SearchClientMediumTest.java
index d294aabbf21..3ea0ce3fd16 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/search/SearchClientMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/search/SearchClientMediumTest.java
@@ -32,7 +32,7 @@ import static org.junit.Assert.fail;
public class SearchClientMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withEsIndexes();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);