]> source.dussan.org Git - sonarqube.git/commitdiff
Improve some medium tests
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 11 Jul 2014 12:37:16 +0000 (14:37 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 11 Jul 2014 12:37:29 +0000 (14:37 +0200)
server/sonar-server/src/test/java/org/sonar/server/debt/DebtMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java

index b76c7800ff5ea67f340bcc8abc80cf8d3d24aaa4..6a4434ea5ef69370dad5c79bf96c33e6e9199a30 100644 (file)
 
 package org.sonar.server.debt;
 
-import org.junit.Rule;
+import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Test;
 import org.sonar.api.server.debt.DebtCharacteristic;
 import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
 import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.server.platform.Platform;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.user.MockUserSession;
 
@@ -32,8 +34,14 @@ import static org.fest.assertions.Assertions.assertThat;
 
 public class DebtMediumTest {
 
-  @Rule
-  public ServerTester serverTester = new ServerTester();
+  @ClassRule
+  public static ServerTester serverTester = new ServerTester();
+
+  @Before
+  public void setUp() throws Exception {
+    serverTester.clearDbAndIndexes();
+    serverTester.get(Platform.class).executeStartupTasks();
+  }
 
   @Test
   public void find_characteristics() throws Exception {
index 66662c8203fa611f192f5b601424f72bb3799e0c..3537e1ccaf887f86ca4ef134c0ad75e8c287e847 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.qualityprofile;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Multimap;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
@@ -66,6 +67,11 @@ public class ActiveRuleBackendMediumTest {
     index = tester.get(ActiveRuleIndex.class);
   }
 
+  @After
+  public void after() throws Exception {
+    dbSession.close();
+  }
+
   @Test
   public void synchronize_index() throws Exception {
 
@@ -232,7 +238,8 @@ public class ActiveRuleBackendMediumTest {
     // insert and index
     QualityProfileDto profileDto = QProfileTesting.newXooP1();
     db.qualityProfileDao().insert(dbSession, profileDto);
-    for (int i = 0; i < 100; i++) {
+    int nb = 100;
+    for (int i = 0; i < nb; i++) {
       RuleDto rule = newRuleDto(RuleKey.of("xoo", "S00" + i));
       db.ruleDao().insert(dbSession, rule);
 
@@ -244,36 +251,36 @@ public class ActiveRuleBackendMediumTest {
 
     // verify index
     Collection<ActiveRule> activeRules = index.findByProfile(profileDto.getKey());
-    assertThat(activeRules).hasSize(100);
+    assertThat(activeRules).hasSize(nb);
   }
 
-//  @Test
-//  public void count_by_profile() {
-//    QualityProfileDto profileDto1 = QProfileTesting.newXooP1();
-//    QualityProfileDto profileDto2 = QProfileTesting.newXooP2();
-//    db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2);
-//
-//    RuleKey ruleKey = RuleTesting.XOO_X1;
-//    RuleDto ruleDto = newRuleDto(ruleKey);
-//    db.ruleDao().insert(dbSession, ruleDto);
-//
-//    ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(profileDto1, ruleDto).setSeverity(Severity.MAJOR);
-//    ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(profileDto2, ruleDto).setSeverity(Severity.MAJOR);
-//    db.activeRuleDao().insert(dbSession, activeRule1, activeRule2);
-//    dbSession.commit();
-//
-//    // 0. Test base case
-//    assertThat(index.countAll()).isEqualTo(2);
-//
-//    // 1. Assert by profileKey
-//    assertThat(index.countByQualityProfileKey(profileDto1.getKey())).isEqualTo(1);
-//
-//    // 2. Assert by term aggregation;
-//    Map<String, Long> counts = index.countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY);
-//    assertThat(counts).hasSize(2);
-//    assertThat(counts.values()).containsOnly(1L, 1L);
-//    assertThat(counts.keySet()).containsOnly(profileDto1.getKey().toString(), profileDto2.getKey().toString());
-//  }
+  @Test
+  public void count_by_profile() {
+    QualityProfileDto profileDto1 = QProfileTesting.newXooP1();
+    QualityProfileDto profileDto2 = QProfileTesting.newXooP2();
+    db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2);
+
+    RuleKey ruleKey = RuleTesting.XOO_X1;
+    RuleDto ruleDto = newRuleDto(ruleKey);
+    db.ruleDao().insert(dbSession, ruleDto);
+
+    ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(profileDto1, ruleDto).setSeverity(Severity.MAJOR);
+    ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(profileDto2, ruleDto).setSeverity(Severity.MAJOR);
+    db.activeRuleDao().insert(dbSession, activeRule1, activeRule2);
+    dbSession.commit();
+
+    // 0. Test base case
+    assertThat(index.countAll()).isEqualTo(2);
+
+    // 1. Assert by profileKey
+    assertThat(index.countByQualityProfileKey(profileDto1.getKey())).isEqualTo(1);
+
+    // 2. Assert by term aggregation;
+    Map<String, Long> counts = index.countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY);
+    assertThat(counts).hasSize(2);
+    assertThat(counts.values()).containsOnly(1L, 1L);
+    assertThat(counts.keySet()).containsOnly(profileDto1.getKey().toString(), profileDto2.getKey().toString());
+  }
 
   @Test
   public void count_all_by_index_field() {
index b3ca675297d8b55896d6f6bb6787c5479096810b..c99be8102625a35a16b24259013aef34735cfe75 100644 (file)
@@ -176,7 +176,6 @@ public class QProfilesWsMediumTest {
     RuleDto rule1 = createRule(profile.getLanguage(), "world");
     createActiveRule(rule0, profile);
     createActiveRule(rule1, profile);
-    ;
     session.commit();
 
     // 0. Assert No Active Rule for profile