static String measureValueDescription() { StringBuilder description = new StringBuilder("Measure value. Value type depends on metric type:"); description.append("<ul>"); for (Metric.ValueType metricType : Metric.ValueType.values()) { description.append("<li>"); description.append(String.format("%s - %s", metricType.name(), metricTypeWsDescription(metricType))); description.append("</li>"); } description.append("</ul>"); return description.toString(); }
@Test public void do_not_verify_permissions_if_user_is_root() { MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization()); db.measures().insertLiveMeasure(project1, metric, m -> m.setValue(15.5d)); userSession.setNonRoot(); SearchWsResponse result = call(singletonList(project1.getDbKey()), singletonList(metric.getKey())); assertThat(result.getMeasuresCount()).isEqualTo(0); userSession.setRoot(); result = call(singletonList(project1.getDbKey()), singletonList(metric.getKey())); assertThat(result.getMeasuresCount()).isEqualTo(1); }
@Test public void set_string_value() { underTest.setMeasureValue(customMeasure, "free-text-string", newMetricDto().setValueType(STRING.name())); assertThat(customMeasure.getTextValue()).isEqualTo("free-text-string"); }
@Test public void ignore_numeric_measure_that_has_text_value_but_not_numeric_value() { OrganizationDto organization = dbTester.organizations().insert(); MetricDto metric1 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("coverage")); MetricDto metric2 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc")); ComponentDto project = dbTester.components().insertPrivateProject(organization); dbTester.measures().insertLiveMeasure(project, metric1, m -> m.setValue(10d).setData((String) null)); dbTester.measures().insertLiveMeasure(project, metric2, m -> m.setValue(null).setData("foo")); Map<String, Double> numericMeasures = createResultSetAndReturnDocsById().get(project.uuid()).getMeasures().getNumericMeasures(); assertThat(numericMeasures).containsOnly(entry("coverage", 10d)); }
@Test public void return_language_distribution_measure() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPrivateProject(organization); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(DATA.name()).setKey("ncloc_language_distribution")); dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setData("<null>=2;java=6;xoo=18")); Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(); assertThat(docsById.get(project.uuid()).getMeasures().getNclocByLanguages()) .containsOnly(entry("<null>", 2), entry("java", 6), entry("xoo", 18)); }
@Test public void does_not_fail_when_quality_gate_has_no_value() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPrivateProject(organization); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(LEVEL.name()).setKey("alert_status")); dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setVariation(null).setData((String) null)); Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(); assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures()).isEmpty(); }
@Test public void return_project_measure_having_leak() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPrivateProject(organization, p -> p.setDbKey("Project-Key").setName("Project Name").setTagsString("platform,java")); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines")); dbTester.measures().insertLiveMeasure(project, metric, m -> m.setVariation(10d)); Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(); assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures()).containsOnly(entry("new_lines", 10d)); }
private MetricDto insertMetric() { return db.measures().insertMetric(m -> m.setValueType(INT.name()).setHidden(false).setDirection(0)); } }
@Test public void return_quality_gate_status_measure() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project1 = dbTester.components().insertPrivateProject(organization); ComponentDto project2 = dbTester.components().insertPrivateProject(organization); ComponentDto project3 = dbTester.components().insertPrivateProject(organization); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(LEVEL.name()).setKey("alert_status")); dbTester.measures().insertLiveMeasure(project2, metric, m -> m.setValue(null).setData(OK.name())); dbTester.measures().insertLiveMeasure(project3, metric, m -> m.setValue(null).setData(ERROR.name())); Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(); assertThat(docsById.get(project2.uuid()).getMeasures().getQualityGateStatus()).isEqualTo("OK"); assertThat(docsById.get(project3.uuid()).getMeasures().getQualityGateStatus()).isEqualTo("ERROR"); }
@Test @UseDataProvider("invalid_values") public void fail_to_create_error_INT_condition_when_value_is_not_an_integer(Metric.ValueType valueType, String value) { MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false).setDirection(0)); QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization()); expectedException.expect(BadRequestException.class); expectedException.expectMessage(format("Invalid value '%s' for metric '%s'", value, metric.getShortName())); underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "LT", value); }
@Test public void fail_when_non_compliant_level_value() { expectedException.expect(BadRequestException.class); underTest.setMeasureValue(customMeasure, "non-compliant-level-value", newMetricDto().setValueType(LEVEL.name())); }
@Test public void set_level_value() { underTest.setMeasureValue(customMeasure, ERROR.name(), newMetricDto().setValueType(LEVEL.name())); assertThat(customMeasure.getTextValue()).isEqualTo(ERROR.name()); }
@Before public void setUp() throws Exception { intMetric = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.INT.name())); ratingMetric = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.RATING.name())); alertStatusMetric = db.measures().insertMetric(m -> m.setKey(CoreMetrics.ALERT_STATUS_KEY)); organization = db.organizations().insert(); project = db.components().insertMainBranch(organization); dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java")); file1 = db.components().insertComponent(ComponentTesting.newFileDto(project, dir)); file2 = db.components().insertComponent(ComponentTesting.newFileDto(project, dir)); }
public static String[] names() { ValueType[] values = values(); String[] names = new String[values.length]; for (int i = 0; i < values.length; i += 1) { names[i] = values[i].name(); } return names; } }
private MetricDto insertMetric() { return db.measures().insertMetric(m -> m .setValueType(INT.name()) .setHidden(false) .setDirection(0)); } }
@Test public void does_not_return_disabled_metrics() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPrivateProject(organization); MetricDto disabledMetric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setEnabled(false).setHidden(false).setKey("disabled")); dbTester.measures().insertLiveMeasure(project, disabledMetric, m -> m.setValue(10d)); Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(); assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures()).isEmpty(); }
@Before public void setUp() { MetricDto stringMetricDto = db.measures().insertMetric(m -> m.setKey(STRING_METRIC.getKey()).setValueType(Metric.ValueType.STRING.name())); MetricDto intMetricDto = db.measures().insertMetric(m -> m.setKey(INT_METRIC.getKey()).setValueType(Metric.ValueType.INT.name())); MetricDto bestValueMMetricDto = db.measures() .insertMetric(m -> m.setKey(METRIC_WITH_BEST_VALUE.getKey()).setValueType(Metric.ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(0.0)); metricRepository.add(stringMetricDto.getId(), STRING_METRIC); metricRepository.add(intMetricDto.getId(), INT_METRIC); metricRepository.add(bestValueMMetricDto.getId(), METRIC_WITH_BEST_VALUE); }
@Test public void set_long_value() { underTest.setMeasureValue(customMeasure, "123456789", newMetricDto().setValueType(WORK_DUR.name())); assertThat(customMeasure.getValue()).isCloseTo(123456789d, defaultOffset()); }
@Test public void filter_projects_by_ncloc() { userSession.logIn(); OrganizationDto organizationDto = db.organizations().insert(); MetricDto ncloc = db.measures().insertMetric(c -> c.setKey(NCLOC).setValueType(INT.name())); ComponentDto project1 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(80d))); ComponentDto project2 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(85d))); ComponentDto project3 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(10d))); SearchProjectsWsResponse result = call(request.setFilter("ncloc <= 80")); assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey()); }
@Test public void non_main_branches_are_not_indexed() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPrivateProject(organization); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc")); dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(10d)); ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey("feature/foo")); dbTester.measures().insertLiveMeasure(branch, metric, m -> m.setValue(20d)); Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(); assertThat(docsById).hasSize(1).containsOnlyKeys(project.uuid()); assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures().get(metric.getKey())).isEqualTo(10d); }