Skip to content

Commit

Permalink
MOSIP-36077 - Restructured the config manager
Browse files Browse the repository at this point in the history
Signed-off-by: Mohanachandran S <[email protected]>
  • Loading branch information
mohanachandran-s committed Oct 3, 2024
2 parents ad75999 + 5cd3a91 commit 96ca082
Show file tree
Hide file tree
Showing 95 changed files with 1,096 additions and 528 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.CertificateGenerationUtil;
import io.mosip.testrig.apirig.utils.CertsUtil;
import io.mosip.testrig.apirig.utils.ConfigManager;
import io.mosip.testrig.apirig.utils.EncryptionDecrptionUtil;
import io.mosip.testrig.apirig.utils.GlobalConstants;
import io.mosip.testrig.apirig.utils.JWKKeyUtil;
import io.mosip.testrig.apirig.utils.KeyCloakUserAndAPIKeyGeneration;
import io.mosip.testrig.apirig.utils.KeycloakUserManager;
import io.mosip.testrig.apirig.utils.MispPartnerAndLicenseKeyGeneration;
import io.mosip.testrig.apirig.utils.OutputValidationUtil;
import io.mosip.testrig.apirig.utils.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.PartnerRegistration;

/**
Expand Down Expand Up @@ -62,14 +61,15 @@ public static void main(String[] arg) {
for (String envName : envMap.keySet()) {
LOGGER.info(String.format("ENV %s = %s%n", envName, envMap.get(envName)));
}
BaseTestCase.setRunContext(getRunType(), jarUrl);
ExtractResource.removeOldMosipTestTestResource();
if (checkRunType().equalsIgnoreCase("JAR")) {
if (getRunType().equalsIgnoreCase("JAR")) {
ExtractResource.extractCommonResourceFromJar();
} else {
ExtractResource.copyCommonResources();
}
ConfigManager.init();
BaseTestCase.suiteSetup();
PMSRevampConfigManger.init();
BaseTestCase.suiteSetup(getRunType());
setLogLevels();
//AdminTestUtil.encryptDecryptUtil = new EncryptionDecrptionUtil();

Expand Down Expand Up @@ -140,7 +140,7 @@ public static void main(String[] arg) {
LOGGER.error("Exception " + e.getMessage());
}

MockSMTPListener.bTerminate = true;
OTPListener.bTerminate = true;

if (BaseTestCase.isTargetEnvLTS())
HealthChecker.bTerminate = true;
Expand Down Expand Up @@ -171,7 +171,7 @@ public static void startTestRunner() {
List<String> modulesToRun = BaseTestCase.listOfModules;
String os = System.getProperty("os.name");
LOGGER.info(os);
if (checkRunType().contains("IDE") || os.toLowerCase().contains("windows")) {
if (getRunType().contains("IDE") || os.toLowerCase().contains("windows")) {
homeDir = new File(System.getProperty("user.dir") + "/testNgXmlFiles");
LOGGER.info("IDE :" + homeDir);
} else {
Expand Down Expand Up @@ -200,28 +200,16 @@ public static void startTestRunner() {
* @return String
* @throws IOException
*/
/*
* public static String getGlobalResourcePath() { if
* (checkRunType().equalsIgnoreCase("JAR")) { return new
* File(jarUrl).getParentFile().getAbsolutePath() +
* "/MosipTestResource/MosipTemporaryTestResource"; } else if
* (checkRunType().equalsIgnoreCase("IDE")) { String path = new
* File(MosipTestRunner.class.getClassLoader().getResource("").getPath()).
* getAbsolutePath() + "/MosipTestResource/MosipTemporaryTestResource"; if
* (path.contains(GlobalConstants.TESTCLASSES)) path =
* path.replace(GlobalConstants.TESTCLASSES, "classes"); return path; } return
* "Global Resource File Path Not Found"; }
*/

