aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-05-01 15:44:29 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-05-01 15:44:29 +0200
commit7238552a384f90a2aeae1a1912127b8ebd65a088 (patch)
treea7492ab4e8cca11ace0270c1fd371b8c6408ed86 /sonar-server
parent9d95233cc673609fb770415ecc16c316d8e03d8f (diff)
downloadsonarqube-7238552a384f90a2aeae1a1912127b8ebd65a088.tar.gz
sonarqube-7238552a384f90a2aeae1a1912127b8ebd65a088.zip
New tests on RuleServiceMediumTest
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule2/RuleServiceMediumTest.java51
1 files changed, 46 insertions, 5 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/RuleServiceMediumTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/RuleServiceMediumTest.java
index 3bbbd9117a0..ff411bf957d 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule2/RuleServiceMediumTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule2/RuleServiceMediumTest.java
@@ -19,20 +19,24 @@
*/
package org.sonar.server.rule2;
-import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
+import org.junit.Ignore;
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.api.server.rule.RuleParamType;
import org.sonar.api.utils.DateUtils;
import org.sonar.check.Cardinality;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.MyBatis;
import org.sonar.core.rule.RuleDto;
+import org.sonar.core.rule.RuleParamDto;
import org.sonar.server.search.Hit;
import org.sonar.server.tester.ServerTester;
-import java.util.Collection;
+import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
@@ -41,6 +45,9 @@ public class RuleServiceMediumTest {
@ClassRule
public static ServerTester tester = new ServerTester();
+ RuleDao dao = tester.get(RuleDao.class);
+ RuleIndex index = tester.get(RuleIndex.class);
+
@Before
public void clear_data_store() {
tester.clearDataStores();
@@ -50,7 +57,6 @@ public class RuleServiceMediumTest {
public void insert_in_db_and_index_in_es() {
// insert db
RuleKey ruleKey = RuleKey.of("javascript", "S001");
- RuleDao dao = tester.get(RuleDao.class);
dao.insert(newRuleDto(ruleKey));
// verify that rule is persisted in db
@@ -61,9 +67,7 @@ public class RuleServiceMediumTest {
assertThat(persistedDto.getLanguage()).isEqualTo("js");
// verify that rule is indexed in es
- RuleIndex index = tester.get(RuleIndex.class);
index.refresh();
-
Hit hit = index.getByKey(ruleKey);
assertThat(hit).isNotNull();
assertThat(hit.getFieldAsString(RuleNormalizer.RuleField.REPOSITORY.key())).isEqualTo(ruleKey.repository());
@@ -81,6 +85,43 @@ public class RuleServiceMediumTest {
assertThat((Boolean) hit.getField(RuleNormalizer.RuleField.TEMPLATE.key())).isFalse();
}
+ @Test
+ @Ignore
+ public void insert_and_index_rule_parameters() {
+ DbSession dbSession = tester.get(MyBatis.class).openSession(false);
+
+ // insert db
+ RuleKey ruleKey = RuleKey.of("javascript", "S001");
+ RuleDto ruleDto = newRuleDto(ruleKey);
+ dao.insert(ruleDto, dbSession);
+ RuleParamDto minParamDto = new RuleParamDto()
+ .setRuleId(ruleDto.getId())
+ .setName("min")
+ .setType(RuleParamType.INTEGER.type())
+ .setDefaultValue("2")
+ .setDescription("Minimum");
+ dao.insert(minParamDto, dbSession);
+ RuleParamDto maxParamDto = new RuleParamDto()
+ .setRuleId(ruleDto.getId())
+ .setName("max")
+ .setType(RuleParamType.INTEGER.type())
+ .setDefaultValue("10")
+ .setDescription("Maximum");
+ dao.insert(maxParamDto, dbSession);
+ dbSession.commit();
+
+ // verify that parameters are persisted in db
+ List<RuleParamDto> persistedDtos = dao.selectParametersByRuleId(ruleDto.getId());
+ assertThat(persistedDtos).hasSize(2);
+
+ // verify that parameters are indexed in es
+ index.refresh();
+ Hit hit = index.getByKey(ruleKey);
+ assertThat(hit).isNotNull();
+ assertThat(hit.getField("params")).isNotNull();
+ //TODO complete assertions
+ }
+
//TODO test delete, update, tags, params
private RuleDto newRuleDto(RuleKey ruleKey) {