Skip to content

Commit

Permalink
INJIMOB-1593 & INJIWEB-178 - Added test cases for create policy in su…
Browse files Browse the repository at this point in the history
…nbird registry and download sunbird VC (#330)

* INJIMOB-1593 & INJIWEB-178 - Added test cases for create policy in sunbird registry and download sunbird VC

Signed-off-by: Mohanachandran S <[email protected]>

* INJIMOB-1593 & INJIWEB-178 - Added test cases for create policy in sunbird registry and download sunbird VC

Signed-off-by: Mohanachandran S <[email protected]>

---------

Signed-off-by: Mohanachandran S <[email protected]>
  • Loading branch information
mohanachandran-s committed Jul 24, 2024
1 parent ff30d65 commit 46a8e39
Show file tree
Hide file tree
Showing 29 changed files with 573 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package io.mosip.testrig.apirig.testscripts;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.testng.ITest;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.internal.BaseTestMethod;
import org.testng.internal.TestResult;

import io.mosip.testrig.apirig.dto.OutputValidationDto;
import io.mosip.testrig.apirig.dto.TestCaseDTO;
import io.mosip.testrig.apirig.testrunner.HealthChecker;
import io.mosip.testrig.apirig.utils.AdminTestException;
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.AuthenticationTestException;
import io.mosip.testrig.apirig.utils.ConfigManager;
import io.mosip.testrig.apirig.utils.GlobalConstants;
import io.mosip.testrig.apirig.utils.OutputValidationUtil;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

public class DeleteWithParam extends AdminTestUtil implements ITest {
private static final Logger logger = Logger.getLogger(DeleteWithParam.class);
protected String testCaseName = "";
public Response response = null;

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
}

/**
* get current testcaseName
*/
@Override
public String getTestName() {
return testCaseName;
}

/**
* Data provider class provides test case list
*
* @return object of data provider
*/
@DataProvider(name = "testcaselist")
public Object[] getTestCaseList(ITestContext context) {
String ymlFile = context.getCurrentXmlTest().getLocalParameters().get("ymlFile");
logger.info("Started executing yml: " + ymlFile);
return getYmlTestData(ymlFile);
}

/**
* Test method for OTP Generation execution
*
* @param objTestParameters
* @param testScenario
* @param testcaseName
* @throws AuthenticationTestException
* @throws AdminTestException
*/
@Test(dataProvider = "testcaselist")
public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException {
testCaseName = testCaseDTO.getTestCaseName();
testCaseName = isTestCaseValidForExecution(testCaseDTO);
if (HealthChecker.signalTerminateExecution) {
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
}
String[] templateFields = testCaseDTO.getTemplateFields();

if (testCaseDTO.getTemplateFields() != null && templateFields.length > 0) {
ArrayList<JSONObject> inputtestCases = AdminTestUtil.getInputTestCase(testCaseDTO);
ArrayList<JSONObject> outputtestcase = AdminTestUtil.getOutputTestCase(testCaseDTO);

for (int i = 0; i < languageList.size(); i++) {
response = deleteWithPathParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(),
getJsonFromTemplate(inputtestCases.get(i).toString(), testCaseDTO.getInputTemplate()),
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName());

Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(),
getJsonFromTemplate(outputtestcase.get(i).toString(), testCaseDTO.getOutputTemplate()),
testCaseDTO, response.getStatusCode());
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));

if (!OutputValidationUtil.publishOutputResult(ouputValid))
throw new AdminTestException("Failed at output validation");
}
}

else {

if (testCaseName.contains("ESignet_")) {
if (ConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) {
throw new SkipException("esignet is not deployed hence skipping the testcase");
}

String tempUrl = ApplnURI;

if (testCaseDTO.getEndPoint().startsWith("$SUNBIRDBASEURL$") && testCaseName.contains("SunBirdR")) {

if (ConfigManager.isInServiceNotDeployedList("sunbirdrc"))
throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE);

if (ConfigManager.getSunBirdBaseURL() != null && !ConfigManager.getSunBirdBaseURL().isBlank())
tempUrl = ConfigManager.getSunBirdBaseURL();
//Once sunbird registry is pointing to specific env, remove the above line and uncomment below line
//tempUrl = ApplnURI.replace(GlobalConstants.API_INTERNAL, ConfigManager.getSunBirdBaseURL());
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$SUNBIRDBASEURL$", ""));
}

response = deleteWithPathParamAndCookie(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());

} else {
response = deleteWithPathParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
}
Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(), getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()),
testCaseDTO, response.getStatusCode());
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));
if (!OutputValidationUtil.publishOutputResult(ouputValid))
throw new AdminTestException("Failed at output validation");
}
}

