Skip to content

Commit

Permalink
Merge pull request #1230 from nandhu-kumar/camdgc-develop
Browse files Browse the repository at this point in the history
MOSIP-30525
  • Loading branch information
lsivanand authored Dec 1, 2023
2 parents 5fd23ff + a7218dc commit 9635425
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2884,6 +2884,8 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {

if (jsonString.contains("$SCHEMAVERSION$"))
jsonString = replaceKeywordWithValue(jsonString, "$SCHEMAVERSION$", generateLatestSchemaVersion());
if (jsonString.contains("$PHONENUMBERFORIDENTITY$"))
jsonString = replaceKeywordWithValue(jsonString, "$PHONENUMBERFORIDENTITY$", phoneNumber);
if (jsonString.contains("$1STLANG$"))
jsonString = replaceKeywordWithValue(jsonString, "$1STLANG$", BaseTestCase.languageList.get(0));
if (jsonString.contains("$2NDLANG$"))
Expand Down Expand Up @@ -4446,6 +4448,9 @@ public static String genStringAsperRegex(String regex) throws Exception {
throw new Exception("invalid regex");

}

public static String schemaRequiredField = "";
String phoneNumber = "";

public static String modifySchemaGenerateHbs() {
return modifySchemaGenerateHbs(false);
Expand Down Expand Up @@ -4473,13 +4478,16 @@ public static String modifySchemaGenerateHbs(boolean regenerateHbs) {

boolean emailFieldAdditionallyAdded = false;
boolean phoneFieldAdditionallyAdded = false;
String phoneNumber = "";
try {

JSONObject schemaFileJson = new JSONObject(schemaFile); // jObj
JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); // objIDJson4
JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); // objIDJson
JSONObject identityPropsJson = schemaIdentityJson.getJSONObject("properties"); // objIDJson2
JSONArray requiredPropsArray = schemaIdentityJson.getJSONArray("required"); // objIDJson1
schemaRequiredField = requiredPropsArray.toString();


String phone = getValueFromAuthActuator("json-property", "phone_number");
String result = phone.replaceAll("\\[\"|\"\\]", "");
Expand All @@ -4488,6 +4496,8 @@ public static String modifySchemaGenerateHbs(boolean regenerateHbs) {
requiredPropsArray.put(result);
phoneFieldAdditionallyAdded = true;
}
if (identityPropsJson.has(result))
phoneNumber = genStringAsperRegex(identityPropsJson.getJSONObject(result).getJSONArray("validators").getJSONObject(0).getString("validator"));

String email = getValueFromAuthActuator("json-property", "emailId");
String emailResult = email.replaceAll("\\[\"|\"\\]", "");
Expand Down Expand Up @@ -4559,9 +4569,10 @@ else if (eachRequiredProp.equals("registrationType")) {
identityJson.put(eachRequiredProp, genStringAsperRegex(eachPropDataJson.getJSONArray("validators").getJSONObject(0).getString("validator")));
}
else if (eachRequiredProp.equals(result)) {
String regexPattern = genStringAsperRegex(eachPropDataJson.getJSONArray("validators").getJSONObject(0).getString("validator"));
if (regexPattern != null)
identityJson.put(eachRequiredProp, regexPattern);
// String regexPattern = genStringAsperRegex(eachPropDataJson.getJSONArray("validators").getJSONObject(0).getString("validator"));
// if (regexPattern != null)
if (phoneNumber != null)
identityJson.put(eachRequiredProp, phoneNumber);

// if(phoneFieldAdditionallyAdded) {
// identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}");
Expand Down Expand Up @@ -4601,14 +4612,16 @@ else if (eachRequiredProp.equals("IDSchemaVersion")) {
}
}
}

if (!ConfigManager.isInServiceNotDeployedList(GlobalConstants.ADMIN)) {
JSONArray requestDocArray = new JSONArray();
JSONObject docJson = new JSONObject();
docJson.put("value", "{{value}}");
docJson.put("category", "{{category}}");
requestDocArray.put(docJson);

// JSONArray requestDocArray = new JSONArray();
// JSONObject docJson = new JSONObject();
// docJson.put("value", "{{value}}");
// docJson.put("category", "{{category}}");
// requestDocArray.put(docJson);
//
// requestJson.getJSONObject("request").put("documents", requestDocArray);
requestJson.getJSONObject("request").put("documents", requestDocArray);
}
requestJson.getJSONObject("request").put("identity", identityJson);
requestJson.put("requesttime", "{{requesttime}}");
requestJson.put("version", "{{version}}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.testng.ITest;
import org.testng.ITestContext;
import org.testng.ITestResult;
Expand Down Expand Up @@ -99,6 +100,25 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
MediaType.APPLICATION_JSON, COOKIENAME,
new KernelAuthentication().getTokenByRole(testCaseDTO.getRole())).asString(),
"response.uin");

JSONArray dobArray = new JSONArray(getValueFromAuthActuator("json-property", "dob"));
JSONArray emailArray = new JSONArray(getValueFromAuthActuator("json-property", "emailId"));
String dob = dobArray.getString(0);
String email = emailArray.getString(0);
if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("DOB")
&& (!isElementPresent(new JSONArray(schemaRequiredField), dob))) {
throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE);
}

if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("Email")
&& (!isElementPresent(new JSONArray(schemaRequiredField), email))) {
throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE);
}

if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("Invalid_BioVal")
&& (ConfigManager.isInServiceNotDeployedList(GlobalConstants.ADMIN))) {
throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE);
}

DateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
Calendar cal = Calendar.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.ITest;
Expand Down Expand Up @@ -152,11 +153,27 @@ public void updateIdentity(TestCaseDTO testCaseDTO) throws AuthenticationTestExc

String email = getValueFromAuthActuator("json-property", "emailId");
String emailResult = email.replaceAll("\\[\"|\"\\]", "");

JSONArray dobArray = new JSONArray(getValueFromAuthActuator("json-property", "dob"));
String dob = dobArray.getString(0);

inputJson = inputJson.replace("\"phone\":", "\"" + result + "\":");
inputJson = inputJson.replace("\"email\":", "\"" + emailResult + "\":");

inputJson = inputJson.replace("$RID$", genRid);

if (testCaseName.startsWith("IdRepository_") && inputJson.contains("dateOfBirth") && (!isElementPresent(new JSONArray(schemaRequiredField), dob))) {
JSONObject reqJson = new JSONObject(inputJson);
reqJson.getJSONObject("request").getJSONObject("identity").remove("dateOfBirth");
inputJson = reqJson.toString();
}

if (testCaseName.startsWith("IdRepository_") && inputJson.contains("email") && (!isElementPresent(new JSONArray(schemaRequiredField), emailResult))) {
JSONObject reqJson = new JSONObject(inputJson);
reqJson.getJSONObject("request").getJSONObject("identity").remove(emailResult);
reqJson.getJSONObject("request").getJSONObject("identity").remove(result);
inputJson = reqJson.toString();
}

if (inputJson.contains("$PRIMARYLANG$"))
inputJson = inputJson.replace("$PRIMARYLANG$", BaseTestCase.languageList.get(0));
Expand Down

0 comments on commit 9635425

Please sign in to comment.