Best Cerberus-source code snippet using org.cerberus.crud.service.impl.TestCaseDepService.readByTestAndTestcase
Source:TestCaseDepService.java
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 org.cerberus.crud.dao.ITestCaseDepDAO;22import org.cerberus.crud.entity.TestCase;23import org.cerberus.crud.entity.TestCaseDep;24import org.cerberus.crud.service.ITestCaseDepService;25import org.cerberus.exception.CerberusException;26import org.springframework.beans.factory.annotation.Autowired;27import org.springframework.stereotype.Service;28import java.util.ArrayList;29import java.util.List;30import java.util.stream.Collectors;31@Service32public class TestCaseDepService implements ITestCaseDepService {33 @Autowired34 private ITestCaseDepDAO testCaseDepDao;35 @Override36 public TestCaseDep readByKey(String test, String testcase, String testDep, String testcaseDep) throws CerberusException {37 return testCaseDepDao.readByKey(test,testcase,testDep,testcaseDep);38 }39 @Override40 public List<TestCaseDep> readByTestAndTestCase(String test, String testcase) throws CerberusException {41 return testCaseDepDao.readByTestAndTestCase(test, testcase);42 }43 @Override44 public List<TestCaseDep> readByTestAndTestCase(List<TestCase> testCaseList) throws CerberusException {45 return testCaseDepDao.readByTestAndTestCase(testCaseList);46 }47 @Override48 public void create(TestCaseDep testCaseDep) throws CerberusException {49 testCaseDepDao.create(testCaseDep);50 }51 @Override52 public void update(TestCaseDep testCaseDep) throws CerberusException {53 testCaseDepDao.update(testCaseDep);54 }55 @Override56 public void delete(TestCaseDep testCaseDep) throws CerberusException {57 testCaseDepDao.delete(testCaseDep);58 }59 @Override60 public void createList(List<TestCaseDep> testCaseDepList) throws CerberusException {61 for(TestCaseDep tc : testCaseDepList) this.create(tc);62 }63 @Override64 public void updateList(List<TestCaseDep> testCaseDepList) throws CerberusException{65 for(TestCaseDep tc : testCaseDepList) this.update(tc);66 }67 @Override68 public void deleteList(List<TestCaseDep> testCaseDepList) throws CerberusException {69 for(TestCaseDep tc : testCaseDepList) this.delete(tc);70 }71 @Override72 public void compareListAndUpdateInsertDeleteElements(String test, String testCase, List<TestCaseDep> newList) throws CerberusException {73 List<TestCaseDep> oldList = testCaseDepDao.readByTestAndTestCase(test, testCase);74 // toUpdate = all in newList and in oldList75 List<TestCaseDep> toUpdate = this.getObjectWithSameKey(newList, oldList);76 this.updateList(toUpdate);77 // toInsert = all in newList not in oldList78 List<TestCaseDep> toInsert = new ArrayList<>(newList);79 toInsert.removeIf( tcd1 -> oldList.stream().anyMatch( tcd2 -> tcd2.hasSameKey(tcd1) )); // remove if it is the same key80 this.createList(toInsert);81 // toDelete = all in oldList and in newList82 List<TestCaseDep> toDelete = new ArrayList<>(oldList);83 toDelete.removeIf( tcd1 -> newList.stream().anyMatch( tcd2 -> tcd2.hasSameKey(tcd1) )); // remove if it is the same key84 this.deleteList(toDelete);85 }86 private List<TestCaseDep> getObjectWithSameKey(List<TestCaseDep> lst1, List<TestCaseDep> lst2) {87 return lst1.stream()88 .filter( ( tcd1 ) -> lst2.stream().anyMatch( ( tcd2 ) -> tcd2.hasSameKey(tcd1)))89 .collect(Collectors.toList());90 }91}...
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!!