How to use execCommand method of org.evomaster.client.java.controller.db.SqlScriptRunner class

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

Source:HeuristicsCalculatorInDBTest.java Github

copy

Full Screen

...13import static org.junit.jupiter.api.Assertions.*;14public class HeuristicsCalculatorInDBTest extends DatabaseTestTemplate {15 @Test16 public void testHeuristic() throws Exception {17 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT)");18 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (10)");19 InstrumentedSutStarter starter = getInstrumentedSutStarter();20 try {21 String url = start(starter);22 url += BASE_PATH;23 startNewTest(url);24 given().accept(ContentType.JSON)25 .get(url + TEST_RESULTS)26 .then()27 .statusCode(200)28 .body("data.extraHeuristics.size()", is(1))29 .body("data.extraHeuristics[0].heuristics.size()", is(0));30 startNewTest(url);31 SqlScriptRunner.execCommand(getConnection(), "SELECT x FROM Foo WHERE x = 12");32 SqlScriptRunner.execCommand(getConnection(), "SELECT x FROM Foo WHERE x = 10");33 given().accept(ContentType.JSON)34 .get(url + TEST_RESULTS)35 .then()36 .statusCode(200)37 .body("data.extraHeuristics.size()", is(1))38 .body("data.extraHeuristics[0].heuristics.size()", is(2))39 .body("data.extraHeuristics[0].heuristics[0].value", greaterThan(0f))40 .body("data.extraHeuristics[0].heuristics[1].value", is(0f));41 startNewActionInSameTest(url, 1);42 SqlScriptRunner.execCommand(getConnection(), "SELECT x FROM Foo WHERE x = 13");43 given().accept(ContentType.JSON)44 .get(url + TEST_RESULTS)45 .then()46 .statusCode(200)47 .body("data.extraHeuristics.size()", is(2))48 .body("data.extraHeuristics[0].heuristics.size()", is(2))49 .body("data.extraHeuristics[0].heuristics[0].value", greaterThan(0f))50 .body("data.extraHeuristics[0].heuristics[1].value", is(0f))51 .body("data.extraHeuristics[1].heuristics.size()", is(1))52 .body("data.extraHeuristics[1].heuristics[0].value", greaterThan(0f));53 } finally {54 starter.stop();55 }56 }57 @Test58 public void testMultiline() throws Exception {59 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT, y INT)");60 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x, y) VALUES (0, 0)");61 int y = 42;62 String select = "select f.x \n from Foo f \n where f.y=" + y;63 InstrumentedSutStarter starter = getInstrumentedSutStarter();64 try {65 String url = start(starter);66 url += BASE_PATH;67 startNewTest(url);68 SqlScriptRunner.execCommand(getConnection(), select);69 double a = getFirstAndStartNew(url);70 assertTrue(a > 0d);71 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x, y) VALUES (1, " + y + ")");72 SqlScriptRunner.execCommand(getConnection(), select);73 double b = getFirstAndStartNew(url);74 assertTrue(b < a);75 assertEquals(0d, b, 0.0001);76 } finally {77 starter.stop();78 }79 }80 @Test81 public void testVarNotInSelect() throws Exception {82 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT, y INT)");83 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x, y) VALUES (0, 0)");84 int y = 42;85 String select = "select f.x from Foo f where f.y=" + y;86 InstrumentedSutStarter starter = getInstrumentedSutStarter();87 try {88 String url = start(starter);89 url += BASE_PATH;90 startNewTest(url);91 SqlScriptRunner.execCommand(getConnection(), select);92 double a = getFirstAndStartNew(url);93 assertTrue(a > 0d);94 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x, y) VALUES (1, " + y + ")");95 SqlScriptRunner.execCommand(getConnection(), select);96 double b = getFirstAndStartNew(url);97 assertTrue(b < a);98 assertEquals(0d, b, 0.0001);99 } finally {100 starter.stop();101 }102 }103 @Test104 public void testInnerJoin() throws Exception {105 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Bar(id INT Primary Key, value INT)");106 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(id INT Primary Key, value INT, bar_id INT, " +107 "CONSTRAINT fk FOREIGN KEY (bar_id) REFERENCES Bar(id) )");108 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Bar (id, value) VALUES (0, 0)");109 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (id, value, bar_id) VALUES (0, 0, 0)");110 int x = 10;111 int y = 20;112 String select = "select f.id, f.value, f.bar_id from Foo f inner join Bar b on f.bar_id=b.id " +113 "where f.value=" + x + " and b.value=" + y + " limit 1";114 InstrumentedSutStarter starter = getInstrumentedSutStarter();115 try {116 String url = start(starter);117 url += BASE_PATH;118 startNewTest(url);119 SqlScriptRunner.execCommand(getConnection(), select);120 double a = getFirstAndStartNew(url);121 assertTrue(a > 0d);122 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (id, value, bar_id) VALUES (1, " + x + ", 0)");123 SqlScriptRunner.execCommand(getConnection(), select);124 double b = getFirstAndStartNew(url);125 assertTrue(b < a);126 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Bar (id, value) VALUES (1, " + y + ")");127 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (id, value, bar_id) VALUES (2, 0, 1)");128 SqlScriptRunner.execCommand(getConnection(), select);129 double c = getFirstAndStartNew(url);130 assertTrue(c < b);131 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Bar (id, value) VALUES (2, " + y + ")");132 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (id, value, bar_id) VALUES (3, " + x + ", 2)");133 SqlScriptRunner.execCommand(getConnection(), select);134 double d = getFirstAndStartNew(url);135 assertTrue(d < c);136 assertEquals(0d, d, 0.0001);137 } finally {138 starter.stop();139 }140 }141 private Double getFirstAndStartNew(String url) {142 double value = Double.parseDouble(given().accept(ContentType.JSON)143 .get(url + TEST_RESULTS)144 .then()145 .statusCode(200)146 .extract().body().path("data.extraHeuristics[0].heuristics[0].value").toString());147 startNewTest(url);...

