Skip to content

Commit

Permalink
MOSIP-34117
Browse files Browse the repository at this point in the history
Signed-off-by: Mohanachandran S <[email protected]>
  • Loading branch information
mohanachandran-s committed Jul 5, 2024
1 parent 2c7afcd commit c098904
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ protected Response postWithBodyAndCookie(String url, String jsonInput, boolean a
}

}

logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, inputJson, url);
try {
Expand Down Expand Up @@ -1117,8 +1117,7 @@ protected Response postWithBodyAndCookieForAutoGeneratedId(String url, String js
if (BaseTestCase.currentModule.equals(GlobalConstants.MIMOTO) || BaseTestCase.currentModule.equals("auth")
|| BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET)
|| BaseTestCase.currentModule.equals(GlobalConstants.RESIDENT)
|| BaseTestCase.currentModule.equals(GlobalConstants.MASTERDATA)
|| BaseTestCase.currentModule.equals(GlobalConstants.PREREG)) {
|| BaseTestCase.currentModule.equals(GlobalConstants.MASTERDATA)) {
inputJson = smtpOtpHandler(inputJson, testCaseName);
}
if (bothAccessAndIdToken) {
Expand Down Expand Up @@ -2036,14 +2035,14 @@ protected Response getWithPathParamAndCookie(String url, String jsonInput, boole
GlobalConstants.ERROR_STRING_1 + jsonInput + GlobalConstants.EXCEPTION_STRING_1 + e.getMessage());
}

if (map.containsKey(GlobalConstants.HEADERTRANSACTIONID)) {
if (map != null && map.containsKey(GlobalConstants.HEADERTRANSACTIONID)) {
headerTransactionID = map.get(GlobalConstants.HEADERTRANSACTIONID).toString();
cookiesMap.put(GlobalConstants.TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
map.remove(GlobalConstants.HEADERTRANSACTIONID);
}

if (map.containsKey(GlobalConstants.VERIFIEDTRANSACTIONID)) {
if (map != null && map.containsKey(GlobalConstants.VERIFIEDTRANSACTIONID)) {
headerTransactionID = map.get(GlobalConstants.VERIFIEDTRANSACTIONID).toString();
cookiesMap.put(GlobalConstants.VERIFIED_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
Expand Down Expand Up @@ -2272,40 +2271,6 @@ protected byte[] postWithBodyAndCookieForPdf(String url, String jsonInput, Strin
}
}

protected byte[] postWithFormDataBodyForPdf(String url, String jsonInput, String cookieName, String role,
String testCaseName) {

HashMap<String, String> formDataMap = new HashMap<>();
jsonInput = inputJsonKeyWordHandeler(jsonInput, testCaseName);
logger.info("inputJson is::" + jsonInput);

JSONObject req = new JSONObject(jsonInput);
logger.info(GlobalConstants.REQ_STR + req);
jsonInput = req.toString();

byte[] pdf = null;

try {
formDataMap = new Gson().fromJson(jsonInput, new TypeToken<HashMap<String, String>>() {
}.getType());
} catch (Exception e) {
logger.error(
GlobalConstants.ERROR_STRING_1 + jsonInput + GlobalConstants.EXCEPTION_STRING_1 + e.getMessage());
}

logger.info("******Post request to EndPointUrl: " + url);
GlobalMethods.reportRequest(null, jsonInput, url);

try {
pdf = RestClient.postRequestWithFormDataBodyForPdf(url, formDataMap);
return pdf;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return pdf;
}

}

protected byte[] getWithQueryParamAndCookieForPdf(String url, String jsonInput, String cookieName, String role,
String testCaseName) {
return getWithQueryParamAndCookieForPdf(url, jsonInput, cookieName, role, testCaseName, false);
Expand Down Expand Up @@ -3175,6 +3140,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {

// Need to handle int replacement
if (jsonString.contains("$HIERARCHYLEVEL$"))
getLocationData();
jsonString = replaceKeywordWithValue(jsonString, "$HIERARCHYLEVEL$", String.valueOf(hierarchyLevel));

if (jsonString.contains("$HIERARCHYNAME$"))
Expand Down Expand Up @@ -3346,18 +3312,10 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
jsonString = replaceKeywordWithValue(jsonString, "$OIDCCLIENT$",
getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.iam.module.clientID"));
}
if (jsonString.contains("$GETCLIENTIDFROMMIMOTOACTUATOR$")) {
jsonString = replaceKeywordWithValue(jsonString, "$GETCLIENTIDFROMMIMOTOACTUATOR$",
getValueFromMimotoActuator("configService:overrides", "mimoto.oidc.partner.clientid"));
}
if (jsonString.contains("$IDPREDIRECTURI$")) {
jsonString = replaceKeywordWithValue(jsonString, "$IDPREDIRECTURI$",
ApplnURI.replace(GlobalConstants.API_INTERNAL, "healthservices") + "/userprofile");
}
if (jsonString.contains("$INJIREDIRECTURI$")) {
jsonString = replaceKeywordWithValue(jsonString, "$INJIREDIRECTURI$",
ApplnURI.replace(GlobalConstants.API_INTERNAL, "inji") + "/redirect");
}
if (jsonString.contains("$BASE64URI$")) {
String redirectUri = ApplnURI.replace(GlobalConstants.API_INTERNAL, GlobalConstants.RESIDENT)
+ propsKernel.getProperty("currentUserURI");
Expand Down Expand Up @@ -6081,44 +6039,6 @@ public static String getValueFromActuator(String section, String key) {
}

}

public static JSONArray mimotoActuatorResponseArray = null;

public static String getValueFromMimotoActuator(String section, String key) {
String url = ApplnURI + propsKernel.getProperty("actuatorMimotoEndpoint");
String actuatorCacheKey = url + section + key;
String value = actuatorValueCache.get(actuatorCacheKey);
if (value != null && !value.isEmpty())
return value;

try {
if (mimotoActuatorResponseArray == null) {
Response response = null;
JSONObject responseJson = null;
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);

responseJson = new JSONObject(response.getBody().asString());
mimotoActuatorResponseArray = responseJson.getJSONArray("propertySources");
}
for (int i = 0, size = mimotoActuatorResponseArray.length(); i < size; i++) {
JSONObject eachJson = mimotoActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains(section)) {
value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key)
.get(GlobalConstants.VALUE).toString();
if (ConfigManager.IsDebugEnabled())
logger.info("Actuator: " + url + " key: " + key + " value: " + value);
break;
}
}
actuatorValueCache.put(actuatorCacheKey, value);

return value;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return "";
}

}

public static JSONArray regprocActuatorResponseArray = null;

Expand Down Expand Up @@ -6511,7 +6431,18 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
}
}
}

if (BaseTestCase.currentModule.equals(GlobalConstants.PREREG)) {
if (request.has(GlobalConstants.REQUEST)) {
if (request.getJSONObject(GlobalConstants.REQUEST).has("otp")) {
emailId = request.getJSONObject(GlobalConstants.REQUEST).getString("userId");
logger.info(emailId);
otp = MockSMTPListener.getOtp(emailId);
request.getJSONObject(GlobalConstants.REQUEST).put("otp", otp);
inputJson = request.toString();
return inputJson;
}
}
}

if (BaseTestCase.currentModule.equals("auth")) {
if (testCaseName.startsWith("auth_GenerateVID") || testCaseName.startsWith("auth_AuthLock")
Expand Down Expand Up @@ -6597,7 +6528,6 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
}

if (BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET)
|| BaseTestCase.currentModule.equals(GlobalConstants.MIMOTO)
|| testCaseName.startsWith("Mimoto_WalletBinding")) {
if (request.has(GlobalConstants.REQUEST)) {
if (request.getJSONObject(GlobalConstants.REQUEST).has("otp")) {
Expand Down Expand Up @@ -6674,8 +6604,7 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
.getString(GlobalConstants.CHALLENGE).endsWith(GlobalConstants.MOSIP_NET)
|| request.getJSONObject(GlobalConstants.REQUEST)
.getJSONArray(GlobalConstants.CHALLENGELIST).getJSONObject(0)
.getString(GlobalConstants.CHALLENGE)
.endsWith(GlobalConstants.OTP_AS_PHONE)) {
.getString(GlobalConstants.CHALLENGE).endsWith(GlobalConstants.OTP_AS_PHONE)) {
emailId = request.getJSONObject(GlobalConstants.REQUEST)
.getJSONArray(GlobalConstants.CHALLENGELIST).getJSONObject(0)
.getString(GlobalConstants.CHALLENGE);
Expand Down Expand Up @@ -7111,4 +7040,4 @@ public String getPasswordPattern() {
return password;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

package io.mosip.testrig.apirig.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import org.apache.log4j.Logger;
Expand All @@ -19,28 +21,48 @@ public static void main(String[] args) {

static String getLanguageID(String langIsoCode) {

String v = "Any-Any";

try {
//String filename = "D:\\Mosip_Automation_Test\\Mosip_Functional_Test_Develop\\mosip-functional-tests\\automationtests\\src\\main\\resources\\config\\lang-isocode-transid.csv";
String filename = MosipTestRunner.getGlobalResourcePath() + "/"+"config/lang-isocode-transid.csv";
//CSVHelper csv = new CSVHelper(IDlookupFile);
CSVHelper csv = new CSVHelper(filename);
String[] rec;
csv.open();
while ((rec = csv.readRecord()) != null) {
if (rec[0].toLowerCase().equals(langIsoCode.toLowerCase())) {
String val = rec[2].trim();
if (val.equals(""))
v = val;
break;
}
}
csv.close();
} catch (IOException e) {
logger.error(e.getMessage());
}
return v;
String value = "Any-Any";

String filename = MosipTestRunner.getGlobalResourcePath() + "/"+"config/lang-isocode-transid.csv";

try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
String line;
while ((line = br.readLine()) != null) {
String[] rec = line.split(",");

// Processing each record
if (rec.length >= 3 && rec[0].toLowerCase().equals(langIsoCode.toLowerCase())) {
value = rec[2].trim();
if (!value.equals("")) {
System.out.println("Value found for translation: " + value);
break;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}

// try {
// //String filename = "D:\\Mosip_Automation_Test\\Mosip_Functional_Test_Develop\\mosip-functional-tests\\automationtests\\src\\main\\resources\\config\\lang-isocode-transid.csv";
// String filename = MosipTestRunner.getGlobalResourcePath() + "/"+"config/lang-isocode-transid.csv";
// //CSVHelper csv = new CSVHelper(IDlookupFile);
// CSVHelper csv = new CSVHelper(filename);
// String[] rec;
// csv.open();
// while ((rec = csv.readRecord()) != null) {
// if (rec[0].toLowerCase().equals(langIsoCode.toLowerCase())) {
// String val = rec[2].trim();
// if (val.equals(""))
// v = val;
// break;
// }
// }
// csv.close();
// } catch (IOException e) {
// logger.error(e.getMessage());
// }
return value;
}

public static String translate(String toLanguageIsoCode, String text) {
Expand Down

0 comments on commit c098904

Please sign in to comment.