Search in sources :

Example 1 with RestAssuredConfig

use of io.restassured.config.RestAssuredConfig in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method configurations_are_merged.

@Test
public void configurations_are_merged() {
    // Given
    RestAssuredMockMvcConfig cfg1 = new RestAssuredMockMvcConfig().with().jsonConfig(jsonConfig().with().numberReturnType(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE));
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setConfig(cfg1).build();
    // When
    RestAssuredMockMvcConfig cfg2 = new RestAssuredMockMvcConfig().sessionConfig(sessionConfig().sessionIdName("php"));
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().config(cfg2).spec(specToMerge);
    // Then
    RestAssuredConfig mergedConfig = implOf(spec).getRestAssuredConfig();
    assertThat(mergedConfig.getSessionConfig().sessionIdName()).isEqualTo("php");
    assertThat(mergedConfig.getJsonConfig().numberReturnType()).isEqualTo(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE);
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) RestAssuredMockMvcConfig(io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) RestAssuredConfig(io.restassured.config.RestAssuredConfig) Test(org.junit.Test)

Example 2 with RestAssuredConfig

use of io.restassured.config.RestAssuredConfig in project rest-assured by rest-assured.

the class RequestSpecBuilder method log.

/**
 * Enabled logging with the specified log detail. Set a {@link LogConfig} to configure the print stream and pretty printing options.
 *
 * @param logDetail The log detail.
 * @return RequestSpecBuilder
 */
public RequestSpecBuilder log(LogDetail logDetail) {
    notNull(logDetail, LogDetail.class);
    RestAssuredConfig restAssuredConfig = spec.getConfig();
    LogConfig logConfig;
    if (restAssuredConfig == null) {
        logConfig = new RestAssuredConfig().getLogConfig();
    } else {
        logConfig = restAssuredConfig.getLogConfig();
    }
    PrintStream printStream = logConfig.defaultStream();
    boolean prettyPrintingEnabled = logConfig.isPrettyPrintingEnabled();
    boolean shouldUrlEncodeRequestUri = logConfig.shouldUrlEncodeRequestUri();
    spec.filter(new RequestLoggingFilter(logDetail, prettyPrintingEnabled, printStream, shouldUrlEncodeRequestUri));
    return this;
}
Also used : PrintStream(java.io.PrintStream) RestAssuredConfig(io.restassured.config.RestAssuredConfig) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) LogConfig(io.restassured.config.LogConfig)

Example 3 with RestAssuredConfig

use of io.restassured.config.RestAssuredConfig in project rest-assured by rest-assured.

the class DecoderConfigITest method filters_can_change_content_decoders.

@Test
public void filters_can_change_content_decoders() {
    given().config(RestAssuredConfig.newConfig().decoderConfig(DecoderConfig.decoderConfig().contentDecoders(DecoderConfig.ContentDecoder.GZIP, DecoderConfig.ContentDecoder.DEFLATE))).filter((requestSpec, responseSpec, ctx) -> {
        final RestAssuredConfig config1 = requestSpec.getConfig();
        assertThat(config1.getDecoderConfig().contentDecoders(), Matchers.contains(DecoderConfig.ContentDecoder.GZIP, DecoderConfig.ContentDecoder.DEFLATE));
        requestSpec.config(config1.decoderConfig(new DecoderConfig(DecoderConfig.ContentDecoder.DEFLATE)));
        return ctx.next(requestSpec, responseSpec);
    }).expect().body("Accept-Encoding", contains("deflate")).when().get("/headersWithValues");
}
Also used : RestAssuredConfig(io.restassured.config.RestAssuredConfig) DecoderConfig(io.restassured.config.DecoderConfig) Test(org.junit.Test)

Aggregations

RestAssuredConfig (io.restassured.config.RestAssuredConfig)3 Test (org.junit.Test)2 DecoderConfig (io.restassured.config.DecoderConfig)1 LogConfig (io.restassured.config.LogConfig)1 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)1 RestAssuredMockMvcConfig (io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig)1 MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)1 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)1 PrintStream (java.io.PrintStream)1