use of org.cerberus.crud.entity.AppService in project cerberus-source by cerberustesting.
the class DataLibService method getDataObjectList.
/**
* Get the dataObject List depending on the type
*
* @param lib
* @param columnList
* @return
*/
private AnswerList<HashMap<String, String>> getDataObjectList(TestDataLib lib, HashMap<String, String> columnList, int rowLimit, TestCaseExecution tCExecution, TestCaseExecutionData testCaseExecutionData) {
AnswerList result = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);
CountryEnvironmentDatabase countryEnvironmentDatabase;
AnswerList responseList;
String system = tCExecution.getApplicationObj().getSystem();
String country = tCExecution.getCountry();
String environment = tCExecution.getEnvironment();
Pattern pattern;
Matcher matcher;
Parameter p;
List<HashMap<String, String>> list;
switch(lib.getType()) {
case TestDataLib.TYPE_CSV:
/**
* Before making the call we check if the Service Path is
* already a proper URL. If it is not, we prefix with the CsvUrl
* defined from corresponding database. This is used to get the
* data from the correct environment.
*/
String servicePathCsv = lib.getCsvUrl();
LOG.debug("Service Path (Csv) : " + lib.getCsvUrl());
// Trying making an URL with database context path.
if (!StringUtil.isURL(servicePathCsv)) {
// Url is not valid, we try to get the corresponding DatabaseURL CsvURL to prefix.
if (!(StringUtil.isNullOrEmpty(lib.getDatabaseCsv()))) {
try {
countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(this.countryEnvironmentDatabaseService.readByKey(system, country, environment, lib.getDatabaseCsv()));
if (countryEnvironmentDatabase == null) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKOANDDATABASECSVURLNOTEXIST);
msg.setDescription(msg.getDescription().replace("%SERVICEURL%", lib.getCsvUrl()).replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", lib.getDatabaseCsv()));
result.setResultMessage(msg);
return result;
} else {
String csvURL = countryEnvironmentDatabase.getCsvUrl();
if (StringUtil.isNullOrEmpty(csvURL)) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKOANDDATABASECSVURLEMPTY);
msg.setDescription(msg.getDescription().replace("%SERVICEURL%", lib.getCsvUrl()).replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", lib.getDatabaseCsv()));
result.setResultMessage(msg);
return result;
}
// soapURL from database is not empty so we prefix the Service URL with it.
servicePathCsv = csvURL + lib.getCsvUrl();
if (!StringUtil.isURL(servicePathCsv)) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKO);
msg.setDescription(msg.getDescription().replace("%SERVICEURL%", servicePathCsv).replace("%SOAPURL%", csvURL).replace("%SERVICEPATH%", lib.getCsvUrl()).replace("%ENTRY%", lib.getName()).replace("%ENTRYID%", lib.getTestDataLibID().toString()));
result.setResultMessage(msg);
return result;
}
}
} catch (CerberusException ex) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKOANDDATABASECSVURLNOTEXIST);
msg.setDescription(msg.getDescription().replace("%SERVICEURL%", lib.getCsvUrl()).replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", lib.getDatabaseCsv()));
result.setResultMessage(msg);
return result;
}
}
}
// Trying make a valid path with csv parameter path.
if (!StringUtil.isURL(servicePathCsv)) {
// Url is still not valid. We try to add the path from csv parameter.
String csv_path = parameterService.getParameterStringByKey("cerberus_testdatalibcsv_path", "", "");
csv_path = StringUtil.addSuffixIfNotAlready(csv_path, File.separator);
servicePathCsv = csv_path + servicePathCsv;
}
// CSV Call is made here.
responseList = fileService.parseCSVFile(servicePathCsv, lib.getSeparator(), columnList);
list = responseList.getDataList();
// if the query returns sucess then we can get the data
if (responseList.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_CSV.getCode()) {
if (list != null && !list.isEmpty()) {
result.setDataList(list);
msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_CSV);
msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())).replace("%CSVURL%", servicePathCsv));
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSVDATABASENODATA);
msg.setDescription(msg.getDescription().replace("%CSVURL%", servicePathCsv));
}
} else {
msg = responseList.getResultMessage();
}
result.setResultMessage(msg);
break;
case TestDataLib.TYPE_SQL:
String connectionName;
String db = lib.getDatabase();
try {
if (StringUtil.isNullOrEmpty(db)) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASEEMPTY);
} else {
countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(countryEnvironmentDatabaseService.readByKey(system, country, environment, db));
if (countryEnvironmentDatabase == null) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASENOTCONFIGURED);
msg.setDescription(msg.getDescription().replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", db));
} else {
connectionName = countryEnvironmentDatabase.getConnectionPoolName();
if (!(StringUtil.isNullOrEmpty(connectionName))) {
Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_propertyexternalsql_timeout", system, 60);
// performs a query that returns several rows containing n columns
responseList = sqlService.queryDatabaseNColumns(connectionName, lib.getScript(), rowLimit, sqlTimeout, system, columnList);
// if the query returns sucess then we can get the data
if (responseList.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_SQL.getCode()) {
list = responseList.getDataList();
if (list != null && !list.isEmpty()) {
result.setDataList(list);
msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SQL);
msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())));
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASENODATA);
}
} else {
msg = responseList.getResultMessage();
}
msg.setDescription(msg.getDescription().replace("%DATABASE%", db));
msg.setDescription(msg.getDescription().replace("%SQL%", lib.getScript()));
msg.setDescription(msg.getDescription().replace("%JDBCPOOLNAME%", connectionName));
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASEJDBCRESSOURCEMPTY);
msg.setDescription(msg.getDescription().replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", db));
}
}
}
} catch (CerberusException ex) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASENOTCONFIGURED);
msg.setDescription(msg.getDescription().replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", db));
}
result.setResultMessage(msg);
break;
case TestDataLib.TYPE_SERVICE:
AppService appService = new AppService();
HashMap<String, String> resultHash = new HashMap<>();
List<HashMap<String, String>> listResult = new ArrayList<HashMap<String, String>>();
// Temporary list of string.
List<String> listTemp1 = null;
// String containing the XML
String responseString = "";
/**
* Before making the call we check if the Service Path is
* already a propper URL. If it is not, we prefix with the
* SoapUrl defined from corresponding database. This is used to
* get the data from the correct environment.
*/
String servicePath = lib.getServicePath();
LOG.debug("Service Path : " + lib.getServicePath());
// Service Call is made here.
AnswerItem ai = serviceService.callService(lib.getService(), lib.getDatabaseUrl(), lib.getEnvelope(), lib.getServicePath(), lib.getMethod(), tCExecution);
msg = ai.getResultMessage();
// if the call returns success then we can process the soap ressponse
if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {
appService = (AppService) ai.getItem();
// Record result in filessytem.
// testCaseExecutionData.addFileList(recorderService.recordServiceCall(tCExecution, null, 0, testCaseExecutionData.getProperty(), appService));
recorderService.recordServiceCall(tCExecution, null, 0, testCaseExecutionData.getProperty(), appService);
// Call successful so we can start to parse the result and build RawData per columns from subdata entries.
/**
* This Step will calculate hashTemp1 : Hash of List from
* the Service response.
*/
// Will contain the nb of row of the target list of Hash.
int finalnbRow = 0;
// Will contain the result of the XML parsing.
HashMap<String, List<String>> hashTemp1 = new HashMap<>();
if (columnList.isEmpty()) {
// No subdata could be found on the testdatalib.
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_NOSUBDATA);
msg.setDescription(msg.getDescription().replace("%ENTRY%", lib.getName()).replace("%ENTRYID%", lib.getTestDataLibID().toString()));
} else {
switch(appService.getResponseHTTPBodyContentType()) {
case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:
Document xmlDocument = xmlUnitService.getXmlDocument(appService.getResponseHTTPBody());
// We get the content of the XML in order to report it log messages.
responseString = appService.getResponseHTTPBody();
for (Map.Entry<String, String> entry : columnList.entrySet()) {
// SubData
String subDataColumnToTreat = entry.getKey();
// Parsing Answer
String subDataParsingAnswer = entry.getValue();
listTemp1 = new ArrayList<>();
try {
// We try to parse the XML with the subdata Parsing Answer.
NodeList candidates = XmlUtil.evaluate(xmlDocument, subDataParsingAnswer);
if (candidates.getLength() > 0) {
for (int i = 0; i < candidates.getLength(); i++) {
// Loop on all Values that match in XML.
// We get the value from XML
String value = candidates.item(i).getNodeValue();
if (value == null) {
// No value found.
if (candidates.item(i) != null) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_CHECK_XPATH);
msg.setDescription(msg.getDescription().replace("%XPATH%", subDataParsingAnswer).replace("%SUBDATA%", subDataColumnToTreat).replace("%ENTRY%", lib.getName()).replace("%ENTRYID%", lib.getTestDataLibID().toString()));
} else {
// no elements were returned by the XPATH expression
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XML_NOTFOUND);
msg.setDescription(msg.getDescription().replace("%XPATH%", subDataParsingAnswer).replace("%SUBDATA%", subDataColumnToTreat).replace("%ENTRY%", lib.getName()).replace("%XMLCONTENT%", responseString).replace("%ENTRYID%", lib.getTestDataLibID().toString()));
}
} else {
// Value were found we add it to the current list.
listTemp1.add(value);
}
}
// Add the Subdata with associated list in the HashMap.
hashTemp1.put(subDataColumnToTreat, listTemp1);
// Getting the nb of row of the final result. (Max of all the Subdata retrieved from the XML)
if (listTemp1.size() > finalnbRow) {
finalnbRow = listTemp1.size();
}
} else {
// no elements were returned by the XPATH expression
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XML_NOTFOUND);
msg.setDescription(msg.getDescription().replace("%XPATH%", subDataParsingAnswer).replace("%SUBDATA%", subDataColumnToTreat).replace("%ENTRY%", lib.getName()).replace("%XMLCONTENT%", responseString).replace("%ENTRYID%", lib.getTestDataLibID().toString()));
}
} catch (XmlUtilException ex) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XMLEXCEPTION);
msg.setDescription(msg.getDescription().replace("%XPATH%", subDataParsingAnswer).replace("%SUBDATA%", subDataColumnToTreat).replace("%ENTRY%", lib.getName()).replace("%ENTRYID%", lib.getTestDataLibID().toString()).replace("%REASON%", ex.toString() + " Detail answer " + responseString));
} catch (Exception ex) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XMLEXCEPTION);
msg.setDescription(msg.getDescription().replace("%XPATH%", lib.getSubDataParsingAnswer()).replace("%SUBDATA%", "").replace("%REASON%", ex.toString()));
}
}
/**
* This Step will convert hashTemp1 (Hash of
* List) to target listResult (list of Hash).
*/
if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {
for (int i = 0; i < finalnbRow; i++) {
// Loop on all Values that match in XML.
resultHash = new HashMap<String, String>();
for (Map.Entry<String, String> entry : columnList.entrySet()) {
// Loop on all SubData of the TestDataLib.
listTemp1 = hashTemp1.get(entry.getKey());
if (listTemp1 != null) {
if (i < listTemp1.size()) {
resultHash.put(entry.getKey(), listTemp1.get(i));
} else {
resultHash.put(entry.getKey(), "");
}
}
}
listResult.add(resultHash);
}
}
/**
* This Step will pick the correct listResult
* (list of Hash) from the type of Property.
*/
if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {
result.setDataList(listResult);
msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SOAP);
msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())).replace("%URL%", servicePath).replace("%OPER%", lib.getMethod()));
}
break;
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
// We get the content of the XML in order to report it log messages.
responseString = appService.getResponseHTTPBody();
for (Map.Entry<String, String> entry : columnList.entrySet()) {
// SubData
String subDataColumnToTreat = entry.getKey();
// Parsing Answer
String subDataParsingAnswer = entry.getValue();
listTemp1 = new ArrayList<>();
try {
// We try to parse the XML with the subdata Parsing Answer.
listTemp1 = jsonService.getFromJson(responseString, subDataParsingAnswer);
if (listTemp1.size() > 0) {
// Add the Subdata with associated list in the HashMap.
hashTemp1.put(subDataColumnToTreat, listTemp1);
// Getting the nb of row of the final result. (Max of all the Subdata retrieved from the XML)
if (listTemp1.size() > finalnbRow) {
finalnbRow = listTemp1.size();
}
} else {
// no elements were returned by the XPATH expression
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_JSON_NOTFOUND);
msg.setDescription(msg.getDescription().replace("%XPATH%", subDataParsingAnswer).replace("%SUBDATA%", subDataColumnToTreat).replace("%ENTRY%", lib.getName()).replace("%XMLCONTENT%", responseString).replace("%ENTRYID%", lib.getTestDataLibID().toString()));
}
} catch (Exception ex) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_JSONEXCEPTION);
msg.setDescription(msg.getDescription().replace("%XPATH%", lib.getSubDataParsingAnswer()).replace("%SUBDATA%", "").replace("%REASON%", ex.toString()));
}
}
/**
* This Step will convert hashTemp1 (Hash of
* List) to target listResult (list of Hash).
*/
if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {
for (int i = 0; i < finalnbRow; i++) {
// Loop on all Values that match in XML.
resultHash = new HashMap<String, String>();
for (Map.Entry<String, String> entry : columnList.entrySet()) {
// Loop on all SubData of the TestDataLib.
listTemp1 = hashTemp1.get(entry.getKey());
if (listTemp1 != null) {
if (i < listTemp1.size()) {
resultHash.put(entry.getKey(), listTemp1.get(i));
} else {
resultHash.put(entry.getKey(), "");
}
}
}
listResult.add(resultHash);
}
}
/**
* This Step will pick the correct listResult
* (list of Hash) from the type of Property.
*/
if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {
result.setDataList(listResult);
msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SOAP);
msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())).replace("%URL%", servicePath).replace("%OPER%", lib.getMethod()));
}
break;
default:
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOTSUPPORTEDSERVICERESULT);
msg.setDescription(msg.getDescription().replace("%FORMAT%", appService.getResponseHTTPBodyContentType()));
}
}
} else {
String soapError = msg.getDescription();
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_SOAPCALLFAILED);
msg.setDescription(msg.getDescription().replace("%SOAPERROR%", soapError));
}
msg.setDescription(msg.getDescription().replace("%SERVICE%", servicePath).replace("%OPERATION%", lib.getMethod()));
result.setResultMessage(msg);
break;
case TestDataLib.TYPE_INTERNAL:
result = testDataLibService.readINTERNALWithSubdataByCriteria(lib.getName(), lib.getSystem(), lib.getCountry(), lib.getEnvironment(), rowLimit, system);
// if the sql service returns a success message then we can process it
if ((result.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !result.getDataList().isEmpty()) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_INTERNAL);
msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())));
result.setResultMessage(msg);
} else if ((result.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && result.getDataList().isEmpty()) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_INTERNALNODATA);
msg.setDescription(msg.getDescription().replace("%SYSTEM%", lib.getSystem()).replace("%ENV%", lib.getEnvironment()).replace("%COUNTRY%", lib.getCountry()));
result.setResultMessage(msg);
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_INTERNAL);
msg.setDescription(msg.getDescription().replace("%SYSTEM%", lib.getSystem()).replace("%ENV%", lib.getEnvironment()).replace("%COUNTRY%", lib.getCountry()));
result.setResultMessage(msg);
}
break;
}
return result;
}
use of org.cerberus.crud.entity.AppService in project cerberus-source by cerberustesting.
the class RecorderService method recordExecutionInformationAfterStepActionandControl.
@Override
public List<TestCaseExecutionFile> recordExecutionInformationAfterStepActionandControl(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {
List<TestCaseExecutionFile> objectFileList = new ArrayList<TestCaseExecutionFile>();
TestCaseExecutionFile objectFile = null;
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
TestCaseExecution myExecution;
boolean doScreenshot;
boolean getPageSource;
String applicationType;
String returnCode;
Integer controlNumber = 0;
if (testCaseStepActionControlExecution == null) {
myExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
doScreenshot = testCaseStepActionExecution.getActionResultMessage().isDoScreenshot();
getPageSource = testCaseStepActionExecution.getActionResultMessage().isGetPageSource();
applicationType = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();
returnCode = testCaseStepActionExecution.getReturnCode();
} else {
myExecution = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();
doScreenshot = testCaseStepActionControlExecution.getControlResultMessage().isDoScreenshot();
getPageSource = testCaseStepActionControlExecution.getControlResultMessage().isGetPageSource();
applicationType = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();
returnCode = testCaseStepActionControlExecution.getReturnCode();
controlNumber = testCaseStepActionControlExecution.getControlSequence();
}
/**
* SCREENSHOT Management. Screenshot only done when : screenshot
* parameter is eq to 2 or screenshot parameter is eq to 1 with the
* correct doScreenshot flag on the last action MessageEvent.
*/
if ((myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot))) {
if (applicationType.equals(Application.TYPE_GUI) || applicationType.equals(Application.TYPE_APK) || applicationType.equals(Application.TYPE_IPA) || applicationType.equals(Application.TYPE_FAT)) {
/**
* Only if the return code is not equal to Cancel, meaning lost
* connectivity with selenium.
*/
if (!returnCode.equals("CA")) {
objectFile = this.recordScreenshot(myExecution, testCaseStepActionExecution, controlNumber);
if (objectFile != null) {
objectFileList.add(objectFile);
}
} else {
LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");
}
}
} else {
LOG.debug(logPrefix + "Not Doing screenshot because of the screenshot parameter or flag on the last Action result.");
}
/**
* PAGESOURCE management. Get PageSource if requested by the last Action
* MessageEvent.
*/
if ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource))) {
if (applicationType.equals(Application.TYPE_GUI) || applicationType.equals(Application.TYPE_APK) || applicationType.equals(Application.TYPE_IPA)) {
/**
* Only if the return code is not equal to Cancel, meaning lost
* connectivity with selenium.
*/
if (!returnCode.equals("CA")) {
objectFile = this.recordPageSource(myExecution, testCaseStepActionExecution, controlNumber);
if (objectFile != null) {
objectFileList.add(objectFile);
}
} else {
LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");
}
}
} else {
LOG.debug(logPrefix + "Not getting page source because of the pageSource parameter or flag on the last Action result.");
}
/**
* Last call XML SOURCE management. Get Source of the XML if requested
* by the last Action or control MessageEvent.
*/
if (applicationType.equals(Application.TYPE_SRV) && ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource)) || (myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot)))) {
// Record the Request and Response.
AppService se = (AppService) testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getLastServiceCalled();
if (se != null) {
// No Calls were performed previously
List<TestCaseExecutionFile> objectFileSOAPList = new ArrayList<TestCaseExecutionFile>();
objectFileSOAPList = this.recordServiceCall(myExecution, testCaseStepActionExecution, controlNumber, null, se);
if (objectFileSOAPList.isEmpty() != true) {
for (TestCaseExecutionFile testCaseExecutionFile : objectFileSOAPList) {
objectFileList.add(testCaseExecutionFile);
}
}
}
}
return objectFileList;
}
use of org.cerberus.crud.entity.AppService in project cerberus-source by cerberustesting.
the class AppServiceDAO method readByCriteria.
@Override
public AnswerList readByCriteria(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<AppService> objectList = new ArrayList<AppService>();
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 appservice srv ");
query.append(" WHERE 1=1");
if (!StringUtil.isNullOrEmpty(searchTerm)) {
searchSQL.append(" and (srv.Service like ?");
searchSQL.append(" or srv.Application like ?");
searchSQL.append(" or srv.Type like ?");
searchSQL.append(" or srv.ServicePath like ?");
searchSQL.append(" or srv.Method like ?");
searchSQL.append(" or srv.Operation like ?");
searchSQL.append(" or srv.ServiceRequest like ?");
searchSQL.append(" or srv.AttachementURL like ?");
searchSQL.append(" or srv.Group like ?");
searchSQL.append(" or srv.Description like ?");
searchSQL.append(" or srv.UsrCreated like ?");
searchSQL.append(" or srv.DateCreated like ?");
searchSQL.append(" or srv.UsrModif like ?");
searchSQL.append(" or srv.DateModif like ?)");
}
if (individualSearch != null && !individualSearch.isEmpty()) {
searchSQL.append(" and ( 1=1 ");
for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
searchSQL.append(" and ");
String q = SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue());
if (q == null || q == "") {
q = "(" + entry.getKey() + " IS NULL OR " + entry.getKey() + " = '')";
}
searchSQL.append(q);
individalColumnSearchValues.addAll(entry.getValue());
}
searchSQL.append(" )");
}
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 + "%");
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);
}
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;
}
use of org.cerberus.crud.entity.AppService in project cerberus-source by cerberustesting.
the class AppServiceDAO method readByKey.
@Override
public AnswerItem readByKey(String key) {
AnswerItem ans = new AnswerItem();
AppService result = null;
final String query = "SELECT * FROM `appservice` srv WHERE `service` = ?";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.service : " + key);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, key);
try (ResultSet resultSet = preStat.executeQuery()) {
if (resultSet.first()) {
result = loadFromResultSet(resultSet);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
ans.setItem(result);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
}
} catch (SQLException exception) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
}
} 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 {
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 (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
// sets the message
ans.setResultMessage(msg);
return ans;
}
use of org.cerberus.crud.entity.AppService in project cerberus-source by cerberustesting.
the class AppServiceDAO method findAppServiceByKey.
@Override
public AppService findAppServiceByKey(String service) throws CerberusException {
boolean throwEx = false;
AppService result = null;
final String query = "SELECT * FROM appservice srv WHERE `service` = ?";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, service);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
String group = resultSet.getString("Group");
String serviceRequest = resultSet.getString("ServiceRequest");
String description = resultSet.getString("Description");
String servicePath = resultSet.getString("servicePath");
String attachementURL = resultSet.getString("AttachementURL");
String operation = resultSet.getString("Operation");
String application = resultSet.getString("Application");
String type = resultSet.getString("Type");
String method = resultSet.getString("Method");
String usrModif = resultSet.getString("UsrModif");
String usrCreated = resultSet.getString("UsrCreated");
Timestamp dateCreated = resultSet.getTimestamp("DateCreated");
Timestamp dateModif = resultSet.getTimestamp("DateModif");
result = this.factoryAppService.create(service, type, method, application, group, serviceRequest, description, servicePath, attachementURL, operation, usrCreated, dateCreated, usrModif, dateModif);
} else {
throwEx = true;
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn("Exception closing connection : " + e.toString());
}
}
if (throwEx) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
}
return result;
}
Aggregations