use of org.sonarqube.ws.client.qualityprofile.SearchWsRequest in project sonarlint-core by SonarSource.
the class ConnectedModeTest method analysisTemplateRule.
@Test
public void analysisTemplateRule() throws Exception {
// WS quality profile is not available before 5.2 so let's skip this test
assumeTrue(ORCHESTRATOR.getServer().version().isGreaterThanOrEquals("5.2"));
SearchWsRequest searchReq = new SearchWsRequest();
searchReq.setQualityProfile("SonarLint IT Java");
searchReq.setProjectKey(PROJECT_KEY_JAVA);
searchReq.setDefaults(false);
SearchWsResponse search = adminWsClient.qualityProfiles().search(searchReq);
QualityProfile qp = null;
for (QualityProfile q : search.getProfilesList()) {
if (q.getName().equals("SonarLint IT Java")) {
qp = q;
}
}
assertThat(qp).isNotNull();
WsRequest request = new PostRequest("/api/rules/create").setParam("custom_key", "myrule").setParam("name", "myrule").setParam("markdown_description", "my_rule_description").setParam("params", "methodName=echo;className=foo.Foo;argumentTypes=int").setParam("template_key", "squid:S2253").setParam("severity", "MAJOR");
WsResponse response = adminWsClient.wsConnector().call(request);
assertTrue(response.isSuccessful());
request = new PostRequest("/api/qualityprofiles/activate_rule").setParam("profile_key", qp.getKey()).setParam("rule_key", "squid:myrule");
response = adminWsClient.wsConnector().call(request);
assertTrue(response.isSuccessful());
try {
updateGlobal();
updateModule(PROJECT_KEY_JAVA);
SaveIssueListener issueListener = new SaveIssueListener();
engine.analyze(createAnalysisConfiguration(PROJECT_KEY_JAVA, PROJECT_KEY_JAVA, "src/main/java/foo/Foo.java", "sonar.java.binaries", new File("projects/sample-java/target/classes").getAbsolutePath()), issueListener, null, null);
assertThat(issueListener.getIssues()).hasSize(3);
assertThat(engine.getRuleDetails("squid:myrule").getHtmlDescription()).contains("my_rule_description");
} finally {
request = new PostRequest("/api/rules/delete").setParam("key", "squid:myrule");
response = adminWsClient.wsConnector().call(request);
assertTrue(response.isSuccessful());
}
}
use of org.sonarqube.ws.client.qualityprofile.SearchWsRequest in project sonarlint-core by SonarSource.
the class ConnectedModeTest method checkForUpdate.
@Test
public void checkForUpdate() throws Exception {
updateGlobal();
updateModule(PROJECT_KEY_JAVA);
ServerConfiguration serverConfig = getServerConfig(true);
StorageUpdateCheckResult result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isFalse();
// restarting server should not lead to notify an update
ORCHESTRATOR.restartServer();
result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isFalse();
// Change a global setting that is not in the whitelist
setSettings(null, "sonar.foo", "bar");
result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isFalse();
// Change a global setting that *is* in the whitelist
setSettingsMultiValue(null, "sonar.inclusions", "**/*");
// Activate a new rule
SearchWsResponse response = newAdminWsClient(ORCHESTRATOR).qualityProfiles().search(new SearchWsRequest().setLanguage("java"));
String profileKey = response.getProfilesList().stream().filter(p -> p.getName().equals("SonarLint IT Java")).findFirst().get().getKey();
ORCHESTRATOR.getServer().adminWsClient().post("api/qualityprofiles/activate_rule", "profile_key", profileKey, "rule_key", "squid:S1228");
result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isTrue();
assertThat(result.changelog()).containsOnly("Global settings updated", "Quality profile 'SonarLint IT Java' for language 'Java' updated");
result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
assertThat(result.needUpdate()).isFalse();
// Change a project setting that is not in the whitelist
setSettings(PROJECT_KEY_JAVA, "sonar.foo", "biz");
result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
assertThat(result.needUpdate()).isFalse();
// Change a project setting that *is* in the whitelist
setSettingsMultiValue(PROJECT_KEY_JAVA, "sonar.exclusions", "**/*.foo");
result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
assertThat(result.needUpdate()).isTrue();
assertThat(result.changelog()).containsOnly("Project settings updated");
}
Aggregations