]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5237 - Fixed sleeping test & added ActiveRule to RuleIndex
authorStephane Gamard <stephane.gamard@searchbox.com>
Tue, 29 Apr 2014 13:54:15 +0000 (15:54 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Tue, 29 Apr 2014 13:54:15 +0000 (15:54 +0200)
sonar-server/src/main/java/org/sonar/server/rule2/RuleIndex.java
sonar-server/src/test/java/org/sonar/server/rule2/RuleMediumTest.java

index 16171b74395d092c1b986df21e3602f1715ed0a2..30372871c56948a2b9c2e8b118a6e2ae1fed4b67 100644 (file)
@@ -19,6 +19,9 @@
  */
 package org.sonar.server.rule2;
 
+import org.sonar.core.qualityprofile.db.ActiveRuleDto;
+
+import org.sonar.core.qualityprofile.db.ActiveRuleDao;
 import org.apache.commons.beanutils.BeanUtils;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.slf4j.Logger;
@@ -43,8 +46,11 @@ public class RuleIndex extends BaseIndex<RuleKey, RuleDto> {
 
   private static final Logger LOG = LoggerFactory.getLogger(RuleIndex.class);
 
-  public RuleIndex(WorkQueue queue, RuleDao dao, Profiling profiling, ESNode node) {
+  private ActiveRuleDao activeRuleDao;
+
+  public RuleIndex(WorkQueue queue, RuleDao dao, ActiveRuleDao ActiveRuleDao, Profiling profiling, ESNode node) {
     super(queue, dao, profiling, node);
+    this.activeRuleDao = ActiveRuleDao;
   }
 
   @Override
@@ -157,10 +163,19 @@ public class RuleIndex extends BaseIndex<RuleKey, RuleDto> {
       Map<String, Object> properties = BeanUtils.describe(rule);
 
       for (Entry<String, Object> property : properties.entrySet()) {
-        LOG.trace("NORMALIZING: {} -> {}",property.getKey(), property.getValue());
+        LOG.info("NORMALIZING: {} -> {}",property.getKey(), property.getValue());
         document.field(property.getKey(), property.getValue());
       }
 
+
+      for(ActiveRuleDto activeRule:activeRuleDao.selectByRuleId(rule.getId())){
+        Map<String, Object> activeRuleProperties = BeanUtils.describe(activeRule);
+        for (Entry<String, Object> activeRuleProp : activeRuleProperties.entrySet()) {
+          LOG.info("NORMALIZING: --- {} -> {}",activeRuleProp.getKey(), activeRuleProp.getValue());
+          document.field(activeRuleProp.getKey(), activeRuleProp.getValue());
+        }
+      }
+
       return document.endObject();
     } catch (IOException e) {
       LOG.error("Could not normalize {} in {}", key, this.getClass().getSimpleName());
index 2d3e514b15a22c655b1012495de31825641f5a8e..f81399820cbd003fbaae7a350004cbbbb5f01c11 100644 (file)
@@ -24,11 +24,15 @@ import org.junit.Test;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.check.Cardinality;
+import org.sonar.core.qualityprofile.db.ActiveRuleDao;
+import org.sonar.core.qualityprofile.db.ActiveRuleDto;
 import org.sonar.core.rule.RuleDao;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.server.search.Hit;
 import org.sonar.server.tester.ServerTester;
 
+import java.util.Date;
+
 import static org.fest.assertions.Assertions.assertThat;
 
 public class RuleMediumTest {
@@ -36,48 +40,61 @@ public class RuleMediumTest {
   @Rule
   public ServerTester tester = new ServerTester();
 
+  private ActiveRuleDto getActiveRuleDto(RuleDto dto){
+    return new ActiveRuleDto()
+      .setId(1)
+      .setNoteCreatedAt(new Date())
+      .setNoteData("Note data, and some more note and here too.")
+      .setRuleId(dto.getId())
+      .setProfileId(1)
+      .setParentId(0)
+      .setSeverity(3);
+    }
 
-  private RuleDto getRuleDto(){
+  private RuleDto getRuleDto() {
     return new RuleDto()
-    .setId(1)
-    .setRuleKey("NewRuleKey")
-    .setRepositoryKey("plugin")
-    .setName("new name")
-    .setDescription("new description")
-    .setStatus(org.sonar.api.rules.Rule.STATUS_DEPRECATED)
-    .setConfigKey("NewConfigKey")
-    .setSeverity(Severity.INFO)
-    .setCardinality(Cardinality.MULTIPLE)
-    .setLanguage("dart")
-    .setParentId(3)
-    .setSubCharacteristicId(100)
-    .setDefaultSubCharacteristicId(101)
-    .setRemediationFunction("linear")
-    .setDefaultRemediationFunction("linear_offset")
-    .setRemediationCoefficient("1h")
-    .setDefaultRemediationCoefficient("5d")
-    .setRemediationOffset("5min")
-    .setDefaultRemediationOffset("10h")
-    .setEffortToFixDescription("squid.S115.effortToFix")
-    .setCreatedAt(DateUtils.parseDate("2013-12-16"))
-    .setUpdatedAt(DateUtils.parseDate("2013-12-17"));
+      .setId(1)
+      .setRuleKey("NewRuleKey")
+      .setRepositoryKey("plugin")
+      .setName("new name")
+      .setDescription("new description")
+      .setStatus(org.sonar.api.rules.Rule.STATUS_DEPRECATED)
+      .setConfigKey("NewConfigKey")
+      .setSeverity(Severity.INFO)
+      .setCardinality(Cardinality.MULTIPLE)
+      .setLanguage("dart")
+      .setParentId(3)
+      .setSubCharacteristicId(100)
+      .setDefaultSubCharacteristicId(101)
+      .setRemediationFunction("linear")
+      .setDefaultRemediationFunction("linear_offset")
+      .setRemediationCoefficient("1h")
+      .setDefaultRemediationCoefficient("5d")
+      .setRemediationOffset("5min")
+      .setDefaultRemediationOffset("10h")
+      .setEffortToFixDescription("squid.S115.effortToFix")
+      .setCreatedAt(DateUtils.parseDate("2013-12-16"))
+      .setUpdatedAt(DateUtils.parseDate("2013-12-17"));
   }
 
   @Test
-  public void test_dao_queue_es_search_loop(){
+  public void test_dao_queue_es_search_loop() {
     RuleDao dao = tester.get(RuleDao.class);
+    ActiveRuleDao adao = tester.get(ActiveRuleDao.class);
     RuleIndex index = tester.get(RuleIndex.class);
 
     RuleDto dto = getRuleDto();
     dao.insert(dto);
 
+    adao.insert(getActiveRuleDto(dto));
+
     try {
-      Thread.sleep(1000000);
+      Thread.sleep(100);
     } catch (InterruptedException e) {
       ;
     }
 
     Hit hit = index.getByKey(dto.getKey());
-    assertThat(hit.getFields().get("key")).isEqualTo(dto.getRuleKey());
+    assertThat(hit.getFields().get("ruleKey")).isEqualTo(dto.getRuleKey());
   }
 }