Skip to content

Commit

Permalink
Merge pull request #14 from osandadeshan/fix
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
osandadeshan authored Jan 25, 2021
2 parents b6dabe9 + 55c177c commit 4666ebe
Show file tree
Hide file tree
Showing 31 changed files with 281 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tags: data_store, regression

## Get configurations of the testing environment

* Configurations of the testing environment
* Print configuration details of the testing environment


## Saving values to Data Store
Expand Down
56 changes: 56 additions & 0 deletions specs/other/GET API From Data Store 1.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Invoke GET API From Data Store With Authentication Specification

Project Name : MaxSoft-IntelliAPI
Developer : Osanda Deshan
Version : 1.0.0
Date : 1/20/2021
Time : 1:58 PM
Description : This is an executable specification file

tags: get_api, regression


|JSON Path|Expected Response Status Code|
|---------|-----------------------------|
|$[0].url |200 |
|$[1].url |200 |
|$[2].url |200 |
|$[3].url |200 |


## Invoke GET Request from a response's JSON Path value with authentication

* Given that a user needs to invoke "Get urls"
* And the user set the request authentication configurations as follows
|Configuration |Configuration Value|
|------------------------------------------------------------------|-------------------|
|Is authentication required? |Yes |
|Do you need to retrieve the access token from the text file? |Yes |
|Provide the access token if you need to authorize the API manually|N/A |
* And the user set the request headers using data stores as follows
|Header Name |Is Data Store Used?|Data Store Type|Data Store Variable Name|Header Value |
|-------------|-------------------|---------------|------------------------|-----------------------------------|
|App-Name |no | | |IntelliAPI |
|Organization |no | | |MaxSoft |
* When the user invokes the API
* Then the status code for the request is "200"
* And the JSON Path Assertions for the response should be equal to the values inside the data stores
|JSON Path |Is Data Store Used?|Data Store Type|Data Store Variable Name|Expected Value |
|--------------|-------------------|---------------|------------------------|------------------------------------------------|
|$[0].name |no | | |First photo |
|$[1].name |no | | |Second photo |
|$[3].name |no | | |Get all tasks with auth header |
* Given that a user needs to invoke a GET API from the JSON Path value <JSON Path>
* And the user set the request authentication configurations as follows
|Configuration |Configuration Value|
|------------------------------------------------------------------|-------------------|
|Is authentication required? |Yes |
|Do you need to retrieve the access token from the text file? |Yes |
|Provide the access token if you need to authorize the API manually|N/A |
* And the user set the request headers using data stores as follows
|Header Name |Is Data Store Used?|Data Store Type|Data Store Variable Name|Header Value |
|-------------|-------------------|---------------|------------------------|-----------------------------------|
|App-Name |no | | |IntelliAPI |
|Organization |no | | |MaxSoft |
* When the user invokes the GET API
* Then the status code for the request is <Expected Response Status Code>
45 changes: 45 additions & 0 deletions specs/other/GET API From Data Store 2.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Invoke GET API From Data Store Without Authentication Specification

Project Name : MaxSoft-IntelliAPI
Developer : Osanda Deshan
Version : 1.0.0
Date : 1/20/2021
Time : 1:58 PM
Description : This is an executable specification file

tags: get_api, regression


|JSON Path|Expected Response Status Code|
|---------|-----------------------------|
|$[0].url |200 |
|$[1].url |200 |
|$[2].url |200 |
|$[3].url |400 |


## Invoke GET Request from a response's JSON Path value without authentication

