How to use SqlScriptRunnerCached class of org.evomaster.client.java.controller.db package

Best EvoMaster code snippet using org.evomaster.client.java.controller.db.SqlScriptRunnerCached

Source:ExternalEvoMasterController.java Github

copy

Full Screen

...5import org.evomaster.client.java.controller.AuthUtils;6import org.evomaster.client.java.controller.ExternalSutController;7import org.evomaster.client.java.controller.InstrumentedSutStarter;8import org.evomaster.client.java.controller.db.DbCleaner;9import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;10import org.evomaster.client.java.controller.problem.ProblemInfo;11import org.evomaster.client.java.controller.problem.RestProblem;12import org.evomaster.client.java.controller.api.dto.AuthenticationDto;13import org.evomaster.client.java.controller.api.dto.SutInfoDto;14import org.h2.tools.Server;15import org.testcontainers.containers.GenericContainer;16import java.sql.Connection;17import java.sql.DriverManager;18import java.sql.SQLException;19import java.util.Arrays;20import java.util.List;21public class ExternalEvoMasterController extends ExternalSutController {22 public static void main(String[] args) {23 int controllerPort = 40100;24 if (args.length > 0) {25 controllerPort = Integer.parseInt(args[0]);26 }27 int sutPort = 12345;28 if (args.length > 1) {29 sutPort = Integer.parseInt(args[1]);30 }31 String jarLocation = "cs/rest-gui/ocvn/web/target";32 if (args.length > 2) {33 jarLocation = args[2];34 }35 if(! jarLocation.endsWith(".jar")) {36 jarLocation += "/ocvn-rest-sut.jar";37 }38 int timeoutSeconds = 120;39 if(args.length > 3){40 timeoutSeconds = Integer.parseInt(args[3]);41 }42 ExternalEvoMasterController controller =43 new ExternalEvoMasterController(controllerPort, jarLocation, sutPort, timeoutSeconds);44 InstrumentedSutStarter starter = new InstrumentedSutStarter(controller);45 starter.start();46 }47 private final int timeoutSeconds;48 private final int sutPort;49 private final int dbPort;50 private final String jarLocation;51 private Connection connection;52 private Server h2;53 private MongoClient mongoClient;54 private static final GenericContainer mongodb = new GenericContainer("mongo:3.2")55 .withExposedPorts(27017);56 public ExternalEvoMasterController() {57 this(40100, "../web/target/web-1.1.1-SNAPSHOT-exec.jar", 12345, 120);58 }59 public ExternalEvoMasterController(int controllerPort, String jarLocation, int sutPort, int timeoutSeconds) {60 this.sutPort = sutPort;61 this.jarLocation = jarLocation;62 this.timeoutSeconds = timeoutSeconds;63 setControllerPort(controllerPort);64 this.dbPort = sutPort + 2;65 }66 @Override67 public String[] getInputParameters() {68 return new String[]{"--server.port=" + sutPort};69 }70 private String dbUrl(boolean withP6Spy) {71 String url = "jdbc";72 if (withP6Spy) {73 url += ":p6spy";74 }75 url += ":h2:tcp://localhost:" + dbPort + "/./temp/tmp_ocvn/testdb_" + dbPort;76 return url;77 }78 @Override79 public String[] getJVMParameters() {80 return new String[]{81 "-Dliquibase.enabled=false",82 "-Dspring.data.mongodb.uri=mongodb://"+mongodb.getContainerIpAddress()+":"+mongodb.getMappedPort(27017)+"/ocvn",83 "-Dspring.datasource.driver-class-name=" + P6SpyDriver.class.getName(),84 "-Dspring.datasource.url=" + dbUrl(true) + ";DB_CLOSE_DELAY=-1",85 "-Dspring.jpa.database-platform=org.hibernate.dialect.H2Dialect",86 "-Dspring.jpa.properties.hibernate.enable_lazy_load_no_trans=true",87 "-Dspring.datasource.username=sa",88 "-Dspring.datasource.password",89 "-Ddg-toolkit.derby.port=0",90 "-Dspring.cache.type=NONE"91 };92 }93 @Override94 public String getBaseURL() {95 return "http://localhost:" + sutPort;96 }97 @Override98 public String getPathToExecutableJar() {99 return jarLocation;100 }101 @Override102 public String getLogMessageOfInitializedServer() {103 return "Started WebApplication in ";104 }105 @Override106 public long getMaxAwaitForInitializationInSeconds() {107 return timeoutSeconds;108 }109 @Override110 public void preStart() {111 mongodb.start();112 try {113 mongoClient = new MongoClient(mongodb.getContainerIpAddress(),114 mongodb.getMappedPort(27017));115 } catch (Exception e) {116 System.out.println("ERROR: " + e.getMessage());117 throw new RuntimeException(e);118 }119 try {120 //starting H2121 h2 = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "" + dbPort);122 h2.start();123 } catch (SQLException e) {124 throw new RuntimeException(e);125 }126 }127 private void closeDataBaseConnection() {128 if (connection != null) {129 try {130 connection.close();131 } catch (SQLException e) {132 e.printStackTrace();133 }134 connection = null;135 }136 }137 @Override138 public void postStart() {139 closeDataBaseConnection();140 try {141 Class.forName("org.h2.Driver");142 connection = DriverManager.getConnection(dbUrl(false), "sa", "");143 } catch (Exception e) {144 throw new RuntimeException(e);145 }146 }147 @Override148 public void preStop() {149 closeDataBaseConnection();150 }151 @Override152 public void postStop() {153 mongodb.stop();154 if (h2 != null) {155 h2.stop();156 }157 }158 @Override159 public String getPackagePrefixesToCover() {160 return "org.devgateway.";161 }162 public void resetStateOfSUT() {163 mongoClient.getDatabase("ocvn").drop();164 mongoClient.getDatabase("ocvn-shadow").drop();165 DbCleaner.clearDatabase_H2(connection);166 SqlScriptRunnerCached.runScriptFromResourceFile(connection,"/init_db.sql");167 }168 @Override169 public ProblemInfo getProblemInfo() {170 return new RestProblem(171 getBaseURL() + "/v2/api-docs?group=1ocDashboardsApi",172 null173 );174 }175 @Override176 public SutInfoDto.OutputFormat getPreferredOutputFormat() {177 return SutInfoDto.OutputFormat.JAVA_JUNIT_4;178 }179 @Override180 public List<AuthenticationDto> getInfoForAuthentication() {...

Full Screen

Full Screen

Source:EmbeddedEvoMasterController.java Github

copy

Full Screen

...5import org.evomaster.client.java.controller.AuthUtils;6import org.evomaster.client.java.controller.EmbeddedSutController;7import org.evomaster.client.java.controller.InstrumentedSutStarter;8import org.evomaster.client.java.controller.db.DbCleaner;9import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;10import org.evomaster.client.java.controller.problem.ProblemInfo;11import org.evomaster.client.java.controller.problem.RestProblem;12import org.evomaster.client.java.controller.api.dto.AuthenticationDto;13import org.evomaster.client.java.controller.api.dto.SutInfoDto;14import org.springframework.boot.SpringApplication;15import org.springframework.context.ConfigurableApplicationContext;16import org.springframework.jdbc.core.JdbcTemplate;17import org.testcontainers.containers.GenericContainer;18import java.sql.Connection;19import java.sql.SQLException;20import java.util.Arrays;21import java.util.List;22import java.util.Map;23/**24 * Class used to start/stop the SUT. This will be controller by the EvoMaster process25 */26public class EmbeddedEvoMasterController extends EmbeddedSutController {27 public static void main(String[] args) {28 int port = 40100;29 if (args.length > 0) {30 port = Integer.parseInt(args[0]);31 }32 EmbeddedEvoMasterController controller = new EmbeddedEvoMasterController(port);33 InstrumentedSutStarter starter = new InstrumentedSutStarter(controller);34 starter.start();35 }36 private ConfigurableApplicationContext ctx;37 private Connection connection;38 private MongoClient mongoClient;39 private static final GenericContainer mongodb = new GenericContainer("mongo:3.2")40 .withExposedPorts(27017);41 public EmbeddedEvoMasterController() {42 this(0);43 }44 public EmbeddedEvoMasterController(int port) {45 setControllerPort(port);46 }47 @Override48 public String startSut() {49 mongodb.start();50 mongoClient = new MongoClient(mongodb.getContainerIpAddress(),51 mongodb.getMappedPort(27017));52 ctx = SpringApplication.run(WebApplication.class,53 new String[]{"--server.port=0",54 "--liquibase.enabled=false",55 "--spring.data.mongodb.uri=mongodb://"+mongodb.getContainerIpAddress()+":"+mongodb.getMappedPort(27017)+"/ocvn",56 "--spring.datasource.url=jdbc:p6spy:h2:mem:testdb;DB_CLOSE_DELAY=-1;",57 "--spring.datasource.driver-class-name=" + P6SpyDriver.class.getName(),58 "--spring.jpa.database-platform=org.hibernate.dialect.H2Dialect",59 "--spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true",60 "--spring.datasource.username=sa",61 "--spring.datasource.password",62 "--dg-toolkit.derby.port=0",63 "--spring.cache.type=NONE"64 });65 if (connection != null) {66 try {67 connection.close();68 } catch (SQLException e) {69 e.printStackTrace();70 }71 }72 JdbcTemplate jdbc = ctx.getBean(JdbcTemplate.class);73 try {74 connection = jdbc.getDataSource().getConnection();75 } catch (SQLException e) {76 e.printStackTrace();77 }78 return "http://localhost:" + getSutPort();79 }80 protected int getSutPort() {81 return (Integer) ((Map) ctx.getEnvironment()82 .getPropertySources().get("server.ports").getSource())83 .get("local.server.port");84 }85 @Override86 public boolean isSutRunning() {87 return ctx != null && ctx.isRunning();88 }89 @Override90 public void stopSut() {91 ctx.stop();92 ctx.close();93 mongodb.stop();94 }95 @Override96 public String getPackagePrefixesToCover() {97 return "org.devgateway.";98 }99 @Override100 public void resetStateOfSUT() {101 mongoClient.getDatabase("ocvn").drop();102 mongoClient.getDatabase("ocvn-shadow").drop();103 DbCleaner.clearDatabase_H2(connection);104 SqlScriptRunnerCached.runScriptFromResourceFile(connection,"/init_db.sql");105 }106 @Override107 public List<AuthenticationDto> getInfoForAuthentication() {108 return Arrays.asList(AuthUtils.getForDefaultSpringFormLogin("ADMIN", "admin", "admin"));109 }110 @Override111 public Connection getConnection() {112 return connection;113 }114 @Override115 public String getDatabaseDriverName() {116 return "org.h2.Driver";117 }118 @Override...

Full Screen

Full Screen

SqlScriptRunnerCached

Using AI Code Generation

copy

Full Screen

1package com.example;2import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;3import org.evomaster.client.java.controller.db.SqlScriptRunnerInterface;4import org.evomaster.client.java.controller.db.SqlScriptRunnerNoCache;5import org.evomaster.client.java.controller.db.SqlScriptRunnerWithCache;6import org.junit.jupiter.api.AfterAll;7import org.junit.jupiter.api.BeforeAll;8import org.junit.jupiter.api.Test;9import java.sql.Connection;10import java.sql.DriverManager;11import java.sql.SQLException;12import static org.junit.jupiter.api.Assertions.assertEquals;13public class SqlScriptRunnerTest {14 private static Connection connection;15 private static SqlScriptRunnerInterface sqlScriptRunner = new SqlScriptRunnerCached();16 public static void init() throws SQLException {17 connection = DriverManager.getConnection("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "");18 }19 public static void tearDown() throws SQLException {20 connection.close();21 }22 public void testSqlScriptRunner() throws SQLException {23 sqlScriptRunner.runInitScript(connection, "sql/init.sql");24 sqlScriptRunner.runCleanScript(connection, "sql/clean.sql");25 }26}27package com.example;28import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;29import org.evomaster.client.java.controller.db.SqlScriptRunnerInterface;30import org.evomaster.client.java.controller.db.SqlScriptRunnerNoCache;31import org.evomaster.client.java.controller.db.SqlScriptRunnerWithCache;32import org.junit.jupiter.api.AfterAll;33import org.junit.jupiter.api.BeforeAll;34import org.junit.jupiter.api.Test;35import java.sql.Connection;36import java.sql.DriverManager;37import java.sql.SQLException;38import static org.junit.jupiter.api.Assertions.assertEquals;39public class SqlScriptRunnerTest {40 private static Connection connection;41 private static SqlScriptRunnerInterface sqlScriptRunner = new SqlScriptRunnerWithCache();42 public static void init() throws SQLException {43 connection = DriverManager.getConnection("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "");44 }45 public static void tearDown() throws SQLException {46 connection.close();47 }

Full Screen

Full Screen

SqlScriptRunnerCached

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.db;2import java.io.File;3import java.io.IOException;4import java.nio.file.Files;5import java.nio.file.Paths;6import java.sql.Connection;7import java.sql.DriverManager;8import java.sql.SQLException;9import java.util.stream.Stream;10public class SqlScriptRunnerCachedExample {11 public static void main(String args[]) throws IOException, SQLException {12 String path = "/Users/andrea/Downloads/sql_script.sql";13 String dbPath = "/Users/andrea/Downloads/test.db";14 File file = new File(dbPath);15 if (file.exists()) {16 file.delete();17 }18 Connection connection = DriverManager.getConnection("jdbc:sqlite:" + dbPath);19 Stream<String> stream = Files.lines(Paths.get(path));20 SqlScriptRunnerCached runner = new SqlScriptRunnerCached(connection);21 runner.runScript(stream);22 connection.close();23 }24}25package org.evomaster.client.java.controller.db;26import java.io.File;27import java.io.IOException;28import java.nio.file.Files;29import java.nio.file.Paths;30import java.sql.Connection;31import java.sql.DriverManager;32import java.sql.SQLException;33import java.util.stream.Stream;34public class SqlScriptRunnerExample {35 public static void main(String args[]) throws IOException, SQLException {36 String path = "/Users/andrea/Downloads/sql_script.sql";37 String dbPath = "/Users/andrea/Downloads/test.db";38 File file = new File(dbPath);39 if (file.exists()) {40 file.delete();41 }42 Connection connection = DriverManager.getConnection("jdbc:sqlite:" + dbPath);43 Stream<String> stream = Files.lines(Paths.get(path));44 SqlScriptRunner runner = new SqlScriptRunner(connection);45 runner.runScript(stream);46 connection.close();47 }48}49package org.evomaster.client.java.controller.db;50import java.io.File;51import java.io.IOException

Full Screen

Full Screen

SqlScriptRunnerCached

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;2public class 3 {3 public static void main(String[] args) {4 runner.runSql("CREATE TABLE IF NOT EXISTS public.employees (id integer NOT NULL, name character varying(255) NOT NULL, PRIMARY KEY (id));");5 runner.runSql("INSERT INTO public.employees (id, name) VALUES (1, 'John');");6 runner.runSql("INSERT INTO public.employees (id, name) VALUES (2, 'Mary');");7 runner.runSql("INSERT INTO public.employees (id, name) VALUES (3, 'Susan');");8 runner.runSql("INSERT INTO public.employees (id, name) VALUES (4, 'Mark');");9 runner.runSql("INSERT INTO public.employees (id, name) VALUES (5, 'Paul');");10 runner.runSql("INSERT INTO public.employees (id, name) VALUES (6, 'Peter');");11 runner.runSql("INSERT INTO public.employees (id, name) VALUES (7, 'George');");12 runner.runSql("INSERT INTO public.employees (id, name) VALUES (8, 'Bill');");13 runner.runSql("INSERT INTO public.employees (id, name) VALUES (9, 'Jane');");14 runner.runSql("INSERT INTO public.employees (id, name) VALUES (10, 'Jill');");15 runner.runSql("INSERT INTO public.employees (id, name) VALUES (11, 'Jack');");16 runner.runSql("INSERT INTO public.employees (id, name) VALUES (12, 'Joe');");17 runner.runSql("INSERT INTO public.employees (id, name) VALUES (13, 'Tom');");18 runner.runSql("INSERT INTO public.employees (id, name) VALUES (14, 'Bob');");19 runner.runSql("INSERT INTO public.employees (id, name) VALUES (15, 'Steve');");20 runner.runSql("INSERT INTO public.employees (id, name) VALUES (16, 'Mike');");21 runner.runSql("INSERT INTO public.employees (id, name) VALUES (17, 'Chris');");

Full Screen

Full Screen

SqlScriptRunnerCached

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;2public class 3 {3 public static void main(String[] args) throws Exception {4 String path = "C:\\Users\\User\\Desktop\\sql\\test.sql";5 runner.runScript(path);6 }7}8import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;9public class 4 {10 public static void main(String[] args) throws Exception {11 String path = "C:\\Users\\User\\Desktop\\sql\\test.sql";12 runner.runScript(path);13 }14}15import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;16public class 5 {17 public static void main(String[] args) throws Exception {18 String path = "C:\\Users\\User\\Desktop\\sql\\test.sql";19 runner.runScript(path);20 }21}22import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;23public class 6 {24 public static void main(String[] args) throws Exception {25 String path = "C:\\Users\\User\\Desktop\\sql\\test.sql";26 runner.runScript(path);27 }28}

Full Screen

Full Screen

SqlScriptRunnerCached

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.db;2import java.io.IOException;3import java.sql.Connection;4import java.sql.SQLException;5public class SqlScriptRunnerCachedTest {6 public static void main(String[] args) throws IOException, SQLException {7 Connection connection = null;8 String path = "src/test/resources/sql/test.sql";9 SqlScriptRunnerCached.runSqlScript(path, connection);10 }11}12package org.evomaster.client.java.controller.db;13import java.io.IOException;14import java.sql.Connection;15import java.sql.SQLException;16public class SqlScriptRunnerTest {17 public static void main(String[] args) throws IOException, SQLException {18 Connection connection = null;19 String path = "src/test/resources/sql/test.sql";20 SqlScriptRunner.runSqlScript(path, connection);21 }22}23package org.evomaster.client.java.controller.db;24import java.io.IOException;25import java.sql.Connection;26import java.sql.SQLException;27public class SqlScriptRunnerTest {28 public static void main(String[] args) throws IOException, SQLException {29 Connection connection = null;

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful