Search in sources :

Example 1 with TestDoc

use of org.sonar.server.test.index.TestDoc 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 TestDoc

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

the class ListAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String testUuid = request.param(TEST_ID);
    String testFileUuid = request.param(TEST_FILE_ID);
    String testFileKey = request.param(TEST_FILE_KEY);
    String sourceFileUuid = request.param(SOURCE_FILE_ID);
    String sourceFileKey = request.param(SOURCE_FILE_KEY);
    Integer sourceFileLineNumber = request.paramAsInt(SOURCE_FILE_LINE_NUMBER);
    SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(WebService.Param.PAGE), request.mandatoryParamAsInt(WebService.Param.PAGE_SIZE));
    SearchResult<TestDoc> tests;
    Map<String, ComponentDto> componentsByTestFileUuid;
    try (DbSession dbSession = dbClient.openSession(false)) {
        tests = searchTests(dbSession, testUuid, testFileUuid, testFileKey, sourceFileUuid, sourceFileKey, sourceFileLineNumber, searchOptions);
        componentsByTestFileUuid = buildComponentsByTestFileUuid(dbSession, tests.getDocs());
    }
    WsTests.ListResponse.Builder responseBuilder = WsTests.ListResponse.newBuilder();
    responseBuilder.setPaging(Common.Paging.newBuilder().setPageIndex(searchOptions.getPage()).setPageSize(searchOptions.getLimit()).setTotal((int) tests.getTotal()).build());
    for (TestDoc testDoc : tests.getDocs()) {
        WsTests.Test.Builder testBuilder = WsTests.Test.newBuilder();
        testBuilder.setId(testDoc.testUuid());
        testBuilder.setName(StringUtils.defaultString(testDoc.name()));
        testBuilder.setFileId(testDoc.fileUuid());
        ComponentDto component = componentsByTestFileUuid.get(testDoc.fileUuid());
        if (component != null) {
            testBuilder.setFileKey(component.getKey());
            testBuilder.setFileName(component.longName());
        }
        testBuilder.setStatus(WsTests.TestStatus.valueOf(testDoc.status()));
        if (testDoc.durationInMs() != null) {
            testBuilder.setDurationInMs(testDoc.durationInMs());
        }
        testBuilder.setCoveredLines(coveredLines(testDoc.coveredFiles()));
        if (testDoc.message() != null) {
            testBuilder.setMessage(testDoc.message());
        }
        if (testDoc.stackTrace() != null) {
            testBuilder.setStacktrace(testDoc.stackTrace());
        }
        responseBuilder.addTests(testBuilder.build());
    }
    WsUtils.writeProtobuf(responseBuilder.build(), request, response);
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) TestDoc(org.sonar.server.test.index.TestDoc) SearchOptions(org.sonar.server.es.SearchOptions)

Example 3 with TestDoc

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

the class ListAction method searchTestsByTestUuid.

private SearchResult<TestDoc> searchTestsByTestUuid(DbSession dbSession, String testUuid, SearchOptions searchOptions) {
    TestDoc testDoc = checkFoundWithOptional(testIndex.getNullableByTestUuid(testUuid), "Test with id '%s' is not found", testUuid);
    checkComponentUuidPermission(dbSession, testDoc.fileUuid());
    return testIndex.searchByTestUuid(testUuid, searchOptions);
}
Also used : TestDoc(org.sonar.server.test.index.TestDoc)

Example 4 with TestDoc

use of org.sonar.server.test.index.TestDoc 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

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