Search in sources :

Example 1 with Jackson2ObjectMapperFactory

use of io.restassured.mapper.factory.Jackson2ObjectMapperFactory in project snow-owl by b2ihealthcare.

the class RestExtensions method givenUnauthenticatedRequest.

public static RequestSpecification givenUnauthenticatedRequest(String api) {
    if (INITIALIZE_ONCE.compareAndSet(false, true)) {
        // change Base URI if defined as sysarg
        final String serverLocation = System.getProperty("test.server.location");
        if (!Strings.isNullOrEmpty(serverLocation)) {
            RestAssured.baseURI = serverLocation;
        }
        RestAssured.config = RestAssuredConfig.config().objectMapperConfig(ObjectMapperConfig.objectMapperConfig().jackson2ObjectMapperFactory(new Jackson2ObjectMapperFactory() {

            @Override
            public com.fasterxml.jackson.databind.ObjectMapper create(Type arg0, String arg1) {
                com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
                mapper.registerModule(new JavaTimeModule());
                // bbanfai: added date format
                final StdDateFormat dateFormat = new StdDateFormat();
                dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
                mapper.setDateFormat(dateFormat);
                mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
                return mapper;
            }
        })).logConfig(LogConfig.logConfig().enableLoggingOfRequestAndResponseIfValidationFails());
    }
    Preconditions.checkArgument(api.startsWith("/"), "Api param should start with a forward slash: '/'");
    return given().port(getPort()).basePath(CONTEXT + api);
}
Also used : ContentType(io.restassured.http.ContentType) Type(java.lang.reflect.Type) Jackson2ObjectMapperFactory(io.restassured.mapper.factory.Jackson2ObjectMapperFactory) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) StdDateFormat(com.fasterxml.jackson.databind.util.StdDateFormat)

Aggregations

StdDateFormat (com.fasterxml.jackson.databind.util.StdDateFormat)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 ContentType (io.restassured.http.ContentType)1 Jackson2ObjectMapperFactory (io.restassured.mapper.factory.Jackson2ObjectMapperFactory)1 Type (java.lang.reflect.Type)1