public static String getGlobalResourcePath() {
if (cachedPath != null) {
return cachedPath;
}

String path = null;
if (checkRunType().equalsIgnoreCase("JAR")) {
if (getRunType().equalsIgnoreCase("JAR")) {
path = new File(jarUrl).getParentFile().getAbsolutePath() + "/MosipTestResource/MosipTemporaryTestResource";
} else if (checkRunType().equalsIgnoreCase("IDE")) {
} else if (getRunType().equalsIgnoreCase("IDE")) {
path = new File(MosipTestRunner.class.getClassLoader().getResource("").getPath()).getAbsolutePath()
+ "/MosipTestResource/MosipTemporaryTestResource";
if (path.contains(GlobalConstants.TESTCLASSES))
Expand All @@ -238,15 +226,6 @@ public static String getGlobalResourcePath() {

public static String getResourcePath() {
return getGlobalResourcePath();
// if (checkRunType().equalsIgnoreCase("JAR")) {
// return new File(jarUrl).getParentFile().getAbsolutePath();
// } else if (checkRunType().equalsIgnoreCase("IDE")) {
// String path = new File(MosipTestRunner.class.getClassLoader().getResource("").getPath()).getAbsolutePath();
// if (path.contains(GlobalConstants.TESTCLASSES))
// path = path.replace(GlobalConstants.TESTCLASSES, "classes");
// return path;
// }
// return "Global Resource File Path Not Found";
}

public static String generatePulicKey() {
Expand Down Expand Up @@ -340,7 +319,7 @@ public static Properties getproperty(String path) {
*
* @return
*/
public static String checkRunType() {
public static String getRunType() {
if (MosipTestRunner.class.getResource("MosipTestRunner.class").getPath().contains(".jar"))
return "JAR";
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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.PMSRevampConfigManger;
import io.restassured.response.Response;

public class AuditValidator extends AdminTestUtil implements ITest {
Expand All @@ -49,7 +50,7 @@ public String getTestName() {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down Expand Up @@ -77,7 +78,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
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")+"'";
String query = "select * from audit.app_audit_log where cr_by = '"+BaseTestCase.currentModule +"-"+props.getProperty("partner_userName")+"'";


logger.info(query);
Expand Down Expand Up @@ -111,7 +112,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
@AfterMethod(alwaysRun = true)
public void setResultTestName(ITestResult result) {

String deleteQuery = "delete from audit.app_audit_log where cr_by = '"+propsKernel.getProperty("partner_userName")+"'";
String deleteQuery = "delete from audit.app_audit_log where cr_by = '"+props.getProperty("partner_userName")+"'";
logger.info(deleteQuery);
AuditDBManager.executeQueryAndDeleteRecord("audit", deleteQuery);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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.PMSRevampConfigManger;
import io.restassured.response.Response;

public class DBValidator extends AdminTestUtil implements ITest {
Expand All @@ -43,7 +44,7 @@ public class DBValidator extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -40,7 +41,7 @@ public class GetWithParam extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -39,7 +40,7 @@ public class GetWithQueryParam extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -39,7 +40,7 @@ public class PatchWithPathParamsAndBody extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -42,7 +43,7 @@ public class PostWithBodyAndPathParams extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -39,7 +40,7 @@ public class PostWithOnlyPathParam extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -41,7 +42,7 @@ public class PutWithPathParamsAndBody extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -39,7 +40,7 @@ public class SimplePatch extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -40,7 +41,7 @@ public class SimplePatchForAutoGenId extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -40,7 +41,7 @@ public class SimplePost extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -43,7 +44,7 @@ public class SimplePostForAutoGenId extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -40,7 +41,7 @@ public class SimplePostWithoutBody extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.PMSRevampConfigManger;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.restassured.response.Response;

Expand All @@ -40,7 +41,7 @@ public class SimplePut extends AdminTestUtil implements ITest {

@BeforeClass
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
if (PMSRevampConfigManger.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.mosip.testrig.apirig.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.log4j.Logger;


import io.mosip.testrig.apirig.testrunner.MosipTestRunner;
public class PMSRevampConfigManger extends ConfigManager{
private static final Logger LOGGER = Logger.getLogger(PMSRevampConfigManger.class);

public static void init() {
Map<String, Object> moduleSpecificPropertiesMap = new HashMap<>();
// Load scope specific properties
try {
String path = MosipTestRunner.getGlobalResourcePath() + "/config/pmsRevamp.properties";
Properties props = getproperties(path);
// Convert Properties to Map and add to moduleSpecificPropertiesMap
for (String key : props.stringPropertyNames()) {
moduleSpecificPropertiesMap.put(key, props.getProperty(key));
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
// Add module specific properties as well.
init(moduleSpecificPropertiesMap);
}
}
Loading

0 comments on commit 96ca082

Please sign in to comment.