How to use testSQLStatement method of com.consol.citrus.actions.ExecuteSQLQueryActionTest class

Best Citrus code snippet using com.consol.citrus.actions.ExecuteSQLQueryActionTest.testSQLStatement

Source:ExecuteSQLQueryActionTest.java Github

copy

Full Screen

...46 executeSQLQueryAction.setJdbcTemplate(jdbcTemplate);47 }48 49 @Test50 public void testSQLStatement() {51 String sql = DB_STMT_1;52 reset(jdbcTemplate);53 54 Map<String, Object> resultMap = new HashMap<String, Object>();55 resultMap.put("ORDERTYPE", "small");56 resultMap.put("STATUS", "in_progress");57 58 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));59 60 List<String> stmts = Collections.singletonList(sql);61 executeSQLQueryAction.setStatements(stmts);62 63 executeSQLQueryAction.execute(context);64 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));65 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");66 Assert.assertNotNull(context.getVariable("${STATUS}"));67 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");68 }69 @Test70 public void testSQLStatementWithTransaction() {71 String sql = DB_STMT_1;72 reset(jdbcTemplate, transactionManager);73 Map<String, Object> resultMap = new HashMap<String, Object>();74 resultMap.put("ORDERTYPE", "small");75 resultMap.put("STATUS", "in_progress");76 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));77 List<String> stmts = Collections.singletonList(sql);78 executeSQLQueryAction.setStatements(stmts);79 executeSQLQueryAction.setTransactionManager(transactionManager);80 executeSQLQueryAction.execute(context);81 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));82 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");83 Assert.assertNotNull(context.getVariable("${STATUS}"));84 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");85 }86 @Test87 public void testSQLStatementLowerCaseColumnNames() {88 String sql = DB_STMT_1;89 reset(jdbcTemplate);90 Map<String, Object> resultMap = new HashMap<String, Object>();91 resultMap.put("ordertype", "small");92 resultMap.put("status", "in_progress");93 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));94 List<String> stmts = Collections.singletonList(sql);95 executeSQLQueryAction.setStatements(stmts);96 executeSQLQueryAction.execute(context);97 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));98 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");99 Assert.assertNotNull(context.getVariable("${STATUS}"));100 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");101 }102 103 @Test104 public void testSQLMultipleStatements() {105 String sql1 = DB_STMT_1;106 String sql2 = DB_STMT_2;107 reset(jdbcTemplate);108 109 Map<String, Object> resultMap1 = new HashMap<String, Object>();110 resultMap1.put("ORDERTYPE", "small");111 resultMap1.put("STATUS", "in_progress");112 113 when(jdbcTemplate.queryForList(sql1)).thenReturn(Collections.singletonList(resultMap1));114 Map<String, Object> resultMap2 = new HashMap<String, Object>();115 resultMap2.put("NAME", "Mickey Mouse");116 resultMap2.put("HEIGHT", "0,3");117 118 when(jdbcTemplate.queryForList(sql2)).thenReturn(Collections.singletonList(resultMap2));119 List<String> stmts = new ArrayList<String>();120 stmts.add(sql1);121 stmts.add(sql2);122 123 executeSQLQueryAction.setStatements(stmts);124 125 executeSQLQueryAction.execute(context);126 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));127 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");128 Assert.assertNotNull(context.getVariable("${STATUS}"));129 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");130 Assert.assertNotNull(context.getVariable("${NAME}"));131 Assert.assertEquals(context.getVariable("${NAME}"), "Mickey Mouse");132 Assert.assertNotNull(context.getVariable("${HEIGHT}"));133 Assert.assertEquals(context.getVariable("${HEIGHT}"), "0,3");134 }135 136 @Test137 public void testSQLResource() {138 String sql1 = "SELECT ORDERTYPE, STATUS FROM orders WHERE ID=5";139 String sql2 = "SELECT NAME, HEIGHT FROM customers WHERE ID=1";140 reset(jdbcTemplate);141 142 Map<String, Object> resultMap1 = new HashMap<String, Object>();143 resultMap1.put("ORDERTYPE", "small");144 resultMap1.put("STATUS", "in_progress");145 146 when(jdbcTemplate.queryForList(sql1)).thenReturn(Collections.singletonList(resultMap1));147 148 Map<String, Object> resultMap2 = new HashMap<String, Object>();149 resultMap2.put("NAME", "Mickey Mouse");150 resultMap2.put("HEIGHT", "0,3");151 152 when(jdbcTemplate.queryForList(sql2)).thenReturn(Collections.singletonList(resultMap2));153 executeSQLQueryAction.setSqlResourcePath("classpath:com/consol/citrus/actions/test-query.sql");154 155 executeSQLQueryAction.execute(context);156 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));157 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");158 Assert.assertNotNull(context.getVariable("${STATUS}"));159 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");160 Assert.assertNotNull(context.getVariable("${NAME}"));161 Assert.assertEquals(context.getVariable("${NAME}"), "Mickey Mouse");162 Assert.assertNotNull(context.getVariable("${HEIGHT}"));163 Assert.assertEquals(context.getVariable("${HEIGHT}"), "0,3");164 }165 166 @Test167 public void testNullValue() {168 String sql = DB_STMT_1;169 reset(jdbcTemplate);170 171 Map<String, Object> resultMap = new HashMap<String, Object>();172 resultMap.put("ORDERTYPE", "small");173 resultMap.put("STATUS", null);174 175 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));176 List<String> stmts = Collections.singletonList(sql);177 executeSQLQueryAction.setStatements(stmts);178 179 executeSQLQueryAction.execute(context);180 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));181 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");182 Assert.assertNotNull(context.getVariable("${STATUS}"));183 Assert.assertEquals(context.getVariable("${STATUS}"), "NULL");184 }185 186 @Test187 public void testVariableSupport() {188 context.setVariable("orderId", "5");189 190 String sql = "select ORDERTYPE, STATUS from orders where ID=${orderId}";191 reset(jdbcTemplate);192 193 Map<String, Object> resultMap = new HashMap<String, Object>();194 resultMap.put("ORDERTYPE", "small");195 resultMap.put("STATUS", "in_progress");196 197 when(jdbcTemplate.queryForList(DB_STMT_1)).thenReturn(Collections.singletonList(resultMap));198 List<String> stmts = Collections.singletonList(sql);199 executeSQLQueryAction.setStatements(stmts);200 201 executeSQLQueryAction.execute(context);202 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));203 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");204 Assert.assertNotNull(context.getVariable("${STATUS}"));205 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");206 }207 208 @Test209 public void testExtractToVariables() {210 String sql = DB_STMT_1;211 reset(jdbcTemplate);212 213 Map<String, Object> resultMap = new HashMap<String, Object>();214 resultMap.put("ORDERTYPE", "small");215 resultMap.put("STATUS", "in_progress");216 217 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));218 List<String> stmts = Collections.singletonList(sql);219 executeSQLQueryAction.setStatements(stmts);220 221 Map<String, String> extractVariables = new HashMap<String, String>();222 extractVariables.put("STATUS", "orderStatus");223 executeSQLQueryAction.setExtractVariables(extractVariables);224 225 executeSQLQueryAction.execute(context);226 Assert.assertNotNull(context.getVariable("${orderStatus}"));227 Assert.assertEquals(context.getVariable("${orderStatus}"), "in_progress");228 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));229 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");230 Assert.assertNotNull(context.getVariable("${STATUS}"));231 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");232 }233 @Test234 public void testExtractToVariablesLowerCaseColumnNames() {235 String sql = DB_STMT_1;236 reset(jdbcTemplate);237 Map<String, Object> resultMap = new HashMap<String, Object>();238 resultMap.put("ordertype", "small");239 resultMap.put("status", "in_progress");240 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));241 List<String> stmts = Collections.singletonList(sql);242 executeSQLQueryAction.setStatements(stmts);243 Map<String, String> extractVariables = new HashMap<String, String>();244 extractVariables.put("ordertype", "orderType");245 extractVariables.put("STATUS", "orderStatus");246 executeSQLQueryAction.setExtractVariables(extractVariables);247 executeSQLQueryAction.execute(context);248 Assert.assertNotNull(context.getVariable("${orderStatus}"));249 Assert.assertEquals(context.getVariable("${orderStatus}"), "in_progress");250 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));251 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");252 Assert.assertNotNull(context.getVariable("${orderType}"));253 Assert.assertEquals(context.getVariable("${orderType}"), "small");254 Assert.assertNotNull(context.getVariable("${STATUS}"));255 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");256 }257 258 @Test(expectedExceptions = {CitrusRuntimeException.class})259 public void testExtractToVariablesUnknownColumnMapping() {260 String sql = DB_STMT_1;261 reset(jdbcTemplate);262 263 Map<String, Object> resultMap = new HashMap<String, Object>();264 resultMap.put("ORDERTYPE", "small");265 resultMap.put("STATUS", "in_progress");266 267 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));268 List<String> stmts = Collections.singletonList(sql);269 executeSQLQueryAction.setStatements(stmts);270 271 Map<String, String> extractVariables = new HashMap<String, String>();272 extractVariables.put("UNKNOWN_COLUMN", "orderStatus");273 executeSQLQueryAction.setExtractVariables(extractVariables);274 275 executeSQLQueryAction.execute(context);276 }277 278 @Test279 public void testResultSetValidation() {280 String sql = DB_STMT_1;281 reset(jdbcTemplate);282 283 Map<String, Object> resultMap = new HashMap<String, Object>();284 resultMap.put("ORDERTYPE", "small");285 resultMap.put("STATUS", "in_progress");286 287 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));288 List<String> stmts = Collections.singletonList(sql);289 executeSQLQueryAction.setStatements(stmts);290 291 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();292 controlResultSet.put("ORDERTYPE", Collections.singletonList("small"));293 controlResultSet.put("STATUS", Collections.singletonList("in_progress"));294 295 executeSQLQueryAction.setControlResultSet(controlResultSet);296 297 executeSQLQueryAction.execute(context);298 299 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));300 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");301 Assert.assertNotNull(context.getVariable("${STATUS}"));302 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");303 }304 @Test305 public void testResultSetValidationLowerCase() {306 String sql = DB_STMT_1;307 reset(jdbcTemplate);308 Map<String, Object> resultMap = new HashMap<String, Object>();309 resultMap.put("ordertype", "small");310 resultMap.put("status", "in_progress");311 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));312 List<String> stmts = Collections.singletonList(sql);313 executeSQLQueryAction.setStatements(stmts);314 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();315 controlResultSet.put("ORDERTYPE", Collections.singletonList("small"));316 controlResultSet.put("STATUS", Collections.singletonList("in_progress"));317 executeSQLQueryAction.setControlResultSet(controlResultSet);318 executeSQLQueryAction.execute(context);319 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));320 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");321 Assert.assertNotNull(context.getVariable("${STATUS}"));322 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");323 }324 325 @Test326 public void testResultSetValidationWithAliasNames() {327 String sql = "select ORDERTYPE AS TYPE, STATUS AS STATE from orders where ID=5";328 reset(jdbcTemplate);329 330 Map<String, Object> resultMap = new HashMap<String, Object>();331 resultMap.put("TYPE", "small");332 resultMap.put("STATE", "in_progress");333 334 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));335 List<String> stmts = Collections.singletonList(sql);336 executeSQLQueryAction.setStatements(stmts);337 338 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();339 controlResultSet.put("TYPE", Collections.singletonList("small"));340 controlResultSet.put("STATE", Collections.singletonList("in_progress"));341 342 executeSQLQueryAction.setControlResultSet(controlResultSet);343 344 executeSQLQueryAction.execute(context);345 Assert.assertNotNull(context.getVariable("${TYPE}"));346 Assert.assertEquals(context.getVariable("${TYPE}"), "small");347 Assert.assertNotNull(context.getVariable("${STATE}"));348 Assert.assertEquals(context.getVariable("${STATE}"), "in_progress");349 }350 351 @Test352 public void testResultSetValidationError() {353 String sql = DB_STMT_1;354 reset(jdbcTemplate);355 356 Map<String, Object> resultMap = new HashMap<String, Object>();357 resultMap.put("ORDERTYPE", "small");358 resultMap.put("STATUS", "in_progress");359 360 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));361 List<String> stmts = Collections.singletonList(sql);362 executeSQLQueryAction.setStatements(stmts);363 364 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();365 controlResultSet.put("ORDERTYPE", Collections.singletonList("xxl")); //this is supposed to cause an error366 controlResultSet.put("STATUS", Collections.singletonList("in_progress"));367 368 executeSQLQueryAction.setControlResultSet(controlResultSet);369 370 try {371 executeSQLQueryAction.execute(context);372 } catch (ValidationException e) {373 Assert.assertNull(context.getVariables().get("${ORDERTYPE}"));374 Assert.assertNull(context.getVariables().get("${STATUS}"));375 376 return;377 }378 Assert.fail("Expected test to fail with " + ValidationException.class + " but was successful");379 }380 381 @Test382 public void testResultSetMultipleRowsValidation() {383 String sql = "select ORDERTYPE, STATUS from orders where ID < 5";384 reset(jdbcTemplate);385 386 List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();387 Map<String, Object> resultRow1 = new HashMap<String, Object>();388 Map<String, Object> resultRow2 = new HashMap<String, Object>();389 Map<String, Object> resultRow3 = new HashMap<String, Object>();390 resultRow1.put("ORDERTYPE", "small");391 resultRow1.put("STATUS", "started");392 resultList.add(resultRow1);393 resultRow2.put("ORDERTYPE", "medium");394 resultRow2.put("STATUS", "in_progress");395 resultList.add(resultRow2);396 resultRow3.put("ORDERTYPE", "big");397 resultRow3.put("STATUS", "finished");398 resultList.add(resultRow3);399 400 when(jdbcTemplate.queryForList(sql)).thenReturn(resultList);401 List<String> stmts = Collections.singletonList(sql);402 executeSQLQueryAction.setStatements(stmts);403 404 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();405 List<String> ordertypeValues = new ArrayList<String>();406 ordertypeValues.add("small");407 ordertypeValues.add("medium");408 ordertypeValues.add("big");409 controlResultSet.put("ORDERTYPE", ordertypeValues);410 411 List<String> statusValues = new ArrayList<String>();412 statusValues.add("started");413 statusValues.add("in_progress");414 statusValues.add("finished");415 controlResultSet.put("STATUS", statusValues);416 417 executeSQLQueryAction.setControlResultSet(controlResultSet);418 419 executeSQLQueryAction.execute(context);420 Assert.assertNotNull(context.getVariable("ORDERTYPE"));421 Assert.assertEquals(context.getVariable("ORDERTYPE"), "small");422 Assert.assertNotNull(context.getVariable("STATUS"));423 Assert.assertEquals(context.getVariable("STATUS"), "started");424 }425 426 @Test427 public void testNullValuesInMultipleRowsValidation() {428 String sql = "select ORDERTYPE, STATUS from orders where ID < 5";429 reset(jdbcTemplate);430 431 List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();432 Map<String, Object> resultRow1 = new HashMap<String, Object>();433 Map<String, Object> resultRow2 = new HashMap<String, Object>();434 Map<String, Object> resultRow3 = new HashMap<String, Object>();435 resultRow1.put("ORDERTYPE", "small");436 resultRow1.put("STATUS", null);437 resultList.add(resultRow1);438 resultRow2.put("ORDERTYPE", "medium");439 resultRow2.put("STATUS", "in_progress");440 resultList.add(resultRow2);441 resultRow3.put("ORDERTYPE", null);442 resultRow3.put("STATUS", "finished");443 resultList.add(resultRow3);444 445 when(jdbcTemplate.queryForList(sql)).thenReturn(resultList);446 List<String> stmts = Collections.singletonList(sql);447 executeSQLQueryAction.setStatements(stmts);448 449 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();450 List<String> ordertypeValues = new ArrayList<String>();451 ordertypeValues.add("small");452 ordertypeValues.add("medium");453 ordertypeValues.add(""); // 1st possibility to validate null values454 controlResultSet.put("ORDERTYPE", ordertypeValues);455 456 List<String> statusValues = new ArrayList<String>();457 statusValues.add("NULL"); // 2nd possibility to validate null values458 statusValues.add("in_progress");459 statusValues.add("finished");460 controlResultSet.put("STATUS", statusValues);461 462 executeSQLQueryAction.setControlResultSet(controlResultSet);463 464 executeSQLQueryAction.execute(context);465 Assert.assertNotNull(context.getVariable("ORDERTYPE"));466 Assert.assertEquals(context.getVariable("ORDERTYPE"), "small");467 Assert.assertNotNull(context.getVariable("STATUS"));468 Assert.assertEquals(context.getVariable("STATUS"), "NULL");469 }470 471 @Test472 public void testIgnoreInMultipleRowsValidation() {473 String sql = "select ORDERTYPE, STATUS from orders where ID < 5";474 reset(jdbcTemplate);475 476 List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();477 Map<String, Object> resultRow1 = new HashMap<String, Object>();478 Map<String, Object> resultRow2 = new HashMap<String, Object>();479 Map<String, Object> resultRow3 = new HashMap<String, Object>();480 resultRow1.put("ORDERTYPE", "small");481 resultRow1.put("STATUS", "started");482 resultList.add(resultRow1);483 resultRow2.put("ORDERTYPE", "medium");484 resultRow2.put("STATUS", "in_progress");485 resultList.add(resultRow2);486 resultRow3.put("ORDERTYPE", "big");487 resultRow3.put("STATUS", "finished");488 resultList.add(resultRow3);489 490 when(jdbcTemplate.queryForList(sql)).thenReturn(resultList);491 List<String> stmts = Collections.singletonList(sql);492 executeSQLQueryAction.setStatements(stmts);493 494 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();495 List<String> ordertypeValues = new ArrayList<String>();496 ordertypeValues.add("small");497 ordertypeValues.add(Citrus.IGNORE_PLACEHOLDER);498 ordertypeValues.add("big");499 500 controlResultSet.put("ORDERTYPE", ordertypeValues);501 502 List<String> statusValues = new ArrayList<String>();503 statusValues.add(Citrus.IGNORE_PLACEHOLDER);504 statusValues.add("in_progress");505 statusValues.add("finished");506 controlResultSet.put("STATUS", statusValues);507 508 executeSQLQueryAction.setControlResultSet(controlResultSet);509 510 executeSQLQueryAction.execute(context);511 Assert.assertNotNull(context.getVariable("ORDERTYPE"));512 Assert.assertEquals(context.getVariable("ORDERTYPE"), "small");513 Assert.assertNotNull(context.getVariable("STATUS"));514 Assert.assertEquals(context.getVariable("STATUS"), "started");515 }516 517 @Test518 public void testExtractMultipleRowValues() {519 String sql = "select distinct STATUS from orders";520 reset(jdbcTemplate);521 522 List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();523 Map<String, Object> resultRow1 = new HashMap<String, Object>();524 Map<String, Object> resultRow2 = new HashMap<String, Object>();525 Map<String, Object> resultRow3 = new HashMap<String, Object>();526 resultRow1.put("ORDERTYPE", "small");527 resultRow1.put("STATUS", "started");528 resultList.add(resultRow1);529 resultRow2.put("ORDERTYPE", null);530 resultRow2.put("STATUS", "in_progress");531 resultList.add(resultRow2);532 resultRow3.put("ORDERTYPE", "big");533 resultRow3.put("STATUS", "finished");534 resultList.add(resultRow3);535 536 when(jdbcTemplate.queryForList(sql)).thenReturn(resultList);537 List<String> stmts = Collections.singletonList(sql);538 executeSQLQueryAction.setStatements(stmts);539 540 Map<String, String> extractVariables = new HashMap<String, String>();541 extractVariables.put("STATUS", "orderStatus");542 extractVariables.put("ORDERTYPE", "orderType");543 executeSQLQueryAction.setExtractVariables(extractVariables);544 545 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();546 List<String> ordertypeValues = new ArrayList<String>();547 ordertypeValues.add("small");548 ordertypeValues.add(Citrus.IGNORE_PLACEHOLDER);549 ordertypeValues.add("big");550 551 controlResultSet.put("ORDERTYPE", ordertypeValues);552 553 List<String> statusValues = new ArrayList<String>();554 statusValues.add("started");555 statusValues.add("in_progress");556 statusValues.add("finished");557 controlResultSet.put("STATUS", statusValues);558 559 executeSQLQueryAction.setControlResultSet(controlResultSet);560 561 executeSQLQueryAction.execute(context);562 Assert.assertNotNull(context.getVariable("orderType"));563 Assert.assertEquals(context.getVariable("orderType"), "small;NULL;big");564 Assert.assertNotNull(context.getVariable("orderStatus"));565 Assert.assertEquals(context.getVariable("orderStatus"), "started;in_progress;finished");566 Assert.assertNotNull(context.getVariable("ORDERTYPE"));567 Assert.assertEquals(context.getVariable("ORDERTYPE"), "small");568 Assert.assertNotNull(context.getVariable("STATUS"));569 Assert.assertEquals(context.getVariable("STATUS"), "started");570 }571 572 @Test573 public void testMultipleStatementsValidationError() {574 String sql1 = DB_STMT_1;575 String sql2 = DB_STMT_2;576 reset(jdbcTemplate);577 578 Map<String, Object> resultMap1 = new HashMap<String, Object>();579 resultMap1.put("ORDERTYPE", "small");580 resultMap1.put("STATUS", "in_progress");581 582 when(jdbcTemplate.queryForList(sql1)).thenReturn(Collections.singletonList(resultMap1));583 584 Map<String, Object> resultMap2 = new HashMap<String, Object>();585 resultMap2.put("NAME", "Mickey Mouse");586 resultMap2.put("HEIGHT", "0,3");587 588 when(jdbcTemplate.queryForList(sql2)).thenReturn(Collections.singletonList(resultMap2));589 List<String> stmts = new ArrayList<String>();590 stmts.add(sql1);591 stmts.add(sql2);592 593 executeSQLQueryAction.setStatements(stmts);594 595 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();596 controlResultSet.put("ORDERTYPE", Collections.singletonList("small"));597 controlResultSet.put("STATUS", Collections.singletonList("in_progress"));598 controlResultSet.put("NAME", Collections.singletonList("Donald Duck")); //this is supposed to cause an error599 controlResultSet.put("HEIGHT", Collections.singletonList("0,3"));600 601 executeSQLQueryAction.setControlResultSet(controlResultSet);602 603 try {604 executeSQLQueryAction.execute(context);605 } catch (ValidationException e) {606 Assert.assertNull(context.getVariables().get("${ORDERTYPE}"));607 Assert.assertNull(context.getVariables().get("${STATUS}"));608 Assert.assertNull(context.getVariables().get("${NAME}"));609 Assert.assertNull(context.getVariables().get("${HEIGHT}"));610 611 return;612 }613 Assert.fail("Expected test to fail with " + ValidationException.class + " but was successful");614 }615 616 @Test617 public void testSQLStatementsWithFileResource() {618 String sql1 = DB_STMT_1;619 String sql2 = "select NAME, HEIGHT\nfrom customers\nwhere ID=1";620 reset(jdbcTemplate);621 622 Map<String, Object> resultMap1 = new HashMap<String, Object>();623 resultMap1.put("ORDERTYPE", "small");624 resultMap1.put("STATUS", "in_progress");625 626 when(jdbcTemplate.queryForList(sql1)).thenReturn(Collections.singletonList(resultMap1));627 628 Map<String, Object> resultMap2 = new HashMap<String, Object>();629 resultMap2.put("NAME", "Mickey Mouse");630 resultMap2.put("HEIGHT", "0,3");631 ...

