*/
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;
*/
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;
}
}
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;
}
@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))
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");
}
}