aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-04-10 10:40:00 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-04-10 11:19:25 +0200
commita09cf3a6f7746be2c4114024688f1fb8221f4732 (patch)
treef34110fd76e49f176ff3fde8550115124006f84b
parent8b16808a43932555a51d8e6e08a615666d747881 (diff)
downloadsonarqube-a09cf3a6f7746be2c4114024688f1fb8221f4732.tar.gz
sonarqube-a09cf3a6f7746be2c4114024688f1fb8221f4732.zip
SONAR-6307 Split test case to isolate behavior
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileChangeParentActionMediumTest.java48
1 files changed, 38 insertions, 10 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileChangeParentActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileChangeParentActionMediumTest.java
index 4258b4a73b9..6db542c2ffe 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileChangeParentActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileChangeParentActionMediumTest.java
@@ -70,50 +70,78 @@ public class QProfileChangeParentActionMediumTest {
}
@Test
- public void change_parent_with_keys() throws Exception {
+ public void change_parent_with_no_parent_before() throws Exception {
QualityProfileDto parent1 = createProfile("xoo", "Parent 1");
- QualityProfileDto parent2 = createProfile("xoo", "Parent 2");
QualityProfileDto child = createProfile("xoo", "Child");
RuleDto rule1 = createRule("xoo", "rule1");
- RuleDto rule2 = createRule("xoo", "rule2");
createActiveRule(rule1, parent1);
- createActiveRule(rule2, parent2);
session.commit();
assertThat(db.activeRuleDao().findByProfileKey(session, child.getKey())).isEmpty();
- // 1. Set parent 1
+ // Set parent
wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileIdentificationParamUtils.PARAM_PROFILE_KEY, child.getKey())
.setParam("parentKey", parent1.getKey().toString())
.execute();
session.clearCache();
- // 1. Check rule 1 enabled
+ // Check rule 1 enabled
List<ActiveRuleDto> activeRules1 = db.activeRuleDao().findByProfileKey(session, child.getKey());
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().ruleKey().rule()).isEqualTo("rule1");
+ }
- // 2. Set parent 2
+ @Test
+ public void replace_existing_parent() throws Exception {
+ QualityProfileDto parent1 = createProfile("xoo", "Parent 1");
+ QualityProfileDto parent2 = createProfile("xoo", "Parent 2");
+ QualityProfileDto child = createProfile("xoo", "Child");
+
+ RuleDto rule1 = createRule("xoo", "rule1");
+ RuleDto rule2 = createRule("xoo", "rule2");
+ createActiveRule(rule1, parent1);
+ createActiveRule(rule2, parent2);
+ session.commit();
+
+ // Set parent 1
+ tester.get(RuleActivator.class).setParent(child.getKey(), parent1.getKey());
+ session.clearCache();
+
+ // Set parent 2 through WS
wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileIdentificationParamUtils.PARAM_PROFILE_KEY, child.getKey())
.setParam("parentKey", parent2.getKey().toString())
.execute();
session.clearCache();
- // 2. Check rule 2 enabled
+ // Check rule 2 enabled
List<ActiveRuleDto> activeRules2 = db.activeRuleDao().findByProfileKey(session, child.getKey());
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().ruleKey().rule()).isEqualTo("rule2");
+ }
- // 3. Remove parent
+ @Test
+ public void remove_parent() throws Exception {
+ QualityProfileDto parent = createProfile("xoo", "Parent 1");
+ QualityProfileDto child = createProfile("xoo", "Child");
+
+ RuleDto rule1 = createRule("xoo", "rule1");
+ createActiveRule(rule1, parent);
+ session.commit();
+
+ // Set parent
+ tester.get(RuleActivator.class).setParent(child.getKey(), parent.getKey());
+ session.clearCache();
+
+ // Remove parent through WS
wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileIdentificationParamUtils.PARAM_PROFILE_KEY, child.getKey())
.execute();
session.clearCache();
- // 3. Check no rule enabled
+ // Check no rule enabled
List<ActiveRuleDto> activeRules = db.activeRuleDao().findByProfileKey(session, child.getKey());
assertThat(activeRules).isEmpty();
}