Full Screen

Full Screen

Source:InitSqlScriptWithSmartDbCleanTest.java Github

copy

Full Screen

...15 return String.join("\n", Arrays.asList("INSERT INTO Bar (id, value) VALUES (0, 0);", "INSERT INTO Foo (id, value, bar_id) VALUES (0, 0, 0);"));16 }17 @Test18 public default void testAccessedFkClean() throws Exception {19 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Bar(id INT Primary Key, value INT)", true);20 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(id INT Primary Key, value INT, bar_id INT, " +21 "CONSTRAINT fk FOREIGN KEY (bar_id) REFERENCES Bar(id) )", true);22 InstrumentedSutStarter starter = getInstrumentedSutStarter();23 try {24 String url = start(starter);25 url += BASE_PATH;26 given().accept(ContentType.JSON)27 .get(url + INFO_SUT_PATH)28 .then()29 .statusCode(200);30 // db is empty31 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;", true);32 assertEquals(0, res.seeRows().size());33 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;", true);34 assertEquals(0, res.seeRows().size());35 startNewTest(url);36 // db with init data37 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;", true);38 assertEquals(1, res.seeRows().size());39 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;", true);40 assertEquals(1, res.seeRows().size());41 given().accept(ContentType.JSON)42 .get(url + TEST_RESULTS)43 .then()44 .statusCode(200);45 startNewTest(url);46 // db with init data47 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;", true);48 assertEquals(1, res.seeRows().size());49 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;", true);50 assertEquals(1, res.seeRows().size());51 // table is accessed with INSERT52 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Bar (id, value) VALUES (1, 1);", true);53 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;", true);54 assertEquals(1, res.seeRows().size());55 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;", true);56 assertEquals(2, res.seeRows().size());57 given().accept(ContentType.JSON)58 .get(url + TEST_RESULTS)59 .then()60 .statusCode(200);61 startNewTest(url);62 // db only contains init data63 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;", true);64 assertEquals(1, res.seeRows().size());65 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;", true);66 assertEquals(1, res.seeRows().size());67 } finally {68 starter.stop();69 }70 }71}...

Full Screen

Full Screen

Source:DatabaseTestTemplate.java Github

copy

Full Screen

...28 @BeforeEach29 public void initTest() throws Exception {30 /*31 Not supported in H232 SqlScriptRunner.execCommand(connection, "DROP DATABASE db_test;");33 SqlScriptRunner.execCommand(connection, "CREATE DATABASE db_test;");34 */35 //custom H2 command36 SqlScriptRunner.execCommand(connection, "DROP ALL OBJECTS;");37 }38 protected Connection getConnection(){39 return connection;40 }41 protected String start(InstrumentedSutStarter starter) {42 boolean started = starter.start();43 assertTrue(started);44 int port = starter.getControllerServerPort();45 startSut(port);46 return "http://localhost:" + port;47 }48 protected void startSut(int port) {49 given().contentType(ContentType.JSON)50 .body(new SutRunDto(true, false, true))...

Full Screen

Full Screen

execCommand

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.db;2import java.io.File;3import java.io.IOException;4import java.sql.SQLException;5public class SqlScriptRunnerExample {6 public static void main(String[] args) throws IOException, SQLException {7 SqlScriptRunner sqlScriptRunner = new SqlScriptRunner();8 String sqlScriptPath = "/home/evomaster/3.sql";9 File sqlScript = new File(sqlScriptPath);10 sqlScriptRunner.execCommand(sqlScript);11 }12}13CREATE DATABASE IF NOT EXISTS test;14USE test;15CREATE TABLE IF NOT EXISTS test_table(16 name VARCHAR(50) NOT NULL,17 PRIMARY KEY (id)18);19package org.evomaster.client.java.controller.db;20import java.io.File;21import java.io.IOException;22import java.sql.SQLException;23public class SqlScriptRunnerExample {24 public static void main(String[] args) throws IOException, SQLException {25 SqlScriptRunner sqlScriptRunner = new SqlScriptRunner();26 String sqlScriptPath = "/home/evomaster/4.sql";27 File sqlScript = new File(sqlScriptPath);28 sqlScriptRunner.execCommand(sqlScript);29 }30}31USE test;32INSERT INTO test_table (name) VALUES ("foo");33INSERT INTO test_table (name) VALUES ("bar");34INSERT INTO test_table (name) VALUES ("baz");35package org.evomaster.client.java.controller.db;36import java.io.File;37import java.io.IOException;38import java.sql.SQLException;39public class SqlScriptRunnerExample {40 public static void main(String[] args) throws IOException, SQLException {41 SqlScriptRunner sqlScriptRunner = new SqlScriptRunner();42 String sqlScriptPath = "/home/evomaster/5.sql";43 File sqlScript = new File(sqlScriptPath);44 sqlScriptRunner.execCommand(sqlScript);45 }46}

Full Screen

Full Screen

execCommand

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.db.SqlScriptRunner;2public class 3 {3 public static void main(String[] args) throws Exception {4 String sqlScript = "CREATE TABLE IF NOT EXISTS test_table (id int, name varchar(255));";5 SqlScriptRunner.execCommand(sqlScript);6 }7}

Full Screen

Full Screen

execCommand

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.db.SqlScriptRunner;2public class 3 {3 public static void main(String[] args) {4 try {5 String command = "ls -l";6 String result = SqlScriptRunner.execCommand(command);7 System.out.println(result);8 } catch (Exception e) {9 e.printStackTrace();10 }11 }12}13import org.evomaster.client.java.controller.db.SqlScriptRunner;14public class 4 {15 public static void main(String[] args) {16 try {17 String command = "ls -l /home";18 String result = SqlScriptRunner.execCommand(command);19 System.out.println(result);20 } catch (Exception e) {21 e.printStackTrace();22 }23 }24}

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