diff --git a/src/main/java/org/hisp/dhis/actions/RestApiActions.java b/src/main/java/org/hisp/dhis/actions/RestApiActions.java index 6d34d42..8ffebc0 100644 --- a/src/main/java/org/hisp/dhis/actions/RestApiActions.java +++ b/src/main/java/org/hisp/dhis/actions/RestApiActions.java @@ -28,18 +28,15 @@ package org.hisp.dhis.actions; -import java.io.File; - -import org.hamcrest.Matchers; -import org.hisp.dhis.request.QueryParamsBuilder; -import org.hisp.dhis.response.dto.ApiResponse; - import io.restassured.RestAssured; -import io.restassured.config.ObjectMapperConfig; import io.restassured.http.ContentType; import io.restassured.mapper.ObjectMapperType; -import io.restassured.response.Response; import io.restassured.specification.RequestSpecification; +import org.hamcrest.Matchers; +import org.hisp.dhis.request.QueryParamsBuilder; +import org.hisp.dhis.response.dto.ApiResponse; + +import java.io.File; /** * @author Gintare Vilkelyte @@ -108,13 +105,11 @@ public ApiResponse post( String resource, String contentType, Object object, Que { String path = queryParams == null ? "" : queryParams.build(); - Response response = this.given() + return new ApiResponse( this.given() .body( object ) .contentType( contentType ) .when() - .post( resource + path ); - - return new ApiResponse( response ); + .post( resource + path ) ); } /** @@ -165,12 +160,10 @@ public ApiResponse get( String resourceId, QueryParamsBuilder queryParamsBuilder { String path = queryParamsBuilder == null ? "" : queryParamsBuilder.build(); - Response response = this.given() + return new ApiResponse( this.given() .contentType( ContentType.TEXT ) .when() - .get( resourceId + path ); - - return new ApiResponse( response ); + .get( resourceId + path ) ); } /** @@ -181,11 +174,9 @@ public ApiResponse get( String resourceId, QueryParamsBuilder queryParamsBuilder */ public ApiResponse delete( String path ) { - Response response = this.given() + return new ApiResponse( this.given() .when() - .delete( path ); - - return new ApiResponse( response ); + .delete( path ) ); } /** @@ -197,24 +188,18 @@ public ApiResponse delete( String path ) */ public ApiResponse update( String resourceId, Object object ) { - Response response = - this.given().body( object, ObjectMapperType.GSON ) - .when() - .put( resourceId ); - - return new ApiResponse( response ); + return new ApiResponse( this.given().body( object, ObjectMapperType.GSON ) + .when() + .put( resourceId ) ); } public ApiResponse update( String resourceId, Object object, String contentType ) { - Response response = - this.given() - .contentType( contentType ) - .body( object, ObjectMapperType.GSON ) - .when() - .put( resourceId ); - - return new ApiResponse( response ); + return new ApiResponse( this.given() + .contentType( contentType ) + .body( object, ObjectMapperType.GSON ) + .when() + .put( resourceId ) ); } public ApiResponse postFile( File file ) @@ -226,13 +211,10 @@ public ApiResponse postFile( File file, QueryParamsBuilder queryParamsBuilder ) { String url = queryParamsBuilder == null ? "" : queryParamsBuilder.build(); - ApiResponse response = new ApiResponse( this.given() + return new ApiResponse( this.given() .body( file ) .when() .post( url ) ); - - return response; - } }