use of org.sonar.api.rule.RuleStatus.DEPRECATED in project sonarqube by SonarSource.
the class ShowActionTest method statistics.
@Test
public void statistics() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
// Active rules
range(0, 10).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition()).forEach(r -> db.qualityProfiles().activateRule(profile, r));
// Deprecated rules
range(0, 3).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey()).setStatus(DEPRECATED)).getDefinition()).forEach(r -> db.qualityProfiles().activateRule(profile, r));
// Projects
range(0, 7).mapToObj(i -> db.components().insertPrivateProjectDto()).forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
ShowResponse result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()));
assertThat(result.getProfile()).extracting(QualityProfile::getActiveRuleCount, QualityProfile::getActiveDeprecatedRuleCount, QualityProfile::getProjectCount).containsExactly(13L, 3L, 7L);
}
use of org.sonar.api.rule.RuleStatus.DEPRECATED in project sonarqube by SonarSource.
the class SearchActionTest method statistics_on_active_rules.
@Test
public void statistics_on_active_rules() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
RuleDefinitionDto rule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
RuleDefinitionDto deprecatedRule1 = db.rules().insertRule(r -> r.setStatus(DEPRECATED)).getDefinition();
RuleDefinitionDto deprecatedRule2 = db.rules().insertRule(r -> r.setStatus(DEPRECATED)).getDefinition();
RuleDefinitionDto inactiveRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
db.qualityProfiles().activateRule(profile, rule);
db.qualityProfiles().activateRule(profile, deprecatedRule1);
db.qualityProfiles().activateRule(profile, deprecatedRule2);
SearchWsResponse result = call(ws.newRequest());
assertThat(result.getProfilesList()).extracting(QualityProfile::getActiveRuleCount, QualityProfile::getActiveDeprecatedRuleCount).containsExactlyInAnyOrder(tuple(3L, 2L));
}
use of org.sonar.api.rule.RuleStatus.DEPRECATED in project sonarqube by SonarSource.
the class SearchActionTest method json_example.
@Test
public void json_example() {
// languages
Language cs = newLanguage("cs", "C#");
Language java = newLanguage("java", "Java");
Language python = newLanguage("py", "Python");
// profiles
QProfileDto sonarWayCs = db.qualityProfiles().insert(p -> p.setName("Sonar way").setKee("AU-TpxcA-iU5OvuD2FL3").setIsBuiltIn(true).setLanguage(cs.getKey()));
QProfileDto myCompanyProfile = db.qualityProfiles().insert(p -> p.setName("My Company Profile").setKee("iU5OvuD2FLz").setLanguage(java.getKey()));
QProfileDto myBuProfile = db.qualityProfiles().insert(p -> p.setName("My BU Profile").setKee("AU-TpxcA-iU5OvuD2FL1").setParentKee(myCompanyProfile.getKee()).setLanguage(java.getKey()));
QProfileDto sonarWayPython = db.qualityProfiles().insert(p -> p.setName("Sonar way").setKee("AU-TpxcB-iU5OvuD2FL7").setIsBuiltIn(true).setLanguage(python.getKey()));
db.qualityProfiles().setAsDefault(sonarWayCs, myCompanyProfile, sonarWayPython);
// rules
List<RuleDefinitionDto> javaRules = range(0, 10).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(java.getKey())).getDefinition()).collect(MoreCollectors.toList());
List<RuleDefinitionDto> deprecatedJavaRules = range(0, 5).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(java.getKey()).setStatus(DEPRECATED)).getDefinition()).collect(MoreCollectors.toList());
range(0, 7).forEach(i -> db.qualityProfiles().activateRule(myCompanyProfile, javaRules.get(i)));
range(0, 2).forEach(i -> db.qualityProfiles().activateRule(myCompanyProfile, deprecatedJavaRules.get(i)));
range(0, 10).forEach(i -> db.qualityProfiles().activateRule(myBuProfile, javaRules.get(i)));
range(0, 5).forEach(i -> db.qualityProfiles().activateRule(myBuProfile, deprecatedJavaRules.get(i)));
range(0, 2).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(python.getKey())).getDefinition()).forEach(rule -> db.qualityProfiles().activateRule(sonarWayPython, rule));
range(0, 3).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey())).getDefinition()).forEach(rule -> db.qualityProfiles().activateRule(sonarWayCs, rule));
// project
range(0, 7).mapToObj(i -> db.components().insertPrivateProjectDto()).forEach(project -> db.qualityProfiles().associateWithProject(project, myBuProfile));
// User
UserDto user = db.users().insertUser();
db.qualityProfiles().addUserPermission(myCompanyProfile, user);
db.qualityProfiles().addUserPermission(myBuProfile, user);
userSession.logIn(user);
underTest = new SearchAction(userSession, new Languages(cs, java, python), dbClient, new ComponentFinder(dbClient, null));
ws = new WsActionTester(underTest);
String result = ws.newRequest().execute().getInput();
assertJson(result).ignoreFields("ruleUpdatedAt", "lastUsed", "userUpdatedAt").isSimilarTo(ws.getDef().responseExampleAsString());
}
Aggregations