diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-06-10 16:21:08 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-06-10 16:21:22 +0200 |
commit | 335134f88041a3f2920d4b8139a12c09c11a6966 (patch) | |
tree | 4f3a0e732ff4cd840f9268aa0bd121a6c82ddf74 | |
parent | 75a41a468640b927490da3c59c2e19251a05b851 (diff) | |
download | sonarqube-335134f88041a3f2920d4b8139a12c09c11a6966.tar.gz sonarqube-335134f88041a3f2920d4b8139a12c09c11a6966.zip |
SONAR-5329 - Added ActiveRuleChange Medium test and base detail map
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java | 16 | ||||
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeMediumTest.java | 56 |
2 files changed, 70 insertions, 2 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java index 1149384bb7d..2932c90b43a 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java @@ -19,6 +19,7 @@ */ package org.sonar.server.qualityprofile; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import org.sonar.core.log.Loggable; import org.sonar.core.qualityprofile.db.ActiveRuleKey; @@ -100,13 +101,24 @@ public class ActiveRuleChange implements Loggable { return parameters; } - public void setParameter(String key, @Nullable String value) { + public ActiveRuleChange setParameter(String key, @Nullable String value) { parameters.put(key, value); + return this; } @Override public Map<String, String> getDetails() { - return null; + ImmutableMap.Builder<String, String> details = ImmutableMap.<String, String>builder(); + + if (this.getType() != null) { + details.put("type", this.getType().name()); + } + + if (this.getKey() != null) { + details.put("key", this.getKey().toString()); + } + + return details.build(); } @Override diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeMediumTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeMediumTest.java new file mode 100644 index 00000000000..c909800bec7 --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeMediumTest.java @@ -0,0 +1,56 @@ +package org.sonar.server.qualityprofile; + +import org.elasticsearch.common.collect.Iterables; +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.core.log.Log; +import org.sonar.core.persistence.DbSession; +import org.sonar.server.db.DbClient; +import org.sonar.server.log.LogService; +import org.sonar.server.log.index.LogIndex; +import org.sonar.server.tester.ServerTester; + +import static org.fest.assertions.Assertions.assertThat; + +public class ActiveRuleChangeMediumTest { + + + @ClassRule + public static ServerTester tester = new ServerTester(); + + LogService service = tester.get(LogService.class); + LogIndex index = tester.get(LogIndex.class); + DbClient db; + DbSession dbSession; + + @Before + public void before() { + tester.clearDbAndIndexes(); + db = tester.get(DbClient.class); + dbSession = tester.get(DbClient.class).openSession(false); + } + + @After + public void after() { + dbSession.close(); + } + + @Test + public void insert_find_active_rule_change() { + ActiveRuleChange change = new ActiveRuleChange() + .setInheritance(ActiveRule.Inheritance.INHERITED) + .setSeverity("BLOCKER") + .setParameter("param1", "value1"); + + service.write(dbSession, Log.Type.ACTIVE_RULE, change); + dbSession.commit(); + + // 0. AssertBase case + assertThat(index.findAll().getHits()).hasSize(1); + + Log log = Iterables.getFirst(index.findAll().getHits(), null); + assertThat(log).isNotNull(); + } +}
\ No newline at end of file |