Skip to content

Commit

Permalink
Add 6 conditions (if step, action and control have been executed or not)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcivel committed Aug 14, 2024
1 parent ec95bbb commit c004c4c
Show file tree
Hide file tree
Showing 9 changed files with 382 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,33 @@ public void addcountryEnvApplicationParams(List<CountryEnvironmentParameters> co
});
}

public TestCaseStepExecution getTestCaseStepExecutionBySortId(int sortID){
for(TestCaseStepExecution tcse : this.testCaseStepExecutionList){
if (sortID == tcse.getTestCaseStep().getSort()){
return tcse;
}
}
return null;
}

public TestCaseStepExecution getTestCaseStepExecutionByStepId(int stepId){
for(TestCaseStepExecution tcse : this.testCaseStepExecutionList){
if (stepId == tcse.getTestCaseStep().getStepId()){
return tcse;
}
}
return null;
}

public TestCaseStepExecution getTestCaseStepExecutionExecuting(){
for(TestCaseStepExecution tcse : this.testCaseStepExecutionList){
if ("PE".equals(tcse.getReturnCode())){
return tcse;
}
}
return null;
}

/**
* Convert the current TestCaseExecution into JSON format
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,23 @@ public void addTestCaseStepActionExecutionList(List<TestCaseStepActionControlExe
}
}

public TestCaseStepActionControlExecution getTestCaseStepActionControlExecutionBySortId(int sortID){
for(TestCaseStepActionControlExecution tcsace : this.testCaseStepActionControlExecutionList){
if (sortID == tcsace.getSort()){
return tcsace;
}
}
return null;
}

public TestCaseStepActionControlExecution getTestCaseStepActionControlExecutionByControlId(int sortID){
for(TestCaseStepActionControlExecution tcsace : this.testCaseStepActionControlExecutionList){
if (sortID == tcsace.getControlId()){
return tcsace;
}
}
return null;
}
public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,33 @@ public void addActionExecutionList(List<TestCaseStepActionExecution> actionExecu
}
}

public TestCaseStepActionExecution getTestCaseStepActionExecutionBySortId(int sortID){
for(TestCaseStepActionExecution tcsae : this.testCaseStepActionExecutionList){
if (sortID == tcsae.getTestCaseStepAction().getSort()){
return tcsae;
}
}
return null;
}

public TestCaseStepActionExecution getTestCaseStepActionExecutionByActionId(int sortID){
for(TestCaseStepActionExecution tcsae : this.testCaseStepActionExecutionList){
if (sortID == tcsae.getTestCaseStepAction().getActionId()){
return tcsae;
}
}
return null;
}

public TestCaseStepActionExecution getTestCaseStepActionExecutionExecuting(){
for(TestCaseStepActionExecution tcsae : this.testCaseStepActionExecutionList){
if ("PE".equals(tcsae.getReturnCode())){
return tcsae;
}
}
return null;
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public enum ConditionOperatorEnum {
CONDITIONOPERATOR_IFSTRINGNOTCONTAINS("ifStringNotContains", false),
CONDITIONOPERATOR_IFTEXTINELEMENT("ifTextInElement", true),
CONDITIONOPERATOR_IFTEXTNOTINELEMENT("ifTextNotInElement", true),
CONDITIONOPERATOR_IFSTEPSTATUSOK("ifStepStatusOK", false),
CONDITIONOPERATOR_IFSTEPSTATUSNE("ifStepStatusNE", false),
CONDITIONOPERATOR_IFACTIONSTATUSOK("ifActionStatusOK", false),
CONDITIONOPERATOR_IFACTIONSTATUSNE("ifActionStatusNE", false),
CONDITIONOPERATOR_IFCONTROLSTATUSOK("ifControlStatusOK", false),
CONDITIONOPERATOR_IFCONTROLSTATUSNE("ifControlStatusNE", false),
CONDITIONOPERATOR_NEVER("never", false);

private final String condition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,34 @@ public AnswerItem<Boolean> evaluateCondition(String conditionOperator, String co
mes = ans.getResultMessage();
break;

case CONDITIONOPERATOR_IFSTEPSTATUSOK:
ans = evaluateCondition_ifStepStatusOK(conditionValue1, execution);
mes = ans.getResultMessage();
break;

case CONDITIONOPERATOR_IFSTEPSTATUSNE:
ans = evaluateCondition_ifStepStatusNE(conditionValue1, execution);
mes = ans.getResultMessage();
break;
case CONDITIONOPERATOR_IFACTIONSTATUSOK:
ans = evaluateCondition_ifActionStatusOK(conditionValue1, conditionValue2, execution);
mes = ans.getResultMessage();
break;

case CONDITIONOPERATOR_IFACTIONSTATUSNE:
ans = evaluateCondition_ifActionStatusNE(conditionValue1, conditionValue2, execution);
mes = ans.getResultMessage();
break;
case CONDITIONOPERATOR_IFCONTROLSTATUSOK:
ans = evaluateCondition_ifControlStatusOK(conditionValue1, conditionValue2, conditionValue3, execution);
mes = ans.getResultMessage();
break;

case CONDITIONOPERATOR_IFCONTROLSTATUSNE:
ans = evaluateCondition_ifControlStatusNE(conditionValue1, conditionValue2, conditionValue3, execution);
mes = ans.getResultMessage();
break;

default:
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_UNKNOWNCONDITION);
mes.setDescription(mes.getDescription().replace("%COND%", conditionToEvaluate.getCondition()));
Expand Down Expand Up @@ -1059,6 +1087,174 @@ private AnswerItem<Boolean> evaluateCondition_ifNumericXXX(String conditionOpera
return ans;
}

private AnswerItem<Boolean> evaluateCondition_ifStepStatusOK(String conditionValue1, TestCaseExecution execution) {
LOG.debug("Checking if Step Status OK");
AnswerItem<Boolean> ans = new AnswerItem<>();
MessageEvent mes;

try {

String status = execution.getTestCaseStepExecutionByStepId(Integer.valueOf(conditionValue1)).getReturnCode();


if (status.equals("OK")) {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_STEPEXECUTIONOK);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
);
} else {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_STEPEXECUTIONOK);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
);
}

} catch (Exception ex){
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_STEPEXECUTIONOK);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
);
}
ans.setResultMessage(mes);
return ans;
}

private AnswerItem<Boolean> evaluateCondition_ifStepStatusNE(String conditionValue1, TestCaseExecution execution) {
LOG.debug("Checking if Step Status NE");
AnswerItem<Boolean> ans = new AnswerItem<>();
MessageEvent mes;

String status = execution.getTestCaseStepExecutionByStepId(Integer.valueOf(conditionValue1)).getReturnCode();


if (status.equals("NE")) {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_STEPEXECUTIONNE);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
);
} else {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_STEPEXECUTIONNE);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
);
}
ans.setResultMessage(mes);
return ans;
}

private AnswerItem<Boolean> evaluateCondition_ifActionStatusOK(String conditionValue1, String conditionValue2, TestCaseExecution execution) {
LOG.debug("Checking if Action Status OK");
AnswerItem<Boolean> ans = new AnswerItem<>();
MessageEvent mes;

String status = execution.getTestCaseStepExecutionByStepId(Integer.valueOf(conditionValue1))
.getTestCaseStepActionExecutionByActionId(Integer.valueOf(conditionValue2))
.getReturnCode();


if (status.equals("OK")) {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_ACTIONEXECUTIONOK);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
.replace("%STR2%", conditionValue2)
);
} else {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_ACTIONEXECUTIONOK);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
.replace("%STR2%", conditionValue2)
);
}
ans.setResultMessage(mes);
return ans;
}

private AnswerItem<Boolean> evaluateCondition_ifActionStatusNE(String conditionValue1, String conditionValue2, TestCaseExecution execution) {
LOG.debug("Checking if Action Status NE");
AnswerItem<Boolean> ans = new AnswerItem<>();
MessageEvent mes;

String status = execution.getTestCaseStepExecutionByStepId(Integer.valueOf(conditionValue1))
.getTestCaseStepActionExecutionByActionId(Integer.valueOf(conditionValue2))
.getReturnCode();


if (status.equals("NE")) {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_ACTIONEXECUTIONNE);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
.replace("%STR2%", conditionValue2)
);
} else {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_ACTIONEXECUTIONNE);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
.replace("%STR2%", conditionValue2)
);
}
ans.setResultMessage(mes);
return ans;
}

private AnswerItem<Boolean> evaluateCondition_ifControlStatusOK(String conditionValue1, String conditionValue2, String conditionValue3, TestCaseExecution execution) {
LOG.debug("Checking if Control Status OK");
AnswerItem<Boolean> ans = new AnswerItem<>();
MessageEvent mes;

String status = execution.getTestCaseStepExecutionByStepId(Integer.valueOf(conditionValue1))
.getTestCaseStepActionExecutionByActionId(Integer.valueOf(conditionValue2))
.getTestCaseStepActionControlExecutionByControlId(Integer.valueOf(conditionValue3))
.getReturnCode();

if (status.equals("OK")) {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_CONTROLEXECUTIONOK);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
.replace("%STR2%", conditionValue2)
.replace("%STR3%", conditionValue3)
);
} else {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_CONTROLEXECUTIONOK);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
.replace("%STR2%", conditionValue2)
.replace("%STR3%", conditionValue3)
);
}
ans.setResultMessage(mes);
return ans;
}

private AnswerItem<Boolean> evaluateCondition_ifControlStatusNE(String conditionValue1, String conditionValue2, String conditionValue3, TestCaseExecution execution) {
LOG.debug("Checking if Control Status NE");
AnswerItem<Boolean> ans = new AnswerItem<>();
MessageEvent mes;

String status = execution.getTestCaseStepExecutionByStepId(Integer.valueOf(conditionValue1))
.getTestCaseStepActionExecutionByActionId(Integer.valueOf(conditionValue2))
.getTestCaseStepActionControlExecutionByControlId(Integer.valueOf(conditionValue3))
.getReturnCode();


if (status.equals("NE")) {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_CONTROLEXECUTIONNE);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
.replace("%STR2%", conditionValue2)
.replace("%STR3%", conditionValue3)
);
} else {
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_CONTROLEXECUTIONNE);
mes.setDescription(mes.getDescription()
.replace("%STR1%", conditionValue1)
.replace("%STR2%", conditionValue2)
.replace("%STR3%", conditionValue3)
);
}
ans.setResultMessage(mes);
return ans;
}

private String caseSensitiveMessageValue(String isCaseSensitive) {

if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {
Expand Down
18 changes: 18 additions & 0 deletions source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ public enum MessageEventEnum {
CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_APPLICATION(1220, "FA", "Condition '%CONDITION%' is not supported for application type '%APPLICATIONTYPE%'.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_MESSAGETYPE(1220, "FA", "Message type %TYPE% not supported for condition '%CONDITION%'.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_IFNUMERIC_GENERICCONVERSIONERROR(1230, "FA", "Cannot convert %STRINGVALUE% to numeric.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_STEPEXECUTIONOK(1210, "FA", "Mandatory parameter '%STR1%' is missing or in a bad format (integer expected), or expected step doesn't exist.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_ACTIONEXECUTIONOK(1210, "FA", "Mandatory parameter '%STR1%' is missing or in a bad format (integer expected), or expected step doesn't exist.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_CONTROLEXECUTIONOK(1210, "FA", "Mandatory parameter '%STR1%' or '%STR2%' is missing or in a bad format (integer expected), or expected step/action doesn't exist.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_STEPEXECUTIONNE(1210, "FA", "Mandatory parameter '%STR1%' is missing or in a bad format (integer expected), or expected step doesn't exist.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_ACTIONEXECUTIONNE(1210, "FA", "Mandatory parameter '%STR1%' is missing or in a bad format (integer expected), or expected step doesn't exist.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_CONTROLEXECUTIONNE(1210, "FA", "Mandatory parameter '%STR1%' or '%STR2%' is missing or in a bad format (integer expected), or expected step/action doesn't exist.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_SELENIUM_CONNECTIVITY(1230, "FA", "Lost connection to Selenium Server! Detailed error : %ERROR%.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_GENERIC(1230, "FA", "Failed to evaluate condition. Detailed error : %ERROR%.", false, false, false, MessageGeneralEnum.EXECUTION_FA_CONDITION),
CONDITIONEVAL_FAILED_TEXTINELEMENT(1240, "FA", "%ERRORMESS%", true, true, true, MessageGeneralEnum.EXECUTION_KO),
Expand All @@ -527,6 +533,12 @@ public enum MessageEventEnum {
CONDITIONEVAL_FALSE_NUMERICGREATEROREQUAL(1210, "NA", "'%STR1%' is not greater or equal than '%STR2%'", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_NUMERICMINOR(1210, "NA", "'%STR1%' is not minor to '%STR2%'", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_NUMERICMINOROREQUAL(1210, "NA", "'%STR1%' is not minor or equal to '%STR2%'", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_STEPEXECUTIONOK(1210, "NA", "Step '%STR1%' has not been executed but expected.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_ACTIONEXECUTIONOK(1210, "NA", "Action '%STR1%' from Step '%STR2%' has not been executed but expected.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_CONTROLEXECUTIONOK(1210, "NA", "Control '%STR1%' from Action '%STR2%' from Step '%STR3%' has not been executed but expected.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_STEPEXECUTIONNE(1210, "NA", "Step '%STR1%' has been executed but it should not.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_ACTIONEXECUTIONNE(1210, "NA", "Action '%STR1%' from Step '%STR2%' has been executed but it should not.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_CONTROLEXECUTIONNE(1210, "NA", "Control '%STR1%' from Action '%STR2%' from Step '%STR3%' has been executed but it should not.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_TEXTINELEMENT(1240, "NA", "%ERRORMESS%", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_FALSE_TEXTNOTINELEMENT(1240, "NA", "%ERRORMESS%", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_ALWAYS(1210, "OK", "", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
Expand All @@ -552,6 +564,12 @@ public enum MessageEventEnum {
CONDITIONEVAL_TRUE_NUMERICGREATEROREQUAL(1210, "OK", "'%STR1%' is greater or equal than '%STR2%'", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_NUMERICMINOR(1210, "OK", "'%STR1%' is minor to '%STR2%'", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_NUMERICMINOROREQUAL(1210, "OK", "'%STR1%' is minor or equal to '%STR2%'", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_STEPEXECUTIONOK(1210, "OK", "Step '%STR1%' has been executed and returned OK.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_ACTIONEXECUTIONOK(1210, "OK", "Action '%STR1%' from Step '%STR2%' has been executed and returned OK.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_CONTROLEXECUTIONOK(1210, "OK", "Control '%STR1%' from Action '%STR2%' from Step '%STR3%' has been executed and returned OK.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_STEPEXECUTIONNE(1210, "OK", "Step '%STR1%' has not been executed.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_ACTIONEXECUTIONNE(1210, "OK", "Action '%STR1%' from Step '%STR2%' has not been executed.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_CONTROLEXECUTIONNE(1210, "OK", "Control '%STR1%' from Action '%STR2%' from Step '%STR3%' has not been executed.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_TEXTINELEMENT(300, "OK", "Element '%STRING1%' with value '%STRING2%' is equal to %STRING3%, %STRING4%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUEMANUAL_TEXTINELEMENT(300, "OK", "Please evaluate if element '%STRING1%' does contain '%STRING2%', case sensitive : '%STRING3%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONDITIONEVAL_TRUE_TEXTNOTINELEMENT(300, "OK", "Element '%STRING1%' with value '%STRING2%' is different than %STRING3%, %STRING4%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
Expand Down
Loading

0 comments on commit c004c4c

Please sign in to comment.