]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7330 Fix BackendCleanupMediumTest
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 25 Feb 2016 12:36:19 +0000 (13:36 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Feb 2016 12:26:54 +0000 (13:26 +0100)
server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/platform/BackendCleanupMediumTest/shared.xml

index b48c0bbc64dc91659994dce5fbc3db7d486bfd80..527e6d0f3b75ca9d5832a5d261bdb495083ec502 100644 (file)
@@ -34,7 +34,6 @@ import org.sonar.server.issue.IssueTesting;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.rule.index.RuleDoc;
 import org.sonar.server.rule.index.RuleIndexDefinition;
-import org.sonar.server.rule.index.RuleNormalizer;
 import org.sonar.server.search.IndexDefinition;
 import org.sonar.server.view.index.ViewDoc;
 import org.sonar.server.view.index.ViewIndexDefinition;
@@ -51,7 +50,7 @@ public class BackendCleanupMediumTest {
     new RuleIndexDefinition(new Settings()),
     new IssueIndexDefinition(new Settings()),
     new ViewIndexDefinition(new Settings())
-  );
+    );
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -78,7 +77,7 @@ public class BackendCleanupMediumTest {
   @Test
   public void clear_indexes() throws Exception {
     esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc());
-    esTester.putDocuments(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), newRuleDoc());
+    esTester.putDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE, newRuleDoc());
 
     backendCleanup.clearIndexes();
 
@@ -89,7 +88,7 @@ public class BackendCleanupMediumTest {
   public void clear_all() throws Exception {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
     esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc());
-    esTester.putDocuments(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), newRuleDoc());
+    esTester.putDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE, newRuleDoc());
 
     backendCleanup.clearAll();
 
@@ -107,22 +106,25 @@ public class BackendCleanupMediumTest {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
     esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc());
     esTester.putDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, new ViewDoc().setUuid("CDEF").setProjects(newArrayList("DEFG")));
-    esTester.putDocuments(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), newRuleDoc());
+    esTester.putDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE, newRuleDoc());
 
     backendCleanup.resetData();
 
-    assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(0);
-    assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(0);
-    assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(0);
-    assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).isEqualTo(0);
-    assertThat(esTester.countDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW)).isEqualTo(0);
+    assertThat(dbTester.countRowsOfTable("projects")).isZero();
+    assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
+    assertThat(dbTester.countRowsOfTable("properties")).isZero();
+    assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).isZero();
+    assertThat(esTester.countDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW)).isZero();
 
     // Rules should not be removed
     assertThat(dbTester.countRowsOfTable("rules")).isEqualTo(1);
-    assertThat(esTester.countDocuments(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType())).isEqualTo(1);
+    assertThat(esTester.countDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE)).isEqualTo(1);
   }
 
   private static RuleDoc newRuleDoc() {
-    return new RuleDoc(ImmutableMap.<String, Object>of(RuleNormalizer.RuleField.RULE_KEY.field(), RuleTesting.XOO_X1));
+    return new RuleDoc(ImmutableMap.<String, Object>of(
+      RuleIndexDefinition.FIELD_RULE_KEY, RuleTesting.XOO_X1,
+      RuleIndexDefinition.FIELD_RULE_REPOSITORY, RuleTesting.XOO_X1.repository()
+    ));
   }
 }
index 3ac6d6657c91afbbc4546300aa76d1043cfe8110..b8d1435944446462b08db3fcfe13c0a946475eeb 100644 (file)
@@ -9,13 +9,16 @@
              depth="[null]" scope="PRJ" qualifier="TRK" version="[null]" path=""/>
 
   <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="NewRuleKey" plugin_name="plugin" name="new name" description="new description" status="DEPRECATED"
-         plugin_config_key="NewConfigKey" priority="0" is_template="[true]" language="dart" created_at="2013-12-16" updated_at="2013-12-16" template_id="3"
+         plugin_config_key="NewConfigKey" priority="0" is_template="[true]" language="dart" template_id="3"
          note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]"
          characteristic_id="100" default_characteristic_id="101"
          remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
          remediation_coeff="1h" default_remediation_coeff="5d"
          remediation_offset="5min" default_remediation_offset="10h"
-         effort_to_fix_description="squid.S115.effortToFix" description_format="MARKDOWN"/>
+         effort_to_fix_description="squid.S115.effortToFix" description_format="MARKDOWN"
+         created_at="2013-12-16" updated_at="2013-12-16"
+         created_at_ms="150000" updated_at_ms="150000"
+  />
 
   <properties id="1" prop_key="sonar.profile.java" text_value="Sonar Way" resource_id="1" user_id="[null]"/>