How to use getTableToClean method of org.evomaster.client.java.controller.internal.SutController class

Best EvoMaster code snippet using org.evomaster.client.java.controller.internal.SutController.getTableToClean

Source:SutController.java Github

copy

Full Screen

...284 // clean accessed tables285 Set<String> tableDataToInit = null;286 if (!accessedTables.isEmpty()){287 List<String> tablesToClean = new ArrayList<>();288 getTableToClean(accessedTables, tablesToClean);289 if (!tablesToClean.isEmpty()){290 if (emDbClean.schemaNames != null && !emDbClean.schemaNames.isEmpty()){291 emDbClean.schemaNames.forEach(sch-> DbCleaner.clearDatabase(getConnectionIfExist(), sch, null, tablesToClean, emDbClean.dbType));292 }else293 DbCleaner.clearDatabase(getConnectionIfExist(), null, null, tablesToClean, emDbClean.dbType);294 tableDataToInit = tablesToClean.stream().filter(a-> tableInitSqlMap.keySet().stream().anyMatch(t-> t.equalsIgnoreCase(a))).collect(Collectors.toSet());295 }296 }297 handleInitSql(tableDataToInit, emDbClean);298 }catch (SQLException e) {299 throw new RuntimeException("SQL Init Execution Error: fail to execute "+e);300 }finally {301 setExecutingInitSql(false);302 }303 }304 private void handleInitSql(Collection<String> tableDataToInit, DbSpecification spec) throws SQLException {305 // init db script306 boolean initAll = initSqlScriptAndGetInsertMap(getConnectionIfExist(), spec);307 if (!initAll && tableDataToInit!= null &&!tableDataToInit.isEmpty()){308 tableDataToInit.forEach(a->{309 tableInitSqlMap.keySet().stream().filter(t-> t.equalsIgnoreCase(a)).forEach(t->{310 tableInitSqlMap.get(t).forEach(c->{311 try {312 SqlScriptRunner.execCommand(getConnectionIfExist(), c);313 } catch (SQLException e) {314 throw new RuntimeException("SQL Init Execution Error: fail to execute "+ c + " with error "+e);315 }316 });317 });318 });319 }320 }321 /**322 * collect info about what table are manipulated by evo in order to generate data directly into it323 * @param tables a list of name of tables324 */325 public void addTableToInserted(List<String> tables){326 accessedTables.addAll(tables);327 }328 private void getTableToClean(List<String> accessedTables, List<String> tablesToClean){329 for (String t: accessedTables){330 if (!findInCollectionIgnoreCase(t, tablesToClean).isPresent()){331 if (findInMapIgnoreCase(t, fkMap).isPresent()){332 tablesToClean.add(t);333 List<String> fk = fkMap.entrySet().stream().filter(e->334 findInCollectionIgnoreCase(t, e.getValue()).isPresent()335 && !findInCollectionIgnoreCase(e.getKey(), tablesToClean).isPresent()).map(Map.Entry::getKey).collect(Collectors.toList());336 if (!fk.isEmpty())337 getTableToClean(fk, tablesToClean);338 }else {339 SimpleLogger.uniqueWarn("Cannot find the table "+t+" in ["+String.join(",", fkMap.keySet())+"]");340 }341 }342 }343 }344 private Optional<String> findInCollectionIgnoreCase(String name, Collection<String> list){345 return list.stream().filter(i-> i.equalsIgnoreCase(name)).findFirst();346 }347 private Optional<? extends Map.Entry<String, ?>> findInMapIgnoreCase(String name, Map<String, ?> list){348 return list.entrySet().stream().filter(x-> x.getKey().equalsIgnoreCase(name)).findFirst();349 }350 /**351 *...

Full Screen

Full Screen

getTableToClean

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.internal;2import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;3import org.evomaster.client.java.controller.api.dto.database.operations.DeleteTable;4import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;5import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;6import java.util.List;7public class SutController {8 private static SutController instance = null;9 private final DatabaseCommandDto dbCommands;10 private SutController(DatabaseCommandDto dbCommands) {11 this.dbCommands = dbCommands;12 }13 public static SutController getInstance() {14 if (instance == null) {15 throw new IllegalStateException("SutController not initialized");16 }17 return instance;18 }19 public static void init(DatabaseCommandDto dbCommands) {20 if (instance != null) {21 throw new IllegalStateException("SutController already initialized");22 }23 instance = new SutController(dbCommands);24 }25 public void resetStateOfSUT() {26 dbCommands.getInsertions().clear();27 dbCommands.getScripts().clear();28 }29 public void addInsertion(InsertionDto insertion) {30 dbCommands.getInsertions().add(insertion);31 }32 public void addScript(SqlScriptDto script) {33 dbCommands.getScripts().add(script);34 }35 public List<DeleteTable> getTableToClean() {36 return dbCommands.getTablesToClean();37 }38}39package org.evomaster.client.java.controller.internal;40import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;41import org.evomaster.client.java.controller.api.dto.database.operations.DeleteTable;42import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;43import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;44import java.util.List;45public class SutController {46 private static SutController instance = null;47 private final DatabaseCommandDto dbCommands;48 private SutController(DatabaseCommandDto dbCommands) {49 this.dbCommands = dbCommands;50 }51 public static SutController getInstance() {52 if (instance == null) {53 throw new IllegalStateException("SutController not initialized");54 }55 return instance;56 }57 public static void init(Database

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.

Run EvoMaster automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful