Skip to content

Commit

Permalink
refs: #10760
Browse files Browse the repository at this point in the history
  • Loading branch information
fp-ps committed Mar 4, 2021
1 parent eba2534 commit 6738608
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.adempiere.exceptions.AdempiereException;
import org.compiere.util.TimeUtil;

import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.Instant;
Expand Down Expand Up @@ -206,4 +207,12 @@ public String extractStringForIndex(final List<String> dataTableRow, final int i
return string;
}

@Nullable
public String extractValueOrNull(@Nullable final String value)
{
if (value == null || value.equals("null"))
return null;

return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package de.metas.cucumber.stepdefs;

import de.metas.common.util.CoalesceUtil;
import de.metas.security.IRoleDAO;
import de.metas.security.Role;
import de.metas.user.UserId;
Expand Down Expand Up @@ -80,7 +81,9 @@ public String getAuthToken(@NonNull final String userLogin, @NonNull final Strin

public APIResponse performHTTPRequest(final String endpointPath,
final String verb,
final @Nullable String payload, final String authToken) throws IOException
final String payload,
final String authToken,
@Nullable final Integer statusCode) throws IOException
{
final CloseableHttpClient httpClient = HttpClients.createDefault();

Expand All @@ -101,13 +104,14 @@ public APIResponse performHTTPRequest(final String endpointPath,
}

setHeaders(request, authToken);
if(payload != null){
if (payload != null)
{
final StringEntity entity = new StringEntity(payload);
request.setEntity(entity);
}

final HttpResponse response = httpClient.execute(request);
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(CoalesceUtil.coalesce(statusCode, 200));

final Header contentType = response.getEntity().getContentType();
final APIResponse.APIResponseBuilder apiResponseBuilder = APIResponse.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,19 @@ public void metasfresh_rest_api_endpoint_api_external_ref_receives_get_request_w
{
testContext.setRequestPayload(payload);

apiResponse = RESTUtil.performHTTPRequest(endpointPath, verb, payload, userAuthToken);
apiResponse = RESTUtil.performHTTPRequest(endpointPath, verb, payload, userAuthToken, null);
testContext.setApiResponse(apiResponse);
}

@When("the metasfresh REST-API endpoint path {string} receives a {string} request with the payload from context and responds with {string} status code")
public void metasfresh_rest_api_endpoint_api_external_ref_receives_get_request_with_the_payload_from_context(
final String endpointPath,
final String verb,
final String statusCode) throws IOException
{
final String payload = testContext.getRequestPayload();

apiResponse = RESTUtil.performHTTPRequest(endpointPath, verb, payload, userAuthToken, Integer.parseInt(statusCode));
testContext.setApiResponse(apiResponse);
}

Expand All @@ -68,7 +80,7 @@ public void metasfresh_rest_api_endpoint_api_external_ref_receives_get_request_w
final String endpointPath,
final String verb) throws IOException
{
apiResponse = RESTUtil.performHTTPRequest(endpointPath, verb, null, userAuthToken);
apiResponse = RESTUtil.performHTTPRequest(endpointPath, verb, null, userAuthToken, null);
testContext.setApiResponse(apiResponse);
}

Expand Down

0 comments on commit 6738608

Please sign in to comment.