-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
26 changed files
with
763 additions
and
59 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
This file was deleted.
Oops, something went wrong.
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,22 +1,87 @@ | ||
package Tests.APITests.APIUtils; | ||
|
||
import Tests.APITests.APIUtils.CMRequest.LoginUser; | ||
import Tests.APITests.APIUtils.CMRequest.VerifyConsentPIN; | ||
import Tests.APITests.APIUtils.HIURequest.HIUConsentRequest; | ||
import io.restassured.RestAssured; | ||
import io.restassured.path.json.JsonPath; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.RequestSpecification; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.List; | ||
|
||
public class APIUtils { | ||
|
||
public Response createConsent(String id) { | ||
RestAssured.baseURI = PropertiesCache.getInstance().getProperty("HIUBackendURL"); | ||
|
||
//create consent-request at HIU | ||
RestAssured.baseURI = PropertiesCache.getInstance().getProperty("HIUBaseURL"); | ||
RestAssured.useRelaxedHTTPSValidation(); | ||
RequestSpecification request = RestAssured.given(); | ||
request.header("Content-Type", "application/json"); | ||
request.header("Authorization", new LoginUser().getHIUAuthToken()); | ||
|
||
HIUConsentRequest hiuConsentRequest = new HIUConsentRequest.ConsentRequestBuilder(id.toLowerCase()).buildConsentReuqest(); | ||
HIUConsentRequest hiuConsentRequest = new HIUConsentRequest.ConsentRequestBuilder(id.toLowerCase()) | ||
.buildConsentReuqest(); | ||
request.body(hiuConsentRequest.getJSONRequestBody().toString()); | ||
Response response = request.post("/v1/hiu/consent-requests"); | ||
|
||
return response; | ||
} | ||
|
||
public String verifyConsentPIN(String consent) { | ||
|
||
//verify consent-pin and generate pin-authorization token | ||
String authToken = "Bearer " + new LoginUser().getCMAuthToken(); | ||
RequestSpecification request = RestAssured.given(); | ||
request.header("Content-Type", "application/json"); | ||
request.header("Authorization", authToken); | ||
|
||
if(consent.equalsIgnoreCase("grant")) { | ||
request.body(new VerifyConsentPIN().getVerifyGrantPINRequestBody()); | ||
} | ||
else if(consent.equalsIgnoreCase("revoke")) { | ||
request.body(new VerifyConsentPIN().getVerifyRevokePINRequestBody()); | ||
} | ||
Response response = request.post("/patients/verify-pin"); | ||
JsonPath jsonPathEvaluator = response.jsonPath(); | ||
return jsonPathEvaluator.getString("temporaryToken"); | ||
} | ||
|
||
public String fetchConsentRequestId(Response response, String patient) { | ||
|
||
//identifies the consent-request-id of patient's consent-request in the GET consent-requests at HIU | ||
String consentRequestId = ""; | ||
JsonPath jsonPathEvaluator = response.jsonPath(); | ||
List<String> patientList = jsonPathEvaluator.getList("patient.id"); | ||
for(int i=0; i<(patientList.size()-1);i++) { | ||
if(patientList.get(i).equalsIgnoreCase(patient)) { | ||
if((jsonPathEvaluator.getString("status[" + i + "]")).equalsIgnoreCase("REQUESTED")) { | ||
consentRequestId = jsonPathEvaluator.getString("consentRequestId[" + i + "]"); | ||
break; | ||
} | ||
} | ||
} | ||
return consentRequestId; | ||
} | ||
|
||
public String fetchConsentStatus(Response response, String consentRequestId) { | ||
|
||
//identifies the status of consent in the GET consent-requests at HIU | ||
String status=""; | ||
JsonPath jsonPathEvaluator = response.jsonPath(); | ||
List<String> consentRequestIds = jsonPathEvaluator.getList("consentRequestId"); | ||
for(int i=0; i<(consentRequestIds.size()-1);i++) { | ||
if(consentRequestIds.get(i).equalsIgnoreCase(consentRequestId)) { | ||
status = jsonPathEvaluator.getString("status[" + i + "]"); | ||
break; | ||
} | ||
} | ||
return status; | ||
} | ||
|
||
|
||
|
||
|
||
} |
11 changes: 5 additions & 6 deletions
11
...APITests/APIUtils/CMPatientDiscovery.java → ...PIUtils/CMRequest/CMPatientDiscovery.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
49 changes: 49 additions & 0 deletions
49
src/test/java/Tests/APITests/APIUtils/CMRequest/ConsentRequest.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,49 @@ | ||
package Tests.APITests.APIUtils.CMRequest; | ||
|
||
public class ConsentRequest { | ||
|
||
public String getGrantConsentRequestBody() { | ||
return " { \n" + | ||
" \"consents\": [ \n" + | ||
" { \n" + | ||
" \"careContexts\": [ \n" + | ||
" { \n" + | ||
" \"careContextReference\": \"NCP10093\", \n" + | ||
" \"patientReference\": \"RVH1004\" \n" + | ||
" } \n" + | ||
" ], \n" + | ||
" \"hiTypes\": [ \n" + | ||
" \"Condition\", \n" + | ||
" \"Observation\", \n" + | ||
" \"DiagnosticReport\", \n" + | ||
" \"MedicationRequest\" \n" + | ||
" ], \n" + | ||
" \"hip\": { \n" + | ||
" \"id\": \"10000005\" \n" + | ||
" }, \n" + | ||
" \"permission\": { \n" + | ||
" \"accessMode\": \"VIEW\", \n" + | ||
" \"dataEraseAt\": \"2020-12-27T10:45:54.688\", \n" + | ||
" \"dateRange\": { \n" + | ||
" \"from\": \"1992-06-25T18:30:00\", \n" + | ||
" \"to\": \"2020-06-26T10:45:54.688\" \n" + | ||
" }, \n" + | ||
" \"frequency\": { \n" + | ||
" \"value\": 1, \n" + | ||
" \"unit\": \"HOUR\", \n" + | ||
" \"repeats\": 0 \n" + | ||
" } \n" + | ||
" } \n" + | ||
" } \n" + | ||
" ] \n" + | ||
"} "; | ||
} | ||
|
||
public String getRevokeConsentRequestBody(String consentArtefactId) { | ||
return " { \n" + | ||
" \"consents\": [ \n" + | ||
" \""+ consentArtefactId +"\" \n" + | ||
" ] \n" + | ||
"} "; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/java/Tests/APITests/APIUtils/CMRequest/CreateConsentPIN.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,12 @@ | ||
package Tests.APITests.APIUtils.CMRequest; | ||
|
||
|
||
public class CreateConsentPIN { | ||
|
||
public String getCreatePINRequestBody() { | ||
return "{\n" + | ||
" \"pin\": \"1234\" \n" + | ||
"}"; | ||
} | ||
|
||
} |
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
40 changes: 40 additions & 0 deletions
40
src/test/java/Tests/APITests/APIUtils/CMRequest/RecoverCMID.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,40 @@ | ||
package Tests.APITests.APIUtils.CMRequest; | ||
|
||
public class RecoverCMID { | ||
|
||
public String getRecoverInitCMIDRequestBody() { | ||
return "{\n" + | ||
" \"name\": { \n" + | ||
" \"first\": \"John\", \n" + | ||
" \"last\": \"\", \n" + | ||
" \"middle\": \"Doe\" \n" + | ||
" }, \n" + | ||
" \"gender\": \"M\", \n" + | ||
" \"dateOfBirth\": { \n" + | ||
" \"date\": 1, \n" + | ||
" \"month\": 1, \n" + | ||
" \"year\": 1966 \n" + | ||
" }, \n" + | ||
" \"verifiedIdentifiers\": [ \n" + | ||
" {\n" + | ||
" \"type\": \"MOBILE\", \n" + | ||
" \"value\": \"+91-9999999999\" \n" + | ||
" } \n" + | ||
" ], \n" + | ||
" \"unverifiedIdentifiers\": [ \n" + | ||
" {\n" + | ||
" \"type\": \"ABPMJAYID\", \n" + | ||
" \"value\": \"PAPITEST1\" \n" + | ||
" }\n" + | ||
" ]\n" + | ||
"}"; | ||
} | ||
|
||
public String getRecoverConfirmCMIDRequestBody(String sessionId) { | ||
return "{\n" + | ||
" \"sessionId\": \""+ sessionId +"\",\n" + | ||
" \"value\": \"666666\" \n" + | ||
"}"; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/Tests/APITests/APIUtils/CMRequest/ResetPassword.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,24 @@ | ||
package Tests.APITests.APIUtils.CMRequest; | ||
|
||
public class ResetPassword { | ||
|
||
public String getGenerateOTPRequestBody() { | ||
return "{\n" + | ||
" \"username\": \"apidemotest10@ncg\" \n" + | ||
"}"; | ||
} | ||
|
||
public String getVerifyOTPRequestBody(String sessionId) { | ||
return "{\n" + | ||
" \"sessionId\": \""+ sessionId +"\",\n" + | ||
" \"value\": \"666666\" \n" + | ||
"}"; | ||
} | ||
|
||
public String getResetPasswordRequestBody() { | ||
return "{\n" + | ||
" \"password\": \"Test135@\" \n" + | ||
"}"; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/Tests/APITests/APIUtils/CMRequest/UpdateProfile.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,32 @@ | ||
package Tests.APITests.APIUtils.CMRequest; | ||
|
||
import java.util.UUID; | ||
|
||
public class UpdateProfile { | ||
|
||
public String getUpdatePasswordRequestBody() { | ||
return "{\n" + | ||
" \"newPassword\": \"Test135@\" ,\n" + | ||
" \"oldPassword\": \"Test135@\" \n" + | ||
"}"; | ||
} | ||
|
||
public String getVerifyPINRequestBody() { | ||
return "{\n" + | ||
" \"pin\": \"1234\",\n" + | ||
" \"requestId\":\"" + generateUUID() +"\""+",\n" + | ||
" \"scope\": \"profile.changepin\" \n" + | ||
"}"; | ||
} | ||
|
||
public String getUpdatePINRequestBody() { | ||
return "{\n" + | ||
" \"pin\": \"1234\" \n" + | ||
"}"; | ||
} | ||
|
||
private String generateUUID() { | ||
return String.valueOf(UUID.randomUUID()); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/Tests/APITests/APIUtils/CMRequest/VerifyConsentPIN.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,27 @@ | ||
package Tests.APITests.APIUtils.CMRequest; | ||
|
||
import java.util.UUID; | ||
|
||
public class VerifyConsentPIN { | ||
|
||
public String getVerifyGrantPINRequestBody() { | ||
return "{\n" + | ||
" \"pin\": \"1234\",\n" + | ||
" \"requestId\": \"" + generateUUID() +"\""+",\n" + | ||
" \"scope\": \"consentrequest.approve\" \n" + | ||
"}"; | ||
} | ||
|
||
public String getVerifyRevokePINRequestBody() { | ||
return "{\n" + | ||
" \"pin\": \"1234\",\n" + | ||
" \"requestId\": \"" + generateUUID() +"\""+",\n" + | ||
" \"scope\": \"consent.revoke\" \n" + | ||
"}"; | ||
} | ||
|
||
private String generateUUID() { | ||
return String.valueOf(UUID.randomUUID()); | ||
} | ||
|
||
} |
Oops, something went wrong.