use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class ActionService method doActionCallService.
private MessageEvent doActionCallService(TestCaseStepActionExecution testCaseStepActionExecution, String value1) {
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);
TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
AnswerItem lastServiceCalledAnswer;
lastServiceCalledAnswer = serviceService.callService(value1, null, null, null, null, tCExecution);
message = lastServiceCalledAnswer.getResultMessage();
if (lastServiceCalledAnswer.getItem() != null) {
AppService lastServiceCalled = (AppService) lastServiceCalledAnswer.getItem();
tCExecution.setLastServiceCalled(lastServiceCalled);
/**
* Record the Request and Response in filesystem.
*/
testCaseStepActionExecution.addFileList(recorderService.recordServiceCall(tCExecution, testCaseStepActionExecution, 0, null, lastServiceCalled));
}
return message;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class ActionService method doActionCalculateProperty.
private MessageEvent doActionCalculateProperty(TestCaseStepActionExecution testCaseStepActionExecution, String value1, String value2) {
MessageEvent message;
AnswerItem<String> answerDecode = new AnswerItem();
if (StringUtil.isNullOrEmpty(value1)) {
// Value1 is a mandatory parameter.
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_MISSINGPROPERTY);
message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY));
} else {
try {
TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
// Getting the Country property definition.
TestCaseCountryProperties tccp = null;
boolean propertyExistOnAnyCountry = false;
for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {
if ((object.getProperty().equalsIgnoreCase(value1)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {
tccp = object;
}
if ((object.getProperty().equalsIgnoreCase(value1))) {
propertyExistOnAnyCountry = true;
}
}
if (tccp == null) {
// Could not find a country property inside the existing execution.
if (propertyExistOnAnyCountry) {
message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);
message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value1).replace("%COUNTRY%", tCExecution.getCountry()));
return message;
} else {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);
message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value1).replace("%COUNTRY%", tCExecution.getCountry()));
return message;
}
} else {
if (!(StringUtil.isNullOrEmpty(value2))) {
// If value2 is fed with something, we control here that value is a valid property name and gets its defintion.
tccp = null;
propertyExistOnAnyCountry = false;
for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {
if ((object.getProperty().equalsIgnoreCase(value2)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {
tccp = object;
}
if ((object.getProperty().equalsIgnoreCase(value2))) {
propertyExistOnAnyCountry = true;
}
}
if (tccp == null) {
// Could not find a country property inside the existing execution.
if (propertyExistOnAnyCountry) {
message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);
message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value2).replace("%COUNTRY%", tCExecution.getCountry()));
return message;
} else {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);
message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value2).replace("%COUNTRY%", tCExecution.getCountry()));
return message;
}
}
}
// We calculate the property here.
long now = new Date().getTime();
TestCaseExecutionData tcExeData;
tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), tccp.getProperty(), 1, tccp.getDescription(), null, tccp.getType(), tccp.getValue1(), tccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING), tccp.getRetryNb(), tccp.getRetryPeriod(), tccp.getDatabase(), tccp.getValue1(), tccp.getValue2(), tccp.getLength(), tccp.getLength(), tccp.getRowLimit(), tccp.getNature(), "", "", "", "", "", "N");
tcExeData.setTestCaseCountryProperties(tccp);
propertyService.calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, tccp, true);
// Property message goes to Action message.
message = tcExeData.getPropertyResultMessage();
if (message.getCodeString().equals("OK")) {
// If Property calculated successfully we summarize the message to a shorter version.
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALCULATEPROPERTY);
message.setDescription(message.getDescription().replace("%PROP%", value1).replace("%VALUE%", tcExeData.getValue()));
if (tcExeData.getDataLibRawData() != null) {
message.setDescription(message.getDescription() + " %NBROWS% row(s) with %NBSUBDATA% Subdata(s) calculated.".replace("%NBROWS%", String.valueOf(tcExeData.getDataLibRawData().size())).replace("%NBSUBDATA%", String.valueOf(tcExeData.getDataLibRawData().get(0).size())));
}
}
if (!(StringUtil.isNullOrEmpty(value2))) {
// If value2 is fed we force the result to value1.
tcExeData.setProperty(value1);
}
// saves the result
try {
testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcExeData));
LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + tcExeData.getIndex() + "' Value : '" + tcExeData.getValue() + "'");
tCExecution.getTestCaseExecutionDataMap().put(tcExeData.getProperty(), tcExeData);
if (tcExeData.getDataLibRawData() != null) {
// If the property is a TestDataLib, we same all rows retreived in order to support nature such as NOTINUSe or RANDOMNEW.
for (int i = 1; i < (tcExeData.getDataLibRawData().size()); i++) {
now = new Date().getTime();
TestCaseExecutionData tcedS = factoryTestCaseExecutionData.create(tcExeData.getId(), tcExeData.getProperty(), (i + 1), tcExeData.getDescription(), tcExeData.getDataLibRawData().get(i).get(""), tcExeData.getType(), "", "", tcExeData.getRC(), "", now, now, now, now, null, 0, 0, "", "", "", "", "", 0, "", "", "", "", "", "", "N");
testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcedS));
}
}
} catch (CerberusException cex) {
LOG.error(cex.getMessage(), cex);
}
}
} catch (Exception ex) {
LOG.error(ex.toString(), ex);
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", ex.toString());
}
}
return message;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class ControlService method doControl.
@Override
public TestCaseStepActionControlExecution doControl(TestCaseStepActionControlExecution testCaseStepActionControlExecution) {
MessageEvent res;
TestCaseExecution tCExecution = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();
AnswerItem<String> answerDecode = new AnswerItem();
/**
* Decode the 2 fields property and values before doing the control.
*/
try {
// then the execution of this control should not performed
if (testCaseStepActionControlExecution.getValue1().contains("%")) {
// When starting a new control, we reset the property list that was already calculated.
tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getValue1(), tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);
testCaseStepActionControlExecution.setValue1((String) answerDecode.getItem());
if (!(answerDecode.isCodeStringEquals("OK"))) {
// If anything wrong with the decode --> we stop here with decode message in the control result.
testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value1"));
testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
testCaseStepActionControlExecution.setEnd(new Date().getTime());
LOG.debug("Control interupted due to decode 'Control Value1' Error.");
return testCaseStepActionControlExecution;
}
}
if (testCaseStepActionControlExecution.getValue2().contains("%")) {
// When starting a new control, we reset the property list that was already calculated.
tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getValue2(), tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);
testCaseStepActionControlExecution.setValue2((String) answerDecode.getItem());
if (!(answerDecode.isCodeStringEquals("OK"))) {
// If anything wrong with the decode --> we stop here with decode message in the control result.
testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value2"));
testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
testCaseStepActionControlExecution.setEnd(new Date().getTime());
LOG.debug("Control interupted due to decode 'Control Value2' Error.");
return testCaseStepActionControlExecution;
}
}
} catch (CerberusEventException cex) {
testCaseStepActionControlExecution.setControlResultMessage(cex.getMessageError());
testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));
return testCaseStepActionControlExecution;
}
/**
* Timestamp starts after the decode. TODO protect when property is
* null.
*/
testCaseStepActionControlExecution.setStart(new Date().getTime());
// When starting a new control, we reset the property list that was already calculated.
tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
try {
switch(testCaseStepActionControlExecution.getControl()) {
case TestCaseStepActionControl.CONTROL_VERIFYSTRINGEQUAL:
res = this.verifyStringEqual(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYSTRINGDIFFERENT:
res = this.verifyStringDifferent(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYSTRINGGREATER:
res = this.verifyStringGreater(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYSTRINGMINOR:
res = this.verifyStringMinor(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYSTRINGCONTAINS:
res = this.verifyStringContains(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:
case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:
case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:
case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:
case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:
case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:
res = this.evaluateControl_ifNumericXXX(testCaseStepActionControlExecution.getControl(), testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT:
// TODO validate properties
res = this.verifyElementPresent(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT:
// TODO validate properties
res = this.verifyElementNotPresent(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTVISIBLE:
// TODO validate properties
res = this.verifyElementVisible(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE:
// TODO validate properties
res = this.verifyElementNotVisible(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS:
res = this.verifyElementEquals(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT:
res = this.verifyElementDifferent(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT:
// TODO validate properties
res = this.verifyElementInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE:
res = this.verifyElementClickable(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE:
res = this.verifyElementNotClickable(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYTEXTINELEMENT:
res = this.verifyTextInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINELEMENT:
res = this.verifyTextNotInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYREGEXINELEMENT:
res = this.VerifyRegexInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE:
res = this.VerifyTextInPage(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE:
res = this.VerifyTextNotInPage(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYTITLE:
res = this.verifyTitle(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYURL:
res = this.verifyUrl(tCExecution, testCaseStepActionControlExecution.getValue1());
break;
case TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG:
res = this.verifyTextInDialog(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE:
res = this.verifyXmlTreeStructure(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
break;
case TestCaseStepActionControl.CONTROL_TAKESCREENSHOT:
res = this.takeScreenshot(tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution);
break;
case TestCaseStepActionControl.CONTROL_GETPAGESOURCE:
res = this.getPageSource(tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution);
break;
default:
res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_UNKNOWNCONTROL);
res.setDescription(res.getDescription().replace("%CONTROL%", testCaseStepActionControlExecution.getControl()));
}
} catch (final CerberusEventException exception) {
res = exception.getMessageError();
} catch (final Exception unexpected) {
LOG.error("Unexpected exception: " + unexpected.getMessage(), unexpected);
res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC).resolveDescription("ERROR", unexpected.getMessage());
}
testCaseStepActionControlExecution.setControlResultMessage(res);
/**
* Updating Control result message only if control is not successful.
* This is to keep the last KO information and preventing KO to be
* transformed to OK.
*/
if (!(res.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {
testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));
}
/**
* We only stop the test if Control Event message is in stop status AND
* the control is FATAL. If control is not fatal, we continue the test
* but refresh the Execution status.
*/
if (res.isStopTest()) {
if (testCaseStepActionControlExecution.getFatal().equals("Y")) {
testCaseStepActionControlExecution.setStopExecution(true);
}
}
testCaseStepActionControlExecution.setEnd(new Date().getTime());
return testCaseStepActionControlExecution;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionService method createAllTestCaseExecution.
@Override
public List<TestCaseExecution> createAllTestCaseExecution(List<TestCase> testCaseList, List<String> envList, List<String> countryList) {
List<TestCaseExecution> result = new ArrayList<TestCaseExecution>();
for (TestCase tc : testCaseList) {
for (String environment : envList) {
for (String country : countryList) {
TestCaseExecution execution = new TestCaseExecution();
execution.setTest(tc.getTest());
execution.setTestCase(tc.getTestCase());
execution.setEnvironment(environment);
execution.setCountry(country);
result.add(execution);
}
}
}
return result;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionService method hashExecution.
private List<TestCaseExecution> hashExecution(List<TestCaseExecution> testCaseExecutions, List<TestCaseExecutionQueue> testCaseExecutionsInQueue) throws ParseException {
LinkedHashMap<String, TestCaseExecution> testCaseExecutionsList = new LinkedHashMap();
for (TestCaseExecution testCaseExecution : testCaseExecutions) {
String key = testCaseExecution.getRobotDecli() + "_" + testCaseExecution.getCountry() + "_" + testCaseExecution.getEnvironment() + "_" + testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();
if ((testCaseExecutionsList.containsKey(key))) {
testCaseExecution.setNbExecutions(testCaseExecutionsList.get(key).getNbExecutions() + 1);
}
testCaseExecutionsList.put(key, testCaseExecution);
}
for (TestCaseExecutionQueue testCaseExecutionInQueue : testCaseExecutionsInQueue) {
TestCaseExecution testCaseExecution = testCaseExecutionInQueueService.convertToTestCaseExecution(testCaseExecutionInQueue);
String key = testCaseExecution.getRobotDecli() + "_" + testCaseExecution.getCountry() + "_" + testCaseExecution.getEnvironment() + "_" + testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();
if ((testCaseExecutionsList.containsKey(key) && testCaseExecutionsList.get(key).getStart() < testCaseExecutionInQueue.getRequestDate().getTime()) || !testCaseExecutionsList.containsKey(key)) {
testCaseExecutionsList.put(key, testCaseExecution);
}
}
List<TestCaseExecution> result = new ArrayList<TestCaseExecution>(testCaseExecutionsList.values());
return result;
}
Aggregations