Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohandey committed Feb 27, 2024
2 parents 864ea89 + 3a02a54 commit fcf306a
Show file tree
Hide file tree
Showing 58 changed files with 431 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
import com.fasterxml.jackson.databind.JsonMappingException;

import io.mosip.testrig.apirig.admin.fw.util.AdminTestException;
import io.mosip.testrig.apirig.admin.fw.util.TestCaseDTO;
import io.mosip.testrig.apirig.authentication.fw.dto.OutputValidationDto;
import io.mosip.testrig.apirig.authentication.fw.precon.JsonPrecondtion;
import io.mosip.testrig.apirig.authentication.fw.precon.MessagePrecondtion;
import io.mosip.testrig.apirig.global.utils.GlobalConstants;
import io.mosip.testrig.apirig.global.utils.GlobalMethods;
import io.mosip.testrig.apirig.kernel.util.ConfigManager;
import io.mosip.testrig.apirig.kernel.util.SlackChannelIntegration;
import io.mosip.testrig.apirig.service.BaseTestCase;

/**
* Perform output validation between expected and actual json file or message
Expand Down Expand Up @@ -459,39 +463,62 @@ public static boolean compareTwoKycMap(Map<String, Object> expMap, Map<String, O
return true;
}

public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(String actualOutputJson,
String expOutputJson, boolean checkErrorsOnlyInResponse, String allowedErrorCode, int responseStatusCode)
throws AdminTestException {
return doJsonOutputValidation(actualOutputJson, expOutputJson, checkErrorsOnlyInResponse,
GlobalConstants.EXPECTED_VS_ACTUAL, doesResponseHasErrors(actualOutputJson), allowedErrorCode,
responseStatusCode);
}
// public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(String actualOutputJson,
// String expOutputJson, boolean checkErrorsOnlyInResponse, String allowedErrorCode, int responseStatusCode)
// throws AdminTestException {
// return doJsonOutputValidation(actualOutputJson, expOutputJson, checkErrorsOnlyInResponse,
// GlobalConstants.EXPECTED_VS_ACTUAL, doesResponseHasErrors(actualOutputJson), allowedErrorCode,
// responseStatusCode);
// }

public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(String actualOutputJson,
String expOutputJson, boolean checkErrorsOnlyInResponse, int responseStatusCode) throws AdminTestException {
return doJsonOutputValidation(actualOutputJson, expOutputJson, checkErrorsOnlyInResponse,
GlobalConstants.EXPECTED_VS_ACTUAL, doesResponseHasErrors(actualOutputJson), null, responseStatusCode);
}
// public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(String actualOutputJson,
// String expOutputJson, boolean checkErrorsOnlyInResponse, int responseStatusCode) throws AdminTestException {
// return doJsonOutputValidation(actualOutputJson, expOutputJson, checkErrorsOnlyInResponse,
// GlobalConstants.EXPECTED_VS_ACTUAL, doesResponseHasErrors(actualOutputJson), null, responseStatusCode);
// }

// public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(String actualOutputJson,
// String expOutputJson, boolean checkErrorsOnlyInResponse, String context, boolean responseHasErrors,
// String allowedErrorCode, int responseStatusCode) throws AdminTestException {
//// Checks output JSON contains server issues and log in report
// reportServerIssues(actualOutputJson);
//
// if (doesResponseHasErrorCode(actualOutputJson, allowedErrorCode))
// return Collections.emptyMap();
// else if (doesResponseHasErrorCode(actualOutputJson, 500))
// throw new AdminTestException("Internal Server Error. Hence marking the test case as failed");
// else if (doesResponseHasErrorCode(actualOutputJson, 404))
// throw new SkipException("API end point is not valid. Hence marking the test case as skipped");
// JsonPrecondtion jsonPrecondtion = new JsonPrecondtion();
// Map<String, String> actual = jsonPrecondtion
// .retrieveMappingAndItsValueToPerformJsonOutputValidation(actualOutputJson);
// Map<String, String> exp = jsonPrecondtion
// .retrieveMappingAndItsValueToPerformJsonOutputValidation(expOutputJson);
//
// return doJsonOutputValidation(actual, exp, checkErrorsOnlyInResponse, context, responseHasErrors,
// allowedErrorCode, responseStatusCode);
// }

public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(String actualOutputJson,
String expOutputJson, boolean checkErrorsOnlyInResponse, String context, boolean responseHasErrors,
String allowedErrorCode, int responseStatusCode) throws AdminTestException {
if (doesResponseHasErrorCode(actualOutputJson, allowedErrorCode))
String expOutputJson, TestCaseDTO testCaseDTO, int responseStatusCode)
throws AdminTestException {
// Checks output JSON contains server issues and log in report
reportServerIssues(actualOutputJson, testCaseDTO);

if (doesResponseHasErrorCode(actualOutputJson, testCaseDTO.getAllowedErrorCodes()))
return Collections.emptyMap();
else if (doesResponseHasErrorCode(actualOutputJson, 500))
throw new AdminTestException("Internal Server Error. Hence marking the test case as failed");
else if (doesResponseHasErrorCode(actualOutputJson, 404))
throw new SkipException("API end point is not valid. Hence marking the test case as skipped");
// else if (!(responseStatusCode >= 200 && responseStatusCode < 300))
// throw new SkipException("API endpoint is not valid. Response code: " + responseStatusCode + " Hence marking the test case as skipped");
JsonPrecondtion jsonPrecondtion = new JsonPrecondtion();
Map<String, String> actual = jsonPrecondtion
.retrieveMappingAndItsValueToPerformJsonOutputValidation(actualOutputJson);
Map<String, String> exp = jsonPrecondtion
.retrieveMappingAndItsValueToPerformJsonOutputValidation(expOutputJson);

return doJsonOutputValidation(actual, exp, checkErrorsOnlyInResponse, context, responseHasErrors,
allowedErrorCode, responseStatusCode);
return doJsonOutputValidation(actual, exp, testCaseDTO.isCheckErrorsOnlyInResponse(), GlobalConstants.EXPECTED_VS_ACTUAL, doesResponseHasErrors(actualOutputJson),
testCaseDTO.getAllowedErrorCodes(), responseStatusCode);
}

public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(Map<String, String> actualOutput,
Expand Down Expand Up @@ -559,5 +586,41 @@ public static boolean doesResponseHasErrorCode(String responseString, String all
}
return responseHasAllowedErrorCode;
}

public static void reportServerIssues(String responseString, TestCaseDTO testCaseDTO) {
JSONObject responseJson = new JSONObject(responseString);

JSONArray errors = new JSONArray();
if (responseJson.has("errors")) {
errors = responseJson.optJSONArray("errors");
} else if (responseJson.has("error")) {
String error = responseJson.getString("error");
JSONObject tempJson = new JSONObject();
tempJson.put("errorCode", error);
tempJson.put("errorMessage", error);
errors.put(tempJson);
}

if (errors.length() == 0) {
return;
}

for (int i = 0; i < errors.length(); i++) {

if (ConfigManager.getServerErrorsToMonitor().contains(errors.getJSONObject(i).getString("errorCode"))) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("On ").append(ConfigManager.getTargetEnvName()).append(" Encountered -- ")
.append(errors.getJSONObject(i).getString("errorCode")).append(" -- ")
.append(errors.getJSONObject(i).getString("errorMessage"))
.append("on this end point - ")
.append(testCaseDTO.getEndPoint());
// Report to slack. If slack integration is done
SlackChannelIntegration.sendMessageToSlack(stringBuilder.toString());

GlobalMethods.reportServerError(errors.getJSONObject(i).getString("errorCode"),
errors.getJSONObject(i).getString("errorMessage"));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public class ConfigManager {
private static String MOUNT_PATH = "mountPath";
private static String AUTHCERTS_PATH = "authCertsPath";
private static String MOUNT_PATH_FOR_SCENARIO = "mountPathForScenario";

private static String SERVER_ERRORS_TO_MONITOR = "serverErrorsToMonitor";

private static String PACKET_UTILITY_BASE_URL = "packetUtilityBaseUrl";

Expand Down Expand Up @@ -237,6 +239,8 @@ public class ConfigManager {
private static String iamUsersPassword;
private static String authDemoServicePort;
private static String authDemoServiceBaseUrl;

private static String serverErrorsToMonitor;

private static String mountPath;
private static String authCertsPath;
Expand Down Expand Up @@ -343,6 +347,11 @@ public static void init() {
? propsKernel.getProperty(AUTH_DEMO_SERVICE_PORT)
: System.getenv(AUTH_DEMO_SERVICE_PORT);
propsKernel.setProperty(AUTH_DEMO_SERVICE_PORT, authDemoServicePort);

serverErrorsToMonitor = System.getenv(SERVER_ERRORS_TO_MONITOR) == null
? propsKernel.getProperty(SERVER_ERRORS_TO_MONITOR)
: propsKernel.getProperty(SERVER_ERRORS_TO_MONITOR) + "," + System.getenv(SERVER_ERRORS_TO_MONITOR);
propsKernel.setProperty(SERVER_ERRORS_TO_MONITOR, serverErrorsToMonitor);

reportExpirationInDays = System.getenv(REPORT_EXPIRATION_IN_DAYS) == null
? propsKernel.getProperty(REPORT_EXPIRATION_IN_DAYS)
Expand Down Expand Up @@ -491,6 +500,10 @@ public static boolean isInTobeExecuteList(String stringToFind) {
}
return false;
}

public static String getServerErrorsToMonitor() {
return serverErrorsToMonitor;
}

public static String getUserAdminName() {
return userAdminName;
Expand Down Expand Up @@ -734,6 +747,10 @@ public static String getS3AccountForPersonaData() {
public static String getPushReportsToS3() {
return push_reports_to_s3;
}

public static String getTargetEnvName() {
return dbDomain;
}

public static String getIdaDbUrl() {
return "jdbc:postgresql://" + dbDomain + ":" + dbPort + "/mosip_ida";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import io.mosip.testrig.apirig.admin.fw.util.AdminTestUtil;
import io.mosip.testrig.apirig.global.utils.GlobalConstants;
import io.mosip.testrig.apirig.global.utils.GlobalMethods;
import io.mosip.testrig.apirig.kernel.util.ConfigManager;
import io.mosip.testrig.apirig.kernel.util.SlackChannelIntegration;
import io.mosip.testrig.apirig.service.BaseTestCase;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
Expand Down Expand Up @@ -88,6 +90,13 @@ else if (parts[1].contains(GlobalConstants.RID_GENERATOR) && (ConfigManager.isIn
if (serviceStatus.equalsIgnoreCase("UP") == false) {
isAllServicesUp = false;
healthCheckFailureMapS.put(controllerPaths.get(i), serviceStatus);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("On ").append(ConfigManager.getTargetEnvName())
.append(" Health check failed for this end point -- ").append(controllerPaths.get(i));
// Report to slack. If slack integration is done
SlackChannelIntegration.sendMessageToSlack(stringBuilder.toString());

GlobalMethods.reportServerError(" Health check failed " + controllerPaths.get(i), serviceStatus);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static void main(String[] arg) {
HealthChecker healthcheck = new HealthChecker();
healthcheck.setCurrentRunningModule(BaseTestCase.currentModule);
Thread trigger = new Thread(healthcheck);
// trigger.start();
trigger.start();
}
KeycloakUserManager.removeUser();
KeycloakUserManager.createUsers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public Object[] getTestCaseList(ITestContext context) {
public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException {
testCaseName = testCaseDTO.getTestCaseName();
if (HealthChecker.signalTerminateExecution) {
throw new SkipException(GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
}
testCaseDTO.setInputTemplate(AdminTestUtil.modifySchemaGenerateHbs(testCaseDTO.isRegenerateHbs()));
String uin = JsonPrecondtion
Expand All @@ -100,7 +101,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
MediaType.APPLICATION_JSON, COOKIENAME,
new KernelAuthentication().getTokenByRole(testCaseDTO.getRole())).asString(),
"response.uin");

testCaseName = isTestCaseValidForExecution(testCaseDTO);

DateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
Expand Down Expand Up @@ -150,7 +151,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad

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

if (!OutputValidationUtil.publishOutputResult(ouputValid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
String[] kycFields = testCaseDTO.getKycFields();

if (HealthChecker.signalTerminateExecution) {
throw new SkipException(GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
}

testCaseName = isTestCaseValidForExecution(testCaseDTO);

if (testCaseDTO.getTestCaseName().contains("uin") || testCaseDTO.getTestCaseName().contains("UIN")) {
if (!BaseTestCase.getSupportedIdTypesValueFromActuator().contains("UIN")
&& !BaseTestCase.getSupportedIdTypesValueFromActuator().contains("uin")) {
Expand All @@ -130,10 +131,10 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
testCaseDTO.setEndPoint(
testCaseDTO.getEndPoint().replace("$KycPartnerKeyURL$", PartnerRegistration.ekycPartnerKeyUrl));
}

if (testCaseDTO.getEndPoint().contains("$UpdatedPartnerKeyURL$")) {
testCaseDTO.setEndPoint(
testCaseDTO.getEndPoint().replace("$UpdatedPartnerKeyURL$", PartnerRegistration.updatedpartnerKeyUrl));
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$UpdatedPartnerKeyURL$",
PartnerRegistration.updatedpartnerKeyUrl));
}

if (testCaseDTO.getEndPoint().contains("$PartnerName$")) {
Expand Down Expand Up @@ -189,8 +190,8 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
}
}

Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(), ActualOPJson, testCaseDTO.isCheckErrorsOnlyInResponse(), response.getStatusCode());
Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil
.doJsonOutputValidation(response.asString(), ActualOPJson, testCaseDTO, response.getStatusCode());
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));

if (!OutputValidationUtil.publishOutputResult(ouputValid))
Expand Down Expand Up @@ -252,8 +253,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
}

ouputValid = OutputValidationUtil.doJsonOutputValidation(jsonObjectFromIdentityData.toString(),
jsonObjectFromKycData.toString(), testCaseDTO.isCheckErrorsOnlyInResponse(),
response.getStatusCode());
jsonObjectFromKycData.toString(), testCaseDTO, response.getStatusCode());
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));

if (!OutputValidationUtil.publishOutputResult(ouputValid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public Object[] getTestCaseList(ITestContext context) {
public void test(TestCaseDTO testCaseDTO) throws AdminTestException {
testCaseName = testCaseDTO.getTestCaseName();
if (HealthChecker.signalTerminateExecution) {
throw new SkipException(GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
}
if (testCaseDTO.getEndPoint().contains("$partnerKeyURL$")) {
testCaseDTO.setEndPoint(
Expand Down Expand Up @@ -134,7 +135,7 @@ public void test(TestCaseDTO testCaseDTO) throws AdminTestException {

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

if (!OutputValidationUtil.publishOutputResult(ouputValid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
String timeSlotTo = null;
testCaseName = testCaseDTO.getTestCaseName();
if (HealthChecker.signalTerminateExecution) {
throw new SkipException(GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
}
Response slotAvailabilityResponse = RestClient.getRequestWithCookie(
ApplnURI + properties.getProperty("appointmentavailabilityurl")
Expand Down Expand Up @@ -114,7 +115,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad

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

if (!OutputValidationUtil.publishOutputResult(ouputValid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public void test(TestCaseDTO testCaseDTO)
throws AuthenticationTestException, AdminTestException, NoSuchAlgorithmException {
testCaseName = testCaseDTO.getTestCaseName();
if (HealthChecker.signalTerminateExecution) {
throw new SkipException(GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
}
testCaseDTO.setInputTemplate(AdminTestUtil.generateHbsForPrereg(false));
String[] templateFields = testCaseDTO.getTemplateFields();
Expand All @@ -106,7 +107,7 @@ public void test(TestCaseDTO testCaseDTO)
Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(),
getJsonFromTemplate(outputtestcase.get(i).toString(), testCaseDTO.getOutputTemplate()),
testCaseDTO.isCheckErrorsOnlyInResponse(), response.getStatusCode());
testCaseDTO, response.getStatusCode());
if (testCaseDTO.getTestCaseName().toLowerCase().contains("dynamic")) {
JSONObject json = new JSONObject(response.asString());
idField = json.getJSONObject("response").get("id").toString();
Expand All @@ -119,9 +120,8 @@ public void test(TestCaseDTO testCaseDTO)
} else {
response = postWithBodyAndCookieForAutoGeneratedId(ApplnURI + testCaseDTO.getEndPoint(), inputJson,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), idKeyName);
Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(), outputJson, testCaseDTO.isCheckErrorsOnlyInResponse(),
response.getStatusCode());
Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil
.doJsonOutputValidation(response.asString(), outputJson, testCaseDTO, response.getStatusCode());
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));
if (!OutputValidationUtil.publishOutputResult(ouputValid))
throw new AdminTestException("Failed at output validation");
Expand Down
Loading

0 comments on commit fcf306a

Please sign in to comment.