Skip to content

Commit

Permalink
Merge pull request #1634 from nandhu-kumar/develop
Browse files Browse the repository at this point in the history
MOSIP-36284 | API/DSL  Make DBManager in API-Test common more generic
  • Loading branch information
mohanachandran-s authored Oct 4, 2024
2 parents 17f533d + b07e1a1 commit cf2dec8
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,162 +19,22 @@
import io.mosip.testrig.apirig.utils.ConfigManager;
import io.mosip.testrig.apirig.utils.GlobalConstants;
public class DBManager {
private static Logger logger = Logger.getLogger(DBManager.class);
private static Logger logger = Logger.getLogger(DBManager.class);

public static void clearPMSDbData() {
public static void executeDBQueries(String dbURL, String dbUser, String dbPassword, String dbSchema, String dbQueryFile) {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getPMSDbUrl(), ConfigManager.getPMSDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getPMSDbSchema());
executeQueries(session, BaseTestCase.getGlobalResourcePath() + "/" + "config/pmsDataDeleteQueries.txt");
session = getDataBaseConnection(dbURL, dbUser, dbPassword, dbSchema);
executeQueries(session, dbQueryFile);
} catch (Exception e) {
logger.error("Error:: While executing PMS DB Quiries." + e.getMessage());
logger.error("Error:: While executing DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}

public static void clearPartnerRevampDbData() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getPMSDbUrl(), ConfigManager.getPMSDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getPMSDbSchema());
executeQueries(session, BaseTestCase.getGlobalResourcePath() + "/" + "config/partnerRevampDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing PMS REVAMP DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}

public static void clearKeyManagerDbDataForPartnerRevamp() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema());
executeQueries(session, BaseTestCase.getGlobalResourcePath() + "/" + "config/partnerRevampDataDeleteQueriesForKeyMgr.txt");
} catch (Exception e) {
logger.error("Error:: While executing PMS DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}
public static void clearIDADbDataForPartnerRevamp() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema());
executeQueries(session, BaseTestCase.getGlobalResourcePath() + "/" + "config/partnerRevampDataDeleteQueriesForIDA.txt");
} catch (Exception e) {
logger.error("Error:: While executing IDA DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}

public static void clearKeyManagerDbData() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema());
executeQueries(session, BaseTestCase.getGlobalResourcePath() + "/" + "config/keyManagerDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing PMS DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}

public static void clearKeyManagerDbCertData() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema());
executeQueries(session, BaseTestCase.getGlobalResourcePath() + "/"
+ "config/keyManagerCertDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing PMS DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}

public static void clearMasterDbData() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema());
executeQueries(session, BaseTestCase.getGlobalResourcePath() + "/" + "config/masterDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing MASTER DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}

public static void clearMasterDbCertData() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema());
executeQueries(session,
BaseTestCase.getGlobalResourcePath() + "/" + "config/masterDataCertDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing MASTER DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}

public static void clearIDADbCertData() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema());
executeQueries(session,
BaseTestCase.getGlobalResourcePath() + "/" + "config/idaCertDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing MASTER DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}

public static void clearIdRepoData()
{
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getIdRepoDbUrl(), ConfigManager.getIdRepoDbUser(),
ConfigManager.getPMSDbPass(), "idrepo");
executeQueries(session,
BaseTestCase.getGlobalResourcePath() + "/" + "config/idrepoCertDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing IDREPO DB Quiries." + e.getMessage());
} finally {
if (session != null) {
session.close();
}
}
}

public static void executeQueries(Session session, String strQueriesFilePath) throws Exception {
if (session != null) {
session.doWork(new Work() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
public class BaseTestCase extends AbstractTestNGSpringContextTests {

protected static Logger logger = Logger.getLogger(BaseTestCase.class);
protected static OTPListener otpListener = null;
public static OTPListener otpListener = null;
public static List<String> preIds = new ArrayList<>();
public ExtentHtmlReporter htmlReporter;
public ExtentReports extent;
Expand Down Expand Up @@ -292,16 +292,7 @@ public static void suiteSetup( String runType) {
if (ConfigManager.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
File logFile = new File("./src/logs/mosip-api-test.log");
if (logFile.exists())
try {
FileUtils.forceDelete(logFile);
} catch (IOException e1) {
logger.error("Failed to delete old log file");
}
logger.info("Test Framework for Mosip api Initialized");
logger.info("Logging initialized: All logs are located at " + "src/logs/mosip-api-test.log");
initialize();
logger.info("Done with BeforeSuite and test case setup! su TEST EXECUTION!\n\n");

Expand All @@ -314,67 +305,119 @@ public static void suiteSetup( String runType) {
setReportName("auth");
BaseTestCase.currentModule = "auth";
BaseTestCase.certsForModule = "IDA";
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
DBManager.executeDBQueries(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema(),
getGlobalResourcePath() + "/" + "config/keyManagerDataDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema(),
getGlobalResourcePath() + "/" + "config/idaDeleteQueriesForEsignet.txt");

DBManager.executeDBQueries(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema(),
getGlobalResourcePath() + "/" + "config/masterDataDeleteQueriesForEsignet.txt");
AuthTestsUtil.initiateAuthTest();
}
if (listOfModules.contains("idrepo")) {
setReportName("idrepo");
BaseTestCase.currentModule = "idrepo";
BaseTestCase.certsForModule = "idrepo";
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
DBManager.clearIdRepoData();
DBManager.executeDBQueries(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema(),
getGlobalResourcePath() + "/" + "config/keyManagerDataDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema(),
getGlobalResourcePath() + "/" + "config/idaDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema(),
getGlobalResourcePath() + "/" + "config/masterDataDeleteQueriesForEsignet.txt");

DBManager.executeDBQueries(ConfigManager.getIdRepoDbUrl(), ConfigManager.getIdRepoDbUser(),
ConfigManager.getPMSDbPass(), "idrepo",
getGlobalResourcePath() + "/" + "config/idrepoCertDataDeleteQueries.txt");

AdminTestUtil.copyIdrepoTestResource();
}
if (listOfModules.contains(GlobalConstants.MASTERDATA)) {
DBManager.clearMasterDbData();
DBManager.executeDBQueries(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema(),
getGlobalResourcePath() + "/" + "config/masterDataDeleteQueries.txt");
BaseTestCase.currentModule = GlobalConstants.MASTERDATA;
setReportName(GlobalConstants.MASTERDATA);
AdminTestUtil.initiateMasterDataTest();
}
if (listOfModules.contains(GlobalConstants.MIMOTO)) {
BaseTestCase.currentModule = GlobalConstants.MIMOTO;
BaseTestCase.certsForModule = GlobalConstants.MIMOTO;
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
DBManager.executeDBQueries(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema(),
getGlobalResourcePath() + "/" + "config/keyManagerDataDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema(),
getGlobalResourcePath() + "/" + "config/idaDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema(),
getGlobalResourcePath() + "/" + "config/masterDataDeleteQueriesForEsignet.txt");
setReportName(GlobalConstants.MIMOTO);
AdminTestUtil.initiateMimotoTest();
}
if (listOfModules.contains(GlobalConstants.ESIGNET)) {
BaseTestCase.currentModule = GlobalConstants.ESIGNET;
BaseTestCase.certsForModule = GlobalConstants.ESIGNET;
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
DBManager.executeDBQueries(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema(),
getGlobalResourcePath() + "/" + "config/keyManagerDataDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema(),
getGlobalResourcePath() + "/" + "config/idaDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema(),
getGlobalResourcePath() + "/" + "config/masterDataDeleteQueriesForEsignet.txt");
setReportName(GlobalConstants.ESIGNET);
AdminTestUtil.initiateesignetTest();
}
if (listOfModules.contains(GlobalConstants.RESIDENT)) {
BaseTestCase.currentModule = GlobalConstants.RESIDENT;
BaseTestCase.certsForModule = GlobalConstants.RESIDENT;
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
DBManager.executeDBQueries(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema(),
getGlobalResourcePath() + "/" + "config/keyManagerDataDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema(),
getGlobalResourcePath() + "/" + "config/idaDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema(),
getGlobalResourcePath() + "/" + "config/masterDataDeleteQueriesForEsignet.txt");
setReportName(GlobalConstants.RESIDENT);
AdminTestUtil.copyResidentTestResource();
}
if (listOfModules.contains("partner")) {
BaseTestCase.currentModule = "partner";
DBManager.clearPMSDbData();
DBManager.clearKeyManagerDbData();
DBManager.executeDBQueries(ConfigManager.getPMSDbUrl(), ConfigManager.getPMSDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getPMSDbSchema(),
getGlobalResourcePath() + "/" + "config/pmsDataDeleteQueries.txt");

DBManager.executeDBQueries(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema(),
getGlobalResourcePath() + "/" + "config/keyManagerDataDeleteQueries.txt");

BaseTestCase.currentModule = "partner";
setReportName("partner");
AdminTestUtil.copyPartnerTestResource();
}
if (listOfModules.contains(GlobalConstants.PARTNERNEW)) {
BaseTestCase.currentModule = GlobalConstants.PARTNERNEW;
DBManager.clearPartnerRevampDbData();
DBManager.clearKeyManagerDbDataForPartnerRevamp();
DBManager.clearIDADbDataForPartnerRevamp();
DBManager.executeDBQueries(ConfigManager.getPMSDbUrl(), ConfigManager.getPMSDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getPMSDbSchema(),
getGlobalResourcePath() + "/" + "config/partnerRevampDataDeleteQueries.txt");

DBManager.executeDBQueries(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema(),
getGlobalResourcePath() + "/" + "config/partnerRevampDataDeleteQueriesForKeyMgr.txt");

DBManager.executeDBQueries(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema(),
getGlobalResourcePath() + "/" + "config/partnerRevampDataDeleteQueriesForIDA.txt");

BaseTestCase.currentModule = GlobalConstants.PARTNERNEW;
setReportName(GlobalConstants.PARTNERNEW);
AdminTestUtil.copyPmsNewTestResource();
Expand All @@ -387,9 +430,15 @@ public static void suiteSetup( String runType) {
if (listOfModules.contains(GlobalConstants.INJICERTIFY)) {
BaseTestCase.currentModule = GlobalConstants.INJICERTIFY;
BaseTestCase.certsForModule = GlobalConstants.INJICERTIFY;
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
DBManager.executeDBQueries(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema(),
getGlobalResourcePath() + "/" + "config/keyManagerDataDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema(),
getGlobalResourcePath() + "/" + "config/idaDeleteQueriesForEsignet.txt");
DBManager.executeDBQueries(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema(),
getGlobalResourcePath() + "/" + "config/masterDataDeleteQueriesForEsignet.txt");
setReportName(GlobalConstants.INJICERTIFY);
AdminTestUtil.copymoduleSpecificAndConfigFile(GlobalConstants.INJICERTIFY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ public OTPListener() {

public void run() {
try {
// Properties kernelprops = ConfigManager.propsKernel;
String a1 = "wss://smtp.";
String externalurl = ConfigManager.getIAMUrl();

if (externalurl.contains("/auth")) {
externalurl = externalurl.replace("/auth", "");
}
String a2 = externalurl.substring(externalurl.indexOf(".") + 1);
String a3 = "/mocksmtp/websocket";

Expand Down

0 comments on commit cf2dec8

Please sign in to comment.