Skip to content

Commit

Permalink
Merge pull request #1591 from Sohandey/develop
Browse files Browse the repository at this point in the history
MOSIP-35390
  • Loading branch information
lsivanand authored Sep 17, 2024
2 parents fac6d5c + 947aa20 commit e9cdc1d
Showing 1 changed file with 171 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public class AdminTestUtil extends BaseTestCase {
public static final String BINDINGCERTCONSENTEMPTYCLAIMFILE = "BINDINGCERTCONSENTEMPTYCLAIMFile";
public static final String BINDINGCERTCONSENTUSER2FILE = "BINDINGCERTCONSENTUSER2File";
public static final String BINDINGCERTVIDCONSENTUSER2FILE = "BINDINGCERTCONSENTVIDUSER2File";
private static String selectedHandlesValue=null;

private static final String UIN_CODE_VERIFIER_POS_1 = generateRandomAlphaNumericString(GlobalConstants.INTEGER_36);

Expand Down Expand Up @@ -7639,6 +7640,8 @@ public String replaceArrayHandleValues(String inputJson, String testCaseName) {
JSONObject request = jsonObj.getJSONObject("request");
JSONObject identity = request.getJSONObject("identity");
JSONArray selectedHandles = identity.getJSONArray("selectedHandles");
String email = getValueFromAuthActuator("json-property", "emailId");
String emailResult = email.replaceAll("\\[\"|\"\\]", "");

for (int i = 0; i < selectedHandles.length(); i++) {
String handle = selectedHandles.getString(i);
Expand Down Expand Up @@ -7813,7 +7816,7 @@ else if (testCaseName.contains("_withinvaliddemofield_inupdate")) {
}
}
//50
if (testCaseName.contains("_withonedemofield")) {
else if (testCaseName.contains("_withonedemofield")) {
if (identity.has("selectedHandles")) {
String firstHandle = selectedHandles.getString(0);
for (int j = 1; j < selectedHandles.length(); j++) {
Expand All @@ -7829,9 +7832,82 @@ else if (testCaseName.contains("_withinvaliddemofield_inupdate")) {
identity.put("selectedHandles", newSelectedHandles);
}
}


//82

else if (testCaseName.contains("_withcasesensitivehandles")) {
for (int j = 0; j < handleArray.length(); j++) {
JSONObject obj = handleArray.getJSONObject(j);
obj.put("value", "HANDLES");
}
}
//77
else if (testCaseName.contains("_replaceselectedhandles")) {
identity.put("selectedHandles", new JSONArray().put(emailResult));
}
//76
else if (testCaseName.contains("_onlywithemail")) {
identity.put("selectedHandles", new JSONArray().put(emailResult));
}

//73
else if (testCaseName.contains("_withoutselectedhandlesinidentity")) {
identity.remove("selectedHandles");
}

else if (testCaseName.contains("_withdublicatevalue")) {
for (int j = 0; j < handleArray.length(); j++) {
JSONObject obj = handleArray.getJSONObject(j);
if (testCaseName.contains("_save_withdublicatevalue"))
selectedHandlesValue=obj.getString("value");
obj.put("value", selectedHandlesValue);
}
}
else if (testCaseName.contains("_withmultipledublicatevalue")) {
JSONObject secondValue = new JSONObject();
secondValue.put("value", selectedHandlesValue);
secondValue.put("tags", new JSONArray().put("handle"));
handleArray.put(secondValue);
}
else if (testCaseName.contains("_removevalueaddexistingvalue")) {
for (int j = 0; j < handleArray.length(); j++) {
JSONObject obj = handleArray.getJSONObject(j);
obj.remove("value");
obj.put("value", selectedHandlesValue);
}
}
else if (testCaseName.contains("_withselectedhandlephone")) {
if (identity.has("selectedHandles")) {
// Remove "email" and "functionalId", keep only "phone"
JSONArray updatedHandles = new JSONArray();
boolean containsPhone = false;

for (int j = 0; j < selectedHandles.length(); j++) {
handle = selectedHandles.getString(j);
if (handle.equalsIgnoreCase("phone")) {
containsPhone = true;
updatedHandles.put("phone"); // Ensure "phone" is kept
}
}

// Add "phone" if not present
if (!containsPhone) {
updatedHandles.put("phone");
}

// Update the identity with the modified selectedHandles array
identity.put("selectedHandles", updatedHandles);
}else if (testCaseName.contains("_removealltagshandles")) {
removeTagsHandles(jsonObj);


} else {
// If "selectedHandles" doesn't exist, create it with "phone"
JSONArray newSelectedHandles = new JSONArray();
newSelectedHandles.put("phone");
identity.put("selectedHandles", newSelectedHandles);
}
}


else {
Expand All @@ -7848,13 +7924,41 @@ else if (testCaseName.contains("_withinvaliddemofield_inupdate")) {

return jsonObj.toString();
}

private void removeTagsHandles(JSONObject jsonObj) {
for (String key : jsonObj.keySet()) {
Object value = jsonObj.get(key);
if (value instanceof JSONObject) {
JSONObject nestedObject = (JSONObject) value;
if (nestedObject.has("tags")) {
JSONArray tagsArray = nestedObject.getJSONArray("tags");
if (tagsArray.length() == 1 && "handles".equals(tagsArray.getString(0))) {
nestedObject.remove("tags");
}
}
removeTagsHandles(nestedObject); // Recursively call for deeper levels
} else if (value instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) value;
for (int i = 0; i < jsonArray.length(); i++) {
Object arrayElement = jsonArray.get(i);
if (arrayElement instanceof JSONObject) {
removeTagsHandles((JSONObject) arrayElement); // Recursively handle each element
}
}
}
}
}

public String replaceArrayHandleValuesForUpdateIdentity(String inputJson, String testCaseName) {
JSONObject jsonObj = new JSONObject(inputJson);
JSONObject request = jsonObj.getJSONObject("request");
JSONObject identity = request.getJSONObject("identity");
JSONArray selectedHandles = identity.getJSONArray("selectedHandles");
String phone = getValueFromAuthActuator("json-property", "phone_number");
String result = phone.replaceAll("\\[\"|\"\\]", "");
String email = getValueFromAuthActuator("json-property", "emailId");
String emailResult = email.replaceAll("\\[\"|\"\\]", "");



// Iterate over each handle in the selectedHandles array
for (int i = 0; i < selectedHandles.length(); i++) {
Expand Down Expand Up @@ -7906,8 +8010,7 @@ public String replaceArrayHandleValuesForUpdateIdentity(String inputJson, String
}
} else if (testCaseName.contains("_withmultipledemohandles")) {
// Handle specific demo handles by checking and adding them to the selectedHandles
String phone = getValueFromAuthActuator("json-property", "phone_number");
String result = phone.replaceAll("\\[\"|\"\\]", "");

boolean containsPhone = false;
for (int j = 0; j < selectedHandles.length(); j++) {
if (result.equalsIgnoreCase(selectedHandles.getString(j))) {
Expand Down Expand Up @@ -8068,16 +8171,13 @@ else if (testCaseName.contains("_withemptyselectedhandle")) {
identity.put("selectedHandles", new JSONArray());
}
}






else if (testCaseName.contains("_witharandomnonhandleattr")) {
if (identity.has("selectedHandles")) {
List<String> existingHandles = new ArrayList<>();
for (int j = 0; i < selectedHandles.length(); i++) {
existingHandles.add(selectedHandles.getString(i));
for (int j = 0; j < selectedHandles.length(); j++) {
existingHandles.add(selectedHandles.getString(j));
}
Iterator<String> keys = identity.keys();
while (keys.hasNext()) {
Expand All @@ -8098,13 +8198,67 @@ else if (testCaseName.contains("_updateselectedhandleswithinvalid")) {
updatedHandlesArray.put("invalidscehema123");
identity.put("selectedHandles", updatedHandlesArray);
}

else if (testCaseName.contains("_withinvaliddhandle")) {
selectedHandles.put("newFieldHandle");
}

else if (testCaseName.contains("_updateselectedhandleswithscehmaattrwhichisnothandle")) {
Iterator<String> keys = identity.keys();
while (keys.hasNext()) {
String key = keys.next();
if (!selectedHandles.toList().contains(key) && identity.optString(key) != null && identity.get(key) instanceof String) {
selectedHandles.put(key);
break;
}
}
}

else if (testCaseName.contains("_removeselectedhandle_updatephone")) {
if (identity.has("selectedHandles")) {
identity.remove("selectedHandles");
}







if (identity.has(result)) {
identity.put(result, generateRandomNumberString(10));
}
}

else if (testCaseName.contains("_withupdatedhandlewhichisnotinschema")) {
JSONArray newSelectedHandles = new JSONArray();
newSelectedHandles.put("invalid12@@");
identity.put("selectedHandles", newSelectedHandles);
}

else if (testCaseName.contains("_replaceselectedhandles")) {
identity.put("selectedHandles", new JSONArray().put(result));
}

else if (testCaseName.contains("_updatewithphoneemail")) {
JSONArray updatedHandles = new JSONArray();
updatedHandles.put(emailResult);
updatedHandles.put(result);

identity.put("selectedHandles", updatedHandles);
}
else if (testCaseName.contains("_withusedphone")) {
if (identity.has(result)) {
identity.put(result, "$ID:AddIdentity_array_handle_value_smoke_Pos_withphonenumber_PHONE$" );
}
}
else if (testCaseName.contains("_withphonevalue")) {
if (identity.has(result)) {
identity.put(result, "$ID:AddIdentity_array_handle_value_smoke_Pos_withselectedhandlephone_PHONE$" );
}
}
else if (testCaseName.contains("_removeselectedhandlesandupdateemail")) {
if (identity.has("selectedHandles")) {
identity.remove("selectedHandles");
}
if (identity.has(emailResult)) {
identity.put(emailResult, "$ID:AddIdentity_array_handle_value_update_smoke_Pos_withselectedhandlephone_EMAIL$" );
}
}

identity.put(handle, handleArray);
}
Expand Down

0 comments on commit e9cdc1d

Please sign in to comment.