Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase
Source:TestCaseCountryPropertiesService.java
...58 private DatabaseSpring dbmanager;59 private final String OBJECT_NAME = "TestCaseCountryProperties";60 private static final Logger LOG = LogManager.getLogger(CountryEnvironmentDatabaseService.class);61 @Override62 public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCaseCountry(String test, String testCase, String country) {63 return testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCaseCountry(test, testCase, country);64 }65 66 @Override67 public List<TestCaseCountryProperties> findOnePropertyPerTestTestCase(String test, String testcase, String oneproperty){68 return testCaseCountryPropertiesDAO.findOnePropertyPerTestTestCase(test,testcase,oneproperty);69 }70 @Override71 public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCase(String test, String testcase) {72 return testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(test, testcase);73 }74 @Override75 public List<TestCaseCountryProperties> findDistinctPropertiesOfTestCase(String test, String testcase) {76 return testCaseCountryPropertiesDAO.findDistinctPropertiesOfTestCase(test, testcase);77 }78 @Override79 public List<String> findCountryByProperty(TestCaseCountryProperties testCaseCountryProperties) {80 return testCaseCountryPropertiesDAO.findCountryByProperty(testCaseCountryProperties);81 }82 @Override83 public TestCaseCountryProperties findTestCaseCountryPropertiesByKey(String test, String testCase, String country, String property) throws CerberusException {84 return testCaseCountryPropertiesDAO.findTestCaseCountryPropertiesByKey(test, testCase, country, property);85 }86 @Override87 public void insertTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties) throws CerberusException {88 testCaseCountryPropertiesDAO.insertTestCaseCountryProperties(testCaseCountryProperties);89 }90 @Override91 public boolean insertListTestCaseCountryProperties(List<TestCaseCountryProperties> testCaseCountryPropertiesList) {92 for (TestCaseCountryProperties tccp : testCaseCountryPropertiesList) {93 try {94 insertTestCaseCountryProperties(tccp);95 } catch (CerberusException ex) {96 LOG.warn(ex.toString());97 return false;98 }99 }100 return true;101 }102 @Override103 public void updateTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties) throws CerberusException {104 testCaseCountryPropertiesDAO.updateTestCaseCountryProperties(testCaseCountryProperties);105 }106 @Override107 public List<String> findCountryByPropertyNameAndTestCase(String test, String testcase, String property) {108 return testCaseCountryPropertiesDAO.findCountryByPropertyNameAndTestCase(test, testcase, property);109 }110 @Override111 public void deleteListTestCaseCountryProperties(List<TestCaseCountryProperties> tccpToDelete) throws CerberusException {112 for (TestCaseCountryProperties tccp : tccpToDelete) {113 deleteTestCaseCountryProperties(tccp);114 }115 }116 @Override117 public void deleteTestCaseCountryProperties(TestCaseCountryProperties tccp) throws CerberusException {118 testCaseCountryPropertiesDAO.deleteTestCaseCountryProperties(tccp);119 }120 @Override121 public List<TestCaseCountryProperties> findAllWithDependencies(String test, String testcase, String country) throws CerberusException {122 if (parameterService.getParameterBooleanByKey("cerberus_property_countrylevelheritage", "", false)) {123 // Heritage is done at property + country level.124 List<TestCaseCountryProperties> tccpList = new ArrayList();125 List<TestCaseCountryProperties> tccpListPerCountry = new ArrayList();126 TestCase mainTC = testCaseService.findTestCaseByKey(test, testcase);127 //find all properties of preTests128 List<TestCase> tcptList = testCaseService.findTestCaseActiveByCriteria("Pre Testing", mainTC.getApplication(), country);129 for (TestCase tcase : tcptList) {130 tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(tcase.getTest(), tcase.getTestCase()));131 tccpListPerCountry.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCaseCountry(tcase.getTest(), tcase.getTestCase(), country));132 }133 //find all properties of the used step134 List<TestCase> tcList = testCaseService.findUseTestCaseList(test, testcase);135 for (TestCase tcase : tcList) {136 tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(tcase.getTest(), tcase.getTestCase()));137 tccpListPerCountry.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCaseCountry(tcase.getTest(), tcase.getTestCase(), country));138 }139 //find all properties of the testcase140 tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(test, testcase));141 tccpListPerCountry.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCaseCountry(test, testcase, country));142 //Keep only one property by name143 //all properties that are defined for the country are included144 HashMap tccpMap = new HashMap();145 for (TestCaseCountryProperties tccp : tccpListPerCountry) {146 tccpMap.put(tccp.getProperty(), tccp);147 }148 //These if/else instructions are done because of the way how the propertyService verifies if149 //the properties exist for the country. 150 for (TestCaseCountryProperties tccp : tccpList) {151 TestCaseCountryProperties p = (TestCaseCountryProperties) tccpMap.get(tccp.getProperty());152 if (p == null) {153 tccpMap.put(tccp.getProperty(), tccp);154 } else if (p.getCountry().compareTo(country) != 0 && tccp.getCountry().compareTo(country) == 0) {155 tccpMap.put(tccp.getProperty(), tccp);156 }157 }158 List<TestCaseCountryProperties> result = new ArrayList<TestCaseCountryProperties>(tccpMap.values());159 return result;160 } else {161 // Heritage is done at property + country level.162 List<TestCaseCountryProperties> tccpList = new ArrayList();163 TestCase mainTC = testCaseService.findTestCaseByKey(test, testcase);164 /**165 * We load here all the properties countries from all related166 * testcases linked with test/testcase The order the load is done is167 * important as it will define the priority of each property.168 * properties coming from Pre Testing is the lower prio then, the169 * property coming from the useStep and then, top priority is the170 * property on the test + testcase.171 */172 //find all properties of preTests173 List<TestCase> tcptList = testCaseService.findTestCaseActiveByCriteria("Pre Testing", mainTC.getApplication(), country);174 for (TestCase tcase : tcptList) {175 tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(tcase.getTest(), tcase.getTestCase()));176 }177 //find all properties of the used step178 List<TestCase> tcList = testCaseService.findUseTestCaseList(test, testcase);179 for (TestCase tcase : tcList) {180 tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(tcase.getTest(), tcase.getTestCase()));181 }182 //find all properties of the testcase183 tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(test, testcase));184 /**185 * We loop here the previous list, keeping by property, the last186 * value (top priority). That will define the level to consider187 * property on the test. testcase.188 */189 HashMap<String, TestCaseCountryProperties> tccpMap1 = new HashMap<String, TestCaseCountryProperties>();190 for (TestCaseCountryProperties tccp : tccpList) {191 tccpMap1.put(tccp.getProperty(), tccp);192 }193 /**194 * We then loop again in order to keep the selected properties for195 * the given country and level found on the previous step by196 * property.197 */198 List<TestCaseCountryProperties> result = new ArrayList<TestCaseCountryProperties>();199 for (TestCaseCountryProperties tccp : tccpList) {200 if (tccp.getCountry().equals(country)) {201 TestCaseCountryProperties tccp_level = (TestCaseCountryProperties) tccpMap1.get(tccp.getProperty());202 if ((tccp_level != null)203 && (((tccp.getTest().equals("Pre Testing")) && (tccp_level.getTest().equals("Pre Testing")))204 || ((tccp.getTest().equals(test)) && (tccp.getTestCase().equals(testcase)) && (tccp_level.getTest().equals(test)) && (tccp_level.getTestCase().equals(testcase)))205 || ((tccp.getTest().equals(tccp_level.getTest())) && (tccp.getTestCase().equals(tccp_level.getTestCase()))))) {206 result.add(tccp);207 }208 }209 }210 return result;211 }212 }213 @Override214 public AnswerList findTestCaseCountryPropertiesByValue1(int testDataLibID, String name, String country, String propertyType) {215 return testCaseCountryPropertiesDAO.findTestCaseCountryPropertiesByValue1(testDataLibID, name, country, propertyType);216 }217 @Override218 public Answer createListTestCaseCountryPropertiesBatch(List<TestCaseCountryProperties> objectList) {219 dbmanager.beginTransaction();220 Answer answer = testCaseCountryPropertiesDAO.createTestCaseCountryPropertiesBatch(objectList);221 if (!answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {222 dbmanager.abortTransaction();223 } else {224 dbmanager.commitTransaction();225 }226 return answer;227 }228 @Override229 public Answer create(TestCaseCountryProperties object) {230 return testCaseCountryPropertiesDAO.create(object);231 }232 @Override233 public Answer delete(TestCaseCountryProperties object) {234 return testCaseCountryPropertiesDAO.delete(object);235 }236 @Override237 public Answer update(TestCaseCountryProperties object) {238 return testCaseCountryPropertiesDAO.update(object);239 }240 @Override241 public Answer createList(List<TestCaseCountryProperties> objectList) {242 Answer ans = new Answer(null);243 for (TestCaseCountryProperties objectToCreate : objectList) {244 ans = testCaseCountryPropertiesDAO.create(objectToCreate);245 }246 return ans;247 }248 @Override249 public Answer deleteList(List<TestCaseCountryProperties> objectList) {250 Answer ans = new Answer(null);251 for (TestCaseCountryProperties objectToDelete : objectList) {252 ans = testCaseCountryPropertiesDAO.delete(objectToDelete);253 }254 return ans;255 }256 @Override257 public Answer compareListAndUpdateInsertDeleteElements(String test, String testCase, List<TestCaseCountryProperties> newList) {258 Answer ans = new Answer(null);259 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);260 Answer finalAnswer = new Answer(msg1);261 List<TestCaseCountryProperties> oldList = new ArrayList();262// try {263 oldList = this.findListOfPropertyPerTestTestCase(test, testCase);264// } catch (CerberusException ex) {265// LOG.error(ex);266// }267 /**268 * Iterate on (Object From Page - Object From Database) If Object in269 * Database has same key : Update and remove from the list. If Object in270 * database does ot exist : Insert it.271 */272 List<TestCaseCountryProperties> listToUpdateOrInsert = new ArrayList(newList);273 listToUpdateOrInsert.removeAll(oldList);274 List<TestCaseCountryProperties> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);275 for (TestCaseCountryProperties objectDifference : listToUpdateOrInsertToIterate) {276 for (TestCaseCountryProperties objectInDatabase : oldList) {277 if (objectDifference.hasSameKey(objectInDatabase)) {...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!