From a3bc53ba27960c9ceb1ed803d9541e2145b41517 Mon Sep 17 00:00:00 2001 From: Nandhukumar Date: Fri, 4 Oct 2024 17:39:48 +0530 Subject: [PATCH] MOSIP-35404 Signed-off-by: Nandhukumar --- .../testrig/apirig/dbaccess/DBManager.java | 150 +----------------- .../apirig/testrunner/BaseTestCase.java | 119 ++++++++++---- .../apirig/testrunner/OTPListener.java | 5 +- 3 files changed, 93 insertions(+), 181 deletions(-) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/dbaccess/DBManager.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/dbaccess/DBManager.java index e8713a7970..596f9fa58e 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/dbaccess/DBManager.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/dbaccess/DBManager.java @@ -19,16 +19,15 @@ 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(); @@ -36,145 +35,6 @@ public static void clearPMSDbData() { } } - 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() { diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/testrunner/BaseTestCase.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/testrunner/BaseTestCase.java index 57b7bdc8b7..63ef029e54 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/testrunner/BaseTestCase.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/testrunner/BaseTestCase.java @@ -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 preIds = new ArrayList<>(); public ExtentHtmlReporter htmlReporter; public ExtentReports extent; @@ -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"); @@ -314,23 +305,42 @@ 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(); @@ -338,43 +348,76 @@ public static void suiteSetup( String runType) { 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(); @@ -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); } diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/testrunner/OTPListener.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/testrunner/OTPListener.java index 03225e2f6c..32d96a5259 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/testrunner/OTPListener.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/testrunner/OTPListener.java @@ -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";