/**
* The method ser current test name to result
*
* @param result
*/
@AfterMethod(alwaysRun = true)
public void setResultTestName(ITestResult result) {
try {
Field method = TestResult.class.getDeclaredField("m_method");
method.setAccessible(true);
method.set(result, result.getMethod().clone());
BaseTestMethod baseTestMethod = (BaseTestMethod) result.getMethod();
Field f = baseTestMethod.getClass().getSuperclass().getDeclaredField("m_methodName");
f.setAccessible(true);
f.set(baseTestMethod, testCaseName);
} catch (Exception e) {
Reporter.log("Exception : " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,36 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
}

else {

if (testCaseName.contains("ESignet_")) {
if (ConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) {
throw new SkipException("esignet is not deployed hence skipping the testcase");
}

String tempUrl = ApplnURI;

if (testCaseDTO.getEndPoint().startsWith("$SUNBIRDBASEURL$") && testCaseName.contains("SunBirdR")) {

if (ConfigManager.isInServiceNotDeployedList("sunbirdrc"))
throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE);

if (ConfigManager.getSunBirdBaseURL() != null && !ConfigManager.getSunBirdBaseURL().isBlank())
tempUrl = ConfigManager.getSunBirdBaseURL();
//Once sunbird registry is pointing to specific env, remove the above line and uncomment below line
//tempUrl = ApplnURI.replace(GlobalConstants.API_INTERNAL, ConfigManager.getSunBirdBaseURL());
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$SUNBIRDBASEURL$", ""));
}

response = getWithPathParamAndCookie(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), auditLogCheck,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), sendEsignetToken);

} else {
response = getWithPathParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), auditLogCheck,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), sendEsignetToken);
}

Map<String, List<OutputValidationDto>> ouputValid = null;
if (testCaseName.contains("_StatusCode")) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,44 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
}

else {
response = postWithBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, auditLogCheck, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), sendEsignetToken);
if (testCaseName.contains("ESignet_")) {
if (ConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) {
throw new SkipException("esignet is not deployed hence skipping the testcase");
}

String tempUrl = ApplnURI;

if (testCaseDTO.getEndPoint().startsWith("$SUNBIRDBASEURL$") && testCaseName.contains("SunBirdR")) {

if (ConfigManager.isInServiceNotDeployedList("sunbirdrc"))
throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE);

if (ConfigManager.getSunBirdBaseURL() != null && !ConfigManager.getSunBirdBaseURL().isBlank())
tempUrl = ConfigManager.getSunBirdBaseURL();
//Once sunbird registry is pointing to specific env, remove the above line and uncomment below line
//tempUrl = ApplnURI.replace(GlobalConstants.API_INTERNAL, ConfigManager.getSunBirdBaseURL());
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$SUNBIRDBASEURL$", ""));

response = postWithBodyAndCookie(tempUrl + testCaseDTO.getEndPoint(), inputJson, auditLogCheck,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), sendEsignetToken);

} else if (testCaseDTO.getEndPoint().startsWith("$ESIGNETMOCKBASEURL$")
&& testCaseName.contains("SunBirdC")) {
if (ConfigManager.isInServiceNotDeployedList("sunbirdrc"))
throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE);

if (ConfigManager.getEsignetMockBaseURL() != null
&& !ConfigManager.getEsignetMockBaseURL().isBlank())
tempUrl = ApplnURI.replace("api-internal.", ConfigManager.getEsignetMockBaseURL());
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$ESIGNETMOCKBASEURL$", ""));

response = postRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + testCaseDTO.getEndPoint(),
inputJson, COOKIENAME, testCaseDTO.getTestCaseName());
}
} else {
response = postWithBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, auditLogCheck,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), sendEsignetToken);
}
Map<String, List<OutputValidationDto>> ouputValid = null;
if (testCaseName.contains("_StatusCode")) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,24 @@ public void test(TestCaseDTO testCaseDTO)
}
String tempUrl = ConfigManager.getEsignetBaseUrl();
if (testCaseDTO.getEndPoint().startsWith("$ESIGNETMOCKBASEURL$")
&& testCaseName.contains("SunBirdRC")) {
&& testCaseName.contains("SunBirdC")) {
if (ConfigManager.isInServiceNotDeployedList("sunbirdrc"))
throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE);

if (ConfigManager.getEsignetMockBaseURL() != null
&& !ConfigManager.getEsignetMockBaseURL().isBlank())
tempUrl = ApplnURI.replace("api-internal.", ConfigManager.getEsignetMockBaseURL());
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$ESIGNETMOCKBASEURL$", ""));
} else if (testCaseDTO.getEndPoint().startsWith("$SUNBIRDBASEURL$") && testCaseName.contains("SunBirdR")) {

if (ConfigManager.isInServiceNotDeployedList("sunbirdrc"))
throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE);

