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);
}
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();
}
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"));
}
Aggregations