How to use executeViaRest method of org.evomaster.client.java.controller.db.SqlScriptRunnerTest class

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

Source:SqlScriptRunnerTest.java Github

copy

Full Screen

...25 char[] buffer = new char[1000];26 Arrays.fill(buffer, '0');27 String value = "bar" + new String(buffer) + "foo";28 String sql = "INSERT INTO Foo (x) VALUES ('" + value + "')";29 executeViaRest(sql);30 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");31 assertEquals(1, res.seeRows().size());32 Object x = res.seeRows().get(0).getValueByName("x");33 assertTrue(x instanceof String);34 assertEquals(value, x);35 }36 @Test37 public void testSimpleRemoteExecution() throws Exception {38 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT);");39 int value = 42;40 String sql = "INSERT INTO Foo (x) VALUES (" + value + ")";41 executeViaRest(sql);42 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");43 assertEquals(1, res.seeRows().size());44 assertEquals(value, res.seeRows().get(0).getValueByName("x"));45 }46 @Test47 public void testInsertWhenIdentity() throws Exception {48 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +49 " id bigint generated by default as identity " +50 ", x integer " +51 ");"52 );53 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");54 assertEquals(0, res.seeRows().size());55 int value = 42;56 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (" + value + ")");57 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");58 assertEquals(1, res.seeRows().size());59 assertEquals(value, res.seeRows().get(0).getValueByName("x"));60 assertNotNull(res.seeRows().get(0).getValueByName("id"));61 }62 @Test63 public void testTwoInsertionsWhenIdentity() throws Exception {64 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +65 " id bigint generated by default as identity " +66 ", x integer " +67 ");"68 );69 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");70 assertEquals(0, res.seeRows().size());71 int a = 42;72 int b = 66;73 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (" + a + ")");74 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (" + b + ")");75 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");76 assertEquals(2, res.seeRows().size());77 assertTrue(res.seeRows().stream().anyMatch(r -> r.getValueByName("x").equals(a)));78 assertTrue(res.seeRows().stream().anyMatch(r -> r.getValueByName("x").equals(b)));79 assertEquals(2, res.seeRows().stream().map(r -> r.getValueByName("id")).distinct().count());80 }81 @Test82 public void testInsertWhenForeignKey() throws Exception {83 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +84 " id bigint generated by default as identity " +85 ", barId bigint not null " +86 ");" +87 " CREATE TABLE Bar(id bigint generated by default as identity);" +88 " ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"89 );90 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");91 assertEquals(0, res.seeRows().size());92 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Bar () VALUES ()");93 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");94 assertEquals(1, res.seeRows().size());95 long id = (Long) res.seeRows().get(0).getValueByName("id");96 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (barId) VALUES (" + id + ")");97 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");98 assertEquals(1, res.seeRows().size());99 assertThrows(Exception.class, () ->100 //wrong foreign key101 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (barId) VALUES (-20)"));102 }103 @Test104 public void testIdentityExtractGeneratedKey() throws Exception {105 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +106 " id bigint generated by default as identity " +107 ", barId bigint not null " +108 ", primary key (id) " +109 ");" +110 " CREATE TABLE Bar(" +111 " id bigint generated by default as identity " +112 ", x integer " +113 ", primary key (id));" +114 " ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"115 );116 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");117 assertEquals(0, res.seeRows().size());118 Long a = SqlScriptRunner.execInsert(getConnection(), "INSERT INTO Bar (id,x) VALUES (default,42);");119 Long b = SqlScriptRunner.execInsert(getConnection(), "INSERT INTO Bar (x) VALUES (66);");120 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");121 assertEquals(2, res.seeRows().size());122 assertNotNull(a);123 assertNotNull(b);124 assertNotEquals(a, b);125 SqlScriptRunner.execInsert(getConnection(), "INSERT INTO Foo (barId) VALUES (" + a + ")");126 SqlScriptRunner.execInsert(getConnection(), "INSERT INTO Foo (barId) VALUES (" + b + ")");127 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");128 assertEquals(2, res.seeRows().size());129 }130 @Test131 public void testInsertionListWithGeneratedKeys() throws Exception {132 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +133 " id bigint generated by default as identity " +134 ", barId bigint not null " +135 ", primary key (id) " +136 ");" +137 " CREATE TABLE Bar(" +138 " id bigint generated by default as identity " +139 ", x integer " +140 ", primary key (id));" +141 " ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"142 );143 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");144 assertEquals(0, res.seeRows().size());145 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");146 assertEquals(0, res.seeRows().size());147 List<InsertionDto> insertions = sql()148 .insertInto("Bar", 0L).d("id", "default").d("x", "42").and()149 .insertInto("Bar", 1L).d("id", "default").d("x", "66").and()150 .insertInto("Foo").r("barId", 0).and()151 .insertInto("Foo").r("barId", 1).dtos();152 SqlScriptRunner.execInsert(getConnection(), insertions);153 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");154 assertEquals(2, res.seeRows().size());155 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");156 assertEquals(2, res.seeRows().size());157 }158 @Test159 public void testTimeStamp() throws Exception {160 SqlScriptRunner.execCommand(getConnection(), "create table Foo (" +161 "id bigint generated by default as identity, " +162 "creation_time timestamp not null, " +163 "primary key (id))");164 String year = "2030";165 String timestamp = year + "-2-17T4:55:50.000Z";166 String sql = "INSERT INTO Foo (CREATION_TIME) VALUES ('" + timestamp + "')";167 SqlScriptRunner.execCommand(getConnection(), sql);168 executeViaRest(sql);169 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");170 assertEquals(2, res.seeRows().size());171 assertTrue(res.seeRows().get(0).getValueByName("creation_time").toString().contains(year));172 assertTrue(res.seeRows().get(1).getValueByName("creation_time").toString().contains(year));173 }174 @Test175 public void testVarchar() throws Exception {176 SqlScriptRunner.execCommand(getConnection(), "create table Foo (" +177 "id bigint generated by default as identity, " +178 "name varchar(255) not null, " +179 "primary key (id))");180 String name = "a name";181 String sql = "INSERT INTO Foo (NAME) VALUES ('" + name + "')";182 SqlScriptRunner.execCommand(getConnection(), sql);183 executeViaRest(sql);184 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");185 assertEquals(2, res.seeRows().size());186 assertEquals(name, res.seeRows().get(0).getValueByName("name"));187 assertEquals(name, res.seeRows().get(1).getValueByName("name"));188 }189 private void executeViaRest(String sql) {190 DatabaseCommandDto dto = new DatabaseCommandDto();191 dto.command = sql;192 InstrumentedSutStarter starter = getInstrumentedSutStarter();193 String url = start(starter);194 given().contentType(ContentType.JSON)195 .body(dto)196 .post(url + BASE_PATH + DATABASE_COMMAND)197 .then()198 .statusCode(200);199 }200 @Test201 public void testStringGeneWithApostrophe() throws Exception {202 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +203 " name VARCHAR(255) " +204 ");"205 );206 List<InsertionDto> insertions = sql()207 .insertInto("Foo", 0L).d("name", "\"'\"").dtos();208 SqlScriptRunner.execInsert(getConnection(), insertions);209 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");210 assertEquals(1, res.seeRows().size());211 }212 @Test213 public void testDoubleIndirectForeignKey() throws Exception {214 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Table1(" +215 " id bigserial not null, " +216 " primary key (id)" +217 ");"218 +219 "CREATE TABLE Table2(" +220 " id int8, " +221 " primary key (id)" +222 ");"223 +224 "CREATE TABLE Table3(" +225 " id int8, " +226 " primary key (id)" +227 ");"228 +229 "alter table Table2 " +230 " add constraint FKTable2 foreign key (id) references Table1;"231 +232 "alter table Table3 " +233 " add constraint FKTable3 foreign key (id) references Table2;"234 );235 List<InsertionDto> insertions = sql()236 .insertInto("Table1", 1000L)237 .and()238 .insertInto("Table2", 1001L).r("Id", 1000L)239 .and()240 .insertInto("Table3", 1002L).r("Id", 1001L).dtos();241 SqlScriptRunner.execInsert(getConnection(), insertions);242 }243 @Test244 public void testNullValue() throws Exception {245 SqlScriptRunner.execCommand(getConnection(), "create table Foo (" +246 "id bigint generated by default as identity, " +247 "creation_time timestamp not null, " +248 "email VARCHAR(255), "+249 "primary key (id))");250 String year = "2030";251 String timestamp = year + "-2-17T4:55:50.000Z";252 String sql = "INSERT INTO Foo (CREATION_TIME, EMAIL) VALUES ('" + timestamp + "', null)";253 SqlScriptRunner.execCommand(getConnection(), sql);254 executeViaRest(sql);255 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT ID,CREATION_TIME, EMAIL FROM Foo;");256 DataRowDto row = res.seeRows().get(0).toDto();257 assertEquals(row.columnData.size(), 3);258 assertEquals(row.columnData.get(2), "NULL");259 }260 @Test261 public void testMultipleInsertWithFk() throws Exception {262 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +263 " id bigint generated by default as identity " +264 ", barId bigint not null " +265 ", primary key (id) " +266 ");" +267 " CREATE TABLE Bar(" +268 " id bigint generated by default as identity " +...

Full Screen

Full Screen

executeViaRest

Using AI Code Generation

copy

Full Screen

1 SqlScriptRunnerTest sqlScriptRunnerTest = new SqlScriptRunnerTest();2 String[] args = new String[2];3 args[0] = "src/test/resources/sqlScripts/insertion.sql";4 args[1] = "src/test/resources/sqlScripts/insertion.sql";5 sqlScriptRunnerTest.executeViaRest(args);6 SqlScriptRunner sqlScriptRunner = new SqlScriptRunner();7 String[] args = new String[2];8 args[0] = "src/test/resources/sqlScripts/insertion.sql";9 args[1] = "src/test/resources/sqlScripts/insertion.sql";10 sqlScriptRunner.executeViaRest(args);11 SqlScriptRunner sqlScriptRunner = new SqlScriptRunner();12 String[] args = new String[2];13 args[0] = "src/test/resources/sqlScripts/insertion.sql";14 args[1] = "src/test/resources/sqlScripts/insertion.sql";15 sqlScriptRunner.executeViaRest(args);16 SqlScriptRunner sqlScriptRunner = new SqlScriptRunner();17 String[] args = new String[2];18 args[0] = "src/test/resources/sqlScripts/insertion.sql";19 args[1] = "src/test/resources/sqlScripts/insertion.sql";20 sqlScriptRunner.executeViaRest(args);21 SqlScriptRunner sqlScriptRunner = new SqlScriptRunner();22 String[] args = new String[2];23 args[0] = "src/test/resources/sqlScripts/insertion.sql";24 args[1] = "src/test/resources/sqlScripts/insertion.sql";25 sqlScriptRunner.executeViaRest(args);26 SqlScriptRunner sqlScriptRunner = new SqlScriptRunner();27 String[] args = new String[2];28 args[0] = "src/test/resources/sqlScripts/insertion.sql";

Full Screen

Full Screen

executeViaRest

Using AI Code Generation

copy

Full Screen

1public class SqlScriptRunnerTest_executeViaRest_0 extends BaseRestIndividual {2 public SqlScriptRunnerTest_executeViaRest_0(){3 super();4 basePath = "";5 basePath = "";6 }7 public boolean isToBeMinimized() {8 return false;9 }10 public String getName() {11 return "SqlScriptRunnerTest_executeViaRest_0";12 }13 public String getDescription() {14 return "Tests the generated example";15 }16 public void evaluateActions() throws Throwable {

Full Screen

Full Screen

executeViaRest

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.db;2import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;3import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;4import java.util.List;5public class SqlScriptRunnerTest {6 public static void main(String[] args) throws Exception {7 List<DatabaseCommandDto> commands = List.of(8 new SqlScriptDto("script1.sql"),9 new SqlScriptDto("script2.sql")10 );11 }12 public static void executeViaRest(String baseUrl, List<DatabaseCommandDto> commands) throws Exception {13 }14}15package org.evomaster.client.java.controller.db;16import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;17import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;18import java.util.List;19public class SqlScriptRunnerTest {20 public static void main(String[] args) throws Exception {21 List<DatabaseCommandDto> commands = List.of(22 new SqlScriptDto("script1.sql"),23 new SqlScriptDto("script2.sql")24 );25 }26 public static void executeViaRest(String baseUrl, List<DatabaseCommandDto> commands) throws Exception {27 }28}

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