Skip to content

Commit

Permalink
Merge pull request #138 from nandhu-kumar/develop
Browse files Browse the repository at this point in the history
MOSIP-37606 | fixed failures
  • Loading branch information
ckm007 authored Nov 21, 2024
2 parents c0d5aac + b0c63ba commit 1341d6e
Show file tree
Hide file tree
Showing 31 changed files with 1,115 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import io.mosip.testrig.apirig.testrunner.JsonPrecondtion;
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.GlobalConstants;
import io.mosip.testrig.apirig.utils.GlobalMethods;
import io.mosip.testrig.apirig.utils.KernelAuthentication;
import io.mosip.testrig.apirig.utils.OutputValidationUtil;
import io.mosip.testrig.apirig.utils.ReportUtil;
Expand All @@ -44,6 +44,7 @@ public class AddIdentity extends AdminTestUtil implements ITest {
private static final Logger logger = Logger.getLogger(AddIdentity.class);
protected String testCaseName = "";
public Response response = null;
private boolean isWaitRequired = false;

/**
* get current testcaseName
Expand Down Expand Up @@ -80,53 +81,99 @@ public Object[] getTestCaseList(ITestContext context) {
* @param objTestParameters
* @param testScenario
* @param testcaseName
* @throws AuthenticationTestException
* @throws AdminTestException
* @throws Exception
*/
@Test(dataProvider = "testcaselist")
public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException {
public void test(TestCaseDTO testCaseDTO) throws Exception {
testCaseName = testCaseDTO.getTestCaseName();
testCaseName = InjiCertifyUtil.isTestCaseValidForExecution(testCaseDTO);
if (HealthChecker.signalTerminateExecution) {
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
}
testCaseDTO.setInputTemplate(AdminTestUtil.modifySchemaGenerateHbs(testCaseDTO.isRegenerateHbs()));
String uin = JsonPrecondtion
.getValueFromJson(
RestClient.getRequestWithCookie(ApplnURI + "/v1/idgenerator/uin", MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, COOKIENAME,
new KernelAuthentication().getTokenByRole(testCaseDTO.getRole())).asString(),
"response.uin");

testCaseName = isTestCaseValidForExecution(testCaseDTO);

DateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
Calendar cal = Calendar.getInstance();
String timestampValue = dateFormatter.format(cal.getTime());
String genRid = "27847" + generateRandomNumberString(10) + timestampValue;

String jsonInput = testCaseDTO.getInput();

String inputJson = getJsonFromTemplate(jsonInput, testCaseDTO.getInputTemplate(), false);

inputJson = inputJson.replace("$UIN$", uin);
inputJson = inputJson.replace("$RID$", genRid);
String phoneNumber = "";
String email = testCaseName +"@mosip.net";
if (inputJson.contains("$PHONENUMBERFORIDENTITY$")) {
if (!phoneSchemaRegex.isEmpty())
try {
phoneNumber = genStringAsperRegex(phoneSchemaRegex);
} catch (Exception e) {
logger.error(e.getMessage());
}
inputJson = replaceKeywordWithValue(inputJson, "$PHONENUMBERFORIDENTITY$", phoneNumber);
inputJson = replaceKeywordWithValue(inputJson, "$EMAILVALUE$", email);
}

response = postWithBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
if (testCaseDTO.getEndPoint().contains("mock-identity-system")) {
String individualIDStr = String.valueOf(Calendar.getInstance().getTimeInMillis());
String phoneStr = generateRandomNumberString(10);
String emailStr = testCaseName + "@mosip.net";
String passWordStr = properties.getProperty("passwordForAddIdentity");
String url = ApplnURI.replace("-internal", "") + testCaseDTO.getEndPoint();

String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate());

inputJson = InjiCertifyUtil.inputstringKeyWordHandeler(inputJson, testCaseName);

if (inputJson.contains("$RANDOMINDIVIDUALIDFORMOCKIDENTITY$")) {
inputJson = replaceKeywordWithValue(inputJson, "$RANDOMINDIVIDUALIDFORMOCKIDENTITY$", individualIDStr);
writeAutoGeneratedId(testCaseName, "UIN", individualIDStr);
}

if (inputJson.contains("$EMAILIDFORMOCKIDENTITY$")) {
inputJson = replaceKeywordWithValue(inputJson, "$EMAILIDFORMOCKIDENTITY$", emailStr);
writeAutoGeneratedId(testCaseName, "EMAIL", emailStr);
}
if (inputJson.contains("$PASSWORDFORMOCKIDENTITY$")) {
inputJson = replaceKeywordWithValue(inputJson, "$PASSWORDFORMOCKIDENTITY$", passWordStr);
writeAutoGeneratedId(testCaseName, "PASSWORD", passWordStr);
}
if (inputJson.contains("$PHONEFORMOCKIDENTITY$")) {
inputJson = replaceKeywordWithValue(inputJson, "$PHONEFORMOCKIDENTITY$", phoneStr);
writeAutoGeneratedId(testCaseName, "PHONE", phoneStr);
}

GlobalMethods.reportRequest(null, inputJson, url);

response = RestClient.post(url, inputJson);

GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
} else {
isWaitRequired = true;
testCaseDTO.setInputTemplate(AdminTestUtil.modifySchemaGenerateHbs(testCaseDTO.isRegenerateHbs()));
String uin = JsonPrecondtion.getValueFromJson(
RestClient.getRequestWithCookie(ApplnURI + "/v1/idgenerator/uin", MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, COOKIENAME,
new KernelAuthentication().getTokenByRole(testCaseDTO.getRole())).asString(),
"response.uin");

testCaseName = isTestCaseValidForExecution(testCaseDTO);

DateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
Calendar cal = Calendar.getInstance();
String timestampValue = dateFormatter.format(cal.getTime());
String genRid = "27847" + generateRandomNumberString(10) + timestampValue;

String jsonInput = testCaseDTO.getInput();

String inputJson = getJsonFromTemplate(jsonInput, testCaseDTO.getInputTemplate(), false);

inputJson = inputJson.replace("$UIN$", uin);
inputJson = inputJson.replace("$RID$", genRid);
String phoneNumber = "";
String email = testCaseName + "@mosip.net";
if (inputJson.contains("$PHONENUMBERFORIDENTITY$")) {
if (!phoneSchemaRegex.isEmpty())
try {
phoneNumber = genStringAsperRegex(phoneSchemaRegex);
} catch (Exception e) {
logger.error(e.getMessage());
}
inputJson = replaceKeywordWithValue(inputJson, "$PHONENUMBERFORIDENTITY$", phoneNumber);
inputJson = replaceKeywordWithValue(inputJson, "$EMAILVALUE$", email);
}

response = postWithBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());

if (testCaseDTO.getTestCaseName().contains("_Pos")) {
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "UIN", uin);
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "RID", genRid);
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "EMAIL",
testCaseDTO.getTestCaseName() + "@mosip.net");
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "PHONE", phoneNumber);
}
if (!phoneNumber.isEmpty())
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "PHONE", phoneNumber);
}

Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(), getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()),
Expand All @@ -135,14 +182,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad

