Skip to content

Commit 8fbf070

Browse files
Ruling: log issue differences
1 parent 621d9b2 commit 8fbf070

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

its/ruling/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<artifactId>sonar-analyzer-commons</artifactId>
4545
<scope>compile</scope>
4646
</dependency>
47+
<dependency>
48+
<groupId>org.sonarsource.sonarqube</groupId>
49+
<artifactId>sonar-ws</artifactId>
50+
<version>${sonar.version}</version>
51+
<scope>test</scope>
52+
</dependency>
4753
</dependencies>
4854

4955
</project>

its/ruling/src/test/java/org/sonar/python/it/PythonRulingTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@
2525
import java.io.File;
2626
import java.nio.file.Files;
2727
import java.util.Collections;
28+
import java.util.List;
29+
import java.util.stream.Collectors;
2830
import org.junit.BeforeClass;
2931
import org.junit.ClassRule;
3032
import org.junit.Test;
33+
import org.sonarqube.ws.Issues;
34+
import org.sonarqube.ws.client.HttpConnector;
35+
import org.sonarqube.ws.client.WsClient;
36+
import org.sonarqube.ws.client.WsClientFactories;
37+
import org.sonarqube.ws.client.issues.SearchRequest;
3138
import org.sonarsource.analyzer.commons.ProfileGenerator;
3239

3340
import static java.nio.charset.StandardCharsets.UTF_8;
41+
import static java.util.Collections.singletonList;
3442
import static org.assertj.core.api.Assertions.assertThat;
3543
import static org.sonar.python.it.RulingHelper.getOrchestrator;
3644

@@ -76,8 +84,28 @@ public void test() throws Exception {
7684
.setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx2000m");
7785
ORCHESTRATOR.executeBuild(build);
7886

87+
String issueDifferences = issues(PROJECT_KEY).stream()
88+
.map(i -> String.join("\t", i.getRule(), "" + i.getSeverity(), i.getComponent(), "" + i.getLine()))
89+
.collect(Collectors.joining("\n"));
90+
assertThat(issueDifferences).isEmpty();
91+
7992
String litsDifferences = new String(Files.readAllBytes(litsDifferencesFile.toPath()), UTF_8);
8093
assertThat(litsDifferences).isEmpty();
8194
}
8295

96+
static WsClient newWsClient() {
97+
return newWsClient(null, null);
98+
}
99+
100+
static WsClient newWsClient(String login, String password) {
101+
return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder()
102+
.url(ORCHESTRATOR.getServer().getUrl())
103+
.credentials(login, password)
104+
.build());
105+
}
106+
107+
static List<Issues.Issue> issues(String projectKey) {
108+
return newWsClient().issues().search(new SearchRequest().setProjects(singletonList(projectKey))).getIssuesList();
109+
}
110+
83111
}

0 commit comments

Comments
 (0)