Skip to content

Commit

Permalink
Merge pull request #501 from pg-techno123/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
lsivanand authored Nov 7, 2023
2 parents a0c9eb1 + 8ca9bb5 commit 76e7d0c
Show file tree
Hide file tree
Showing 12 changed files with 22,787 additions and 4,243 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package io.mosip.testrig.dslrig.ivv.e2e.methods;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import org.apache.log4j.Logger;
import org.json.JSONObject;

import io.mosip.testrig.apirig.admin.fw.util.AdminTestException;
import io.mosip.testrig.apirig.admin.fw.util.TestCaseDTO;
import io.mosip.testrig.apirig.authentication.fw.precon.JsonPrecondtion;
import io.mosip.testrig.apirig.authentication.fw.util.AuthenticationTestException;
import io.mosip.testrig.apirig.dbaccess.AuditDBManager;
import io.mosip.testrig.apirig.dbaccess.DBManager;
import io.mosip.testrig.apirig.service.BaseTestCase;
import io.mosip.testrig.apirig.testscripts.PatchWithPathParam;
import io.mosip.testrig.apirig.testscripts.SimplePost;
Expand All @@ -22,76 +27,84 @@ public class HolidayDeclaration extends BaseTestCaseUtil implements StepInterfac
private static final String GenerateHolidayYml = "ivv_masterdata/Holiday/CreateHoliday.yml";
private static final String UpdateHolidayStatus = "ivv_masterdata/UpdateHolidayStatus/UpdateHolidayStatus.yml";
SimplePost holidayDeclaration = new SimplePost();
CenterHelper centerHelper=new CenterHelper();
PatchWithPathParam activateHoliday=new PatchWithPathParam();
int holidayId = 0;
CenterHelper centerHelper = new CenterHelper();
PatchWithPathParam activateHoliday = new PatchWithPathParam();
String holidayId = "";

@Override
public void run() throws RigInternalError {
step.getScenario().getVidPersonaProp().clear();

String holidayLocationCode = centerHelper.getLocationCodeHoliday();

Object[] testObj = holidayDeclaration.getYmlTestData(GenerateHolidayYml);

TestCaseDTO test = (TestCaseDTO) testObj[0];
if (step.getParameters().size() == 1) {
holidayId = step.getParameters().get(0);
if (holidayId.startsWith("$$"))
holidayId = step.getScenario().getVariables().get(holidayId);
String deleteQuery = "delete from master.loc_holiday where id = '" + holidayId + "'";
logger.info(deleteQuery);
AuditDBManager.executeQueryAndDeleteRecord("master", deleteQuery);
} else {

String holidayLocationCode = centerHelper.getLocationCodeHoliday();

Object[] testObj = holidayDeclaration.getYmlTestData(GenerateHolidayYml);

TestCaseDTO test = (TestCaseDTO) testObj[0];

Object[] testObjPatch = activateHoliday.getYmlTestData(UpdateHolidayStatus);

TestCaseDTO testPatch = (TestCaseDTO) testObjPatch[0];

String input2 = testPatch.getInput();
String input = test.getInput();
input = JsonPrecondtion.parseAndReturnJsonContent(input, holidayLocationCode, "locationCode");
input = JsonPrecondtion.parseAndReturnJsonContent(input, BaseTestCase.getLanguageList().get(0), "langCode");
LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
// input = JsonPrecondtion.parseAndReturnJsonContent(input,LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), "holidayDate");
input = JsonPrecondtion.parseAndReturnJsonContent(input,
"mosip" + BaseTestCase.generateRandomAlphaNumericString(6), "holidayDesc");
input = JsonPrecondtion.parseAndReturnJsonContent(input, BaseTestCase.generateRandomAlphaNumericString(6),
"holidayName");

test.setInput(input);

try {
holidayDeclaration.test(test);
Response response = holidayDeclaration.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
holidayId = jsonResp.getJSONObject("response").get("holidayId").toString();
}

} catch (AuthenticationTestException | AdminTestException e) {
this.hasError = true;
throw new RigInternalError(e.getMessage());
}

Object[] testObjPatch = activateHoliday.getYmlTestData(UpdateHolidayStatus);
// ActivateHolidayCall

TestCaseDTO testPatch = (TestCaseDTO) testObjPatch[0];
try {
// input2 = input2.replace("holidayId", String.valueOf(holidayId));
String stringValue = String.valueOf(holidayId);
// input2 = input2.replace("\"{{holidayId}}\"", "\"" + holidayId + "\"");
input2 = JsonPrecondtion.parseAndReturnJsonContent(input2, stringValue, "holidayId");
input2 = JsonPrecondtion.parseAndReturnJsonContent(input2, "true", "isActive");
testPatch.setInput(input2);

String input2=testPatch.getInput();
String input = test.getInput();
input = JsonPrecondtion.parseAndReturnJsonContent(input, holidayLocationCode, "locationCode");
input = JsonPrecondtion.parseAndReturnJsonContent(input, BaseTestCase.getLanguageList().get(0), "langCode");
//input = JsonPrecondtion.parseAndReturnJsonContent(input, PacketUtility.appointmentDate, "holidayDate");
input = JsonPrecondtion.parseAndReturnJsonContent(input,
"mosip" + BaseTestCase.generateRandomAlphaNumericString(6), "holidayDesc");
input = JsonPrecondtion.parseAndReturnJsonContent(input, BaseTestCase.generateRandomAlphaNumericString(6),
"holidayName");
activateHoliday.test(testPatch);
Response response = activateHoliday.response;

test.setInput(input);

try {
holidayDeclaration.test(test);
Response response = holidayDeclaration.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
holidayId = jsonResp.getJSONObject("response").getInt("holidayId");
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
logger.info(jsonResp.getJSONObject("response"));
}

} catch (Exception e) {
this.hasError = true;
throw new RigInternalError(e.getMessage());
}
if (step.getOutVarName() != null) {
step.getScenario().getVariables().put(step.getOutVarName(), holidayId);
return;
}

} catch (AuthenticationTestException | AdminTestException e) {
this.hasError=true;throw new RigInternalError(e.getMessage());

}


