Skip to content

Commit

Permalink
Merge pull request #1625 from mohanachandran-s/develop
Browse files Browse the repository at this point in the history
MOSIP-36077 - Restructured the config manager
  • Loading branch information
lsivanand authored Sep 30, 2024
2 parents 246de19 + 0a09092 commit 8c43f21
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package io.mosip.testrig.apirig.dbaccess;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
Expand All @@ -19,14 +17,11 @@
import org.hibernate.jdbc.Work;
import org.testng.Assert;

import io.mosip.testrig.apirig.testrunner.MosipTestRunner;
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.ConfigManager;

public class AuditDBManager extends AdminTestUtil {
private static final Logger DBCONNECTION_LOGGER = Logger.getLogger(AuditDBManager.class);
private static Map<String, Object> records;
private static List<Map<String, Object>> allRecords;
public static String env = System.getProperty("env.user");
public static Map<String, SessionFactory> sessionFactoryMapS = Collections
.synchronizedMap(new HashMap<String, SessionFactory>());
Expand Down Expand Up @@ -104,40 +99,38 @@ private static Session getDataBaseConnection(String dbName) {
Session session = null;
SessionFactory sessionFactory = sessionFactoryMapS.get(dbName);
if (sessionFactory == null) {
try {
try {
sessionFactory = getDataBaseConnectionSessionFactory(dbName);
sessionFactoryMapS.put(dbName, sessionFactory);
} catch (HibernateException e) {
DBCONNECTION_LOGGER.error("Exception in Database Connection with following message: " + e.getMessage());
} catch (NullPointerException e) {
Assert.assertTrue(false, "Exception in getting the SessionFactory for DB Schema : " + dbName );
Assert.assertTrue(false, "Exception in getting the SessionFactory for DB Schema : " + dbName);
}
}
if (sessionFactory != null) {
session = sessionFactory.getCurrentSession();
session.beginTransaction();
DBCONNECTION_LOGGER.info("Session begined with Schema : " + dbName);
}
return session;
return session;
}

private static SessionFactory getDataBaseConnectionSessionFactory(String dbName) {
SessionFactory factory = null;
String dbschema = ConfigManager.getAuditDbSchema();

if(dbName.equalsIgnoreCase("partner"))
dbschema=ConfigManager.getIdaDbSchema();
if(dbName.equalsIgnoreCase("master"))
dbschema=ConfigManager.getMasterDbSchema();
if (dbName.equalsIgnoreCase("partner"))
dbschema = ConfigManager.getIdaDbSchema();

if (dbName.equalsIgnoreCase("master"))
dbschema = ConfigManager.getMasterDbSchema();

try {
Configuration config = new Configuration();
config.setProperty("hibernate.connection.driver_class", ConfigManager.getproperty("driver_class"));
config.setProperty("hibernate.connection.url",
"jdbc:" + ConfigManager.getproperty("postgresqlUser") + "://"
+ ConfigManager.getDbServer() + ":" + ConfigManager.getDbPort()
+ "/mosip_" + dbschema);
config.setProperty("hibernate.connection.url", "jdbc:" + ConfigManager.getproperty("postgresqlUser") + "://"
+ ConfigManager.getDbServer() + ":" + ConfigManager.getDbPort() + "/mosip_" + dbschema);
config.setProperty("hibernate.connection.username", ConfigManager.getAuditDbUser());
config.setProperty("hibernate.connection.password", ConfigManager.getAuditDbPass());
config.setProperty("hibernate.default_schema", ConfigManager.getproperty(dbName + "_default_schema"));
Expand All @@ -146,21 +139,20 @@ private static SessionFactory getDataBaseConnectionSessionFactory(String dbName)
config.setProperty("hibernate.show_sql", ConfigManager.getproperty("show_sql"));
config.setProperty("hibernate.current_session_context_class",
ConfigManager.getproperty("current_session_context_class"));
factory = config.buildSessionFactory();
factory = config.buildSessionFactory();
} catch (HibernateException e) {
DBCONNECTION_LOGGER.error("Exception in Database Connection with following message: " + e.getMessage());
} catch (NullPointerException e) {
Assert.assertTrue(false, "Exception in getting the SessionFactory for DB Schema : " + dbschema );
Assert.assertTrue(false, "Exception in getting the SessionFactory for DB Schema : " + dbschema);
}
return factory;
}


public static void closeDataBaseConnection(Session session) {
if (session != null) {
DBCONNECTION_LOGGER.info("Session closed");
session.close();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.apache.commons.lang3.SerializationUtils;
import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.ISuiteResult;
Expand Down Expand Up @@ -187,6 +185,14 @@ private String getCommitId() {
}

}

private static String convertMillisToTime(long milliseconds) {
long seconds = (milliseconds / 1000) % 60;
long minutes = (milliseconds / (1000 * 60)) % 60;
long hours = (milliseconds / (1000 * 60 * 60)) % 24;
// Format time into HH:MM:SS
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}

protected PrintWriter createWriter(String outdir) throws IOException {
new File(outdir).mkdirs();
Expand Down Expand Up @@ -253,7 +259,6 @@ protected void writeDocumentEnd() {

protected void writeSuiteSummary() {
NumberFormat integerFormat = NumberFormat.getIntegerInstance();
NumberFormat decimalFormat = NumberFormat.getNumberInstance();
LocalDate currentDate = LocalDate.now();
String formattedDate =null;
String branch = null;
Expand Down Expand Up @@ -335,7 +340,7 @@ protected void writeSuiteSummary() {
if (reportKnownIssueTestCases) {
writer.print("<th># Known_Issues</th>");
}
writer.print("<th>Execution Time (ms)</th>");
writer.print("<th>Execution Time (HH:MM:SS)</th>");
// writer.print("<th>Included Groups</th>");
// writer.print("<th>Excluded Groups</th>");
writer.print(GlobalConstants.TR);
Expand Down Expand Up @@ -388,7 +393,7 @@ protected void writeSuiteSummary() {
if (reportKnownIssueTestCases) {
writeTableData(integerFormat.format(knownIssueTests), (knownIssueTests > 0 ? "num thich-orange-bg" : "num"));
}
writeTableData(decimalFormat.format(duration), "num");
writeTableData(convertMillisToTime(duration), "num");
// writeTableData(testResult.getIncludedGroups());
// writeTableData(testResult.getExcludedGroups());

Expand Down Expand Up @@ -435,7 +440,7 @@ protected void writeSuiteSummary() {
writeTableHeader(integerFormat.format(totalKnownIssueTests),
(totalKnownIssueTests > 0 ? "num thich-orange-bg" : "num"));
}
writeTableHeader(decimalFormat.format(totalDuration), "num");
writeTableHeader(convertMillisToTime(totalDuration), "num");
writer.print(GlobalConstants.TR);
}

Expand Down Expand Up @@ -505,7 +510,7 @@ protected void writeScenarioSummary() {
writer.print("<th>Unique Identifier</th>");
writer.print("<th>Test Case</th>");
writer.print("<th>Test Case Description</th>");
writer.print("<th>Execution Time (ms)</th>");
writer.print("<th>Execution Time (HH:MM:SS)</th>");
writer.print(GlobalConstants.TR);
writer.print("</thead>");

Expand Down Expand Up @@ -636,7 +641,7 @@ private int writeScenarioSummary(String description, List<ClassResult> classResu
.append(methodName).append("</a></td>").append("<td style=\"text-align:center;\">")
.append(testCaseDescription).append("</td>")
.append("<td style=\"text-align:center;\" rowspan=\"").append(resultsCount).append("\">")
.append(duration).append("</td></tr>");
.append(convertMillisToTime(duration)).append("</td></tr>");

scenarioIndex++;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -39,8 +40,6 @@
import io.mosip.testrig.apirig.utils.GlobalConstants;
import io.mosip.testrig.apirig.utils.GlobalMethods;
import io.mosip.testrig.apirig.utils.KernelAuthentication;
import io.mosip.testrig.apirig.utils.KeycloakUserManager;
import io.mosip.testrig.apirig.utils.PartnerRegistration;
import io.mosip.testrig.apirig.utils.RestClient;
import io.restassured.RestAssured;
import io.restassured.response.Response;
Expand Down Expand Up @@ -346,8 +345,18 @@ public static void suiteSetup() {

public static void setReportName(String moduleName) {
System.getProperties().setProperty("emailable.report2.name",
"mosip-" + environment + "-" + moduleName + "-" + System.currentTimeMillis() + "-report.html");
"mosip-" + environment + "-" + moduleName + "-" + getCurrentDateTime() + "-report.html");
}

// Method to get the current date and time in the specified format
public static String getCurrentDateTime() {
// Get the current date and time
LocalDateTime now = LocalDateTime.now();
// Define the desired formatter with the pattern "yyyy-MM-dd_HH:mm:ss"
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm");
// Format the current date and time using the formatter
return now.format(formatter);
}

/**
* After the entire test suite clean up rest assured
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
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.GlobalMethods;
import io.mosip.testrig.apirig.utils.JWKKeyUtil;
import io.mosip.testrig.apirig.utils.KeyCloakUserAndAPIKeyGeneration;
import io.mosip.testrig.apirig.utils.KeycloakUserManager;
Expand Down Expand Up @@ -69,7 +66,6 @@ public static void main(String[] arg) {
} else {
ExtractResource.copyCommonResources();
}
// ConfigManager.init();
BaseTestCase.suiteSetup();
setLogLevels();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.log4j.Logger;

import io.mosip.testrig.apirig.testrunner.MosipTestRunner;

public class ConfigManager {
private static final Logger LOGGER = Logger.getLogger(ConfigManager.class);

Expand Down Expand Up @@ -110,8 +106,7 @@ public static String getproperty(String key) {


public static String getRolesForUser(String userId) {
Properties props = getproperties(MosipTestRunner.getGlobalResourcePath() + "/" + "config/Kernel.properties");
return props.getProperty("roles." + userId);
return getproperty("roles." + userId);
}

public static String getServerErrorsToMonitor() { return getproperty("serverErrorsToMonitor"); }
Expand Down
16 changes: 6 additions & 10 deletions apitest-commons/src/main/resources/config/Kernel.properties
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ auditActuatorEndpoint=/v1/auditmanager/actuator/info
validateBindingEndpoint=ida-binding
esignetWellKnownEndPoint=/v1/esignet/oidc/.well-known/openid-configuration
signupSettingsEndPoint=/v1/signup/settings

esignetActuatorPropertySection=esignet-default.properties



Expand Down Expand Up @@ -210,10 +210,7 @@ hibernate.show_sql=true
hibernate.current_session_context_class=thread
db-su-user=postgres
postgres-password=
pms_db_schema=pms
km_db_schema=keymgr
master_db_schema=master
audit_db_schema=audit
ida_db_schema=ida


Expand Down Expand Up @@ -241,6 +238,7 @@ usePreConfiguredOtp=false
eSignetDeployed=yes
partnerUrlSuffix=oYf63Lax0DY2QkYMRHnrmDqhmO3RMWQagwm0ftgLlkuin1KOND/666/576732
reportIgnoredTestCases=no
reportKnownIssueTestCases=no
servicesNotDeployed=
esignetMockBaseURL=esignet-insurance.
sunBirdBaseURL=registry
Expand All @@ -258,6 +256,8 @@ admin_password=mosip123
admin_userName=220005
admin_zone_password=mosip123
admin_zone_userName=globaladmin
mockNotificationChannel=email,phone
mountPathForReport=/home/mosip/testrig/report



Expand All @@ -272,13 +272,9 @@ langselect=0

#----------------------------------AuthDemoService Host properties----------------------------------------------------------#
#Uncommemnt the below to run locally
authDemoServiceBaseURL=http://localhost
authDemoServicePort=8082
authCertsPath=
#authCertsPath=
#Uncommemnt the below to run in Docker
#authDemoServiceBaseURL=http://authdemo.apitestrig
#authDemoServicePort=80
#authCertsPath=/home/mosip/authcerts
authCertsPath=/home/mosip/authcerts


mosip_components_base_urls=
Expand Down

0 comments on commit 8c43f21

Please sign in to comment.