use of org.cerberus.crud.entity.TestCaseExecutionData in project cerberus-source by cerberustesting.
the class PropertyService method decodeStringWithExistingProperties.
@Override
public AnswerItem<String> decodeStringWithExistingProperties(String stringToDecode, TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, boolean forceCalculation) throws CerberusEventException {
MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);
AnswerItem<String> answer = new AnswerItem();
answer.setResultMessage(msg);
answer.setItem(stringToDecode);
String country = tCExecution.getCountry();
long now = new Date().getTime();
String stringToDecodeInit = stringToDecode;
if (LOG.isDebugEnabled()) {
LOG.debug("Starting to decode string (Property) : " + stringToDecode);
}
/**
* Look at all the potencial properties still contained in
* StringToDecode (considering that properties are between %).
*/
List<String> internalPropertiesFromStringToDecode = this.getPropertiesListFromString(stringToDecode);
if (LOG.isDebugEnabled()) {
LOG.debug("Internal potencial properties still found inside property '" + stringToDecode + "' : " + internalPropertiesFromStringToDecode);
}
if (internalPropertiesFromStringToDecode.isEmpty()) {
// We escape if no property found on the string to decode
if (LOG.isDebugEnabled()) {
LOG.debug("Finished to decode (no properties detected in string) : . result : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");
}
answer.setItem(stringToDecode);
answer.setResultMessage(msg);
return answer;
}
/**
* Get the list of properties needed to calculate the required property
*/
List<TestCaseCountryProperties> tcProperties = tCExecution.getTestCaseCountryPropertyList();
List<TestCaseCountryProperties> linkedProperties = new ArrayList();
for (String internalProperty : internalPropertiesFromStringToDecode) {
// Looping on potential properties in string to decode.
List<TestCaseCountryProperties> newLinkedProperties = new ArrayList();
newLinkedProperties = this.getListOfPropertiesLinkedToProperty(country, internalProperty, new ArrayList(), tcProperties);
linkedProperties.addAll(newLinkedProperties);
if (LOG.isDebugEnabled()) {
LOG.debug("Property " + internalProperty + " need calculation of these (" + newLinkedProperties.size() + ") property(ies) " + newLinkedProperties);
}
}
/**
* For all linked properties, calculate it if needed.
*/
for (TestCaseCountryProperties eachTccp : linkedProperties) {
TestCaseExecutionData tcExeData;
/**
* First create testCaseExecutionData object
*/
now = new Date().getTime();
tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), eachTccp.getProperty(), 1, eachTccp.getDescription(), null, eachTccp.getType(), eachTccp.getValue1(), eachTccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING), eachTccp.getRetryNb(), eachTccp.getRetryPeriod(), eachTccp.getDatabase(), eachTccp.getValue1(), eachTccp.getValue2(), eachTccp.getLength(), eachTccp.getLength(), eachTccp.getRowLimit(), eachTccp.getNature(), tCExecution.getApplicationObj().getSystem(), tCExecution.getEnvironment(), tCExecution.getCountry(), "", null, "N");
tcExeData.setTestCaseCountryProperties(eachTccp);
tcExeData.settCExecution(tCExecution);
if (LOG.isDebugEnabled()) {
LOG.debug("Trying to calculate Property : '" + tcExeData.getProperty() + "' " + tcExeData);
}
/* First check if property has already been calculated
* if action is calculateProperty, then set isKnownData to false.
*/
tcExeData = getExecutionDataFromList(tCExecution.getTestCaseExecutionDataMap(), eachTccp, forceCalculation, tcExeData);
/**
* If testcasecountryproperty not defined, set ExecutionData with
* the same resultMessage
*/
if (eachTccp.getResult() != null) {
tcExeData.setPropertyResultMessage(eachTccp.getResult());
}
/*
* If not already calculated, or calculateProperty, then calculate it and insert or update it.
*/
if (MessageEventEnum.PROPERTY_PENDING.equals(tcExeData.getPropertyResultMessage().getSource())) {
calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, eachTccp, forceCalculation);
msg = tcExeData.getPropertyResultMessage();
// saves the result
try {
testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcExeData));
/**
* Add TestCaseExecutionData in TestCaseExecutionData List
* of the TestCaseExecution
*/
LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + String.valueOf(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, "", tcExeData.getSystem(), tcExeData.getEnvironment(), tcExeData.getCountry(), tcExeData.getDataLib(), null, "N");
testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcedS));
}
}
} catch (CerberusException cex) {
LOG.error(cex.getMessage(), cex);
}
}
/**
* After calculation, replace properties by value calculated
*/
stringToDecode = decodeStringWithAlreadyCalculatedProperties(stringToDecode, tCExecution);
if (LOG.isDebugEnabled()) {
LOG.debug("Property " + eachTccp.getProperty() + " calculated with Value = " + tcExeData.getValue() + ", Value1 = " + tcExeData.getValue1() + ", Value2 = " + tcExeData.getValue2());
}
/**
* Log TestCaseExecutionData
*/
if (tCExecution.getVerbose() > 0) {
LOG.info(tcExeData.toJson(false, true));
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Finished to decode String (property) : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");
}
answer.setResultMessage(msg);
answer.setItem(stringToDecode);
return answer;
}
use of org.cerberus.crud.entity.TestCaseExecutionData in project cerberus-source by cerberustesting.
the class PropertyService method decodeStringWithAlreadyCalculatedProperties.
private String decodeStringWithAlreadyCalculatedProperties(String stringToReplace, TestCaseExecution tCExecution) {
String variableValue = "";
String variableString1 = "";
String variableString2 = "";
TestCaseExecutionData tced;
for (String key1 : tCExecution.getTestCaseExecutionDataMap().keySet()) {
tced = tCExecution.getTestCaseExecutionDataMap().get(key1);
if ((tced.getType() != null) && (tced.getType().equals(TestCaseCountryProperties.TYPE_GETFROMDATALIB))) {
// Key value of the DataLib.
if (tced.getValue() != null) {
stringToReplace = stringToReplace.replace("%property." + tced.getProperty() + "%", tced.getValue());
stringToReplace = stringToReplace.replace("%" + tced.getProperty() + "%", tced.getValue());
}
// For each subdata of the getFromDataLib property, we try to replace with PROPERTY(SUBDATA).
if (!(tced.getDataLibRawData() == null)) {
int ind = 0;
for (HashMap<String, String> dataRow : tced.getDataLibRawData()) {
// We loop every row result.
for (String key : dataRow.keySet()) {
// We loop every subdata
if (dataRow.get(key) != null) {
variableValue = dataRow.get(key);
variableString1 = tced.getProperty() + "(" + (ind + 1) + ")" + "(" + key + ")";
stringToReplace = stringToReplace.replace("%property." + variableString1 + "%", variableValue);
stringToReplace = stringToReplace.replace("%" + variableString1 + "%", variableValue);
variableString2 = tced.getProperty() + "." + (ind + 1) + "." + key;
stringToReplace = stringToReplace.replace("%property." + variableString2 + "%", variableValue);
stringToReplace = stringToReplace.replace("%" + variableString2 + "%", variableValue);
if (key.equals("")) {
// If subdata is empty we can omit the () or .
variableString1 = tced.getProperty() + "(" + (ind + 1) + ")";
stringToReplace = stringToReplace.replace("%property." + variableString1 + "%", variableValue);
stringToReplace = stringToReplace.replace("%" + variableString1 + "%", variableValue);
variableString2 = tced.getProperty() + "." + (ind + 1);
stringToReplace = stringToReplace.replace("%property." + variableString2 + "%", variableValue);
stringToReplace = stringToReplace.replace("%" + variableString2 + "%", variableValue);
}
if (ind == 0) {
// Dimention of the data is not mandatory for the 1st row.
variableString1 = tced.getProperty() + "(" + key + ")";
stringToReplace = stringToReplace.replace("%property." + variableString1 + "%", variableValue);
stringToReplace = stringToReplace.replace("%" + variableString1 + "%", variableValue);
variableString2 = tced.getProperty() + "." + key;
stringToReplace = stringToReplace.replace("%property." + variableString2 + "%", variableValue);
stringToReplace = stringToReplace.replace("%" + variableString2 + "%", variableValue);
}
}
}
ind++;
}
}
} else if (tced.getValue() != null) {
/* Replacement in case of normal PROPERTY */
stringToReplace = stringToReplace.replace("%property." + tced.getProperty() + "%", tced.getValue());
stringToReplace = stringToReplace.replace("%" + tced.getProperty() + "%", tced.getValue());
}
}
return stringToReplace;
}
use of org.cerberus.crud.entity.TestCaseExecutionData in project cerberus-source by cerberustesting.
the class TestCaseExecutionDataDAO method readByIdByCriteria.
@Override
public AnswerList<TestCaseExecutionData> readByIdByCriteria(long id, int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<TestCaseExecutionData> objectList = new ArrayList<TestCaseExecutionData>();
StringBuilder searchSQL = new StringBuilder();
List<String> individalColumnSearchValues = new ArrayList<String>();
StringBuilder query = new StringBuilder();
// SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
// were applied -- used for pagination p
query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testcaseexecutiondata exd ");
searchSQL.append(" where 1=1 ");
if (!StringUtil.isNullOrEmpty(searchTerm)) {
searchSQL.append(" and (`Property` like ?");
searchSQL.append(" or `description` like ?");
searchSQL.append(" or `Value` like ?");
searchSQL.append(" or `Type` like ?");
searchSQL.append(" or `Value1` like ?");
searchSQL.append(" or `Value2` like ?");
searchSQL.append(" or `RC` like ?");
searchSQL.append(" or `RMessage` like ?)");
}
if (individualSearch != null && !individualSearch.isEmpty()) {
searchSQL.append(" and ( 1=1 ");
for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
searchSQL.append(" and ");
searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
individalColumnSearchValues.addAll(entry.getValue());
}
searchSQL.append(" )");
}
if (!(id == -1)) {
searchSQL.append(" and (`id` = ? )");
}
query.append(searchSQL);
if (!StringUtil.isNullOrEmpty(column)) {
query.append(" order by ").append(column).append(" ").append(dir);
}
if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
} else {
query.append(" limit ").append(start).append(" , ").append(amount);
}
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
int i = 1;
if (!StringUtil.isNullOrEmpty(searchTerm)) {
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
}
for (String individualColumnSearchValue : individalColumnSearchValues) {
preStat.setString(i++, individualColumnSearchValue);
}
if (!(id == -1)) {
preStat.setLong(i++, id);
}
ResultSet resultSet = preStat.executeQuery();
try {
// gets the data
while (resultSet.next()) {
objectList.add(this.loadFromResultSet(resultSet));
}
// get the total number of rows
resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
int nrTotalRows = 0;
if (resultSet != null && resultSet.next()) {
nrTotalRows = resultSet.getInt(1);
}
if (objectList.size() >= MAX_ROW_SELECTED) {
// Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.
LOG.error("Partial Result in the query.");
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
response = new AnswerList(objectList, nrTotalRows);
} else if (objectList.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
response = new AnswerList(objectList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
response = new AnswerList(objectList, nrTotalRows);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
response.setResultMessage(msg);
response.setDataList(objectList);
return response;
}
Aggregations