//ActivateHolidayCall

try {

//input2 = input2.replace("holidayId", String.valueOf(holidayId));
String stringValue = String.valueOf(holidayId);
//input2 = input2.replace("\"{{holidayId}}\"", "\"" + holidayId + "\"");
input2 = JsonPrecondtion.parseAndReturnJsonContent(input2, stringValue, "holidayId");
input2 = JsonPrecondtion.parseAndReturnJsonContent(input2, "true", "isActive");
testPatch.setInput(input2);

activateHoliday.test(testPatch);
Response response= activateHoliday.response;

if (response!= null)
{
JSONObject jsonResp = new JSONObject(response.getBody().asString());
logger.info( jsonResp.getJSONObject("response"));}

} catch (Exception e) {
this.hasError=true;
throw new RigInternalError(e.getMessage());

}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -21,6 +22,7 @@
import org.testng.Assert;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.SkipException;
Expand Down Expand Up @@ -565,30 +567,34 @@ public static String JsonToCsvConverter(String jsonFilePath) {
for (JsonNode jsonNode : rootNode) {

List<String> stepList = new ArrayList<>();
stepList.add(jsonNode.get("tc_no").asText());
stepList.add(jsonNode.get("tags").asText());
stepList.add(jsonNode.get("persona_class").asText());
stepList.add(jsonNode.get("persona").asText());
stepList.add(jsonNode.get("group_name").asText());
stepList.add(jsonNode.get("description").asText());
stepList.add(jsonNode.get("Scenario").asText());
stepList.add(jsonNode.get("Tag").asText());
stepList.add(jsonNode.get("Persona").asText());
stepList.add(jsonNode.get("Persona").asText());
stepList.add(jsonNode.get("Group").asText());
stepList.add(jsonNode.get("Description").asText());

Pattern pattern = Pattern.compile("(.*?)\\((.*?),(.*)\\)");

for (int stepIndex = 0; stepIndex < maxSteps; stepIndex++) {

String string = jsonNode.get("step" + stepIndex) == null ? ""
: jsonNode.get("step" + stepIndex).asText();
Matcher matcher = pattern.matcher(string);
String stepDescription = "";
String stepAction = "";
JsonNode stepJsonNode = jsonNode.get("Step-" + stepIndex) == null ? null
: jsonNode.get("Step-" + stepIndex);
if (stepJsonNode != null) {
stepAction = stepJsonNode.get("Action").asText();
stepDescription = stepJsonNode.get("Description").asText();
}
Matcher matcher = pattern.matcher(stepAction);

if (matcher.matches()) {
logger.info("The string contains a comma between parentheses");
stepList.add(jsonNode.get("step" + stepIndex) == null ? ""
: "\"" + jsonNode.get("step" + stepIndex).asText() + "\"");
// logger.info("The string contains a comma between parentheses");
stepList.add(stepAction == null ? "" : "\"" + stepAction + "\"");
} else {
stepList.add(jsonNode.get("step" + stepIndex) == null ? ""
: jsonNode.get("step" + stepIndex).asText());
logger.info("The string does not contain a comma between parentheses");
stepList.add(stepAction == null ? "" : stepAction);
// logger.info("The string does not contain a comma between parentheses");
}
addStepDetails(stepAction, stepDescription);
}

for (String string : stepList) {
Expand All @@ -601,7 +607,39 @@ public static String JsonToCsvConverter(String jsonFilePath) {
// Log the error
return "";
}
if (ConfigManager.IsDebugEnabled()) {
String keyValues ="";
// Iterate through the map and print its contents
for (Map.Entry<String, String[]> entry : stepsMap.entrySet()) {
keyValues += entry.getKey();
String[] values = entry.getValue();
for (int i = 0; i < values.length; i++) {
keyValues += "," + values[i];
}
keyValues += "\r\n";
}
logger.info(keyValues);
}
return tempCSVPath;
}

private static final Map<String, String[]> stepsMap = new HashMap<>();

private static void addStepDetails(String stepInput, String description) {
if (stepInput.isEmpty() || description.isEmpty())
return;
// Find the index of the first "(" character
int indexOfOpenParenthesis = stepInput.indexOf("(");
if (indexOfOpenParenthesis != -1) {
// Extract the substring "e2e_" up to the first "("
String step = stepInput.substring(stepInput.indexOf("e2e_"), indexOfOpenParenthesis);
if (stepsMap.get(step) == null) {
String[] descAndExample = new String[2];
descAndExample[0] = description;
descAndExample[1] = stepInput;
stepsMap.put(step, descAndExample);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ private static void copyTestResources() {
TestResources.copyTestResource("/ivv_masterdata");
TestResources.copyTestResource("/syncdata");
TestResources.copyTestResource("/regproc");
TestResources.copyTestResource("/dbFiles");
}

public static String getExternalResourcePath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ roles=GLOBAL_ADMIN,ID_AUTHENTICATION,REGISTRATION_ADMIN,REGISTRATION_SUPERVISOR,
roles.111997=AUTH_PARTNER,PARTNER_ADMIN,PMS_ADMIN,POLICYMANAGER,REGISTRATION_SUPERVISOR

##DB_Connectivity
postgresql-password=mosip123
driver_class=org.postgresql.Driver
pool_size=1
dialect=org.hibernate.dialect.PostgreSQLDialect
Expand All @@ -189,6 +190,10 @@ audit_url=jdbc:postgresql://api-internal.qa-upgrade3.mosip.net:30090/mosip_audit
audit_username=postgres
audit_password=mosip123
audit_default_schema=audit

#master details
master_default_schema=master

#ida-partner details
DB_PORT=
installation-domain=
Expand All @@ -212,15 +217,16 @@ threadCount=9
langselect=0
#----------------------------------Database properties----------------------------------------------------------#

postgresqlUser=postgresql
db-port=5432
db-server=api-internal.qa-upgrade3.mosip.net
db-server=qa-upgrade3.mosip.net
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.pool_size=1
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=true
hibernate.current_session_context_class=thread
db-su-user=postgres
db-su-password=mosip123
postgresql-password=mosip123
pms_db_schema=pms
km_db_schema=keymgr
master_db_schema=master
Expand Down Expand Up @@ -290,4 +296,4 @@ scenariosToExecute=
#-- supported values yes or no
useExternalScenarioSheet=no

partnerUrlSuffix=oYf63Lax0DY2QkYMRHnrmDqhmO3RMWQagwm0ftgLlkuin1KOND/666/576732
partnerUrlSuffix=oYf63Lax0DY2QkYMRHnrmDqhmO3RMWQagwm0ftgLlkuin1KOND/666/576732
Loading

0 comments on commit 76e7d0c

Please sign in to comment.