How to use Query method of org.cerberus.crud.dao.impl.TestCaseDAO class

Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.TestCaseDAO.Query

Source:TestCaseService.java Github

copy

Full Screen

1/**2 * Cerberus Copyright (C) 2013 - 2017 cerberustesting3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4 *5 * This file is part of Cerberus.6 *7 * Cerberus is free software: you can redistribute it and/or modify8 * it under the terms of the GNU General Public License as published by9 * the Free Software Foundation, either version 3 of the License, or10 * (at your option) any later version.11 *12 * Cerberus is distributed in the hope that it will be useful,13 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 * GNU General Public License for more details.16 *17 * You should have received a copy of the GNU General Public License18 * along with Cerberus. If not, see <http://www.gnu.org/licenses/>.19 */20package org.cerberus.crud.service.impl;21import java.util.ArrayList;22import java.util.Collections;23import java.util.Date;24import java.util.HashMap;25import java.util.HashSet;26import java.util.List;27import java.util.Map;28import java.util.Set;29import javax.servlet.http.HttpServletRequest;30import org.apache.logging.log4j.LogManager;31import org.apache.logging.log4j.Logger;32import org.cerberus.crud.dao.ITestCaseDAO;33import org.cerberus.crud.entity.CampaignLabel;34import org.cerberus.crud.entity.CampaignParameter;35import org.cerberus.crud.entity.Invariant;36import org.cerberus.crud.entity.Label;37import org.cerberus.crud.entity.TestCase;38import org.cerberus.crud.entity.TestCaseCountry;39import org.cerberus.crud.entity.TestCaseCountryProperties;40import org.cerberus.crud.entity.TestCaseDep;41import org.cerberus.crud.entity.TestCaseLabel;42import org.cerberus.crud.entity.TestCaseStep;43import org.cerberus.crud.entity.TestCaseStepAction;44import org.cerberus.crud.entity.TestCaseStepActionControl;45import org.cerberus.crud.factory.IFactoryTest;46import org.cerberus.crud.factory.IFactoryTestCase;47import org.cerberus.crud.service.ICampaignLabelService;48import org.cerberus.crud.service.ICampaignParameterService;49import org.cerberus.crud.service.IInvariantService;50import org.cerberus.crud.service.ILabelService;51import org.cerberus.crud.service.IParameterService;52import org.cerberus.crud.service.ITestCaseCountryPropertiesService;53import org.cerberus.crud.service.ITestCaseCountryService;54import org.cerberus.crud.service.ITestCaseDepService;55import org.cerberus.crud.service.ITestCaseLabelService;56import org.cerberus.crud.service.ITestCaseService;57import org.cerberus.crud.service.ITestCaseStepActionControlService;58import org.cerberus.crud.service.ITestCaseStepActionService;59import org.cerberus.crud.service.ITestCaseStepService;60import org.cerberus.crud.service.ITestService;61import org.cerberus.dto.TestCaseListDTO;62import org.cerberus.dto.TestListDTO;63import org.cerberus.engine.entity.MessageEvent;64import org.cerberus.engine.entity.MessageGeneral;65import org.cerberus.engine.execution.IExecutionCheckService;66import org.cerberus.enums.MessageEventEnum;67import org.cerberus.enums.MessageGeneralEnum;68import org.cerberus.exception.CerberusException;69import org.cerberus.util.answer.Answer;70import org.cerberus.util.answer.AnswerItem;71import org.cerberus.util.answer.AnswerList;72import org.json.JSONArray;73import org.springframework.beans.factory.annotation.Autowired;74import org.springframework.stereotype.Service;75/**76 * @author bcivel77 * @author tbernardes78 */79@Service80public class TestCaseService implements ITestCaseService {81 private static final Logger LOG = LogManager.getLogger(TestCaseService.class);82 @Autowired83 private ITestCaseDAO testCaseDao;84 @Autowired85 private ITestService testService;86 @Autowired87 private IFactoryTest factoryTest;88 @Autowired89 private ITestCaseCountryService testCaseCountryService;90 @Autowired91 private IInvariantService invariantService;92 @Autowired93 private ITestCaseCountryPropertiesService testCaseCountryPropertiesService;94 @Autowired95 private ITestCaseStepService testCaseStepService;96 @Autowired97 private ITestCaseStepActionService testCaseStepActionService;98 @Autowired99 private ITestCaseStepActionControlService testCaseStepActionControlService;100 @Autowired101 private IFactoryTestCase factoryTCase;102 @Autowired103 private ICampaignLabelService campaignLabelService;104 @Autowired105 private ILabelService labelService;106 @Autowired107 private ICampaignParameterService campaignParameterService;108 @Autowired109 private IParameterService parameterService;110 @Autowired111 private IExecutionCheckService executionCheckService;112 @Autowired113 private ITestCaseDepService testCaseDepService;114 @Autowired115 private ITestCaseLabelService testCaseLabelService;116 @Override117 public TestCase findTestCaseByKey(String test, String testCase) throws CerberusException {118 return testCaseDao.findTestCaseByKey(test, testCase);119 }120 @Override121 public TestCase findTestCaseByKeyWithDependency(String test, String testCase) throws CerberusException {122 TestCase newTcase;123 newTcase = findTestCaseByKey(test, testCase);124 if (newTcase == null) {125 //TODO:FN temporary debug messages126 LOG.warn("test case is null - test: " + test + " testcase: " + testCase);127 } else {128 List<TestCaseCountry> testCaseCountry = testCaseCountryService.findTestCaseCountryByTestTestCase(test, testCase);129 List<TestCaseCountry> testCaseCountryToAdd = new ArrayList<>();130 for (TestCaseCountry tcc : testCaseCountry) {131 List<TestCaseCountryProperties> properties = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCaseCountry(test, testCase, tcc.getCountry());132 tcc.setTestCaseCountryProperty(properties);133 testCaseCountryToAdd.add(tcc);134 }135 newTcase.setTestCaseCountries(testCaseCountryToAdd);136 String initialTest = test;137 String initialTc = testCase;138 List<TestCaseStep> tcs = testCaseStepService.getListOfSteps(test, testCase);139 List<TestCaseStep> tcsToAdd = new ArrayList<>();140 for (TestCaseStep step : tcs) {141 int stepNumber = step.getStep();142 int initialStep = step.getStep();143 if (step.getUseStep().equals("Y")) {144 test = step.getUseStepTest();145 testCase = step.getUseStepTestCase();146 stepNumber = step.getUseStepStep();147 }148 List<TestCaseStepAction> tcsa = testCaseStepActionService.getListOfAction(test, testCase, stepNumber);149 List<TestCaseStepAction> tcsaToAdd = new ArrayList<>();150 for (TestCaseStepAction action : tcsa) {151 List<TestCaseStepActionControl> tcsac = testCaseStepActionControlService.findControlByTestTestCaseStepSequence(test, testCase, stepNumber, action.getSequence());152 List<TestCaseStepActionControl> tcsacToAdd = new ArrayList<>();153 for (TestCaseStepActionControl control : tcsac) {154 control.setTest(initialTest);155 control.setTestCase(initialTc);156 control.setStep(initialStep);157 tcsacToAdd.add(control);158 }159 action.setControls(tcsacToAdd);160 action.setTest(initialTest);161 action.setTestCase(initialTc);162 action.setStep(initialStep);163 tcsaToAdd.add(action);164 }165 step.setActions(tcsaToAdd);166 tcsToAdd.add(step);167 }168 newTcase.setSteps(tcsToAdd);169 List<TestCaseDep> testCaseDependendies = testCaseDepService.readByTestAndTestCase(initialTest, initialTc);170 newTcase.setDependencies(testCaseDependendies);171 List<TestCaseLabel> testCaseLabel = testCaseLabelService.readByTestTestCase(initialTest, initialTc, null).getDataList();172 newTcase.setTestCaseLabels(testCaseLabel);173 }174 return newTcase;175 }176 @Override177 public AnswerItem<TestCase> findTestCaseByKeyWithDependencies(String test, String testCase, boolean withSteps) throws CerberusException {178 HashMap<String, TestCaseCountry> testCaseCountries;179 HashMap<String, Invariant> countryInvariants;180 AnswerItem<TestCase> answerTestCase = this.readByKey(test, testCase);181 if (answerTestCase.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerTestCase.getItem() != null) {182 testCaseCountries = testCaseCountryService.readByTestTestCaseToHashCountryAsKey(test, testCase);183 countryInvariants = invariantService.readByIdNameToHash("COUNTRY");184 answerTestCase.getItem().setInvariantCountries(invariantService.convertCountryPropertiesToCountryInvariants(testCaseCountries, countryInvariants));185 answerTestCase.getItem().setDependencies(testCaseDepService.readByTestAndTestCase(answerTestCase.getItem().getTest(), answerTestCase.getItem().getTestCase()));186 answerTestCase.getItem().setLabels(labelService.findLabelsFromTestCase(test, testCase, null).get(testCase));187 List<TestCase> testcases = new ArrayList<>();188 testcases.add(factoryTCase.create(test, testCase));189 answerTestCase.getItem().setTestCaseCountryProperties(testCaseCountryPropertiesService.findDistinctPropertiesOfTestCaseFromTestcaseList(testcases, countryInvariants));190 if (withSteps) {191 answerTestCase.getItem().setSteps(testCaseStepService.readByTestTestCaseStepsWithDependencies(test, testCase).getDataList());192 answerTestCase.getItem().setTestCaseInheritedProperties(testCaseCountryPropertiesService.findDistinctInheritedPropertiesOfTestCase(answerTestCase.getItem(), countryInvariants));193 }194 }195 return answerTestCase;196 }197 @Override198 public List<TestCase> findTestCaseByTest(String test) {199 return testCaseDao.findTestCaseByTest(test);200 }201 @Override202 public AnswerList<TestCase> findTestCasesByTestByCriteriaWithDependencies(List<String> system, String test, int startPosition, int length, String sortInformation, String searchParameter, Map<String, List<String>> individualSearch, boolean isCalledFromListPage) throws CerberusException {203 AnswerList<TestCase> testCases = this.readByTestByCriteria(system, test, startPosition, length, sortInformation, searchParameter, individualSearch);204 if (testCases.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && testCases.getDataList().size() > 0 && isCalledFromListPage) {//the service was able to perform the query, then we should get all values205 HashMap<String, Invariant> countryInvariants = invariantService.readByIdNameToHash("COUNTRY");206 List<TestCaseCountry> testCaseCountries = testCaseCountryService.readByTestTestCase(system, test, null, testCases.getDataList()).getDataList();207 HashMap<String, HashMap<String, TestCaseCountry>> testCaseCountryHash = testCaseCountryService.convertListToHashMapTestTestCaseAsKey(testCaseCountries);208 List<TestCaseDep> testCaseDependencies = testCaseDepService.readByTestAndTestCase(testCases.getDataList());209 HashMap<String, List<TestCaseDep>> testCaseDependenciesHash = testCaseDepService.convertTestCaseDepListToHash(testCaseDependencies);210 HashMap<String, List<Label>> labels = labelService.findLabelsFromTestCase(test, null, testCases.getDataList());211 for (TestCase testCase : testCases.getDataList()) {212 if (testCaseCountryHash.containsKey(testCase.getTest() + "_" + testCase.getTestCase())) {213 testCase.setInvariantCountries(invariantService.convertCountryPropertiesToCountryInvariants(testCaseCountryHash.get(testCase.getTest() + "_" + testCase.getTestCase()), countryInvariants));214 }215 if (labels.containsKey(testCase.getTestCase())) {216 testCase.setLabels(labels.get(testCase.getTestCase()));217 }218 if (testCaseDependenciesHash.containsKey(testCase.getTestCase())) {219 testCase.setDependencies(testCaseDependenciesHash.get(testCase.getTestCase()));220 }221 }222 }223 return testCases;224 }225 @Override226 public List<TestCase> findTestCaseByTestSystem(String test, String system) {227 return testCaseDao.findTestCaseByTestSystem(test, system);228 }229 @Override230 public List<TestCase> findTestCaseByApplication(final String application) {231 return testCaseDao.findTestCaseByApplication(application);232 }233 @Override234 public boolean updateTestCaseInformation(TestCase testCase) {235 return testCaseDao.updateTestCaseInformation(testCase);236 }237 @Override238 public boolean updateTestCaseInformationCountries(TestCase tc) {239 return testCaseDao.updateTestCaseInformationCountries(tc);240 }241 @Override242 public boolean createTestCase(TestCase testCase) throws CerberusException {243 return testCaseDao.createTestCase(testCase);244 }245 @Override246 public List<TestCase> getTestCaseForPrePostTesting(String test, String application, String country, String system, String build, String revision) {247 List<TestCase> tmpTests = testCaseDao.findTestCaseByCriteria(test, application, country, "Y");248 List<TestCase> resultTests = new ArrayList<>();249 for (TestCase tmpTest : tmpTests) {250 // We check here if build/revision is compatible.251 if (executionCheckService.checkRangeBuildRevision(tmpTest, build, revision, system)) {252 resultTests.add(tmpTest);253 }254 }255 return resultTests;256 }257 @Override258 public List<TestCase> findTestCaseByAllCriteria(TestCase tCase, String text, String system) {259 return this.testCaseDao.findTestCaseByCriteria(tCase, text, system);260 }261 @Override262 public AnswerList<TestCase> readByVarious(String[] test, String[] app, String[] creator, String[] implementer, String[] system,263 String[] campaign, List<Integer> labelid, String[] priority, String[] type, String[] status, int length) {264 return testCaseDao.readByVarious(test, app, creator, implementer, system, campaign, labelid, priority, type, status, length);265 }266 /**267 * @param column268 * @return269 * @since 0.9.1270 */271 @Override272 public List<String> findUniqueDataOfColumn(String column) {273 return this.testCaseDao.findUniqueDataOfColumn(column);274 }275 @Override276 public List<String> findTestWithTestCaseActiveAutomatedBySystem(String system) {277 TestCase tCase = factoryTCase.create(null, null, null, null, null, null, null, null,278 null, true, true, false, -1, null, null, null, null, true, null, null,279 null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);280 List<String> result = new ArrayList<>();281 List<TestCase> testCases = findTestCaseByAllCriteria(tCase, null, system);282 for (TestCase testCase : testCases) {283 if (!testCase.getType().equals("PRIVATE")) {284 result.add(testCase.getTest());285 }286 }287 Set<String> uniqueResult = new HashSet<>(result);288 result = new ArrayList<>();289 result.addAll(uniqueResult);290 Collections.sort(result);291 return result;292 }293 @Override294 public List<TestCase> findTestCaseActiveAutomatedBySystem(String test, String system) {295 TestCase tCase = factoryTCase.create(test, null, null, null, null, null, null, null,296 null, true, true, false, -1, null, null, null, null, true, null, null,297 null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);298 List<TestCase> result = new ArrayList<>();299 List<TestCase> testCases = findTestCaseByAllCriteria(tCase, null, system);300 for (TestCase testCase : testCases) {301 if (!testCase.getType().equals("PRIVATE")) {302 result.add(testCase);303 }304 }305 return result;306 }307 @Override308 public boolean deleteTestCase(TestCase testCase) {309 return testCaseDao.deleteTestCase(testCase);310 }311 @Override312 public String getMaxNumberTestCase(String test) {313 return this.testCaseDao.getMaxNumberTestCase(test);314 }315 @Override316 public AnswerList<TestCase> findTestCaseByCampaign(String campaign) {317 final AnswerItem<Map<String, List<String>>> parsedCampaignParameters = campaignParameterService.parseParametersByCampaign(campaign);318 List<String> countries = parsedCampaignParameters.getItem().get(CampaignParameter.COUNTRY_PARAMETER);319 AnswerList<TestCase> testCases = null;320 if (countries != null && !countries.isEmpty()) {321 testCases = this.findTestCaseByCampaignNameAndCountries(campaign, countries.toArray(new String[countries.size()]));322 } else {323 testCases = this.findTestCaseByCampaignNameAndCountries(campaign, null);324 }325 326 return testCases;327 }328 @Override329 public AnswerList<TestCase> findTestCaseByCampaignNameAndCountries(String campaign, String[] countries) {330 AnswerList<TestCase> result = new AnswerList<>();331 String[] status = null;332 String[] system = null;333 String[] application = null;334 String[] priority = null;335 String[] type = null;336 AnswerItem<Map<String, List<String>>> parameters = campaignParameterService.parseParametersByCampaign(campaign);337 for (Map.Entry<String, List<String>> entry : parameters.getItem().entrySet()) {338 String cle = entry.getKey();339 List<String> valeur = entry.getValue();340 switch (cle) {341 case CampaignParameter.PRIORITY_PARAMETER:342 priority = valeur.toArray(new String[valeur.size()]);343 break;344 case CampaignParameter.STATUS_PARAMETER:345 status = valeur.toArray(new String[valeur.size()]);346 break;347 case CampaignParameter.SYSTEM_PARAMETER:348 system = valeur.toArray(new String[valeur.size()]);349 break;350 case CampaignParameter.APPLICATION_PARAMETER:351 application = valeur.toArray(new String[valeur.size()]);352 break;353 case CampaignParameter.TESTCASE_TYPE_PARAMETER:354 type = valeur.toArray(new String[valeur.size()]);355 break;356 }357 }358 AnswerList<CampaignLabel> label = campaignLabelService.readByVarious(campaign);359 List<Integer> labelIdList = new ArrayList<>();360 List<CampaignLabel> labelList = label.getDataList();361 for (CampaignLabel campaignLabel : labelList) {362 labelIdList.add(campaignLabel.getLabelId());363 }364 labelIdList = labelService.enrichWithChild(labelIdList);365 Integer maxReturn = parameterService.getParameterIntegerByKey("cerberus_campaign_maxtestcase", "", 1000);366 result = testCaseDao.findTestCaseByCampaignNameAndCountries(campaign, countries, labelIdList, status, system, application, priority, type, maxReturn);367 return result;368 }369 @Override370 public List<TestCase> findUseTestCaseList(String test, String testCase) throws CerberusException {371 List<TestCase> result = new ArrayList<>();372 List<TestCaseStep> tcsList = testCaseStepService.getListOfSteps(test, testCase);373 for (TestCaseStep tcs : tcsList) {374 if (("Y").equals(tcs.getUseStep())) {375 /**376 * We prepend the TestCase in order to leave at the end of the377 * list the testcase with the higher prio (which correspond to378 * the 1st Use Step found) #1907. That way, if inside the same379 * testcase, you import 2 use Step that define a property that380 * has the same name, the 1st step imported will define the381 * property value.382 */383 result.add(0, this.findTestCaseByKey(tcs.getUseStepTest(), tcs.getUseStepTestCase()));384 }385 }386 return result;387 }388 @Override389 public List<TestCase> findByCriteria(String[] test, String[] app, String[] active, String[] priority, String[] status, String[] type, String[] targetMajor, String[] targetMinor, String[] creator, String[] implementer, String[] campaign, String[] battery) {390 return testCaseDao.findTestCaseByCriteria(test, app, active, priority, status, type, targetMajor, targetMinor, creator, implementer, campaign);391 }392 @Override393 public String findSystemOfTestCase(String test, String testcase) throws CerberusException {394 return testCaseDao.findSystemOfTestCase(test, testcase);395 }396 @Override397 public AnswerList<TestListDTO> findTestCasesThatUseTestDataLib(int testDataLibId, String name, String country) {398 return testCaseCountryPropertiesService.findTestCaseCountryPropertiesByValue1(testDataLibId, name, country, TestCaseCountryProperties.TYPE_GETFROMDATALIB);399 }400 public boolean containsTestCase(final List<TestCaseListDTO> list, final String number) {401 return list.stream().filter(o -> o.getTestCaseNumber().equals(number)).findFirst().isPresent();402 }403 @Override404 public AnswerList<TestListDTO> findTestCasesThatUseService(String service) {405 AnswerList<TestListDTO> testCaseByServiceByDataLib = testCaseDao.findTestCaseByServiceByDataLib(service);406 AnswerList<TestListDTO> testCaseByService = testCaseDao.findTestCaseByService(service);407 List<TestListDTO> listOfTestCaseByDataLib = testCaseByServiceByDataLib.getDataList();408 List<TestListDTO> listOfTestCaseByService = testCaseByService.getDataList();409 List<TestListDTO> newTestCase = new ArrayList<>();410 if (!listOfTestCaseByDataLib.isEmpty()) {411 for (TestListDTO datalibList : listOfTestCaseByDataLib) {412 for (TestListDTO serviceList : listOfTestCaseByService) {413 if (datalibList.getTest().equals(serviceList.getTest())) {414 List<TestCaseListDTO> testCaseDataLibList = datalibList.getTestCaseList();415 for (TestCaseListDTO testCaseService : serviceList.getTestCaseList()) {416 if (!containsTestCase(testCaseDataLibList, testCaseService.getTestCaseNumber())) {417 testCaseDataLibList.add(testCaseService);418 }419 }420 } else {421 newTestCase.add(serviceList);422 }423 }424 }425 listOfTestCaseByDataLib.addAll(newTestCase);426 testCaseByServiceByDataLib.setDataList(listOfTestCaseByDataLib);427 return testCaseByServiceByDataLib;428 } else {429 return testCaseByService;430 }431 }432 @Override433 public AnswerList readTestCaseByStepsInLibrary(String test) {434 return testCaseDao.readTestCaseByStepsInLibrary(test);435 }436 @Override437 public AnswerList<TestCase> readByTestByCriteria(List<String> system, String test, int start, int amount, String sortInformation, String searchTerm, Map<String, List<String>> individualSearch) {438 return testCaseDao.readByTestByCriteria(system, test, start, amount, sortInformation, searchTerm, individualSearch);439 }440 @Override441 public AnswerItem<TestCase> readByKey(String test, String testCase) {442 return testCaseDao.readByKey(test, testCase);443 }444 @Override445 public AnswerItem<TestCase> readByKeyWithDependency(String test, String testCase) {446 AnswerItem<TestCase> answer = new AnswerItem<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));447 AnswerItem<TestCase> ai = testCaseDao.readByKey(test, testCase);448 if (ai.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && ai.getItem() != null) {449 TestCase tc = (TestCase) ai.getItem();450 AnswerList<TestCaseStep> al = testCaseStepService.readByTestTestCaseStepsWithDependencies(tc.getTest(), tc.getTestCase());451 if (al.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && al.getDataList() != null) {452 tc.setSteps(al.getDataList());453 }454 answer.setResultMessage(al.getResultMessage());455 answer.setItem(tc);456 }457 return answer;458 }459 @Override460 public AnswerList<String> readDistinctValuesByCriteria(List<String> system, String test, String searchParameter, Map<String, List<String>> individualSearch, String columnName) {461 return testCaseDao.readDistinctValuesByCriteria(system, test, searchParameter, individualSearch, columnName);462 }463 @Override464 public AnswerList<TestCase> readStatsBySystem(List<String> system, Date to) {465 return testCaseDao.readStatsBySystem(system, to);466 }467 @Override468 public Answer update(String keyTest, String keyTestCase, TestCase testCase) {469 // We first create the corresponding test if it doesn,'t exist.470 if (testCase.getTest() != null) {471 if (!testService.exist(testCase.getTest())) {472 testService.create(factoryTest.create(testCase.getTest(), "", "Y", null, testCase.getUsrModif(), null, "", null));473 }474 }475 return testCaseDao.update(keyTest, keyTestCase, testCase);476 }477 @Override478 public Answer create(TestCase testCase) {479 // We first create the corresponding test if it doesn,'t exist.480 if (testCase.getTest() != null) {481 if (!testService.exist(testCase.getTest())) {482 testService.create(factoryTest.create(testCase.getTest(), "", "Y", null, testCase.getUsrCreated(), null, "", null));483 }484 }485 return testCaseDao.create(testCase);486 }487 @Override488 public Answer delete(TestCase testCase) {489 return testCaseDao.delete(testCase);490 }491 @Override492 public TestCase convert(AnswerItem<TestCase> answerItem) throws CerberusException {493 if (answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {494 //if the service returns an OK message then we can get the item495 return (TestCase) answerItem.getItem();496 }497 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));498 }499 @Override500 public List<TestCase> convert(AnswerList<TestCase> answerList) throws CerberusException {501 if (answerList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {502 //if the service returns an OK message then we can get the item503 return (List<TestCase>) answerList.getDataList();504 }505 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));506 }507 @Override508 public void convert(Answer answer) throws CerberusException {509 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {510 //if the service returns an OK message then we can get the item511 return;512 }513 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));514 }515 @Override516 public boolean hasPermissionsRead(TestCase testCase, HttpServletRequest request) {517 // Access right calculation.518 return true;519 }520 @Override521 public boolean hasPermissionsUpdate(TestCase testCase, HttpServletRequest request) {522 // Access right calculation.523 if (testCase.getStatus().equalsIgnoreCase("WORKING")) { // If testcase is WORKING only TestAdmin can update it524 return request.isUserInRole("TestAdmin");525 } else {526 return request.isUserInRole("Test");527 }528 }529 @Override530 public boolean hasPermissionsCreate(TestCase testCase, HttpServletRequest request) {531 // Access right calculation.532 return request.isUserInRole("Test");533 }534 @Override535 public boolean hasPermissionsDelete(TestCase testCase, HttpServletRequest request) {536 // Access right calculation.537 return request.isUserInRole("TestAdmin");538 }539 @Override540 public void importWithDependency(TestCase testCase) throws CerberusException {541 //TODO ------------------------542 //Check Cerberus version compatibility. If not stop543 //-------------------------------544 //insert testcase545 Answer testCaseImported = this.create(testCase);546 if (!testCaseImported.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {547 MessageGeneral msg = new MessageGeneral(MessageGeneralEnum.GENERIC_ERROR);548 msg.setDescription(testCaseImported.getResultMessage().getDescription());549 throw new CerberusException(msg);550 }551 //for tcstep, insert steps552 for (TestCaseStep tcs : testCase.getSteps()) {553 Answer testCaseStepImported = testCaseStepService.create(tcs);554 if (!testCaseStepImported.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {555 throw new CerberusException(new MessageGeneral(testCaseStepImported.getResultMessage().getMessage()));556 }557 for (TestCaseStepAction tcsa : tcs.getActions()) {558 Answer testCaseStepActionImported = testCaseStepActionService.create(tcsa);559 if (!testCaseStepActionImported.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {560 throw new CerberusException(new MessageGeneral(testCaseStepActionImported.getResultMessage().getMessage()));561 }562 for (TestCaseStepActionControl tcsac : tcsa.getControls()) {563 Answer testCaseStepActionControlImported = testCaseStepActionControlService.create(tcsac);564 if (!testCaseStepActionControlImported.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {565 throw new CerberusException(new MessageGeneral(testCaseStepActionControlImported.getResultMessage().getMessage()));566 }567 }568 }569 }570 //insert tccountry, insert countries571 for (TestCaseCountry tcc : testCase.getTestCaseCountries()) {572 Answer testCaseCountryImported = testCaseCountryService.create(tcc);573 if (!testCaseCountryImported.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {574 throw new CerberusException(new MessageGeneral(testCaseCountryImported.getResultMessage().getMessage()));575 }576 for (TestCaseCountryProperties tccp : tcc.getTestCaseCountryProperty()) {577 Answer testCaseCountryPropertiesImported = testCaseCountryPropertiesService.create(tccp);578 if (!testCaseCountryPropertiesImported.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {579 throw new CerberusException(new MessageGeneral(testCaseCountryPropertiesImported.getResultMessage().getMessage()));580 }581 }582 }583 //insert testcasedependencies584 for (TestCaseDep tcd : testCase.getDependencies()) {585 testCaseDepService.create(tcd);586 }587 //insert testcaselabel588 for (TestCaseLabel tcl : testCase.getTestCaseLabels()) {589 testCaseLabelService.create(tcl);590 }591 }592}...

Full Screen

Full Screen

Query

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.dao.impl;2import java.sql.Connection;3import java.sql.PreparedStatement;4import java.sql.ResultSet;5import java.sql.SQLException;6import java.util.ArrayList;7import java.util.List;8import org.apache.logging.log4j.LogManager;9import org.apache.logging.log4j.Logger;10import org.cerberus.crud.dao.ITestCaseDAO;11import org.cerberus.crud.entity.TestCase;12import org.cerberus.crud.factory.IFactoryTestCase;13import org.cerberus.database.DatabaseSpring;14import org.cerberus.exception.CerberusException;15import org.cerberus.crud.factory.impl.FactoryTestCase;16import org.springframework.beans.factory.annotation.Autowired;17import org.springframework.stereotype.Repository;18public class TestCaseDAO implements ITestCaseDAO {19 private DatabaseSpring databaseSpring;20 private IFactoryTestCase factoryTestCase;21 private static final Logger LOG = LogManager.getLogger(TestCaseDAO.class);22 private final String OBJECT_NAME = "TestCase";23 private final int MAX_ROW_SELECTED = 10000;24 private final String SQL_DUPLICATED_KEY = "23000";25 private final int MYSQL_DUPLICATED_KEY = 1062;26 public List<TestCase> findAll() throws CerberusException {27 boolean throwEx = false;

Full Screen

Full Screen

Query

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.dao.ITestCaseDAO;2import org.cerberus.crud.entity.TestCase;3import org.springframework.beans.factory.annotation.Autowired;4import org.springframework.stereotype.Controller;5import org.springframework.web.bind.annotation.RequestMapping;6import org.springframework.web.bind.annotation.RequestMethod;7import org.springframework.web.servlet.ModelAndView;8import java.util.List;9public class TestCaseController {10 ITestCaseDAO testCaseDAO;11 @RequestMapping(value = "/testCase", method = RequestMethod.GET)12 public ModelAndView getTestCase() {13 ModelAndView model = new ModelAndView("testCase");14 List<TestCase> testCaseList = testCaseDAO.findAll();15 model.addObject("testCaseList", testCaseList);16 return model;17 }18}19MariaDB [cerberus]> select * from testcase;

Full Screen

Full Screen

Query

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCase;2import org.cerberus.crud.dao.ITestCaseDAO;3import org.springframework.context.ApplicationContext;4import org.springframework.context.support.ClassPathXmlApplicationContext;5import java.util.List;6import java.util.logging.Level;7import java.util.logging.Logger;8Logger logger = Logger.getLogger("org.cerberus");9ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/config/BeanLocations.xml");10ITestCaseDAO testCaseDAO = (ITestCaseDAO) context.getBean("TestCaseDAO");11List<TestCase> testCases = testCaseDAO.findAll();12for (TestCase testCase : testCases) {13 logger.log(Level.INFO, "TestCase: {0}", testCase.toString());14}15logger.log(Level.INFO, "Number of test cases: {0}", testCases.size());16logger.log(Level.INFO, "First test case: {0}", testCases.get(0).toString());17logger.log(Level.INFO, "Last test case: {0}", testCases.get(testCases.size() - 1).toString());18logger.log(Level.INFO, "TC0001 test case: {0}", testCaseDAO.findTestCaseByKey("TC0001").toString());19logger.log(Level.INFO, "TC0002 test case: {0}", testCaseDAO.findTestCaseByKey("TC0002").toString());20logger.log(Level.INFO, "TC0003 test case: {0}", testCaseDAO.findTestCaseByKey("TC0003").toString());

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful