]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5329 - Added reader fields for QProfileActivity
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 20 Jun 2014 07:25:26 +0000 (09:25 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 20 Jun 2014 07:25:32 +0000 (09:25 +0200)
sonar-core/src/main/java/org/sonar/core/activity/Activity.java
sonar-server/src/main/java/org/sonar/server/activity/index/ActivityDoc.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActivity.java
sonar-server/src/main/java/org/sonar/server/search/BaseDoc.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java

index 835ca8dfb1eadac0faa571ead46ef6ce54767b6a..caf56919d965fcdfbc298c38081fc252c96b9ebb 100644 (file)
@@ -31,12 +31,14 @@ public interface Activity {
     NONE, QPROFILE, SERVER
   }
 
+  Type type();
+
+  String action();
+
   Date time();
 
   String author();
 
-  String action();
-
   Map<String, String> details();
 
   String message();
index d38c0cb6eb1f1f589f0e2005b38ffc0369b26a15..baa7be28955392eb72ab94f6d79c54cce73ea577 100644 (file)
@@ -46,6 +46,11 @@ public class ActivityDoc extends BaseDoc implements Activity {
     return this.getNullableField(ActivityNormalizer.LogFields.AUTHOR.field());
   }
 
+  @Override
+  public Type type() {
+    return Type.valueOf((String) this.getNullableField(ActivityNormalizer.LogFields.TYPE.field()));
+  }
+
   @Override
   public String action() {
     return this.getNullableField(ActivityNormalizer.LogFields.ACTION.field());
index 5d138b14fcff6c73221567320a28c44be4161a2e..fd2c453d0f6f3b7c88aea8326c22d9637db8dda4 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.qualityprofile;
 
-import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.core.activity.Activity;
 import org.sonar.server.activity.index.ActivityDoc;
@@ -31,36 +31,45 @@ import java.util.Map;
  */
 public class QProfileActivity extends ActivityDoc implements Activity {
 
+  private String ruleName = "Not Yet Implemented";
+  private String authorName = "Not Yet Implemented";
+
   protected QProfileActivity(Map<String, Object> fields) {
     super(fields);
+    Map<String, String> details = getField("details");
+    for (Map.Entry detail : details.entrySet()) {
+      fields.put((String) detail.getKey(), detail.getValue());
+    }
   }
 
   public String profileKey(){
-    // TODO
-    return null;
+    return getField("profileKey");
   }
 
   public RuleKey ruleKey(){
-    return RuleKey.parse((String) getField("details.ruleKey"));
+    return RuleKey.parse((String) getField("ruleKey"));
   }
 
   public String ruleName(){
-    // TODO
-    return null;
+    return this.ruleName;
   }
 
   public String authorName(){
-    // TODO
-    return null;
+    return this.authorName;
   }
 
   public String severity(){
-    return (String) getField("details.severity");
+    return (String) getField("severity");
   }
 
-  public Map<String, String> parameters(){
-    // TODO
-    return ImmutableMap.of();
+  public Map<String, String> parameters() {
+    Map<String, String> params = Maps.newHashMap();
+    for (String key : fields.keySet()) {
+      if (key.startsWith("param_")) {
+        params.put(key.replace("param_", ""), (String) fields.get(key));
+      }
+    }
+    return params;
   }
 
 }
index d7b930532fce61266886f7dab7d48d757dba28d1..9b1b8cd6329ebf04ebae3763e21b477f815d4593 100644 (file)
@@ -27,7 +27,7 @@ import java.util.Map;
  */
 public abstract class BaseDoc {
 
-  private final Map<String, Object> fields;
+  protected final Map<String, Object> fields;
 
   protected BaseDoc(Map<String, Object> fields) {
     this.fields = fields;
index 56e41b423f1389f203f0b12cd559c15e6278b809..1e6207bb3d57b5e9be324a88c68dee0375ed0baa 100644 (file)
 package org.sonar.server.qualityprofile;
 
 import com.google.common.collect.Multimap;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
@@ -129,7 +132,6 @@ public class QProfileServiceMediumTest {
   }
 
   @Test
-  @Ignore
   public void search_qprofile_activity() throws InterruptedException {
     tester.get(ActivityService.class).write(dbSession, Activity.Type.QPROFILE,
       ActiveRuleChange.createFor(ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1))
@@ -142,7 +144,14 @@ public class QProfileServiceMediumTest {
     assertThat(activities).hasSize(1);
 
     QProfileActivity activity = activities.get(0);
+    assertThat(activity.type()).isEqualTo(Activity.Type.QPROFILE);
+    assertThat(activity.action()).isEqualTo(ActiveRuleChange.Type.ACTIVATED.name());
     assertThat(activity.ruleKey()).isEqualTo(RuleTesting.XOO_X1);
-    assertThat(activity.ruleName()).isEqualTo("Rule name");
+    assertThat(activity.profileKey()).isEqualTo(XOO_P1_KEY);
+    assertThat(activity.parameters().get("max")).isEqualTo("10");
+    assertThat(activity.severity()).isEqualTo(Severity.MAJOR);
+    //TODO Implement folding Name and Author from from service
+//    assertThat(activity.ruleName()).isEqualTo("Rule name");
+//    assertThat(activity.authorName()).isEqualTo("me");
   }
 }