How to use setExtractVariables method of com.consol.citrus.actions.ExecuteSQLQueryAction class

Best Citrus code snippet using com.consol.citrus.actions.ExecuteSQLQueryAction.setExtractVariables

Source:ExecuteSQLQueryActionTest.java Github

copy

Full Screen

...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 632 when(jdbcTemplate.queryForList(sql2)).thenReturn(Collections.singletonList(resultMap2));633 executeSQLQueryAction.setSqlResourcePath("classpath:com/consol/citrus/actions/test-sql-query-statements.sql");634 635 executeSQLQueryAction.execute(context);636 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));637 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");638 Assert.assertNotNull(context.getVariable("${STATUS}"));639 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");640 Assert.assertNotNull(context.getVariable("${NAME}"));641 Assert.assertEquals(context.getVariable("${NAME}"), "Mickey Mouse");642 Assert.assertNotNull(context.getVariable("${HEIGHT}"));643 Assert.assertEquals(context.getVariable("${HEIGHT}"), "0,3");644 }645 646 @Test647 public void testResultSetScriptValidation() {648 String sql = "select ORDERTYPES, STATUS from orders where ID=5";649 reset(jdbcTemplate);650 651 Map<String, Object> resultMap = new HashMap<String, Object>();652 resultMap.put("ORDERTYPE", "small");653 resultMap.put("STATUS", "in_progress");654 655 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));656 List<String> stmts = Collections.singletonList(sql);657 executeSQLQueryAction.setStatements(stmts);658 659 ScriptValidationContext scriptValidationContext = new ScriptValidationContext(ScriptTypes.GROOVY);660 scriptValidationContext.setValidationScript("assert rows.size() == 1\n" +661 "assert rows[0].ORDERTYPE == 'small'\n" +662 "assert rows[0] == [ORDERTYPE:'small', STATUS:'in_progress']");663 executeSQLQueryAction.setScriptValidationContext(scriptValidationContext);664 665 executeSQLQueryAction.execute(context);666 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));667 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");668 Assert.assertNotNull(context.getVariable("${STATUS}"));669 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");670 }671 672 @Test673 public void testResultSetScriptValidationMultipleStmts() {674 String sql1 = "select ORDERTYPES, STATUS from orders where ID=5";675 String sql2 = "select ERRORTYPES from types";676 reset(jdbcTemplate);677 678 Map<String, Object> resultMap = new HashMap<String, Object>();679 resultMap.put("ORDERTYPE", "small");680 resultMap.put("STATUS", "in_progress");681 682 List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();683 for (int i = 1; i < 4; i++) {684 Map<String, Object> columnMap = new HashMap<String, Object>();685 columnMap.put("ID", String.valueOf(i));686 columnMap.put("NAME", "error" + i);687 688 results.add(columnMap);689 }690 691 when(jdbcTemplate.queryForList(sql1)).thenReturn(Collections.singletonList(resultMap));692 when(jdbcTemplate.queryForList(sql2)).thenReturn(results);693 List<String> stmts = new ArrayList<String>();694 stmts.add(sql1);695 stmts.add(sql2);696 executeSQLQueryAction.setStatements(stmts);697 698 ScriptValidationContext scriptValidationContext = new ScriptValidationContext(ScriptTypes.GROOVY);699 scriptValidationContext.setValidationScript("assert rows.size() == 4\n" +700 "assert rows[0].ORDERTYPE == 'small'\n" +701 "assert rows[0] == [ORDERTYPE:'small', STATUS:'in_progress']\n" +702 "assert rows[1].ID == '1'\n" +703 "assert rows[3].NAME == 'error3'\n");704 executeSQLQueryAction.setScriptValidationContext(scriptValidationContext);705 706 executeSQLQueryAction.execute(context);707 }708 709 @Test710 public void testResultSetScriptValidationWrongValue() {711 String sql = "select ORDERTYPES, STATUS from orders where ID=5";712 reset(jdbcTemplate);713 714 Map<String, Object> resultMap = new HashMap<String, Object>();715 resultMap.put("ORDERTYPE", "small");716 resultMap.put("STATUS", "in_progress");717 718 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));719 List<String> stmts = Collections.singletonList(sql);720 executeSQLQueryAction.setStatements(stmts);721 722 ScriptValidationContext scriptValidationContext = new ScriptValidationContext(ScriptTypes.GROOVY);723 scriptValidationContext.setValidationScript("assert rows.size() == 1\n" +724 "assert rows[0] == [ORDERTYPE:'big', STATUS:'in_progress']");725 executeSQLQueryAction.setScriptValidationContext(scriptValidationContext);726 727 try {728 executeSQLQueryAction.execute(context);729 } catch (ValidationException e) {730 Assert.assertTrue(e.getCause() instanceof AssertionError);731 return;732 }733 734 Assert.fail("Missing validation exception due to script validation error");735 }736 737 @Test738 public void testResultSetScriptValidationCombination() {739 String sql = "select ORDERTYPES, STATUS from orders where ID=5";740 reset(jdbcTemplate);741 742 Map<String, Object> resultMap = new HashMap<String, Object>();743 resultMap.put("ORDERTYPE", "small");744 resultMap.put("STATUS", "in_progress");745 746 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));747 List<String> stmts = Collections.singletonList(sql);748 executeSQLQueryAction.setStatements(stmts);749 750 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();751 controlResultSet.put("ORDERTYPE", Collections.singletonList("small"));752 controlResultSet.put("STATUS", Collections.singletonList("in_progress"));753 754 executeSQLQueryAction.setControlResultSet(controlResultSet);755 756 ScriptValidationContext scriptValidationContext = new ScriptValidationContext(ScriptTypes.GROOVY);757 scriptValidationContext.setValidationScript("assert rows.size() == 1\n" +758 "assert rows[0].ORDERTYPE == 'small'\n" +759 "assert rows[0] == [ORDERTYPE:'small', STATUS:'in_progress']");760 executeSQLQueryAction.setScriptValidationContext(scriptValidationContext);761 762 executeSQLQueryAction.execute(context);763 }764 @Test765 public void testResultSetValidationWithVariableAndFunction() {766 String sql = DB_STMT_1;767 reset(jdbcTemplate);768 Map<String, Object> resultMap = new HashMap<String, Object>();769 resultMap.put("ORDERTYPE", "testVariableValue");770 resultMap.put("STATUS", "in_progress");771 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));772 List<String> stmts = Collections.singletonList(sql);773 executeSQLQueryAction.setStatements(stmts);774 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();775 controlResultSet.put("ORDERTYPE", Collections.singletonList("${testVariable}"));776 controlResultSet.put("STATUS", Collections.singletonList("citrus:concat('in_', ${progressVar})"));777 executeSQLQueryAction.setControlResultSet(controlResultSet);778 context.getVariables().put("testVariable", "testVariableValue");779 context.getVariables().put("progressVar", "progress");780 executeSQLQueryAction.execute(context);781 }782 @Test783 public void testBinaryBlobColumnValues() {784 String sql = "select ORDERTYPE, BINARY_DATA from orders where ID=5";785 reset(jdbcTemplate);786 Map<String, Object> resultMap = new HashMap<String, Object>();787 resultMap.put("ORDERTYPE", "small");788 resultMap.put("BINARY_DATA", "some_binary_data".getBytes());789 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));790 List<String> stmts = Collections.singletonList(sql);791 executeSQLQueryAction.setStatements(stmts);792 Map<String, String> extractVariables = new HashMap<String, String>();793 extractVariables.put("BINARY_DATA", "binaryData");794 executeSQLQueryAction.setExtractVariables(extractVariables);795 executeSQLQueryAction.execute(context);796 Assert.assertNotNull(context.getVariable("${binaryData}"));797 Assert.assertEquals(context.getVariable("${binaryData}"), Base64.encodeBase64String("some_binary_data".getBytes()));798 Assert.assertEquals(new String(Base64.decodeBase64(context.getVariable("${binaryData}"))), "some_binary_data");799 }800}...

