Search in sources :

Example 6 with ServerIssue

use of org.sonar.scanner.protocol.input.ScannerInput.ServerIssue in project sonarqube by SonarSource.

the class IssuesActionTest method return_minimal_fields.

@Test
public void return_minimal_fields() throws Exception {
    ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY);
    ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY);
    ComponentDto file = ComponentTesting.newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath(null);
    db.getDbClient().componentDao().insert(db.getSession(), project, module, file);
    db.getSession().commit();
    indexIssues(IssueDocTesting.newDoc("EFGH", file).setRuleKey("squid:AvoidCycle").setSeverity("BLOCKER").setStatus("RESOLVED").setResolution(null).setManualSeverity(false).setMessage(null).setLine(null).setChecksum(null).setAssignee(null));
    addBrowsePermissionOnComponent(project);
    WsTester.TestRequest request = tester.newGetRequest("batch", "issues").setParam("key", PROJECT_KEY);
    ServerIssue serverIssue = ServerIssue.parseDelimitedFrom(new ByteArrayInputStream(request.execute().output()));
    assertThat(serverIssue.getKey()).isEqualTo("EFGH");
    assertThat(serverIssue.getModuleKey()).isEqualTo(MODULE_KEY);
    assertThat(serverIssue.hasPath()).isFalse();
    assertThat(serverIssue.getRuleRepository()).isEqualTo("squid");
    assertThat(serverIssue.getRuleKey()).isEqualTo("AvoidCycle");
    assertThat(serverIssue.hasLine()).isFalse();
    assertThat(serverIssue.hasMsg()).isFalse();
    assertThat(serverIssue.hasResolution()).isFalse();
    assertThat(serverIssue.getStatus()).isEqualTo("RESOLVED");
    assertThat(serverIssue.getSeverity()).isEqualTo(Severity.BLOCKER);
    assertThat(serverIssue.getManualSeverity()).isFalse();
    assertThat(serverIssue.hasChecksum()).isFalse();
    assertThat(serverIssue.hasAssigneeLogin()).isFalse();
}
Also used : WsTester(org.sonar.server.ws.WsTester) ByteArrayInputStream(java.io.ByteArrayInputStream) ComponentDto(org.sonar.db.component.ComponentDto) ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue) Test(org.junit.Test)

Example 7 with ServerIssue

use of org.sonar.scanner.protocol.input.ScannerInput.ServerIssue in project sonarqube by SonarSource.

the class IssuesActionTest method issues_attached_on_module.

@Test
public void issues_attached_on_module() throws Exception {
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto project = ComponentTesting.newProjectDto(organizationDto, PROJECT_UUID).setKey(PROJECT_KEY);
    ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY);
    db.getDbClient().componentDao().insert(db.getSession(), project, module);
    db.getSession().commit();
    indexIssues(IssueDocTesting.newDoc("EFGH", module).setRuleKey("squid:AvoidCycle").setSeverity("BLOCKER").setStatus("RESOLVED").setResolution("FALSE-POSITIVE").setManualSeverity(false).setMessage("Do not use this method").setLine(200).setChecksum("123456").setAssignee("john"));
    addBrowsePermissionOnComponent(project);
    WsTester.TestRequest request = tester.newGetRequest("batch", "issues").setParam("key", MODULE_KEY);
    ServerIssue previousIssue = ServerIssue.parseDelimitedFrom(new ByteArrayInputStream(request.execute().output()));
    assertThat(previousIssue.getKey()).isEqualTo("EFGH");
    assertThat(previousIssue.getModuleKey()).isEqualTo(MODULE_KEY);
    assertThat(previousIssue.hasPath()).isFalse();
    assertThat(previousIssue.getRuleRepository()).isEqualTo("squid");
    assertThat(previousIssue.getRuleKey()).isEqualTo("AvoidCycle");
    assertThat(previousIssue.getLine()).isEqualTo(200);
    assertThat(previousIssue.getMsg()).isEqualTo("Do not use this method");
    assertThat(previousIssue.getResolution()).isEqualTo("FALSE-POSITIVE");
    assertThat(previousIssue.getStatus()).isEqualTo("RESOLVED");
    assertThat(previousIssue.getSeverity()).isEqualTo(Severity.BLOCKER);
    assertThat(previousIssue.getManualSeverity()).isFalse();
    assertThat(previousIssue.getChecksum()).isEqualTo("123456");
    assertThat(previousIssue.getAssigneeLogin()).isEqualTo("john");
}
Also used : WsTester(org.sonar.server.ws.WsTester) ByteArrayInputStream(java.io.ByteArrayInputStream) ComponentDto(org.sonar.db.component.ComponentDto) ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 8 with ServerIssue

use of org.sonar.scanner.protocol.input.ScannerInput.ServerIssue in project sonarqube by SonarSource.

the class DefaultServerIssuesLoader method parseIssues.

private static void parseIssues(InputStream is, Function<ServerIssue, Void> consumer) {
    try {
        ServerIssue previousIssue = ServerIssue.parseDelimitedFrom(is);
        while (previousIssue != null) {
            consumer.apply(previousIssue);
            previousIssue = ServerIssue.parseDelimitedFrom(is);
        }
    } catch (IOException e) {
        throw new IllegalStateException("Unable to get previous issues", e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue) IOException(java.io.IOException)

Example 9 with ServerIssue

use of org.sonar.scanner.protocol.input.ScannerInput.ServerIssue in project sonarqube by SonarSource.

the class ServerIssueValueCoder method put.

@Override
public void put(Value value, Object object, CoderContext context) {
    ServerIssue issue = (ServerIssue) object;
    value.putByteArray(issue.toByteArray());
}
Also used : ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue)

Example 10 with ServerIssue

use of org.sonar.scanner.protocol.input.ScannerInput.ServerIssue in project sonarqube by SonarSource.

the class DefaultServerIssuesLoaderTest method loadFromWs.

@Test
public void loadFromWs() throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ServerIssue.newBuilder().setKey("ab1").build().writeDelimitedTo(bos);
    ServerIssue.newBuilder().setKey("ab2").build().writeDelimitedTo(bos);
    InputStream is = new ByteArrayInputStream(bos.toByteArray());
    WsTestUtil.mockStream(wsClient, "/batch/issues.protobuf?key=foo", is);
    final List<ServerIssue> result = new ArrayList<>();
    loader.load("foo", issue -> {
        result.add(issue);
        return null;
    });
    assertThat(result).extracting("key").containsExactly("ab1", "ab2");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ServerIssue (org.sonar.scanner.protocol.input.ScannerInput.ServerIssue)13 Test (org.junit.Test)10 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ComponentDto (org.sonar.db.component.ComponentDto)6 WsTester (org.sonar.server.ws.WsTester)6 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 DefaultTempFolder (org.sonar.api.utils.internal.DefaultTempFolder)1 DownloadException (org.sonarsource.sonarlint.core.client.api.exceptions.DownloadException)1 IssueStore (org.sonarsource.sonarlint.core.container.connected.IssueStore)1