Full Screen

Full Screen

testSQLStatement

Using AI Code Generation

copy

Full Screen

1public void testSQLStatement() {2 ExecuteSQLQueryAction executeSQLQueryAction = new ExecuteSQLQueryAction();3 executeSQLQueryAction.setDataSource(dataSource);4 executeSQLQueryAction.setSqlResource(new ClassPathResource("select.sql"));5 executeSQLQueryAction.setRowMapper(new MapRowMapper());6 executeSQLQueryAction.execute(context);7 Assert.assertNotNull(context.getVariable("sqlResultSet"));8 Assert.assertTrue(context.getVariable("sqlResultSet") instanceof List);9 Assert.assertEquals(2, ((List)context.getVariable("sqlResultSet")).size());10}11public void testSQLStatement() {12 execute(sqlQuery()13 .statement("select * from test_table")14 .rowMapper(new MapRowMapper())15 .variable("sqlResultSet"));16 assertThat(context.getVariable("sqlResultSet"), instanceOf(List.class));17 assertThat(context.getVariable("sqlResultSet"), hasSize(2));18}19public void testSQLStatement() {20 run(sqlQuery()21 .statement("select * from test_table")22 .rowMapper(new MapRowMapper())23 .variable("sqlResultSet"));24 assertThat(context.getVariable("sqlResultSet"), instanceOf(List.class));25 assertThat(context.getVariable("sqlResultSet"), hasSize(2));26}27public void testSQLStatement() {28 run(sqlQuery()29 .statement("select * from test_table")30 .rowMapper(new MapRowMapper())31 .variable("sqlResultSet"));32 assertThat(context.getVariable("sqlResultSet"), instanceOf(List.class));33 assertThat(context.getVariable("sqlResultSet"), hasSize(2));34}35public void testSQLStatement() {36 run(sqlQuery()37 .statement("select * from test_table")38 .rowMapper(new MapRowMapper())39 .variable("sqlResultSet"));40 assertThat(context.getVariable("sqlResultSet"), instanceOf(List.class));

Full Screen

Full Screen

testSQLStatement

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;4import org.springframework.beans.factory.annotation.Autowired;5import org.springframework.jdbc.core.JdbcTemplate;6import org.springframework.jdbc.core.RowMapper;7import org.springframework.jdbc.datasource.SingleConnectionDataSource;8import org.testng.annotations.Test;9import javax.sql.DataSource;10import java.sql.ResultSet;11import java.sql.SQLException;12import java.util.List;13import java.util.Map;14public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusSpringSupport {15 private JdbcTemplate jdbcTemplate;16 public void testSQLStatement() {17 description("Execute SQL statement");18 variable("id", "1");19 executeSQL().statement("INSERT INTO CUSTOMER (ID, FIRSTNAME, LASTNAME) VALUES (${id}, 'John', 'Doe')");20 executeSQL().statement("UPDATE CUSTOMER SET FIRSTNAME = 'Jane' WHERE ID = ${id}");21 executeSQL().statement("DELETE FROM CUSTOMER WHERE ID = ${id}");22 }

Full Screen

Full Screen

testSQLStatement

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import java.io.IOException;3import java.util.ArrayList;4import java.util.List;5import com.consol.citrus.Citrus;6import com.consol.citrus.TestCase;7import com.consol.citrus.actions.AbstractTestAction;8import com.consol.citrus.context.TestContext;9import com.consol.citrus.db.driver.JdbcConnection;10import com.consol.citrus.db.driver.JdbcResultSet;11import com.consol.citrus.db.driver.JdbcStatement;12import com.consol.citrus.db.driver.JdbcStatementFactory;13import com.consol.citrus.db.driver.JdbcStatementResult;14import com.consol.citrus.db.driver.JdbcStatementResultType;15import com.consol.citrus.db.driver.JdbcStatementType;16import com.consol.citrus.db.driver.JdbcTable;17import com.consol.citrus.db.driver.JdbcTableColumn;18import com.consol.citrus.db.driver.JdbcTableColumnValue;19import com.consol.citrus.db.driver.JdbcTableManager;20import com.consol.citrus.db.driver.JdbcTableManagerFactory;21import com.consol.citrus.db.driver.JdbcType;22import com.consol.citrus.db.driver.StatementMetadata;23import com.consol.citrus.db.driver.StatementParameter;24import com.consol.citrus.db.driver.StatementParameterType;25import com.consol.citrus.db.driver.StatementResult;26import com.consol.citrus.db.driver.StatementResultType;27import com.consol.citrus.db.driver.StatementType;28import com.consol.citrus.db.driver.TypeConverter;29import com.consol.citrus.db.driver.TypeConverterFactory;30import com.consol.citrus.db.driver.TypeConverterProvider;31import com.consol.citrus.db.driver.TypeConverterProviderImpl;32import com.consol.citrus.db.driver.TypeConverterRegistry;33import com.consol.citrus.db.driver.TypeConverterRegistryImpl;34import com.consol.citrus.db.driver.TypeConverterRegistryProvider;35import com.consol.citrus.db.driver.TypeConverterRegistryProviderImpl;36import com.consol.citrus.db.driver.TypeConverterFactoryImpl;37import com.consol.citrus.db.driver.TypeConverterImpl;38import com.consol.citrus.db.driver.TypeConverterProviderImpl;39import com.consol.citrus.db.driver.TypeConverterRegistryImpl;40import com.con

Full Screen

Full Screen

testSQLStatement

Using AI Code Generation

copy

Full Screen

1public void testSQLStatement() throws Exception {2 testSQLStatement("select * from test_table");3}4public void testSQLStatementWithParams() throws Exception {5 testSQLStatement("select * from test_table where id = ?", 1);6}7public void testSQLStatementWithParams() throws Exception {8 testSQLStatement("select * from test_table where id = ? and name = ?", 1, "test");9}10public void testSQLStatementWithParams() throws Exception {11 testSQLStatement("select * from test_table where id = ? and name = ?", 1, "test", 1);12}13public void testSQLStatementWithParams() throws Exception {14 testSQLStatement("select * from test_table where id = ? and name = ?", 1, "test", 1, "test");15}16public void testSQLStatementWithParams() throws Exception {

Full Screen

Full Screen

testSQLStatement

Using AI Code Generation

copy

Full Screen

1String query = "SELECT * FROM `test` WHERE `id` = 1";2int expectedRows = 1;3String[] expectedColumnNames = { "id", "name", "age" };4String[] expectedColumnValues = { "1", "John", "22" };5testSQLStatement(query, expectedRows, expectedColumnNames, expectedColumnValues);6String query = "SELECT * FROM `test` WHERE `id` = 1";7int expectedRows = 1;8String[] expectedColumnNames = { "id", "name", "age" };9String[] expectedColumnValues = { "1", "John", "22" };10testSQLStatement(query, expectedRows, expectedColumnNames, expectedColumnValues);11String query = "SELECT * FROM `test` WHERE `id` = 1";12int expectedRows = 1;13String[] expectedColumnNames = { "id", "name", "age" };14String[] expectedColumnValues = { "1", "John", "22" };15testSQLStatement(query, expectedRows, expectedColumnNames, expectedColumnValues);

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