Search in sources :

Example 26 with UseDataProvider

use of com.tngtech.java.junit.dataprovider.UseDataProvider in project sonarqube by SonarSource.

the class LoadPeriodsStepTest method feed_period_by_version.

@Test
@UseDataProvider("projectAndViewRoots")
public void feed_period_by_version(Component root) {
    setupRoot(root);
    dbTester.prepareDbUnit(getClass(), "shared.xml");
    settings.setProperty("sonar.leak.period", "0.9");
    underTest.execute();
    // Analysis form 2008-11-11
    Period period = periodsHolder.getPeriod();
    assertThat(period).isNotNull();
    assertThat(period.getMode()).isEqualTo(LEAK_PERIOD_MODE_VERSION);
    assertThat(period.getModeParameter()).isEqualTo("0.9");
    assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
    assertThat(period.getAnalysisUuid()).isEqualTo("u1000");
    assertThat(logTester.logs()).hasSize(1);
    assertThat(logTester.logs().get(0)).startsWith("Compare to version (0.9) (");
}
Also used : Period(org.sonar.server.computation.task.projectanalysis.period.Period) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 27 with UseDataProvider

use of com.tngtech.java.junit.dataprovider.UseDataProvider in project sonarqube by SonarSource.

the class EvaluationResultTextConverterTest method evaluate_adds_only_period_if_metric_starts_with_new_prefix.

@Test
@UseDataProvider("all_operators_for_error_warning_levels")
public void evaluate_adds_only_period_if_metric_starts_with_new_prefix(Condition.Operator operator, Measure.Level level) {
    String metricMsg = "trololo_metric_msg";
    int periodIndex = 1;
    String periodLabel = "periodLabel";
    when(i18n.message(Locale.ENGLISH, "metric." + SOME_VARIATION_METRIC.getKey() + ".name", SOME_VARIATION_METRIC.getName())).thenReturn(metricMsg);
    Date date = new Date();
    Period period = new Period(SOME_MODE, null, date.getTime(), SOME_ANALYSIS_UUID);
    periodsHolder.setPeriod(period);
    when(periods.label(period.getMode(), period.getModeParameter(), date)).thenReturn(periodLabel);
    Condition condition = new Condition(SOME_VARIATION_METRIC, operator.getDbValue(), ERROR_THRESHOLD, WARNING_THRESHOLD, true);
    assertThat(underTest.asText(condition, new EvaluationResult(level, null))).isEqualTo(metricMsg + " " + toSign(operator) + " " + (getThreshold(level)) + " " + periodLabel);
}
Also used : Period(org.sonar.server.computation.task.projectanalysis.period.Period) Date(java.util.Date) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 28 with UseDataProvider

use of com.tngtech.java.junit.dataprovider.UseDataProvider in project sonarqube by SonarSource.

the class EvaluationResultTextConverterTest method evaluate_adds_variation_and_period_if_metric_does_not_starts_with_variation_prefix.

@Test
@UseDataProvider("all_operators_for_error_warning_levels")
public void evaluate_adds_variation_and_period_if_metric_does_not_starts_with_variation_prefix(Condition.Operator operator, Measure.Level level) {
    String metricMsg = "trololo_metric_msg";
    String variationMsg = "_variation_";
    int periodIndex = 1;
    String periodLabel = "periodLabel";
    when(i18n.message(Locale.ENGLISH, "metric." + INT_METRIC.getKey() + ".name", INT_METRIC.getName())).thenReturn(metricMsg);
    when(i18n.message(Locale.ENGLISH, "variation", "variation")).thenReturn(variationMsg);
    Date date = new Date();
    Period period = new Period(SOME_MODE, null, date.getTime(), SOME_ANALYSIS_UUID);
    periodsHolder.setPeriod(period);
    when(periods.label(period.getMode(), period.getModeParameter(), date)).thenReturn(periodLabel);
    Condition condition = new Condition(INT_METRIC, operator.getDbValue(), ERROR_THRESHOLD, WARNING_THRESHOLD, true);
    assertThat(underTest.asText(condition, new EvaluationResult(level, null))).isEqualTo(metricMsg + " " + variationMsg + " " + toSign(operator) + " " + (getThreshold(level)) + " " + periodLabel);
}
Also used : Period(org.sonar.server.computation.task.projectanalysis.period.Period) Date(java.util.Date) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 29 with UseDataProvider

use of com.tngtech.java.junit.dataprovider.UseDataProvider in project sonarqube by SonarSource.

the class PurgeDatastoresStepTest method do_not_call_purge_method_of_the_purge_task_for_other_report_components.

@Test
@UseDataProvider("nonRootProjectComponentTypes")
public void do_not_call_purge_method_of_the_purge_task_for_other_report_components(Component.Type type) {
    Component component = ReportComponent.builder(type, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).build();
    verify_do_not_call_purge_method_of_the_purge_task(component);
}
Also used : ViewsComponent(org.sonar.server.computation.task.projectanalysis.component.ViewsComponent) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 30 with UseDataProvider

use of com.tngtech.java.junit.dataprovider.UseDataProvider in project sonarqube by SonarSource.

the class DbMigrationStatusActionTest method defensive_test_all_values_of_Status_must_be_supported.

// this test will raise a IllegalArgumentException when an unsupported value is added to the Status enum
@Test
@UseDataProvider("statusRequiringDbMigration")
public void defensive_test_all_values_of_Status_must_be_supported(DatabaseVersion.Status status) throws Exception {
    when(databaseVersion.getStatus()).thenReturn(status);
    for (Status migrationStatus : filter(Arrays.asList(DatabaseMigrationState.Status.values()), not(in(ImmutableList.of(NONE, RUNNING, FAILED, SUCCEEDED))))) {
        when(migrationState.getStatus()).thenReturn(migrationStatus);
        underTest.handle(request, response);
    }
}
Also used : Status(org.sonar.server.platform.db.migration.DatabaseMigrationState.Status) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)32 Test (org.junit.Test)32 Period (org.sonar.server.computation.task.projectanalysis.period.Period)8 Component (org.sonar.server.computation.task.projectanalysis.component.Component)5 ReportComponent (org.sonar.server.computation.task.projectanalysis.component.ReportComponent)4 MeasureDto (org.sonar.db.measure.MeasureDto)3 PropertyTesting.newComponentPropertyDto (org.sonar.db.property.PropertyTesting.newComponentPropertyDto)3 PropertyTesting.newGlobalPropertyDto (org.sonar.db.property.PropertyTesting.newGlobalPropertyDto)3 PropertyTesting.newUserPropertyDto (org.sonar.db.property.PropertyTesting.newUserPropertyDto)3 Date (java.util.Date)2 InOrder (org.mockito.InOrder)2 PostProjectAnalysisTask (org.sonar.api.ce.posttask.PostProjectAnalysisTask)2 ComponentDto (org.sonar.db.component.ComponentDto)2 ViewsComponent (org.sonar.server.computation.task.projectanalysis.component.ViewsComponent)2 Metric (org.sonar.server.computation.task.projectanalysis.metric.Metric)2 MetricImpl (org.sonar.server.computation.task.projectanalysis.metric.MetricImpl)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)1 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)1 Endpoint (com.nike.riposte.server.http.Endpoint)1