Search in sources :

Example 1 with CoveredFileDoc

use of org.sonar.server.test.index.CoveredFileDoc in project sonarqube by SonarSource.

the class CoveredFilesAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String testId = request.mandatoryParam(TEST_ID);
    TestDoc testDoc = checkFoundWithOptional(index.getNullableByTestUuid(testId), "Test with id '%s' is not found", testId);
    userSession.checkComponentUuidPermission(UserRole.CODEVIEWER, testDoc.fileUuid());
    List<CoveredFileDoc> coveredFiles = index.coveredFiles(testId);
    Map<String, ComponentDto> componentsByUuid = buildComponentsByUuid(coveredFiles);
    WsTests.CoveredFilesResponse.Builder responseBuilder = WsTests.CoveredFilesResponse.newBuilder();
    if (!coveredFiles.isEmpty()) {
        for (CoveredFileDoc doc : coveredFiles) {
            WsTests.CoveredFilesResponse.CoveredFile.Builder fileBuilder = WsTests.CoveredFilesResponse.CoveredFile.newBuilder();
            fileBuilder.setId(doc.fileUuid());
            fileBuilder.setCoveredLines(doc.coveredLines().size());
            ComponentDto component = componentsByUuid.get(doc.fileUuid());
            if (component != null) {
                fileBuilder.setKey(component.key());
                fileBuilder.setLongName(component.longName());
            }
            responseBuilder.addFiles(fileBuilder);
        }
    }
    writeProtobuf(responseBuilder.build(), request, response);
}
Also used : CoveredFileDoc(org.sonar.server.test.index.CoveredFileDoc) ComponentDto(org.sonar.db.component.ComponentDto) TestDoc(org.sonar.server.test.index.TestDoc) WsTests(org.sonarqube.ws.WsTests)

Example 2 with CoveredFileDoc

use of org.sonar.server.test.index.CoveredFileDoc in project sonarqube by SonarSource.

the class CoveredFilesActionTest method fail_when_test_uuid_is_unknown.

@Test
public void fail_when_test_uuid_is_unknown() {
    userSessionRule.addComponentUuidPermission(UserRole.CODEVIEWER, "SonarQube", "test-file-uuid");
    when(testIndex.getNullableByTestUuid(anyString())).thenReturn(Optional.<TestDoc>absent());
    when(testIndex.coveredFiles("test-uuid")).thenReturn(Arrays.asList(new CoveredFileDoc().setFileUuid(FILE_1_ID).setCoveredLines(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), new CoveredFileDoc().setFileUuid(FILE_2_ID).setCoveredLines(Arrays.asList(1, 2, 3))));
    OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
    when(dbClient.componentDao().selectByUuids(any(DbSession.class), anyList())).thenReturn(Arrays.asList(newFileDto(newProjectDto(organizationDto), null, FILE_1_ID).setKey("org.foo.Bar.java").setLongName("src/main/java/org/foo/Bar.java"), newFileDto(newProjectDto(organizationDto), null, FILE_2_ID).setKey("org.foo.File.java").setLongName("src/main/java/org/foo/File.java")));
    expectedException.expect(NotFoundException.class);
    expectedException.expectMessage("Test with id 'test-uuid' is not found");
    ws.newRequest().setParam(TEST_ID, "test-uuid").execute();
}
Also used : DbSession(org.sonar.db.DbSession) CoveredFileDoc(org.sonar.server.test.index.CoveredFileDoc) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 3 with CoveredFileDoc

use of org.sonar.server.test.index.CoveredFileDoc in project sonarqube by SonarSource.

the class CoveredFilesActionTest method covered_files.

@Test
public void covered_files() {
    userSessionRule.addComponentUuidPermission(UserRole.CODEVIEWER, "SonarQube", "test-file-uuid");
    when(testIndex.getNullableByTestUuid(anyString())).thenReturn(Optional.of(new TestDoc().setFileUuid("test-file-uuid")));
    when(testIndex.coveredFiles("test-uuid")).thenReturn(Arrays.asList(new CoveredFileDoc().setFileUuid(FILE_1_ID).setCoveredLines(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), new CoveredFileDoc().setFileUuid(FILE_2_ID).setCoveredLines(Arrays.asList(1, 2, 3))));
    OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
    when(dbClient.componentDao().selectByUuids(any(DbSession.class), anyList())).thenReturn(Arrays.asList(newFileDto(newProjectDto(organizationDto), null, FILE_1_ID).setKey("org.foo.Bar.java").setLongName("src/main/java/org/foo/Bar.java"), newFileDto(newProjectDto(organizationDto), null, FILE_2_ID).setKey("org.foo.File.java").setLongName("src/main/java/org/foo/File.java")));
    TestRequest request = ws.newRequest().setParam(TEST_ID, "test-uuid");
    assertJson(request.execute().getInput()).isSimilarTo(getClass().getResource("CoveredFilesActionTest/tests-covered-files.json"));
}
Also used : DbSession(org.sonar.db.DbSession) CoveredFileDoc(org.sonar.server.test.index.CoveredFileDoc) TestDoc(org.sonar.server.test.index.TestDoc) OrganizationDto(org.sonar.db.organization.OrganizationDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Aggregations

CoveredFileDoc (org.sonar.server.test.index.CoveredFileDoc)3 Test (org.junit.Test)2 DbSession (org.sonar.db.DbSession)2 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 TestDoc (org.sonar.server.test.index.TestDoc)2 ComponentDto (org.sonar.db.component.ComponentDto)1 TestRequest (org.sonar.server.ws.TestRequest)1 WsTests (org.sonarqube.ws.WsTests)1