if (!OutputValidationUtil.publishOutputResult(ouputValid))
throw new AdminTestException("Failed at output validation");
if (testCaseDTO.getTestCaseName().contains("_Pos")) {
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "UIN", uin);
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "RID", genRid);
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "EMAIL", testCaseDTO.getTestCaseName() + "@mosip.net");
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "PHONE", phoneNumber);
}
if (!phoneNumber.isEmpty())
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "PHONE", phoneNumber);

}

/**
Expand All @@ -169,9 +209,11 @@ public void setResultTestName(ITestResult result) {
public void waittime() {

try {
logger.info(
"waiting for " + properties.getProperty("Delaytime") + " mili secs after UIN Generation In IDREPO");
Thread.sleep(Long.parseLong(properties.getProperty("Delaytime")));
if (isWaitRequired == true) {
logger.info("waiting for " + properties.getProperty("Delaytime")
+ " mili secs after UIN Generation In IDREPO");
Thread.sleep(Long.parseLong(properties.getProperty("Delaytime")));
}

} catch (Exception e) {
logger.error("Exception : " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package io.mosip.testrig.apirig.injicertify.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.injicertify.utils.InjiCertifyConfigManager;
import io.mosip.testrig.apirig.injicertify.utils.InjiCertifyUtil;
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.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 (InjiCertifyConfigManager.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 = InjiCertifyUtil.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 (InjiCertifyConfigManager.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 (InjiCertifyConfigManager.isInServiceNotDeployedList("sunbirdrc"))
throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE);

if (InjiCertifyConfigManager.getSunBirdBaseURL() != null && !InjiCertifyConfigManager.getSunBirdBaseURL().isBlank())
tempUrl = InjiCertifyConfigManager.getSunBirdBaseURL();
//Once sunbird registry is pointing to specific env, remove the above line and uncomment below line
//tempUrl = ApplnURI.replace(GlobalConstants.API_INTERNAL, MimotoConfigManager.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());
}
}
}
Loading

0 comments on commit 1341d6e

Please sign in to comment.