Skip to content

Commit

Permalink
chore: improvements (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
vilkg authored Feb 17, 2021
1 parent f53c540 commit 0491828
Showing 1 changed file with 20 additions and 38 deletions.
58 changes: 20 additions & 38 deletions src/main/java/org/hisp/dhis/actions/RestApiActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vilkelyte.gintare@gmail.com>
Expand Down Expand Up @@ -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 ) );
}

/**
Expand Down Expand Up @@ -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 ) );
}

/**
Expand All @@ -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 ) );
}

/**
Expand All @@ -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 )
Expand All @@ -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;

}
}

0 comments on commit 0491828

Please sign in to comment.