use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ComponentTreeActionTest method load_developer_measures_by_developer_uuid.
@Test
public void load_developer_measures_by_developer_uuid() {
ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid");
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key");
componentDb.insertDeveloperAndSnapshot(developer);
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file1-uuid"));
ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null, "file2-uuid"));
componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer));
MetricDto ncloc = insertNclocMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, project, projectSnapshot).setDeveloperId(developer.getId()), newMeasureDto(ncloc, file1, projectSnapshot).setValue(3d).setDeveloperId(developer.getId()), // measures are not specific to the developer
newMeasureDto(ncloc, file1, projectSnapshot).setDeveloperId(null), newMeasureDto(ncloc, file2, projectSnapshot).setDeveloperId(null));
db.commit();
ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(PARAM_DEVELOPER_ID, "developer-uuid").setParam(PARAM_STRATEGY, CHILDREN_STRATEGY).setParam(PARAM_METRIC_KEYS, "ncloc"));
assertThat(response.getComponentsCount()).isEqualTo(2);
WsMeasures.Component file = response.getComponents(0);
assertThat(file.getId()).isEqualTo("file1-uuid");
assertThat(file.getMeasuresCount()).isEqualTo(1);
assertThat(file.getMeasures(0).getValue()).isEqualTo("3");
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ComponentTreeActionTest method insertJsonExampleData.
private void insertJsonExampleData() {
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-id").setKey("MY_PROJECT").setName("My Project").setQualifier(Qualifiers.PROJECT);
componentDb.insertComponent(project);
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()).setPeriodMode("previous_version").setPeriodParam("1.0-SNAPSHOT"));
ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null).setUuid("AVIwDXE-bJbJqrw6wFv5").setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java").setName("ElementImpl.java").setLanguage("java").setQualifier(Qualifiers.FILE).setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"));
ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null).setUuid("AVIwDXE_bJbJqrw6wFwJ").setKey("com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java").setName("ElementImplTest.java").setLanguage("java").setQualifier(Qualifiers.UNIT_TEST_FILE).setPath("src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java"));
ComponentDto dir = componentDb.insertComponent(newDirectory(project, "src/main/java/com/sonarsource/markdown/impl").setUuid("AVIwDXE-bJbJqrw6wFv8").setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl").setQualifier(Qualifiers.DIRECTORY));
MetricDto complexity = insertComplexityMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, file1, projectSnapshot).setValue(12.0d), newMeasureDto(complexity, dir, projectSnapshot).setValue(35.0d).setVariation(0.0d), newMeasureDto(complexity, project, projectSnapshot).setValue(42.0d));
MetricDto ncloc = insertNclocMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file1, projectSnapshot).setValue(114.0d), newMeasureDto(ncloc, dir, projectSnapshot).setValue(217.0d).setVariation(0.0d), newMeasureDto(ncloc, project, projectSnapshot).setValue(1984.0d));
MetricDto newViolations = insertNewViolationsMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(newViolations, file1, projectSnapshot).setVariation(25.0d), newMeasureDto(newViolations, dir, projectSnapshot).setVariation(25.0d), newMeasureDto(newViolations, project, projectSnapshot).setVariation(255.0d));
db.commit();
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ProjectMeasuresIndexerTest method update_existing_document_when_indexing_one_project.
@Test
public void update_existing_document_when_indexing_one_project() throws Exception {
String uuid = "PROJECT-UUID";
esTester.putDocuments(INDEX_TYPE_PROJECT_MEASURES, new ProjectMeasuresDoc().setId(uuid).setKey("Old Key").setName("Old Name").setTags(singletonList("old tag")).setAnalysedAt(new Date(1_000_000L)));
ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), uuid).setKey("New key").setName("New name").setTagsString("new tag");
SnapshotDto analysis = componentDbTester.insertProjectAndSnapshot(project);
underTest.indexProject(project.uuid(), ProjectIndexer.Cause.NEW_ANALYSIS);
assertThat(esTester.getIds(INDEX_TYPE_PROJECT_MEASURES)).containsOnly(uuid);
SearchRequestBuilder request = esTester.client().prepareSearch(INDEX_TYPE_PROJECT_MEASURES).setQuery(boolQuery().must(matchAllQuery()).filter(boolQuery().must(termQuery("_id", uuid)).must(termQuery(FIELD_KEY, "New key")).must(termQuery(FIELD_NAME, "New name")).must(termQuery(FIELD_TAGS, "new tag")).must(termQuery(FIELD_ANALYSED_AT, new Date(analysis.getCreatedAt())))));
assertThat(request.get().getHits()).hasSize(1);
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ComponentActionTest method insertJsonExampleData.
private void insertJsonExampleData() {
ComponentDto project = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID);
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project).setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()).setPeriodMode("previous_version").setPeriodParam("1.0-SNAPSHOT");
ComponentDto file = newFileDto(project, null).setUuid("AVIwDXE-bJbJqrw6wFv5").setKey("MY_PROJECT:ElementImpl.java").setName("ElementImpl.java").setQualifier(Qualifiers.FILE).setLanguage("java").setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java");
componentDb.insertComponents(project, file);
dbClient.snapshotDao().insert(dbSession, projectSnapshot);
MetricDto complexity = insertComplexityMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, file, projectSnapshot).setValue(12.0d).setVariation(2.0d));
MetricDto ncloc = insertNclocMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file, projectSnapshot).setValue(114.0d).setVariation(3.0d));
MetricDto newViolations = insertNewViolationMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(newViolations, file, projectSnapshot).setVariation(25.0d));
db.commit();
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class SearchActionTest method return_measures_on_leak_period.
@Test
public void return_measures_on_leak_period() throws Exception {
ComponentDto project = newProjectDto(db.organizations().insert());
SnapshotDto projectSnapshot = db.components().insertProjectAndSnapshot(project);
setBrowsePermissionOnUser(project);
MetricDto coverage = insertCoverageMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, project, projectSnapshot).setValue(15.5d).setVariation(10d));
db.commit();
SearchWsResponse result = call(singletonList(project.key()), singletonList("coverage"));
List<Measure> measures = result.getMeasuresList();
assertThat(measures).hasSize(1);
Measure measure = measures.get(0);
assertThat(measure.getMetric()).isEqualTo("coverage");
assertThat(measure.getValue()).isEqualTo("15.5");
assertThat(measure.getPeriods().getPeriodsValueList()).extracting(WsMeasures.PeriodValue::getIndex, WsMeasures.PeriodValue::getValue).containsOnly(tuple(1, "10.0"));
}
Aggregations