* Given that a user needs to invoke "Get urls"
* And the user set the request authentication configurations as follows
|Configuration |Configuration Value|
|------------------------------------------------------------------|-------------------|
|Is authentication required? |Yes |
|Do you need to retrieve the access token from the text file? |Yes |
|Provide the access token if you need to authorize the API manually|N/A |
* And the user set the request headers using data stores as follows
|Header Name |Is Data Store Used?|Data Store Type|Data Store Variable Name|Header Value |
|-------------|-------------------|---------------|------------------------|-----------------------------------|
|App-Name |no | | |IntelliAPI |
|Organization |no | | |MaxSoft |
* When the user invokes the API
* Then the status code for the request is "200"
* And the JSON Path Assertions for the response should be equal to the values inside the data stores
|JSON Path |Is Data Store Used?|Data Store Type|Data Store Variable Name|Expected Value |
|--------------|-------------------|---------------|------------------------|------------------------------------------------|
|$[0].name |no | | |First photo |
|$[1].name |no | | |Second photo |
|$[3].name |no | | |Get all tasks with auth header |
* Given that a user needs to invoke a GET API from the JSON Path value <JSON Path>
* When the user invokes the GET API
* Then the status code for the request is <Expected Response Status Code>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.maxsoft.intelliapi.common;
package com.maxsoft.intelliapi;

/**
* Project Name : MaxSoft-IntelliAPI
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.maxsoft.intelliapi.common;
package com.maxsoft.intelliapi;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.maxsoft.intelliapi.executionhooks;
package com.maxsoft.intelliapi;

import com.maxsoft.intelliapi.util.LogUtil;
import com.thoughtworks.gauge.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.maxsoft.intelliapi.common;
package com.maxsoft.intelliapi;

/**
* Project Name : MaxSoft-IntelliAPI
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/maxsoft/intelliapi/api/ApiInvoker.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.maxsoft.intelliapi.api;

import com.maxsoft.intelliapi.util.FrameworkUtil;
import com.maxsoft.intelliapi.common.BodyType;
import com.maxsoft.intelliapi.common.HttpMethod;
import com.maxsoft.intelliapi.BodyType;
import com.maxsoft.intelliapi.HttpMethod;
import io.restassured.http.Headers;

import java.security.InvalidParameterException;

import static com.maxsoft.intelliapi.api.ApiRequestPayload.getApiEndpointToBeInvoked;
import static com.maxsoft.intelliapi.api.FormDataHttpMethodsProcessor.postFormDataApiWithAuthMultipleHeaders;
import static com.maxsoft.intelliapi.api.FormDataHttpMethodsProcessor.putFormDataApiWithAuthMultipleHeaders;
import static com.maxsoft.intelliapi.api.JsonHttpMethodsProcessor.*;
import static com.maxsoft.intelliapi.common.BodyType.JSON;
import static com.maxsoft.intelliapi.common.Constants.*;
import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.getApiEndpointToBeInvoked;
import static com.maxsoft.intelliapi.api.FormDataRequestProcessor.postFormDataApiWithAuthMultipleHeaders;
import static com.maxsoft.intelliapi.api.FormDataRequestProcessor.putFormDataApiWithAuthMultipleHeaders;
import static com.maxsoft.intelliapi.api.JsonRequestProcessor.*;
import static com.maxsoft.intelliapi.BodyType.JSON;
import static com.maxsoft.intelliapi.Constants.*;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.*;

import static com.maxsoft.intelliapi.common.Constants.*;
import static com.maxsoft.intelliapi.Constants.*;
import static com.maxsoft.intelliapi.util.LogUtil.printInfo;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario;
import static com.maxsoft.intelliapi.util.reader.ApiDocumentReader.*;
Expand All @@ -20,7 +20,7 @@
* Description :
**/

