Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-6306 Show rule stats on quality profile inheritance items
- Loading branch information
1 parent
5a4027c
commit 9fa4c60
Showing
6 changed files
with
251 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...nar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-inheritance.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"profile": { | ||
"key": "xoo-my-bu-profile-23456", | ||
"name": "My BU Profile", | ||
"parent": "xoo-my-company-profile-12345", | ||
"activeRuleCount": 3, | ||
"overridingRuleCount": 1 | ||
}, | ||
"ancestors": [ | ||
{ | ||
"key": "xoo-my-company-profile-12345", | ||
"name": "My Company Profile", | ||
"parent": "xoo-my-group-profile-01234", | ||
"activeRuleCount": 3 | ||
}, | ||
{ | ||
"key": "xoo-my-group-profile-01234", | ||
"name": "My Group Profile", | ||
"activeRuleCount": 2 | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"key": "xoo-for-project-one-34567", | ||
"name": "For Project One", | ||
"activeRuleCount": 5 | ||
}, | ||
{ | ||
"key": "xoo-for-project-two-45678", | ||
"name": "For Project Two", | ||
"activeRuleCount": 4, | ||
"overridingRuleCount": 1 | ||
} | ||
] | ||
} |
136 changes: 136 additions & 0 deletions
136
...src/test/java/org/sonar/server/qualityprofile/ws/QProfileInheritanceActionMediumTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* SonarQube, open source software quality management tool. | ||
* Copyright (C) 2008-2014 SonarSource | ||
* mailto:contact AT sonarsource DOT com | ||
* | ||
* SonarQube is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* SonarQube is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.server.qualityprofile.ws; | ||
|
||
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; | ||
import org.sonar.core.persistence.DbSession; | ||
import org.sonar.core.qualityprofile.db.ActiveRuleDto; | ||
import org.sonar.core.qualityprofile.db.QualityProfileDto; | ||
import org.sonar.core.rule.RuleDto; | ||
import org.sonar.server.db.DbClient; | ||
import org.sonar.server.exceptions.NotFoundException; | ||
import org.sonar.server.qualityprofile.QProfileName; | ||
import org.sonar.server.qualityprofile.QProfileTesting; | ||
import org.sonar.server.qualityprofile.RuleActivation; | ||
import org.sonar.server.qualityprofile.RuleActivator; | ||
import org.sonar.server.tester.ServerTester; | ||
import org.sonar.server.ws.WsTester; | ||
|
||
public class QProfileInheritanceActionMediumTest { | ||
|
||
@ClassRule | ||
public static final ServerTester tester = new ServerTester(); | ||
|
||
private WsTester wsTester; | ||
|
||
private DbClient db; | ||
|
||
private DbSession session; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
tester.clearDbAndIndexes(); | ||
db = tester.get(DbClient.class); | ||
session = db.openSession(false); | ||
|
||
wsTester = new WsTester(tester.get(QProfilesWs.class)); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
session.close(); | ||
} | ||
|
||
@Test | ||
public void inheritance_nominal() throws Exception { | ||
RuleDto rule1 = createRule("xoo", "rule1"); | ||
RuleDto rule2 = createRule("xoo", "rule2"); | ||
RuleDto rule3 = createRule("xoo", "rule3"); | ||
|
||
/* | ||
* groupWide (2) <- companyWide (2) <- buWide (2, 1 overriding) <- (forProject1 (2), forProject2 (2)) | ||
*/ | ||
QualityProfileDto groupWide = createProfile("xoo", "My Group Profile", "xoo-my-group-profile-01234"); | ||
createActiveRule(rule1, groupWide); | ||
createActiveRule(rule2, groupWide); | ||
session.commit(); | ||
|
||
QualityProfileDto companyWide = createProfile("xoo", "My Company Profile", "xoo-my-company-profile-12345"); | ||
setParent(groupWide, companyWide); | ||
|
||
QualityProfileDto buWide = createProfile("xoo", "My BU Profile", "xoo-my-bu-profile-23456"); | ||
setParent(companyWide, buWide); | ||
overrideActiveRuleSeverity(rule1, buWide, Severity.CRITICAL); | ||
|
||
QualityProfileDto forProject1 = createProfile("xoo", "For Project One", "xoo-for-project-one-34567"); | ||
setParent(buWide, forProject1); | ||
createActiveRule(rule3, forProject1); | ||
session.commit(); | ||
|
||
QualityProfileDto forProject2 = createProfile("xoo", "For Project Two", "xoo-for-project-two-45678"); | ||
setParent(buWide, forProject2); | ||
overrideActiveRuleSeverity(rule2, forProject2, Severity.CRITICAL); | ||
|
||
wsTester.newGetRequest("api/qualityprofiles", "inheritance").setParam("profileKey", buWide.getKee()).execute().assertJson(getClass(), "inheritance-buWide.json"); | ||
} | ||
|
||
@Test(expected = NotFoundException.class) | ||
public void fail_if_not_found() throws Exception { | ||
wsTester.newGetRequest("api/qualityprofiles", "inheritance").setParam("profileKey", "polop").execute(); | ||
} | ||
|
||
private QualityProfileDto createProfile(String lang, String name, String key) { | ||
QualityProfileDto profile = QProfileTesting.newDto(new QProfileName(lang, name), key); | ||
db.qualityProfileDao().insert(session, profile); | ||
session.commit(); | ||
return profile; | ||
} | ||
|
||
private void setParent(QualityProfileDto profile, QualityProfileDto parent) { | ||
tester.get(RuleActivator.class).setParent(parent.getKey(), profile.getKey()); | ||
} | ||
|
||
private RuleDto createRule(String lang, String id) { | ||
RuleDto rule = RuleDto.createFor(RuleKey.of("blah", id)) | ||
.setLanguage(lang) | ||
.setSeverity(Severity.BLOCKER) | ||
.setStatus(RuleStatus.READY); | ||
db.ruleDao().insert(session, rule); | ||
return rule; | ||
} | ||
|
||
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) { | ||
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule) | ||
.setSeverity(rule.getSeverityString()); | ||
db.activeRuleDao().insert(session, activeRule); | ||
return activeRule; | ||
} | ||
|
||
private void overrideActiveRuleSeverity(RuleDto rule, QualityProfileDto profile, String severity) { | ||
tester.get(RuleActivator.class).activate(session, new RuleActivation(rule.getKey()).setSeverity(severity), profile.getKey()); | ||
session.commit(); | ||
} | ||
} |
Oops, something went wrong.