use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method findTestCaseCountryPropertiesByKey.
@Override
public TestCaseCountryProperties findTestCaseCountryPropertiesByKey(String test, String testcase, String country, String property) throws CerberusException {
TestCaseCountryProperties result = null;
boolean throwException = false;
final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ? AND hex(`property`) = hex(?)";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, test);
preStat.setString(2, testcase);
preStat.setString(3, country);
preStat.setBytes(4, property.getBytes("UTF-8"));
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
String description = resultSet.getString("description");
String type = resultSet.getString("type");
String database = resultSet.getString("database");
String value1 = resultSet.getString("value1");
String value2 = resultSet.getString("value2");
String length = resultSet.getString("length");
int rowLimit = resultSet.getInt("rowLimit");
String nature = resultSet.getString("nature");
int retryNb = resultSet.getInt("RetryNb");
int retryPeriod = resultSet.getInt("RetryPeriod");
int cacheExpire = resultSet.getInt("CacheExpire");
result = factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire);
} else {
throwException = true;
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} catch (UnsupportedEncodingException ex) {
LOG.error(ex.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
if (throwException) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
}
return result;
}
use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesService method compareListAndUpdateInsertDeleteElements.
@Override
public Answer compareListAndUpdateInsertDeleteElements(String test, String testCase, List<TestCaseCountryProperties> newList) {
Answer ans = new Answer(null);
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
List<TestCaseCountryProperties> oldList = new ArrayList();
// try {
oldList = this.findListOfPropertyPerTestTestCase(test, testCase);
// } catch (CerberusException ex) {
// LOG.error(ex);
// }
/**
* Iterate on (Object From Page - Object From Database) If Object in
* Database has same key : Update and remove from the list. If Object in
* database does ot exist : Insert it.
*/
List<TestCaseCountryProperties> listToUpdateOrInsert = new ArrayList(newList);
listToUpdateOrInsert.removeAll(oldList);
List<TestCaseCountryProperties> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
for (TestCaseCountryProperties objectDifference : listToUpdateOrInsertToIterate) {
for (TestCaseCountryProperties objectInDatabase : oldList) {
if (objectDifference.hasSameKey(objectInDatabase)) {
ans = this.update(objectDifference);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
listToUpdateOrInsert.remove(objectDifference);
}
}
}
/**
* Iterate on (Object From Database - Object From Page). If Object in
* Page has same key : remove from the list. Then delete the list of
* Object
*/
List<TestCaseCountryProperties> listToDelete = new ArrayList(oldList);
listToDelete.removeAll(newList);
List<TestCaseCountryProperties> listToDeleteToIterate = new ArrayList(listToDelete);
for (TestCaseCountryProperties objectDifference : listToDeleteToIterate) {
for (TestCaseCountryProperties objectInPage : newList) {
if (objectDifference.hasSameKey(objectInPage)) {
listToDelete.remove(objectDifference);
}
}
}
if (!listToDelete.isEmpty()) {
ans = this.deleteList(listToDelete);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
// We insert only at the end (after deletion of all potencial enreg - linked with #1281)
if (!listToUpdateOrInsert.isEmpty()) {
ans = this.createList(listToUpdateOrInsert);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
return finalAnswer;
}
use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class LoadTestCaseService method loadTestCase.
@Override
public void loadTestCase(TestCaseExecution tCExecution) {
TestCase testCase = tCExecution.getTestCaseObj();
String test = testCase.getTest();
String testcase = testCase.getTestCase();
List<TestCaseCountry> testCaseCountry = new ArrayList<TestCaseCountry>();
List<TestCaseCountryProperties> testCaseCountryProperty = new ArrayList<TestCaseCountryProperties>();
List<TestCaseStep> testCaseStep = new ArrayList<TestCaseStep>();
List<TestCaseStep> PretestCaseStep = new ArrayList<TestCaseStep>();
/**
* Get List of PreTest for selected TestCase
*/
LOG.debug("Loading pretests for " + tCExecution.getCountry() + tCExecution.getTestCaseObj().getApplication());
List<String> login = this.testCaseStepService.getLoginStepFromTestCase(tCExecution.getCountry(), tCExecution.getTestCaseObj().getApplication());
/**
* Load Steps of PreTest
*/
if (login != null) {
for (String tsCase : login) {
TestCaseCountry preTestCaseCountry = factoryTestCaseCountry.create("Pre Tests", tsCase, tCExecution.getCountry());
preTestCaseCountry.setTestCaseCountryProperty(this.loadProperties(preTestCaseCountry));
testCaseCountry.add(preTestCaseCountry);
TestCase preTestCase = factoryTCase.create("Pre Tests", tsCase);
LOG.debug("add all pretest");
PretestCaseStep.addAll(loadTestCaseStep(preTestCase));
}
}
/**
* Load Information of TestCase
*/
TestCase testCaseToAdd = factoryTCase.create(test, testcase);
LOG.debug("add all step");
testCaseStep.addAll(loadTestCaseStep(testCaseToAdd));
LOG.debug("search all countryprop");
List<TestCaseCountryProperties> testCaseCountryPropertyToAdd = this.testCaseCountryPropertiesService.findListOfPropertyPerTestTestCaseCountry(test, testcase, tCExecution.getCountry());
LOG.debug("add all countryprop");
if (testCaseCountryPropertyToAdd != null) {
testCaseCountryProperty.addAll(testCaseCountryPropertyToAdd);
}
/**
* Set Execution Object
*/
testCase.setTestCaseCountry(testCaseCountry);
LOG.debug("set testcasestep");
testCase.setTestCaseStep(testCaseStep);
LOG.debug("setTestCaseCountryProperties");
testCase.setTestCaseCountryProperties(testCaseCountryProperty);
LOG.debug("settCase");
tCExecution.setTestCaseObj(testCase);
}
Aggregations