public class ApiRequestPayload {
public class ApiRequestPayloadProcessor {

public static void initializeApiToBeInvoked(String apiEndpointName) {
setApiEndpoint(apiEndpointName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static com.maxsoft.intelliapi.common.Constants.*;
import static com.maxsoft.intelliapi.Constants.*;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.*;
import static com.maxsoft.intelliapi.util.LogUtil.printError;
import static com.maxsoft.intelliapi.util.LogUtil.printInfo;
Expand All @@ -30,7 +30,7 @@
* Description :
**/

public class ApiResponse {
public class ApiResponseProcessor {

public static void saveStatusCode(Response response) {
saveValueForScenario(VAR_API_RESPONSE_STATUS_CODE, String.valueOf(response.statusCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import java.util.Collections;
import java.util.Map;

import static com.maxsoft.intelliapi.api.ApiRequestPayload.getFormData;
import static com.maxsoft.intelliapi.api.ApiResponse.*;
import static com.maxsoft.intelliapi.common.Constants.*;
import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.getFormData;
import static com.maxsoft.intelliapi.api.ApiResponseProcessor.*;
import static com.maxsoft.intelliapi.Constants.*;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario;
import static io.restassured.RestAssured.given;
import static io.restassured.config.EncoderConfig.encoderConfig;
Expand All @@ -25,7 +25,7 @@
* Description :
**/

public class FormDataHttpMethodsProcessor {
public class FormDataRequestProcessor {

public static void postFormDataApiWithAuthMultipleHeaders(String invokingEndpoint, String accessToken, Headers headers) {
Response response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.restassured.http.Headers;
import io.restassured.response.Response;

import static com.maxsoft.intelliapi.api.ApiResponse.*;
import static com.maxsoft.intelliapi.common.Constants.AUTHORIZATION_HEADER_NAME;
import static com.maxsoft.intelliapi.api.ApiResponseProcessor.*;
import static com.maxsoft.intelliapi.Constants.AUTHORIZATION_HEADER_NAME;
import static io.restassured.RestAssured.given;

/**
Expand All @@ -17,7 +17,7 @@
* Description :
**/

public class JsonHttpMethodsProcessor {
public class JsonRequestProcessor {

public static void getApiWithAuthMultipleHeaders(String invokingEndpoint, String accessToken, Headers headers) {
Response response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import java.util.Collections;

import static com.maxsoft.intelliapi.common.Constants.*;
import static com.maxsoft.intelliapi.Constants.*;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.saveValueForScenario;
import static com.maxsoft.intelliapi.util.LogUtil.printInfo;
import static com.mongodb.client.model.Filters.eq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Collections;
import java.util.List;

import static com.maxsoft.intelliapi.common.Constants.*;
import static com.maxsoft.intelliapi.Constants.*;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.saveValueForScenario;
import static com.maxsoft.intelliapi.util.LogUtil.printError;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.maxsoft.intelliapi.stepimpl.api;

import com.maxsoft.intelliapi.api.ApiInvoker;
import com.thoughtworks.gauge.Step;
import io.restassured.http.Headers;

import static com.maxsoft.intelliapi.Constants.*;
import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.getHeaders;
import static com.maxsoft.intelliapi.api.JsonRequestProcessor.getApiWithAuthMultipleHeaders;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario;
import static com.maxsoft.intelliapi.util.FrameworkUtil.isTrue;
import static com.maxsoft.intelliapi.util.FrameworkUtil.readAccessToken;
import static com.maxsoft.intelliapi.util.LogUtil.printInfo;

/**
* Project Name : MaxSoft-IntelliAPI
* Developer : Osanda Deshan
* Version : 1.0.0
* Date : 1/20/2021
* Time : 6:21 PM
* Description :
**/

public class ApiRequestInvokerStepImpl {

/* Use this method when you need to pass the JSON request in previous step and the access token from the text file
into the GET/POST/PUT/DELETE API. The "saveRequestAuthConfigurations" must use before using this step */
@Step("When the user invokes the API")
public void invokeApi() {
String jsonRequest = String.valueOf(getSavedValueForScenario(VAR_API_JSON_REQUEST_BODY));
String headerNamesList = getSavedValueForScenario(VAR_API_HEADER_NAMES_LIST);
String headerValuesList = getSavedValueForScenario(VAR_API_HEADER_VALUES_LIST);

if (headerNamesList == null || headerNamesList.equals("") ||
headerValuesList == null || headerValuesList.equals("")) {
ApiInvoker.invoke(jsonRequest, new Headers());
} else {
ApiInvoker.invoke(jsonRequest, new Headers(getHeaders(headerNamesList, headerValuesList)));
}
}

/* Use this method to invoke a GET API from a request url in the response's JSON path.
The "saveApiEndpointInResponseBody" must use before using this step */
@Step("When the user invokes the GET API")
public void doGetRequestFromDataStore() {
String invokingEndpoint = getSavedValueForScenario(VAR_API_ENDPOINT);
String headerNamesList = getSavedValueForScenario(VAR_API_HEADER_NAMES_LIST);
String headerValuesList = getSavedValueForScenario(VAR_API_HEADER_VALUES_LIST);

String accessToken, isAuthenticationRequired, isAccessTokenRetrievedFromTextFile, accessTokenString;
String accessTokenInFile = readAccessToken();

try {
isAuthenticationRequired = getSavedValueForScenario(IS_AUTHENTICATION_REQUIRED).toLowerCase();
isAccessTokenRetrievedFromTextFile = getSavedValueForScenario(RETRIEVE_TOKEN_FROM_TEXT_FILE).toLowerCase();
accessTokenString = getSavedValueForScenario(MANUAL_TOKEN);
} catch (Exception ex) {
isAuthenticationRequired = "";
isAccessTokenRetrievedFromTextFile = "";
accessTokenString = "";
}

if (isTrue(isAuthenticationRequired)) {
if (isTrue(isAccessTokenRetrievedFromTextFile)) {
accessToken = accessTokenInFile;
} else {
accessToken = accessTokenString;
}
} else {
accessToken = "";
}

printInfo("");
printInfo("");
printInfo("Invoked API Endpoint:\n" + invokingEndpoint + "\n\n");
printInfo("HTTP Method is: GET\n\n");

if (headerNamesList == null || headerNamesList.equals("") ||
headerValuesList == null || headerValuesList.equals("")) {
getApiWithAuthMultipleHeaders(invokingEndpoint, accessToken, new Headers());
} else {
getApiWithAuthMultipleHeaders(invokingEndpoint, accessToken,
new Headers(getHeaders(headerNamesList, headerValuesList)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

import java.util.List;

import static com.maxsoft.intelliapi.api.ApiRequestPayload.*;
import static com.maxsoft.intelliapi.Constants.*;
import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.*;
import static com.maxsoft.intelliapi.api.ApiResponseProcessor.saveResponseJsonPathValue;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.*;
import static com.maxsoft.intelliapi.util.FrameworkUtil.*;
import static com.maxsoft.intelliapi.common.Constants.*;
import static com.maxsoft.intelliapi.util.LogUtil.printInfo;
import static com.maxsoft.intelliapi.util.DataStoreProcessor.*;

/**
* Project Name : MaxSoft-IntelliAPI
Expand All @@ -31,6 +32,12 @@ public void apiToBeInvoked(String apiEndpointName) {
initializeApiToBeInvoked(apiEndpointName);
}

// Use this method before invoking a GET API from a request url in the response's JSON path
@Step("Given that a user needs to invoke a GET API from the JSON Path value <jsonPath>")
public void saveApiEndpointInResponseBody(String jsonPath) {
saveResponseJsonPathValue(SCENARIO, VAR_API_ENDPOINT, jsonPath);
}

// Use this method to replace the placeholders inside the API Endpoint in Excel
@Step("And the user set values to the API endpoint placeholders as follows <table>")
public void setApiEndpointReplacements(Table table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.List;

import static com.maxsoft.intelliapi.api.ApiResponse.*;
import static com.maxsoft.intelliapi.api.ApiResponseProcessor.*;

/**
* Project Name : MaxSoft-IntelliAPI
Expand Down
Loading

0 comments on commit 4666ebe

Please sign in to comment.