Search in sources :

Example 11 with UseDataProvider

use of com.tngtech.java.junit.dataprovider.UseDataProvider in project riposte by Nike-Inc.

the class VerifyResponseHttpStatusCodeHandlingRfcCorrectnessComponentTest method verify_response_status_code_scenarios.

@Test
@UseDataProvider("responseStatusCodeScenariosDataProvider")
public void verify_response_status_code_scenarios(int desiredStatusCode, boolean shouldReturnEmptyPayload) {
    for (int i = 0; i < 3; i++) {
        // Run this scenario 3 times in quick succession to catch potential keep-alive connection pooling issues.
        logger.info("=== RUN " + i + " ===");
        String callId = UUID.randomUUID().toString();
        ExtractableResponse response = given().config(config().redirect(redirectConfig().followRedirects(false))).baseUri("http://localhost").port(edgeRouterServerConfig.endpointsPort()).basePath(BackendEndpoint.MATCHING_PATH).header(BackendEndpoint.DESIRED_RESPONSE_HTTP_STATUS_CODE_HEADER_KEY, String.valueOf(desiredStatusCode)).header(BackendEndpoint.SHOULD_RETURN_EMPTY_PAYLOAD_BODY_HEADER_KEY, String.valueOf(shouldReturnEmptyPayload)).header(BackendEndpoint.CALL_ID_REQUEST_HEADER_KEY, callId).when().get().then().extract();
        assertThat(response.statusCode()).isEqualTo(desiredStatusCode);
        assertThat(response.header(CALL_ID_RESPONSE_HEADER_KEY)).isEqualTo(callId);
        if (isContentAlwaysEmptyStatusCode(desiredStatusCode)) {
            assertThat(response.asString()).isNullOrEmpty();
            assertThat(response.header(CONTENT_LENGTH)).isEqualTo("0");
            assertThat(response.header(TRANSFER_ENCODING)).isNull();
        } else {
            assertThat(response.header(CONTENT_LENGTH)).isNull();
            assertThat(response.header(TRANSFER_ENCODING)).isEqualTo(CHUNKED);
            if (shouldReturnEmptyPayload)
                assertThat(response.asString()).isNullOrEmpty();
            else
                assertThat(response.asString()).isEqualTo(callId + BackendEndpoint.NON_EMPTY_PAYLOAD);
        }
        logger.info("=== END RUN " + i + " ===");
    }
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) Endpoint(com.nike.riposte.server.http.Endpoint) SimpleProxyRouterEndpoint(com.nike.riposte.server.http.impl.SimpleProxyRouterEndpoint) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 12 with UseDataProvider

use of com.tngtech.java.junit.dataprovider.UseDataProvider in project riposte by Nike-Inc.

the class MediaRangeTest method test_media_range_constructor_throws_exception_with_null_values.

/**
     * MediaRange constructor should throw an IllegalArgumentException when the type, subtype, or qualityFactor properties are null.
     * Additionally, the constructor should throw an IllegalArgumentException when the quality factor value is less than 0 or greater than 1.
     */
@Test
@UseDataProvider("nullMediaRangeConstructorTestSet")
public void test_media_range_constructor_throws_exception_with_null_values(final String expectedErrorMessage, final ThrowingCallable callable) {
    // when
    Throwable ex = catchThrowable(callable);
    // then
    assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith(expectedErrorMessage);
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 13 with UseDataProvider

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

the class PropertiesDaoTest method selectProjectProperties_supports_all_values.

@Test
@UseDataProvider("allValuesForSelect")
public void selectProjectProperties_supports_all_values(String dbValue, String expected) throws SQLException {
    ComponentDto projectDto = insertProject("A");
    insertProperty("project.one", dbValue, projectDto.getId(), null);
    List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.key());
    assertThat(dtos).hasSize(1);
    assertThatDto(dtos.iterator().next()).hasKey("project.one").hasResourceId(projectDto.getId()).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 14 with UseDataProvider

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

the class LogbackHelperTest method apply_accepts_any_level_as_hardcoded_level.

@Test
@UseDataProvider("logbackLevels")
public void apply_accepts_any_level_as_hardcoded_level(Level level) {
    LogLevelConfig config = LogLevelConfig.newBuilder().immutableLevel("bar", level).build();
    LoggerContext context = underTest.apply(config, props);
    assertThat(context.getLogger("bar").getLevel()).isEqualTo(level);
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 15 with UseDataProvider

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

the class ConditionToConditionTest method apply_converts_all_values_of_operator.

@Test
@UseDataProvider("allOperatorValues")
public void apply_converts_all_values_of_operator(Condition.Operator operator) {
    Condition condition = new Condition(newMetric(METRIC_KEY), operator.getDbValue(), ERROR_THRESHOLD, WARN_THRESHOLD, true);
    ConditionToCondition underTest = new ConditionToCondition(of(condition, SOME_CONDITION_STATUS));
    assertThat(underTest.apply(condition).getOperator().name()).isEqualTo(operator.name());
}
Also used : Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) 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