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 4258b4a73b9c..6db542c2ffe7 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 void after() { } @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 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 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 activeRules = db.activeRuleDao().findByProfileKey(session, child.getKey()); assertThat(activeRules).isEmpty(); }