Search in sources :

Example 1 with UseDataProvider

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

the class PropertiesDaoTest method selectEnabledDescendantModuleProperties_supports_all_values.

@Test
@UseDataProvider("allValuesForSelect")
public void selectEnabledDescendantModuleProperties_supports_all_values(String dbValue, String expected) throws SQLException {
    String projectUuid = "A";
    ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid);
    dbClient.componentDao().insert(session, project);
    long projectId = project.getId();
    insertProperty("project.one", dbValue, projectId, null);
    List<PropertyDto> dtos = underTest.selectEnabledDescendantModuleProperties(projectUuid, dbTester.getSession());
    assertThat(dtos).hasSize(1);
    assertThatDto(dtos.iterator().next()).hasKey("project.one").hasResourceId(projectId).hasNoUserId().hasValue(expected);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) PropertyTesting.newUserPropertyDto(org.sonar.db.property.PropertyTesting.newUserPropertyDto) PropertyTesting.newComponentPropertyDto(org.sonar.db.property.PropertyTesting.newComponentPropertyDto) PropertyTesting.newGlobalPropertyDto(org.sonar.db.property.PropertyTesting.newGlobalPropertyDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 2 with UseDataProvider

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

the class PropertiesDaoTest method saveProperty_deletes_then_inserts_global_properties_when_they_exist_in_db.

@Test
@UseDataProvider("valueUpdatesDataProvider")
public void saveProperty_deletes_then_inserts_global_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) throws SQLException {
    long id = insertProperty("global", oldValue, null, null, DATE_1);
    when(system2.now()).thenReturn(DATE_4);
    underTest.saveProperty(new PropertyDto().setKey("global").setValue(newValue));
    assertThatPropertiesRow(id).doesNotExist();
    PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global").hasNoResourceId().hasNoUserId().hasCreatedAt(DATE_4);
    if (newValue == null || newValue.isEmpty()) {
        propertiesRowAssert.isEmpty();
    } else if (newValue.length() > 4000) {
        propertiesRowAssert.hasClobValue(newValue);
    } else {
        propertiesRowAssert.hasTextValue(newValue);
    }
}
Also used : PropertyTesting.newUserPropertyDto(org.sonar.db.property.PropertyTesting.newUserPropertyDto) PropertyTesting.newComponentPropertyDto(org.sonar.db.property.PropertyTesting.newComponentPropertyDto) PropertyTesting.newGlobalPropertyDto(org.sonar.db.property.PropertyTesting.newGlobalPropertyDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 3 with UseDataProvider

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

the class PostProjectAnalysisTasksExecutorTest method finished_does_not_fail_if_listener_throws_exception_and_execute_subsequent_listeners.

@Test
@UseDataProvider("booleanValues")
public void finished_does_not_fail_if_listener_throws_exception_and_execute_subsequent_listeners(boolean allStepsExecuted) {
    PostProjectAnalysisTask postProjectAnalysisTask1 = mock(PostProjectAnalysisTask.class);
    PostProjectAnalysisTask postProjectAnalysisTask2 = mock(PostProjectAnalysisTask.class);
    PostProjectAnalysisTask postProjectAnalysisTask3 = mock(PostProjectAnalysisTask.class);
    InOrder inOrder = inOrder(postProjectAnalysisTask1, postProjectAnalysisTask2, postProjectAnalysisTask3);
    doThrow(new RuntimeException("Faking a listener throws an exception")).when(postProjectAnalysisTask2).finished(any(PostProjectAnalysisTask.ProjectAnalysis.class));
    new PostProjectAnalysisTasksExecutor(ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, system2, new PostProjectAnalysisTask[] { postProjectAnalysisTask1, postProjectAnalysisTask2, postProjectAnalysisTask3 }).finished(allStepsExecuted);
    inOrder.verify(postProjectAnalysisTask1).finished(projectAnalysisArgumentCaptor.capture());
    inOrder.verify(postProjectAnalysisTask2).finished(projectAnalysisArgumentCaptor.capture());
    inOrder.verify(postProjectAnalysisTask3).finished(projectAnalysisArgumentCaptor.capture());
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) PostProjectAnalysisTask(org.sonar.api.ce.posttask.PostProjectAnalysisTask) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with UseDataProvider

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

the class DuplicationRepositoryImplTest method addDuplication_inner_throws_IAE_if_file_type_is_not_FILE.

@Test
@UseDataProvider("allComponentTypesButFile")
public void addDuplication_inner_throws_IAE_if_file_type_is_not_FILE(Component.Type type) {
    expectFileTypeIAE();
    Component component = mockComponentGetType(type);
    underTest.add(component, SOME_DUPLICATION);
}
Also used : 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 5 with UseDataProvider

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

the class MeasureRepositoryImplTest method update_throws_IAE_if_valueType_of_Measure_is_not_the_same_as_the_Metric_valueType_unless_NO_VALUE.

@Test
@UseDataProvider("measures")
public void update_throws_IAE_if_valueType_of_Measure_is_not_the_same_as_the_Metric_valueType_unless_NO_VALUE(Measure measure) {
    for (Metric.MetricType metricType : Metric.MetricType.values()) {
        if (metricType.getValueType() == measure.getValueType() || measure.getValueType() == Measure.ValueType.NO_VALUE) {
            continue;
        }
        try {
            final MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
            underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
            underTest.update(FILE_COMPONENT, metric, measure);
            fail("An IllegalArgumentException should have been raised");
        } catch (IllegalArgumentException e) {
            assertThat(e).hasMessage(format("Measure's ValueType (%s) is not consistent with the Metric's ValueType (%s)", measure.getValueType(), metricType.getValueType()));
        }
    }
}
Also used : MetricImpl(org.sonar.server.computation.task.projectanalysis.metric.MetricImpl) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) 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