Full Screen

Full Screen

Source:ExecuteSQLQueryAction.java Github

copy

Full Screen

...315 * respective target variable names (values).316 *317 * @param variablesMap the variables to be created out of database values318 */319 public ExecuteSQLQueryAction setExtractVariables(Map<String, String> variablesMap) {320 this.extractVariables = variablesMap;321 return this;322 }323 /**324 * Sets the script validation context.325 * @param scriptValidationContext the scriptValidationContext to set326 */327 public ExecuteSQLQueryAction setScriptValidationContext(328 ScriptValidationContext scriptValidationContext) {329 this.scriptValidationContext = scriptValidationContext;330 return this;331 }332 /**333 * Gets the validator....

Full Screen

Full Screen

Source:SQLActionParser.java Github

copy

Full Screen

...194 * User can extract column values to test variables. Map holds column names (keys) and195 * respective target variable names (values).196 * @param variablesMap the variables to be created out of database values197 */198 public void setExtractVariables(Map<String, String> variablesMap) {199 variablesMap.forEach(builder::extract);200 }201 /**202 * Sets the script validation context.203 * @param scriptValidationContext the scriptValidationContext to set204 */205 public void setScriptValidationContext(ScriptValidationContext scriptValidationContext) {206 if (scriptValidationContext.getValidationScript() != null) {207 builder.validateScript(scriptValidationContext.getValidationScript(), scriptValidationContext.getScriptType());208 }209 if (scriptValidationContext.getValidationScriptResourcePath() != null) {210 builder.validateScriptResource(scriptValidationContext.getValidationScriptResourcePath(),211 scriptValidationContext.getScriptType(),212 Charset.forName(scriptValidationContext.getValidationScriptResourceCharset()));...

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusTest;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import com.consol.citrus.testng.CitrusParameters;4import org.springframework.http.HttpStatus;5import org.testng.annotations.Test;6public class 4 extends TestNGCitrusTestDesigner {7@Test(dataProvider = "4")8@CitrusParameters({"var1", "var2", "var3", "var4", "var5", "var6", "var7", "var8", "var9", "var10", "var11", "var12", "var13", "var14", "var15", "var16", "var17", "var18", "var19", "var20", "var21", "var22", "var23", "var24", "var25", "var26", "var27", "var28", "var29", "var30", "var31", "var32", "var33", "var34", "var35", "var36", "var37", "var38", "var39", "var40", "var41", "var42", "var43", "var44", "var45", "var46", "var47", "var48", "var49", "var50", "var51", "var52", "var53", "var54", "var55", "var56", "var57", "var58", "var59", "var60", "var61", "var62", "var63", "var64", "var65", "var66", "var67", "var68", "var69", "var70", "var71", "var72", "var73", "var74", "var75", "var76", "var77", "var78", "var79", "var80", "var81", "var82", "var83", "var84", "var85", "var86", "var87", "var88", "var89", "var90", "var91", "var92", "var93", "var94", "var95", "var96", "var97", "var98", "var99", "var100", "var101", "var102", "var103", "var104", "var105", "

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.TestAction;3import com.consol.citrus.actions.ExecuteSQLQueryAction;4import com.consol.citrus.dsl.builder.BuilderSupport;5import com.consol.citrus.dsl.builder.ExecuteSQLBuilder;6import com.consol.citrus.dsl.builder.VariableBuilderSupport;7import com.consol.citrus.exceptions.CitrusRuntimeException;8import com.consol.citrus.variable.VariableExtractor;9import com.consol.citrus.variable.dictionary.DataDictionary;10import org.springframework.jdbc.core.JdbcTemplate;11import org.springframework.jdbc.datasource.DriverManagerDataSource;12import org.springframework.util.StringUtils;13import javax.sql.DataSource;14import java.util.HashMap;15import java.util.Map;16public class ExecuteSQLQueryActionBuilder extends AbstractTestContainerBuilder<ExecuteSQLQueryAction, ExecuteSQLQueryActionBuilder> implements ExecuteSQLBuilder<ExecuteSQLQueryActionBuilder> {17 private final ExecuteSQLQueryAction action;18 public ExecuteSQLQueryActionBuilder(ExecuteSQLQueryAction action) {19 super(action);20 this.action = action;21 }22 public ExecuteSQLQueryActionBuilder dataSource(DataSource dataSource) {23 action.setDataSource(dataSource);24 return this;25 }26 public ExecuteSQLQueryActionBuilder dataSource(DriverManagerDataSource dataSource) {27 action.setDataSource(dataSource);28 return this;29 }30 public ExecuteSQLQueryActionBuilder dataSource(JdbcTemplate dataSource) {31 action.setDataSource(dataSource);32 return this;33 }34 public ExecuteSQLQueryActionBuilder dataSource(String dataSource) {35 action.setDataSource(dataSource);36 return this;37 }

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import org.springframework.context.annotation.Bean;3import org.springframework.context.annotation.Configuration;4import org.springframework.context.annotation.Import;5import com.consol.citrus.dsl.design.TestDesigner;6import com.consol.citrus.dsl.design.TestDesignerBeforeSuiteSupport;7import com.consol.citrus.dsl.runner.TestRunner;8import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;9import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;10import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;11import com.consol.citrus.sql.connection.DatabaseConnection;12import com.consol.citrus.sql.connection.JdbcDatabaseConnection;13import com.consol.citrus.sql.message.SqlMessageHeaders;14import com.consol.citrus.testng.CitrusParameters;15import org.testng.annotations.Test;16import java.util.HashMap;17import java.util.Map;18public class 4 extends TestNGCitrusTestRunner {19 public DatabaseConnection databaseConnection() {20 JdbcDatabaseConnection connection = new JdbcDatabaseConnection();21 connection.setDriver("org.hsqldb.jdbcDriver");22 connection.setUrl("jdbc:hsqldb:mem:sampledb");23 connection.setUsername("sa");24 connection.setPassword("");25 return connection;26 }27 @CitrusParameters({"name", "age"})28 public void 4() {29 description("This is a test to demonstrate how to use setExtractVariables method of com.consol.citrus.actions.ExecuteSQLQueryAction class");30 variable("name", "John");31 variable("age", "42");32 variable("sqlQuery", "SELECT * FROM PERSON WHERE NAME = '${name}' AND AGE = ${age}");33 variable("variableNames", "name,age");34 executeSQLQuery()35 .statement("${sqlQuery}")36 .extractVariables("${variableNames}")37 .validate("name", "John")38 .validate("age", "42");39 }40}41package com.consol.citrus.samples;42import org.springframework.context.annotation.Bean;43import org.springframework.context.annotation.Configuration;44import org.springframework.context.annotation.Import;45import com.consol.citrus.dsl.design.TestDesigner;46import com.consol.citrus.dsl.design.TestDesignerBeforeSuiteSupport;47import com.consol

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.testng;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.builder.ExecuteSQLQueryBuilder;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import com.consol.citrus.testng.CitrusParameters;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.jdbc.core.JdbcTemplate;8import org.testng.annotations.Test;9import java.util.HashMap;10import java.util.Map;11public class ExecuteSQLQueryJavaIT extends TestNGCitrusTestDesigner {12 private JdbcTemplate jdbcTemplate;13 @CitrusParameters({"id", "name", "age"})14 public void executeSQLQueryJavaIT() {15 variable("id", "citrus:randomNumber(3)");16 variable("name", "citrus:concat('Name_', citrus:randomNumber(3))");17 variable("age", "citrus:randomNumber(2)");18 echo("Create table in database");19 executeSQLQuery(new ExecuteSQLQueryBuilder()20 .sqlQuery("CREATE TABLE test_table (id INTEGER, name VARCHAR(255), age INTEGER)")21 .dataSource(jdbcTemplate.getDataSource()));22 echo("Insert data into database");23 executeSQLQuery(new ExecuteSQLQueryBuilder()24 .sqlQuery("INSERT INTO test_table (id, name, age) VALUES (${id}, '${name}', ${age})")25 .dataSource(jdbcTemplate.getDataSource()));26 echo("Query data from database");27 executeSQLQuery(new ExecuteSQLQueryBuilder()28 .sqlQuery("SELECT * FROM test_table WHERE id = ${id}")29 .dataSource(jdbcTemplate.getDataSource())30 .extractVariables("id", "name", "age"));31 echo("Verify query result");32 echo("ID: ${id}");33 echo("Name: ${name}");34 echo("Age: ${age}");35 echo("Drop table from database");36 executeSQLQuery(new ExecuteSQLQueryBuilder()37 .sqlQuery("DROP TABLE test_table")38 .dataSource(jdbcTemplate.getDataSource()));39 }40}41package com.consol.citrus.dsl.testng;42import com.consol.citrus.annotations.CitrusTest;43import com.consol.citrus.dsl.builder.ExecuteSQLQueryBuilder;44import com.consol.citrus

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import java.util.HashMap;3import java.util.Map;4import org.springframework.context.annotation.Bean;5import org.springframework.context.annotation.Configuration;6import org.springframework.context.annotation.Import;7import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder;8import com.consol.citrus.dsl.builder.HttpActionBuilder;9import com.consol.citrus.dsl.builder.HttpServerBuilder;10import com.consol.citrus.dsl.builder.SendActionBuilder;11import com.consol.citrus.dsl.builder.SendSoapMessageActionBuilder;12import com.consol.citrus.dsl.builder.SetVariableActionBuilder;13import com.consol.citrus.dsl.builder.VariableBuilder;14import com.consol.citrus.dsl.builder.XPathBuilder;15import com.consol.citrus.dsl.runner.TestRunner;16import com.consol.citrus.http.client.HttpClient;17import com.consol.citrus.http.server.HttpServer;18import com.consol.citrus.message.MessageType;19import com.consol.citrus.ws.client.WebServiceClient;20import com.consol.citrus.ws.server.WebServiceServer;21@Import({ com.consol.citrus.dsl.design.TestDesigner.class })22public class 4 {23 public TestRunner 4(TestRunner runner) {24 .sql(builder -> builder25 .statement("select * from table where id = 1")26 .extractVariables("id" , "name")27 );28 return runner;29 }30}31package com.consol.citrus;32import java.util.HashMap;33import java.util.Map;34import org.springframework.context.annotation.Bean;35import org.springframework.context.annotation.Configuration;36import org.springframework.context.annotation.Import;37import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder;38import com.consol.citrus.dsl.builder.HttpActionBuilder;39import com.consol.citrus.dsl.builder.HttpServerBuilder;40import com.consol.citrus.dsl.builder.SendActionBuilder;41import com.consol.citrus.dsl.builder.SendSoapMessageActionBuilder;42import com.consol.citrus.dsl.builder.SetVariableActionBuilder;43import com.consol.citrus.dsl.builder.VariableBuilder;44import com.consol.citrus.dsl.builder.XPathBuilder;45import com.consol.citrus.dsl.runner.TestRunner;46import com.consol.citrus.http.client.HttpClient

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import org.springframework.beans.factory.annotation.Autowired;5import org.testng.annotations.Test;6import java.util.HashMap;7import java.util.Map;8public class setExtractVariables extends TestNGCitrusTestDesigner {9private TestRunner runner;10public void setExtractVariables() {11runner.variable("extractVariables", "com.consol.citrus.actions.ExecuteSQLQueryAction.setExtractVariables");12Map<String, String> extractVariables = new HashMap<String, String>();13extractVariables.put("id", "citrus:randomNumber(3)");14extractVariables.put("name", "citrus:concat('Hello', 'World')");15extractVariables.put("value", "citrus:concat('Hello', 'World')");16extractVariables.put("description", "citrus:concat('Hello', 'World')");17extractVariables.put("active", "citrus:randomBoolean()");18extractVariables.put("created", "citrus:currentDate()");19extractVariables.put("updated", "citrus:currentDate()");20extractVariables.put("version", "citrus:randomNumber(3)");21extractVariables.put("type", "citrus:randomNumber(3)");22extractVariables.put("category", "citrus:randomNumber(3)");23extractVariables.put("tags", "citrus:randomNumber(3)");24extractVariables.put("code", "citrus:randomNumber(3)");25extractVariables.put("id", "citrus:randomNumber(3)");26extractVariables.put("name", "citrus:concat('Hello', 'World')");27extractVariables.put("value", "citrus:concat('Hello', 'World')");28extractVariables.put("description", "citrus:concat('Hello', 'World')");29extractVariables.put("active", "citrus:randomBoolean()");30extractVariables.put("created", "citrus:currentDate()");31extractVariables.put("updated", "citrus:currentDate()");32extractVariables.put("version", "citrus:randomNumber(3)");33extractVariables.put("type", "citrus:randomNumber(3)");34extractVariables.put("category", "citrus:randomNumber(3)");35extractVariables.put("tags", "citrus:randomNumber(3)");36extractVariables.put("code", "citrus:randomNumber(3)");37extractVariables.put("id", "citrus:randomNumber

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import com.consol.citrus.testng.CitrusParameters;6import org.testng.annotations.Test;7public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {8 @Test(dataProvider = "testDesignerDataProvider")9 @CitrusParameters({"designer"})10 public void executeSQLQueryActionJavaITest(TestDesigner designer) {11 designer.sql(builder -> builder12 .statement("SELECT * FROM CUSTOMER WHERE ID = 1")13 .extractVariables("customer")14 );15 }16}17package com.consol.citrus.dsl.design;18import com.consol.citrus.dsl.design.TestDesigner;19import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;20import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;21import com.consol.citrus.testng.CitrusParameters;22import org.testng.annotations.Test;23public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {24 @Test(dataProvider = "testDesignerDataProvider")25 @CitrusParameters({"designer"})26 public void executeSQLQueryActionJavaITest(TestDesigner designer) {27 designer.sql(builder -> builder28 .dataSource("dataSource")29 .statement("SELECT * FROM CUSTOMER WHERE ID = 1")30 );31 }32}33package com.consol.citrus.dsl.design;34import com.consol.citrus.dsl.design.TestDesigner;35import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;36import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;37import com.consol.citrus.testng.CitrusParameters;38import org.testng.annotations.Test;39public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {40 @Test(dataProvider = "testDesignerDataProvider")41 @CitrusParameters({"designer"})42 public void executeSQLQueryActionJavaITest(TestDesigner designer) {

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.actions.ExecuteSQLQueryAction;3import com.consol.citrus.annotations.CitrusTest;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.jdbc.core.JdbcTemplate;7import org.testng.annotations.Test;8import java.util.HashMap;9import java.util.Map;10public class ExecuteSQLQueryActionJavaIT extends TestNGCitrusTestDesigner {11 private JdbcTemplate jdbcTemplate;12 public void executeSQLQueryActionJavaIT() {13 variable("sqlQuery", "select * from books where title = 'Citrus: Test Automation'");14 executeSQLQueryAction()15 .dataSource(jdbcTemplate)16 .sqlQuery("${sqlQuery}")17 .extractVariables("id", "title", "author");18 echo("Book id: ${id}");19 echo("Book title: ${title}");20 echo("Book author: ${author}");21 assertThat("${id}").isEqualTo("1");22 assertThat("${title}").isEqualTo("Citrus: Test Automation");23 assertThat("${author}").isEqualTo("Christian Schaefer");24 }25}26package com.consol.citrus.samples;27import com.consol.citrus.actions.ExecuteSQLQueryAction;28import com.consol.citrus.annotations.CitrusTest;29import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;30import org.springframework.beans.factory.annotation.Autowired;31import org.springframework.jdbc.core.JdbcTemplate;32import org.testng.annotations.Test;33import java.util.HashMap;34import java.util.Map;35public class ExecuteSQLQueryActionJavaIT extends TestNGCitrusTestDesigner {36 private JdbcTemplate jdbcTemplate;37 public void executeSQLQueryActionJavaIT() {38 variable("sqlQuery", "select * from books where title = 'Citrus: Test Automation'");39 executeSQLQueryAction()40 .dataSource(jdbcTemplate)41 .sqlQuery("${sqlQuery}")42 .extractVariables("id", "title", "author");43 echo("Book id: ${id

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 XmlTestRunner runner = new XmlTestRunner();4 runner.load(new ClassPathResource("4.xml"));5 runner.run();6 }7}8import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;9import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;10import com.consol.citrus.testng.CitrusParameters;11import org.testng.annotations.Test;12public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {13 @Test(dataProvider = "testDesignerDataProvider")14 @CitrusParameters({"designer"})15 public void executeSQLQueryActionJavaITest(TestDesigner designer) {16 designer.sql(builder -> builder17 .dataSource("dataSource")18 .statement("SELECT * FROM CUSTOMER WHERE ID = 1")19 );20 }21}22package com.consol.citrus.dsl.design;23import com.consol.citrus.dsl.design.TestDesigner;24import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;25import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;26import com.consol.citrus.testng.CitrusParameters;27import org.testng.annotations.Test;28public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {29 @Test(dataProvider = "testDesignerDataProvider")30 @CitrusParameters({"designer"})31 public void executeSQLQueryActionJavaITest(TestDesigner designer) {

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.actions.ExecuteSQLQueryAction;3import com.consol.citrus.annotations.CitrusTest;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.jdbc.core.JdbcTemplate;7import org.testng.annotations.Test;8import java.util.HashMap;9import java.util.Map;10public class ExecuteSQLQueryActionJavaIT extends TestNGCitrusTestDesigner {11 private JdbcTemplate jdbcTemplate;12 public void executeSQLQueryActionJavaIT() {13 variable("sqlQuery", "select * from books where title = 'Citrus: Test Automation'");14 executeSQLQueryAction()15 .dataSource(jdbcTemplate)16 .sqlQuery("${sqlQuery}")17 .extractVariables("id", "title", "author");18 echo("Book id: ${id}");19 echo("Book title: ${title}");20 echo("Book author: ${author}");21 assertThat("${id}").isEqualTo("1");22 assertThat("${title}").isEqualTo("Citrus: Test Automation");23 assertThat("${author}").isEqualTo("Christian Schaefer");24 }25}26package com.consol.citrus.samples;27import com.consol.citrus.actions.ExecuteSQLQueryAction;28import com.consol.citrus.annotations.CitrusTest;29import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;30import org.springframework.beans.factory.annotation.Autowired;31import org.springframework.jdbc.core.JdbcTemplate;32import org.testng.annotations.Test;33import java.util.HashMap;34import java.util.Map;35public class ExecuteSQLQueryActionJavaIT extends TestNGCitrusTestDesigner {36 private JdbcTemplate jdbcTemplate;37 public void executeSQLQueryActionJavaIT() {38 variable("sqlQuery", "select * from books where title = 'Citrus: Test Automation'");39 executeSQLQueryAction()40 .dataSource(jdbcTemplate)41 .sqlQuery("${sqlQuery}")42 .extractVariables("id", "title", "author");43 echo("Book id: ${id

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 XmlTestRunner runner = new XmlTestRunner();4 runner.load(new ClassPathResource("4.xml"));5 runner.run();6 }7}8 .statement("SELECT * FROM CUSTOMER WHERE ID = 1")9 .extractVariables("customer")10 );11 }12}13package com.consol.citrus.dsl.design;14import com.consol.citrus.dsl.design.TestDesigner;15import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;16import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;17import com.consol.citrus.testng.CitrusParameters;18import org.testng.annotations.Test;19public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {20 @Test(dataProvider = "testDesignerDataProvider")21 @CitrusParameters({"designer"})22 public void executeSQLQueryActionJavaITest(TestDesigner designer) {23 designer.sql(builder -> builder24 .dataSource("dataSource")25 .statement("SELECT * FROM CUSTOMER WHERE ID = 1")26 );27 }28}29package com.consol.citrus.dsl.design;30import com.consol.citrus.dsl.design.TestDesigner;31import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;32import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;33import com.consol.citrus.testng.CitrusParameters;34import org.testng.annotations.Test;35public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {36 @Test(dataProvider = "testDesignerDataProvider")37 @CitrusParameters({"designer"})38 public void executeSQLQueryActionJavaITest(TestDesigner designer) {

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.actions.ExecuteSQLQueryAction;3import com.consol.citrus.annotations.CitrusTest;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.jdbc.core.JdbcTemplate;7import org.testng.annotations.Test;8import java.util.HashMap;9import java.util.Map;10public class ExecuteSQLQueryActionJavaIT extends TestNGCitrusTestDesigner {11 private JdbcTemplate jdbcTemplate;12 public void executeSQLQueryActionJavaIT() {13 variable("sqlQuery", "select * from books where title = 'Citrus: Test Automation'");14 executeSQLQueryAction()15 .dataSource(jdbcTemplate)16 .sqlQuery("${sqlQuery}")17 .extractVariables("id", "title", "author");18 echo("Book id: ${id}");19 echo("Book title: ${title}");20 echo("Book author: ${author}");21 assertThat("${id}").isEqualTo("1");22 assertThat("${title}").isEqualTo("Citrus: Test Automation");23 assertThat("${author}").isEqualTo("Christian Schaefer");24 }25}26package com.consol.citrus.samples;27import com.consol.citrus.actions.ExecuteSQLQueryAction;28import com.consol.citrus.annotations.CitrusTest;29import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;30import org.springframework.beans.factory.annotation.Autowired;31import org.springframework.jdbc.core.JdbcTemplate;32import org.testng.annotations.Test;33import java.util.HashMap;34import java.util.Map;35public class ExecuteSQLQueryActionJavaIT extends TestNGCitrusTestDesigner {36 private JdbcTemplate jdbcTemplate;37 public void executeSQLQueryActionJavaIT() {38 variable("sqlQuery", "select * from books where title = 'Citrus: Test Automation'");39 executeSQLQueryAction()40 .dataSource(jdbcTemplate)41 .sqlQuery("${sqlQuery}")42 .extractVariables("id", "title", "author");43 echo("Book id: ${id

Full Screen

Full Screen

setExtractVariables

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 XmlTestRunner runner = new XmlTestRunner();4 runner.load(new ClassPathResource("4.xml"));5 runner.run();6 }7}

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