How to use isEmpty method of org.evomaster.client.java.controller.db.QueryResult class

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

Source:SqlScriptRunnerTest.java Github

copy

Full Screen

...27 @Test28 public void testInsertEmpty() throws Exception{29 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT auto_increment);");30 QueryResult before = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo");31 assertTrue(before.isEmpty());32 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo() VALUES();");33 QueryResult after = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo");34 assertFalse(after.isEmpty());35 }36 @Test37 public void testLargeString() throws Exception{38 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x CLOB);");39 char[] buffer = new char[1000];40 Arrays.fill(buffer, '0');41 String value = "bar" + new String(buffer) + "foo";42 String sql = "INSERT INTO Foo (x) VALUES ('" + value + "')";43 executeViaRest(sql);44 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");45 assertEquals(1, res.seeRows().size());46 Object x = res.seeRows().get(0).getValueByName("x");47 assertTrue(x instanceof String);48 assertEquals(value, x);49 }50 @Test51 public void testSimpleRemoteExecution() throws Exception {52 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT);");53 int value = 42;54 String sql = "INSERT INTO Foo (x) VALUES (" + value + ")";55 executeViaRest(sql);56 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");57 assertEquals(1, res.seeRows().size());58 assertEquals(value, res.seeRows().get(0).getValueByName("x"));59 }60 @Test61 public void testInsertWhenIdentity() throws Exception {62 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +63 " id bigint generated by default as identity " +64 ", x integer " +65 ");"66 );67 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");68 assertEquals(0, res.seeRows().size());69 int value = 42;70 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (" + value + ")");71 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");72 assertEquals(1, res.seeRows().size());73 assertEquals(value, res.seeRows().get(0).getValueByName("x"));74 assertNotNull(res.seeRows().get(0).getValueByName("id"));75 }76 @Test77 public void testTwoInsertionsWhenIdentity() throws Exception {78 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +79 " id bigint generated by default as identity " +80 ", x integer " +81 ");"82 );83 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");84 assertEquals(0, res.seeRows().size());85 int a = 42;86 int b = 66;87 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (" + a + ")");88 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (" + b + ")");89 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");90 assertEquals(2, res.seeRows().size());91 assertTrue(res.seeRows().stream().anyMatch(r -> r.getValueByName("x").equals(a)));92 assertTrue(res.seeRows().stream().anyMatch(r -> r.getValueByName("x").equals(b)));93 assertEquals(2, res.seeRows().stream().map(r -> r.getValueByName("id")).distinct().count());94 }95 @Test96 public void testInsertWhenForeignKey() throws Exception {97 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +98 " id bigint generated by default as identity " +99 ", barId bigint not null " +100 ");" +101 " CREATE TABLE Bar(id bigint generated by default as identity primary key);" +102 " ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"103 );104 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");105 assertEquals(0, res.seeRows().size());106 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Bar () VALUES ()");107 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");108 assertEquals(1, res.seeRows().size());109 long id = (Long) res.seeRows().get(0).getValueByName("id");110 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (barId) VALUES (" + id + ")");111 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");112 assertEquals(1, res.seeRows().size());113 assertThrows(Exception.class, () ->114 //wrong foreign key115 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (barId) VALUES (-20)"));116 }117 @Test118 public void testIdentityExtractGeneratedKey() throws Exception {119 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +120 " id bigint generated by default as identity " +121 ", barId bigint not null " +122 ", primary key (id) " +123 ");" +124 " CREATE TABLE Bar(" +125 " id bigint generated by default as identity " +126 ", x integer " +127 ", primary key (id));" +128 " ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"129 );130 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");131 assertEquals(0, res.seeRows().size());132 Long a = SqlScriptRunner.execInsert(getConnection(), "INSERT INTO Bar (id,x) VALUES (default,42);");133 Long b = SqlScriptRunner.execInsert(getConnection(), "INSERT INTO Bar (x) VALUES (66);");134 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");135 assertEquals(2, res.seeRows().size());136 assertNotNull(a);137 assertNotNull(b);138 assertNotEquals(a, b);139 SqlScriptRunner.execInsert(getConnection(), "INSERT INTO Foo (barId) VALUES (" + a + ")");140 SqlScriptRunner.execInsert(getConnection(), "INSERT INTO Foo (barId) VALUES (" + b + ")");141 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");142 assertEquals(2, res.seeRows().size());143 }144 @Test145 public void testInsertionListWithGeneratedKeys() throws Exception {146 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +147 " id bigint generated by default as identity " +148 ", barId bigint not null " +149 ", primary key (id) " +150 ");" +151 " CREATE TABLE Bar(" +152 " id bigint generated by default as identity " +153 ", x integer " +154 ", primary key (id));" +155 " ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"156 );157 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");158 assertEquals(0, res.seeRows().size());159 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");160 assertEquals(0, res.seeRows().size());161 List<InsertionDto> insertions = sql()162 .insertInto("Bar", 0L).d("id", "default").d("x", "42").and()163 .insertInto("Bar", 1L).d("id", "default").d("x", "66").and()164 .insertInto("Foo").r("barId", 0).and()165 .insertInto("Foo").r("barId", 1).dtos();166 SqlScriptRunner.execInsert(getConnection(), insertions);167 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");168 assertEquals(2, res.seeRows().size());169 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");170 assertEquals(2, res.seeRows().size());171 }172 @Test173 public void testTimeStamp() throws Exception {174 SqlScriptRunner.execCommand(getConnection(), "create table Foo (" +175 "id bigint generated by default as identity, " +176 "creation_time timestamp not null, " +177 "primary key (id))");178 String year = "2030";179 String timestamp = year + "-2-17T4:55:50.000Z";180 String sql = "INSERT INTO Foo (CREATION_TIME) VALUES ('" + timestamp + "')";181 SqlScriptRunner.execCommand(getConnection(), sql);182 executeViaRest(sql);183 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");184 assertEquals(2, res.seeRows().size());185 assertTrue(res.seeRows().get(0).getValueByName("creation_time").toString().contains(year));186 assertTrue(res.seeRows().get(1).getValueByName("creation_time").toString().contains(year));187 }188 @Test189 public void testVarchar() throws Exception {190 SqlScriptRunner.execCommand(getConnection(), "create table Foo (" +191 "id bigint generated by default as identity, " +192 "name varchar(255) not null, " +193 "primary key (id))");194 String name = "a name";195 String sql = "INSERT INTO Foo (NAME) VALUES ('" + name + "')";196 SqlScriptRunner.execCommand(getConnection(), sql);197 executeViaRest(sql);198 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");199 assertEquals(2, res.seeRows().size());200 assertEquals(name, res.seeRows().get(0).getValueByName("name"));201 assertEquals(name, res.seeRows().get(1).getValueByName("name"));202 }203 private void executeViaRest(String sql) {204 DatabaseCommandDto dto = new DatabaseCommandDto();205 dto.command = sql;206 InstrumentedSutStarter starter = getInstrumentedSutStarter();207 String url = start(starter);208 given().contentType(ContentType.JSON)209 .body(dto)210 .post(url + BASE_PATH + DATABASE_COMMAND)211 .then()212 .statusCode(200);213 }214 @Test215 public void testStringGeneWithApostrophe() throws Exception {216 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +217 " name VARCHAR(255) " +218 ");"219 );220 List<InsertionDto> insertions = sql()221 .insertInto("Foo", 0L).d("name", "\"'\"").dtos();222 SqlScriptRunner.execInsert(getConnection(), insertions);223 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");224 assertEquals(1, res.seeRows().size());225 }226 @Test227 public void testDoubleIndirectForeignKey() throws Exception {228 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Table1(" +229 " id bigserial not null, " +230 " primary key (id)" +231 ");"232 +233 "CREATE TABLE Table2(" +234 " id int8, " +235 " primary key (id)" +236 ");"237 +238 "CREATE TABLE Table3(" +239 " id int8, " +240 " primary key (id)" +241 ");"242 +243 "alter table Table2 " +244 " add constraint FKTable2 foreign key (id) references Table1;"245 +246 "alter table Table3 " +247 " add constraint FKTable3 foreign key (id) references Table2;"248 );249 List<InsertionDto> insertions = sql()250 .insertInto("Table1", 1000L)251 .and()252 .insertInto("Table2", 1001L).r("Id", 1000L)253 .and()254 .insertInto("Table3", 1002L).r("Id", 1001L).dtos();255 SqlScriptRunner.execInsert(getConnection(), insertions);256 }257 @Test258 public void testNullValue() throws Exception {259 SqlScriptRunner.execCommand(getConnection(), "create table Foo (" +260 "id bigint generated by default as identity, " +261 "creation_time timestamp not null, " +262 "email VARCHAR(255), "+263 "primary key (id))");264 String year = "2030";265 String timestamp = year + "-2-17T4:55:50.000Z";266 String sql = "INSERT INTO Foo (CREATION_TIME, EMAIL) VALUES ('" + timestamp + "', null)";267 SqlScriptRunner.execCommand(getConnection(), sql);268 executeViaRest(sql);269 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT ID,CREATION_TIME, EMAIL FROM Foo;");270 DataRowDto row = res.seeRows().get(0).toDto();271 assertEquals(row.columnData.size(), 3);272 assertEquals(row.columnData.get(2), "NULL");273 }274 @Test275 public void testMultipleInsertWithFk() throws Exception {276 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +277 " id bigint generated by default as identity " +278 ", barId bigint not null " +279 ", primary key (id) " +280 ");" +281 " CREATE TABLE Bar(" +282 " id bigint generated by default as identity " +283 ", x integer " +284 ", primary key (id));" +285 " ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"286 );287 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");288 assertEquals(0, res.seeRows().size());289 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Foo;");290 assertEquals(0, res.seeRows().size());291 List<InsertionDto> insertion1 = sql()292 .insertInto("Bar", 100L).d("id", "default").d("x", "42").and()293 .insertInto("Bar", 101L).d("id", "default").d("x", "66").dtos();294 Map<Long, Long> map = SqlScriptRunner.execInsert(getConnection(), insertion1).idMapping;295 List<InsertionDto> insertion2 = sql()296 .insertInto("Foo").d("barId", map.get(100L).toString()).and()297 .insertInto("Foo").d("barId", map.get(101L).toString()).dtos();298 SqlScriptRunner.execInsert(getConnection(), insertion2);299 res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");300 assertEquals(2, res.seeRows().size());301 }302 @Test303 public void testDoubleAlias() throws Exception{304 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT)");305 String select = "select f.x as y from Foo f where x>0";306 QueryResult res = SqlScriptRunner.execCommand(getConnection(), select);307 assertTrue(res.isEmpty());308 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (42)");309 res = SqlScriptRunner.execCommand(getConnection(), select);310 assertTrue(!res.isEmpty());311 }312 @Test313 public void testBase() throws Exception {314 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT)");315 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "select * from Foo");316 assertTrue(res.isEmpty());317 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (4)");318 res = SqlScriptRunner.execCommand(getConnection(), "select * from Foo");319 assertFalse(res.isEmpty());320 }321 @Test322 public void testParentheses() throws Exception{323 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT)");324 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (5)");325 QueryResult res = SqlScriptRunner.execCommand(getConnection(), "select * from Foo where x = (5)");326 assertFalse(res.isEmpty());327 }328 @Test329 public void testConstants() throws Exception {330 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT)");331 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (4)");332 String select = "select x, 1 as y, null as z, 'bar' as w from Foo";333 QueryResult res = SqlScriptRunner.execCommand(getConnection(), select);334 assertFalse(res.isEmpty());335 DataRow row = res.seeRows().get(0);336 assertEquals(4, row.getValue(0));337 assertEquals(1, row.getValue(1));338 assertEquals(null, row.getValue(2));339 assertEquals("bar", row.getValue(3));340 }341 @Test342 public void testNested() throws Exception{343 String select = "select t.a, t.b from (select x as a, 1 as b from Foo where x<10) t where a>3";344 SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x INT)");345 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (1)");346 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (4)");347 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (7)");348 SqlScriptRunner.execCommand(getConnection(), "INSERT INTO Foo (x) VALUES (20)");...

Full Screen

Full Screen

isEmpty

Using AI Code Generation

copy

Full Screen

1insert into PERSON (id, name, surname) values (1, 'John', 'Smith');2insert into PERSON (id, name, surname) values (2, 'Jane', 'Doe');3insert into PERSON (id, name, surname) values (3, 'John', 'Doe');4select * from PERSON where name = 'John' and surname = 'Doe';5select * from PERSON where name = 'John' and surname = 'Smith';6select * from PERSON where name = 'Jane' and surname = 'Doe';7if (queryResult.isEmpty()) {8}9if (!queryResult.isEmpty()) {10}11if (queryResult.isEmpty()) {12}13if (!queryResult.isEmpty()) {14}15if (queryResult.isEmpty()) {16}17if (!queryResult.isEmpty()) {18}19if (queryResult.isEmpty()) {20}21if (!queryResult.isEmpty()) {22}23if (queryResult.isEmpty()) {24}25if (!queryResult.isEmpty()) {26}27if (queryResult.isEmpty()) {28}29if (!queryResult.isEmpty()) {30}31if (queryResult.isEmpty()) {32}33if (!queryResult.isEmpty()) {34}35if (queryResult.isEmpty()) {36}

Full Screen

Full Screen

isEmpty

Using AI Code Generation

copy

Full Screen

1public void test1() throws Exception {2 String sql = "SELECT * FROM table_name WHERE id=3";3 QueryResult result = new QueryResult(sql);4 result.next();5 boolean isEmpty = result.isEmpty();6 assertFalse(isEmpty);7}8public void test2() throws Exception {9 String sql = "SELECT * FROM table_name WHERE id=3";10 QueryResult result = new QueryResult(sql);11 boolean isEmpty = result.isEmpty();12 assertFalse(isEmpty);13}14public void test3() throws Exception {15 String sql = "SELECT * FROM table_name WHERE id=3";16 QueryResult result = new QueryResult(sql);17 result.next();18 boolean isEmpty = result.isEmpty();19 assertFalse(isEmpty);20}21public void test4() throws Exception {22 String sql = "SELECT * FROM table_name WHERE id=3";23 QueryResult result = new QueryResult(sql);24 result.next();25 result.next();26 boolean isEmpty = result.isEmpty();27 assertFalse(isEmpty);28}29public void test5() throws Exception {30 String sql = "SELECT * FROM table_name WHERE id=3";31 QueryResult result = new QueryResult(sql);32 result.next();33 boolean isEmpty = result.isEmpty();34 assertFalse(is

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