-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #669 from Sohandey/develop
Develop
- Loading branch information
Showing
18 changed files
with
583 additions
and
2 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
apitest/src/main/java/io/mosip/testrig/apirig/testscripts/AuditValidator.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,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()); | ||
} | ||
} | ||
} |
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
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
4
apitest/src/main/resources/preReg/AuditLog/AuditLogResult.hbs
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,4 @@ | ||
{ | ||
"module_name": "{{module_name}}", | ||
"cr_by": "{{cr_by}}" | ||
} |
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,3 @@ | ||
{ | ||
"moduleName": "{{moduleName}}" | ||
} |
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
3 changes: 3 additions & 0 deletions
3
...ources/preReg/GetAllApplicationsWithapplicationId/GetAllApplicationsWithapplicationId.hbs
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,3 @@ | ||
{ | ||
"applicationId": "{{applicationId}}" | ||
} |
Oops, something went wrong.