-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from osandadeshan/fix
Fix
- Loading branch information
Showing
31 changed files
with
281 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
2 changes: 1 addition & 1 deletion
2
...m/maxsoft/intelliapi/common/BodyType.java → ...java/com/maxsoft/intelliapi/BodyType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
2 changes: 1 addition & 1 deletion
2
.../maxsoft/intelliapi/common/Constants.java → ...ava/com/maxsoft/intelliapi/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../executionhooks/ExecutionContextHook.java → ...soft/intelliapi/ExecutionContextHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...maxsoft/intelliapi/common/HttpMethod.java → ...va/com/maxsoft/intelliapi/HttpMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiRequestInvokerStepImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.