Skip to content

Commit

Permalink
Merge pull request #669 from Sohandey/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ckm007 authored May 15, 2024
2 parents 64a125c + daf6f82 commit 07a2a5a
Show file tree
Hide file tree
Showing 18 changed files with 583 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package io.mosip.testrig.apirig.testscripts;

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

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
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.dbaccess.AuditDBManager;
import io.mosip.testrig.apirig.dto.OutputValidationDto;
import io.mosip.testrig.apirig.dto.TestCaseDTO;
import io.mosip.testrig.apirig.testrunner.BaseTestCase;
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.restassured.response.Response;

public class AuditValidator extends AdminTestUtil implements ITest {
private static final Logger logger = Logger.getLogger(AuditValidator.class);
protected String testCaseName = "";
public static List<String> templateFields = new ArrayList<>();
public Response response = null;
/**
* get current testcaseName
*/
@Override
public String getTestName() {
return testCaseName;
}

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

/**
* 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(dataProvider = "testcaselist")
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);
}
String[] templateFields = testCaseDTO.getTemplateFields();
List<String> queryProp = Arrays.asList(templateFields);
logger.info(queryProp);
String query = "select * from audit.app_audit_log where cr_by = '"+BaseTestCase.currentModule +"-"+propsKernel.getProperty("partner_userName")+"'";


logger.info(query);
Map<String, Object> response = AuditDBManager.executeQueryAndGetRecord(testCaseDTO.getRole(), query);


Map<String, List<OutputValidationDto>> objMap = new HashMap<>();
List<OutputValidationDto> objList = new ArrayList<>();
OutputValidationDto objOpDto = new OutputValidationDto();
if(response.size()>0) {

objOpDto.setStatus("PASS");
}
else {
objOpDto.setStatus(GlobalConstants.FAIL_STRING);
}

objList.add(objOpDto);
objMap.put(GlobalConstants.EXPECTED_VS_ACTUAL, objList);

if (!OutputValidationUtil.publishOutputResult(objMap))
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) {

String deleteQuery = "delete from audit.app_audit_log where cr_by = '"+propsKernel.getProperty("partner_userName")+"'";
logger.info(deleteQuery);
AuditDBManager.executeQueryAndDeleteRecord("audit", deleteQuery);
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 @@ -16,6 +16,120 @@ AddLostUinApplication:
"bookingType": "LOST_FORGOTTEN_UIN",
"applicationStatusCode": "SUBMITTED"
}'
Prereg_AddLostUinApplication_Invalid_id:
endPoint: /preregistration/v1/applications/lostuin
role: batch
templateFields: ["langCode"]
restMethod: post
inputTemplate: preReg/AddLostUinApplication/addLostUinApplication
outputTemplate: preReg/error
input: '{
"version": "1.0",
"requesttime": "$TIMESTAMP$",
"langCode": "eng",
"id": "n.create"
}'
output: '{
"errors": [
{
"errorCode": "PRG_CORE_REQ_014"
}
]
}'
Prereg_AddLostUinApplication_invalid_lang_code:
endPoint: /preregistration/v1/applications/lostuin
role: batch
templateFields: ["langCode"]
restMethod: post
inputTemplate: preReg/AddLostUinApplication/addLostUinApplication
outputTemplate: preReg/error
input: '{
"version": "1.0",
"requesttime": "$TIMESTAMP$",
"langCode": "e@@dd",
"id": "mosip.pre-registration.lostuin.create"
}'
output: '{
"bookingType": "LOST_FORGOTTEN_UIN",
"applicationStatusCode": "SUBMITTED"
}'
Prereg_AddLostUinApplication_without_version:
endPoint: /preregistration/v1/applications/lostuin
role: batch
templateFields: ["langCode"]
restMethod: post
inputTemplate: preReg/AddLostUinApplication/addLostUinApplication
outputTemplate: preReg/error
input: '{
"version": "",
"requesttime": "$TIMESTAMP$",
"langCode": "eng",
"id": "mosip.pre-registration.lostuin.create"
}'
output: '{
"errors": [
{
"errorCode": "PRG_CORE_REQ_014"
}
]
}'
Prereg_AddLostUinApplication_without_version_attribute:
endPoint: /preregistration/v1/applications/lostuin
role: batch
templateFields: ["langCode"]
restMethod: post
inputTemplate: preReg/AddLostUinApplication/addLostUinApplication
outputTemplate: preReg/error
input: '{
"version": "$IGNORE$",
"requesttime": "$TIMESTAMP$",
"langCode": "eng",
"id": "mosip.pre-registration.lostuin.create"
}'
output: '{
"errors": [
{
"errorCode": "PRG_CORE_REQ_014"
}
]
}'
Prereg_AddLostUinApplication_with_INVALID_version:
endPoint: /preregistration/v1/applications/lostuin
role: batch
templateFields: ["langCode"]
restMethod: post
inputTemplate: preReg/AddLostUinApplication/addLostUinApplication
outputTemplate: preReg/error
input: '{
"version": "$353F@GGWYS",
"requesttime": "$TIMESTAMP$",
"langCode": "eng",
"id": "mosip.pre-registration.lostuin.create"
}'
output: '{
"errors": [
{
"errorCode": "PRG_CORE_REQ_014"
}
]
}'
Prereg_AddLostUinApplication_Valid_Smoke_sid:
endPoint: /preregistration/v1/applications/lostuin
role: batch
templateFields: ["langCode"]
restMethod: post
inputTemplate: preReg/AddLostUinApplication/addLostUinApplication
outputTemplate: preReg/AddLostUinApplication/addLostUinApplicationResult
input: '{
"version": "1.0",
"requesttime": "$TIMESTAMP$",
"langCode": "eng",
"id": "mosip.pre-registration.lostuin.create"
}'
output: '{
"bookingType": "LOST_FORGOTTEN_UIN",
"applicationStatusCode": "SUBMITTED"
}'

Prereg_AddLostUinApplication_inValid_langcode:
endPoint: /preregistration/v1/applications/lostuin
Expand All @@ -35,4 +149,23 @@ AddLostUinApplication:
"errorCode": "PRG_CORE_REQ_014"
}
]
}'
Prereg_AddLostUinApplication_without_any_data:
endPoint: /preregistration/v1/applications/lostuin
role: batch
restMethod: post
inputTemplate: preReg/AddLostUinApplication/addLostUinApplication
outputTemplate: preReg/error
input: '{
"version": "",
"requesttime": "",
"langCode": "",
"id": ""
}'
output: '{
"errors": [
{
"errorCode": "PRG_CORE_REQ_014"
}
]
}'
14 changes: 14 additions & 0 deletions apitest/src/main/resources/preReg/AuditLog/AuditLog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
addContact:
Prereg_AddContact_All_Valid_Smoke:
endPoint: SELECT module_name,cr_by FROM audit.app_audit_log where module_name LIKE '%partner%' order by action_dtimes desc LIMIT 5
role: audit
templateFields: ["partnerQuery","partner service"]
restMethod: post
inputTemplate: partner/authPartner/AddContacts/addContact
outputTemplate: partner/authPartner/AddContacts/addContactResult
input: '{
}'
output: '{
"module_name": "partner service"
"cr_by": "111997"
}'
4 changes: 4 additions & 0 deletions apitest/src/main/resources/preReg/AuditLog/AuditLogResult.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"module_name": "{{module_name}}",
"cr_by": "{{cr_by}}"
}
3 changes: 3 additions & 0 deletions apitest/src/main/resources/preReg/AuditLog/auditlog.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"moduleName": "{{moduleName}}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,36 @@ DeleteLostUinApplication:
}'
output: '{
"deletedBy": "$IGNORE$"
}'
Prereg_DeleteLostUinApplication_after_its_deletion:
endPoint: /preregistration/v1/applications/prereg/{applicationId}
role: batch
checkErrorsOnlyInResponse: true
restMethod: delete
inputTemplate: preReg/DeleteLostUinApplication/deleteLostUinApplication
outputTemplate: preReg/error
input: '{
"applicationId": "$ID:CreatePrereg_Valid_Smoke_sid_preRegistrationId$"
}'
output: '{
"errors": [
{
"errorCode": "PRG_PAM_APP_005"
}
]
}'
Prereg_DeleteLostUinApplication_multiple_application_sid:
endPoint: /preregistration/v1/applications/prereg/{applicationId}
role: batch
checkErrorsOnlyInResponse: true
restMethod: delete
inputTemplate: preReg/DeleteLostUinApplication/deleteLostUinApplication
outputTemplate: preReg/DeleteLostUinApplication/deleteLostUinApplicationResult
input: '{
"applicationId": "$ID:CreatePrereg_All_Valid_Smoke_UpdateDocRefID_sid_preRegistrationId$"
}'
output: '{
"deletedBy": "$IGNORE$"
}'
Prereg_DeleteLostUinApplication_inValid_preRegistrationId_sid:
endPoint: /preregistration/v1/applications/prereg/{applicationId}
Expand All @@ -27,4 +57,20 @@ DeleteLostUinApplication:
"errorCode": "PRG_PAM_APP_005"
}
]
}'
Prereg_DeleteLostUinApplication_random_number_sid:
endPoint: /preregistration/v1/applications/prereg/{applicationId}
role: batch
restMethod: delete
inputTemplate: preReg/DeleteLostUinApplication/deleteLostUinApplication
outputTemplate: preReg/error
input: '{
"applicationId": "12736445738389"
}'
output: '{
"errors": [
{
"errorCode": "PRG_PAM_APP_005"
}
]
}'
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ GetAllApplications:
"type": null
}'
output: '{
}'
Prereg_GetAllApplications_InValid:
endPoint: /preregistration/v1/applications
role: batch
checkErrorsOnlyInResponse: true
restMethod: get
inputTemplate: preReg/GetAllApplications/getAllApplications
outputTemplate: preReg/error
input: '{
"type": "263gedbdbegegedb"
}'
output: '{
"errors": [
{
"errorCode": "PRG_APP_016"
}
]
}'
Prereg_GetAllApplications_InValid_Type:
endPoint: /preregistration/v1/applications?type={type}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"applicationId": "{{applicationId}}"
}
Loading

0 comments on commit 07a2a5a

Please sign in to comment.