Skip to content

Commit

Permalink
Refactor comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
PasinduYeshan committed Sep 6, 2023
1 parent 18d4d52 commit 053e760
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public abstract class AbstractHTTPFunction {
protected static final String TYPE_APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";
protected static final String TYPE_TEXT_PLAIN = "text/plain";
private static final char DOMAIN_SEPARATOR = '.';
private static final String RESPONSE = "response";
private final List<String> allowedDomains;

private CloseableHttpClient client;
Expand Down Expand Up @@ -101,7 +102,7 @@ protected void executeHttpMethod(HttpUriRequest request, Map<String, Object> eve
if (contentType != null && contentType.getValue().contains(TYPE_TEXT_PLAIN)) {
// For 'text/plain', put the response body into the JSON object as a single field.
json = new JSONObject();
json.put("response", jsonString);
json.put(RESPONSE, jsonString);
} else {
JSONParser parser = new JSONParser();
json = (JSONObject) parser.parse(jsonString);
Expand Down Expand Up @@ -188,8 +189,10 @@ private String getParentDomainFromUrl(URI url) {
}

/**
* Validate the headers and return a Map<String, String> of headers.
* Validate the headers.
*
* @param headers Map of headers.
* @return Map of headers.
*/
protected Map<String, String> validateHeaders(Map<String, ?> headers) {

Expand All @@ -204,6 +207,7 @@ protected Map<String, String> validateHeaders(Map<String, ?> headers) {
/**
* Set headers to the request.
* Default Accept header is set to application/json.
*
* @param request HttpUriRequest.
* @param headers Map of headers.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public void httpPost(String endpointURL, Object... params) {

if (MapUtils.isNotEmpty(payloadData)) {
/*
* For the header "Content-Type : application/x-www-form-urlencoded" request body data is set to
* UrlEncodedFormEntity format. For the other cases request body data is set to StringEntity format.
For the header "Content-Type : application/x-www-form-urlencoded" request body data is set to
UrlEncodedFormEntity format. For the other cases request body data is set to StringEntity format.
*/
if (TYPE_APPLICATION_FORM_URLENCODED.equals(headers.get(CONTENT_TYPE))) {
List<NameValuePair> entities = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void testHttpGetMethodUrlValidation() throws JsTestException, NoSuchField
/**
* Test http get method with headers.
* Check if the headers are sent with the request.
*
* @throws JsTestException
*/
@Test
Expand All @@ -142,6 +143,7 @@ public void testHttpGetMethodWithHeaders() throws JsTestException {

/**
* Tests the behavior of the httpGet function when provided with null headers.
*
* @throws IllegalArgumentException if the provided arguments are not valid.
*/
@Test(expectedExceptions = IllegalArgumentException.class)
Expand All @@ -152,6 +154,7 @@ public void testHttpGetWithNullHeaders() {

/**
* Tests the behavior of the httpGet function when invalid number of arguments are provided.
*
* @throws IllegalArgumentException if the provided arguments are not valid.
*/
@Test(expectedExceptions = IllegalArgumentException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public void testHttpPostMethodUrlValidation() throws JsTestException, NoSuchFiel
/**
* Test httpPost with headers.
* Check if the headers are sent with the request.
*
* @throws JsTestException
*/
@Test
Expand All @@ -143,6 +144,7 @@ public void testHttpPostWithHeaders() throws JsTestException {

/**
* Tests the behavior of the httpPost function when provided with null headers.
*
* @throws IllegalArgumentException if the provided arguments are not valid.
*/
@Test(expectedExceptions = IllegalArgumentException.class)
Expand All @@ -155,6 +157,7 @@ public void testHttpPostWithNullHeaders() {

/**
* Tests the behavior of the httpPost function when provided with invalid number of arguments.
*
* @throws IllegalArgumentException if the provided arguments are not valid.
*/
@Test(expectedExceptions = IllegalArgumentException.class)
Expand Down

0 comments on commit 053e760

Please sign in to comment.