if (ConfigManager.getSunBirdBaseURL() != null && !ConfigManager.getSunBirdBaseURL().isBlank())
tempUrl = ConfigManager.getSunBirdBaseURL();
//Once sunbird registry is pointing to specific env, remove the above line and uncomment below line
//tempUrl = ApplnURI.replace(GlobalConstants.API_INTERNAL, ConfigManager.getSunBirdBaseURL());
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$SUNBIRDBASEURL$", ""));
}
if (testCaseName.contains("_AuthorizationCode_")) {
response = postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(
Expand Down
3 changes: 3 additions & 0 deletions apitest/src/main/resources/config/Kernel.properties
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ partnerUrlSuffix=oYf63Lax0DY2QkYMRHnrmDqhmO3RMWQagwm0ftgLlkuin1KOND/666/576732
reportIgnoredTestCases=no
servicesNotDeployed=
esignetMockBaseURL=esignet-insurance.
sunBirdBaseURL=https://registry.dev1.mosip.net
#Once sunbird registry is pointing to specific env, remove the above line and uncomment below line
#sunBirdBaseURL=registry
slack-webhook-url=
serverErrorsToMonitor=IDA-MLC-018
pmsAuthInternal=true
Expand Down
6 changes: 4 additions & 2 deletions apitest/src/main/resources/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,7 @@ passwordToReset=12341234_AaB
XSRFTOKEN=7d01b2a8-b89d-41ad-9361-d7f6294021d1
codeChallenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
codeVerifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
policyNumberForSunBirdRC=654321
challengeValueForSunBirdRC=eyJmdWxsTmFtZSI6IkthaWYgU2lkZGlxdWUiLCJkb2IiOiIyMDAwLTA3LTI2In0=
policyNumberForSunBirdRC=326253801
challengeValueForSunBirdRC=eyJmdWxsTmFtZSI6IlJvaGFuIEt1bWFyIiwiZG9iIjoiMTk5OS0xMC0xMiJ9
fullNameForSunBirdRC=Rohan Kumar
dobForSunBirdRC=1999-10-12
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DownloadIssuerCredential:
Mimoto_DownloadIssuerCredential_All_Valid_Smoke:
Mimoto_DownloadIssuerCredential_IssuerMosip_All_Valid_Smoke:
endPoint: /residentmobileapp/credentials/download
role: resident
restMethod: get
Expand Down Expand Up @@ -86,7 +86,7 @@ DownloadIssuerCredential:
]
}'

Mimoto_DownloadIssuerCredential_Expired_AuthorizationCode_Neg:
Mimoto_DownloadIssuerCredential_Reused_AuthorizationCode_Neg:
endPoint: /residentmobileapp/credentials/download
role: resident
restMethod: get
Expand All @@ -95,7 +95,7 @@ DownloadIssuerCredential:
outputTemplate: mimoto/DownloadIssuerCredential/DownloadIssuerCredentialResult
input: '{
"grant_type": "authorization_code",
"code": "XjIsJgQAX3lrhMmXgRn-jerNMCqf0GdiBLx5MbMigNY",
"code": "$ID:ESignet_AuthorizationCode_uin_All_Valid_Smoke_sid_code$",
"redirect_uri": "$INJIREDIRECTURI$",
"code_verifier": "$CODEVERIFIER$",
"issuer": "Mosip",
Expand All @@ -107,4 +107,21 @@ DownloadIssuerCredential:
"errorCode":"RESIDENT-APP-035"
}
]
}'
Mimoto_DownloadIssuerCredential_IssuerSunBird_All_Valid_Smoke:
endPoint: /residentmobileapp/credentials/download
role: resident
restMethod: get
checkErrorsOnlyInResponse: true
inputTemplate: mimoto/DownloadIssuerCredential/DownloadIssuerCredential
outputTemplate: mimoto/DownloadIssuerCredential/DownloadIssuerCredentialResult
input: '{
"grant_type": "authorization_code",
"code": "$ID:ESignet_AuthorizationCode_SunBirdC_All_Valid_Smoke_sid_code$",
"redirect_uri": "$INJIREDIRECTURI$",
"code_verifier": "$CODEVERIFIER$",
"issuer": "Sunbird",
"credential": "InsuranceCredential"
}'
output: '{
}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"encodedHash": "{{encodedHash}}",
"requestTime": "{{requestTime}}",
"request": {
"transactionId": "{{transactionId}}",
"individualId": "{{individualId}}",
"challengeList" : [
{
"authFactorType" : "{{authFactorType}}",
"challenge" : "{{challenge}}",
"format": "{{format}}"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
AuthenticateUserSunBirdC:
Mimoto_ESignet_AuthenticateUser_SunBirdC_Valid_Smoke:
endPoint: $ESIGNETMOCKBASEURL$/v1/esignet/authorization/authenticate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: mimoto/SunBirdC/AuthenticateUserSunBirdC/AuthenticateUserSunBirdC
outputTemplate: mimoto/SunBirdC/AuthenticateUserSunBirdC/AuthenticateUserSunBirdCResult
input: '{
"encodedHash": "$ID:ESignet_OAuthDetailsRequest_SunBirdC_all_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:ESignet_OAuthDetailsRequest_SunBirdC_all_Valid_Smoke_sid_transactionId$",
"individualId": "$POLICYNUMBERFORSUNBIRDRC$",
"authFactorType" : "KBA",
"challenge" : "$CHALLENGEVALUEFORSUNBIRDC$",
"format": "base64url-encoded-json"
}'
output: '{
}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit 46a8e39

Please sign in to comment.