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

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

Source:ExecuteSQLQueryActionTest.java Github

copy

Full Screen

...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);...

Full Screen

Full Screen

Source:ExecuteSQLQueryAction.java Github

copy

Full Screen

...305 * the expected values.306 *307 * @param controlResultSet308 */309 public ExecuteSQLQueryAction setControlResultSet(Map<String, List<String>> controlResultSet) {310 this.controlResultSet = controlResultSet;311 return this;312 }313 /**314 * User can extract column values to test variables. Map holds column names (keys) and315 * 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 /**...

Full Screen

Full Screen

Source:SQLActionParser.java Github

copy

Full Screen

...186 * Set expected control result set. Keys represent the column names, values187 * the expected values.188 * @param controlResultSet189 */190 public void setControlResultSet(Map<String, List<String>> controlResultSet) {191 controlResultSet.forEach((key, value) -> builder.validate(key, value.toArray(new String[0])));192 }193 /**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 */...

Full Screen

Full Screen

setControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import com.consol.citrus.annotations.CitrusXmlTest;3import com.consol.citrus.testng.CitrusParameters;4import com.consol.citrus.testng.CitrusXmlTestNGSupport;5import org.testng.annotations.Test;6public class ExecuteSQLQueryActionJavaITest extends CitrusXmlTestNGSupport {7@Test(dataProvider = "testDataProvider")8@CitrusParameters({"package", "testName"})9@CitrusXmlTest(name = "ExecuteSQLQueryActionJavaITest")10public void executeSQLQueryActionJavaITest(String packageName, String testName) {11executeTest(packageName, testName);12}13}

Full Screen

Full Screen

setControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import com.consol.citrus.message.MessageType;5import org.springframework.http.HttpStatus;6import org.springframework.jdbc.core.JdbcTemplate;7import org.springframework.jdbc.datasource.DriverManagerDataSource;8import org.testng.annotations.Test;9public class ExecuteSQLQueryActionIT extends TestNGCitrusTestDesigner {10 public void executeSQLQueryActionIT() {11 variable("id", "1");12 variable("name", "Citrus");13 variable("price", "42.42");14 DriverManagerDataSource dataSource = new DriverManagerDataSource();15 dataSource.setDriverClassName("org.hsqldb.jdbcDriver");16 dataSource.setUrl("jdbc:hsqldb:mem:TEST_DB");17 dataSource.setUsername("sa");18 dataSource.setPassword("");19 JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);20 jdbcTemplate.execute("create table PRODUCT (ID INTEGER, NAME VARCHAR(255), PRICE DOUBLE)");21 http(httpActionBuilder -> httpActionBuilder22 .client("httpClient")23 .send()24 .post()25 .payload("<Product><id>${id}</id><name>${name}</name><price>${price}</price></Product>")26 .contentType("application/xml"));27 http(httpActionBuilder -> httpActionBuilder28 .client("httpClient")29 .receive()30 .response(HttpStatus.OK)31 .messageType(MessageType.PLAINTEXT)32 .payload("<Product><id>${id}</id><name>${name}</name><price>${price}</price></Product>"));33 executeSQLQuery(dataSource, sqlQueryActionBuilder -> sqlQueryActionBuilder34 .statement("select * from PRODUCT")35 .validate("ID", "${id}")36 .validate("NAME", "${name}")37 .validate("PRICE", "${price}"));38 executeSQLQuery(dataSource, sqlQueryActionBuilder -> sqlQueryActionBuilder39 .statement("select * from PRODUCT")40 .setControlResultSet(jdbcTemplate.queryForList("select * from PRODUCT")));41 }42}43package com.consol.citrus.samples;44import com.consol.citrus.annotations.CitrusTest;45import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner

Full Screen

Full Screen

setControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import java.util.HashMap;3import java.util.Map;4import org.testng.annotations.Test;5import com.consol.citrus.annotations.CitrusTest;6import com.consol.citrus.testng.CitrusParameters;7import com.consol.citrus.testng.TestNGCitrusSupport;8import com.consol.citrus.variable.GlobalVariables;9public class ExecuteSQLQueryAction_setControlResultSet_Test extends TestNGCitrusSupport {10 @CitrusParameters({"controlResultSet", "variable"})11 public void executeSQLQueryAction_setControlResultSet_Test() {12 description("Test to check setControlResultSet method of ExecuteSQLQueryAction class");13 variable("variable", "controlResultSet");14 ExecuteSQLQueryAction.Builder builder = new ExecuteSQLQueryAction.Builder();15 builder.sqlQuery("select * from table");16 builder.dataSource("dataSource");17 builder.controlResultSet("controlResultSet");18 builder.validationCallback(new ExecuteSQLQueryAction.ValidationCallback() {19 public void validate(ExecuteSQLQueryAction.ResultSetValidationContext context) {

Full Screen

Full Screen

setControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl;2import com.consol.citrus.TestActionBuilder;3import com.consol.citrus.actions.ExecuteSQLQueryAction;4import com.consol.citrus.context.TestContext;5import com.consol.citrus.dsl.builder.BuilderSupport;6import com.consol.citrus.dsl.builder.DelegatingTestActionBuilder;7import com.consol.citrus.dsl.builder.TestActionBuilderSupport;8import com.consol.citrus.jdbc.message.JdbcMessageHeaders;9import org.springframework.jdbc.core.JdbcTemplate;10import org.springframework.jdbc.datasource.SingleConnectionDataSource;11import javax.sql.DataSource;12import java.sql.Connection;13import java.util.Map;14public class ExecuteSQLQueryActionBuilder extends TestActionBuilderSupport<ExecuteSQLQueryAction, ExecuteSQLQueryActionBuilder> {15 private final ExecuteSQLQueryAction action;16 public ExecuteSQLQueryActionBuilder(String sqlQuery, String dataSource) {17 this.action = new ExecuteSQLQueryAction();18 action.setSqlQuery(sqlQuery);19 action.setDataSource(dataSource);20 }21 public ExecuteSQLQueryActionBuilder(String sqlQuery, JdbcTemplate jdbcTemplate) {22 this.action = new ExecuteSQLQueryAction();23 action.setSqlQuery(sqlQuery);24 action.setJdbcTemplate(jdbcTemplate);25 }26 public ExecuteSQLQueryActionBuilder(String sqlQuery, DataSource dataSource) {27 this.action = new ExecuteSQLQueryAction();28 action.setSqlQuery(sqlQuery);29 action.setDataSource(dataSource);30 }31 public ExecuteSQLQueryActionBuilder(String sqlQuery, Connection connection) {32 this.action = new ExecuteSQLQueryAction();33 action.setSqlQuery(sqlQuery);34 action.setDataSource(new SingleConnectionDataSource(connection, true));35 }36 public ExecuteSQLQueryActionBuilder(String sqlQuery) {37 this.action = new ExecuteSQLQueryAction();38 action.setSqlQuery(sqlQuery);39 }40 public ExecuteSQLQueryActionBuilder result(String result) {41 action.setResult(result);42 return this;43 }44 public ExecuteSQLQueryActionBuilder resultMap(Map<String, Object> resultMap) {45 action.setResultMap(resultMap);46 return this;47 }48 public ExecuteSQLQueryActionBuilder controlResultSet(String controlResultSet) {49 action.setControlResultSet(controlResultSet);50 return this;51 }52 public ExecuteSQLQueryActionBuilder validateResultSet(boolean validateResultSet) {53 action.setValidateResultSet(validateResultSet);54 return this;55 }56 public ExecuteSQLQueryActionBuilder variable(String variable) {57 action.setVariable(variable);

Full Screen

Full Screen

setControlResultSet

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.UnitTestSupport;5import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder;6import com.consol.citrus.dsl.builder.PurgeJdbcActionBuilder;7import com.consol.citrus.dsl.builder.SendActionBuilder;8import com.consol.citrus.dsl.builder.VariableBuilder;9import com.consol.citrus.dsl.builder.VariablesBuilder;10import com.consol.citrus.exceptions.CitrusRuntimeException;11import com.consol.citrus.jdbc.message.JdbcMessage;12import com.consol.citrus.message.MessageType;13import com.consol.citrus.testng.AbstractTestNGUnitTest;14import org.mockito.Mockito;15import org.springframework.jdbc.core.JdbcTemplate;16import org.springframework.jdbc.datasource.DriverManagerDataSource;17import org.springframework.jdbc.support.rowset.SqlRowSet;18import org.testng.Assert;19import org.testng.annotations.Test;20import java.util.ArrayList;21import java.util.List;22import static org.mockito.Mockito.*;23public class ExecuteSQLQueryActionTest extends AbstractTestNGUnitTest {24 private JdbcTemplate jdbcTemplate = Mockito.mock(JdbcTemplate.class);25 public void testExecuteSQLQueryBuilder() {26 MockTestDesigner builder = new MockTestDesigner(applicationContext) {27 public void configure() {28 executeSQLQuery(new ExecuteSQLQueryActionBuilder()29 .statement("SELECT * FROM CUSTOMERS")30 .rowMapper(new TestRowMapper())31 .validateResultSet("result", "CUSTOMER_ID", "1")32 .validateResultSet("result", "CUSTOMER_NAME", "John Doe")33 .validateResultSet("result", "CUSTOMER_ADDRESS", "1234 Main Street")34 .validateResultSet("result", "CUSTOMER_CITY", "Anytown")35 .validateResultSet("result", "CUSTOMER_STATE", "CA")36 .validateResultSet("result", "CUSTOMER_ZIP", "98765")37 .validateResultSet("result", "CUSTOMER_COUNTRY", "USA")38 .validateResultSet("result", "CUSTOMER_PHONE", "123-555-1212")39 .validateResultSet("result", "CUSTOMER_FAX", "123-555-1213")40 .validateResultSet("result", "CUSTOMER_EMAIL", "

Full Screen

Full Screen

setControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import org.testng.annotations.Test;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {5public void executeSQLQueryActionJavaITest() {6variable("query", "SELECT * FROM COUNTRY");7sql(builder -> builder8.server("myDataSource")9.query("{{query}}")10.validate("COUNTRY_NAME", "United States")11.validate("POPULATION", "298444215")12.validate("COUNTRY_CODE", "USA")13);14}15}16package com.consol.citrus.dsl.design;17import org.testng.annotations.Test;18import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;19public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {20public void executeSQLQueryActionJavaITest() {21variable("query", "SELECT * FROM COUNTRY");22sql(builder -> builder23.server("myDataSource")24.query("{{query}}")25.validate("COUNTRY_NAME", "United States")26.validate("POPULATION", "298444215")27.validate("COUNTRY_CODE", "USA")28);29}30}31package com.consol.citrus.dsl.design;32import org.testng.annotations.Test;33import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;34public class ExecuteSQLQueryActionJavaITest extends TestNGCitrusTestDesigner {35public void executeSQLQueryActionJavaITest() {36variable("query", "SELECT * FROM COUNTRY");37sql(builder -> builder38.server("myDataSource")39.query("{{query}}")40.validate("COUNTRY_NAME", "United States")41.validate("POPULATION", "298444215")42.validate("COUNTRY_CODE", "USA")43);44}45}46package com.consol.citrus.dsl.design;47import org.testng.annotations.Test;48import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;

Full Screen

Full Screen

setControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import java.sql.ResultSet;3import java.sql.SQLException;4import java.util.ArrayList;5import java.util.List;6import javax.sql.DataSource;7import org.springframework.jdbc.core.JdbcTemplate;8import org.springframework.jdbc.core.RowMapper;9import org.springframework.util.StringUtils;10import com.consol.citrus.context.TestContext;11import com.consol.citrus.exceptions.CitrusRuntimeException;12import com.consol.citrus.message.Message;13import com.consol.citrus.message.MessageType;14import com.consol.citrus.message.MessageTypeResolver;15import com.consol.citrus.message.MessageTypeUtils;16import com.consol.citrus.util.FileUtils;17import com.consol.citrus.validation.context.ValidationContext;18import com.consol.citrus.validation.context.ValidationContextUtils;19public class ExecuteSQLQueryAction extends AbstractSQLAction {20 public static final String DEFAULT_RESULT_VARIABLE = "sqlQueryResult";21 private String resultVariable = DEFAULT_RESULT_VARIABLE;22 private String sqlQuery;23 private List<String> parameters = new ArrayList<String>();24 private ResultSet resultSet;25 public ExecuteSQLQueryAction() {26 super("query");27 }28 public ExecuteSQLQueryAction(Builder builder) {29 super("query", builder);30 this.resultVariable = builder.resultVariable;31 this.sqlQuery = builder.sqlQuery;32 this.parameters = builder.parameters;33 }34 public void doExecute(TestContext context) {35 if (resultSet == null) {36 if (StringUtils.hasText(sqlQuery)) {37 resultSet = new JdbcTemplate(getDataSource(context)).queryForRowSet(context.replaceDynamicContentInString(sqlQuery), context.replaceDynamicContentInCollection(parameters));38 } else {39 throw new CitrusRuntimeException("Neither sqlQuery nor resultSet is set for SQL query action - unable to execute query");40 }41 }42 context.setVariable(resultVariable, resultSet);43 log.info("Executed SQL query: " + sqlQuery);44 }

Full Screen

Full Screen

setControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.runner;2import com.consol.citrus.dsl.junit.JUnit4CitrusTest;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder;5import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupport;6import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupportImpl;7import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupportImpl.ExecuteSQLQueryActionBuilderImpl;8import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupportImpl.ExecuteSQLQueryActionBuilderImpl.ExecuteSQLQueryActionBuilderImpl1;9import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupportImpl.ExecuteSQLQueryActionBuilderImpl.ExecuteSQLQueryActionBuilderImpl1.ExecuteSQLQueryActionBuilderImpl2;10import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupportImpl.ExecuteSQLQueryActionBuilderImpl.ExecuteSQLQueryActionBuilderImpl1.ExecuteSQLQueryActionBuilderImpl2.ExecuteSQLQueryActionBuilderImpl3;11import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupportImpl.ExecuteSQLQueryActionBuilderImpl.ExecuteSQLQueryActionBuilderImpl1.ExecuteSQLQueryActionBuilderImpl2.ExecuteSQLQueryActionBuilderImpl3.ExecuteSQLQueryActionBuilderImpl4;12import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupportImpl.ExecuteSQLQueryActionBuilderImpl.ExecuteSQLQueryActionBuilderImpl1.ExecuteSQLQueryActionBuilderImpl2.ExecuteSQLQueryActionBuilderImpl3.ExecuteSQLQueryActionBuilderImpl4.ExecuteSQLQueryActionBuilderImpl5;13import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupportImpl.ExecuteSQLQueryActionBuilderImpl.ExecuteSQLQueryActionBuilderImpl1.ExecuteSQLQueryActionBuilderImpl2.ExecuteSQLQueryActionBuilderImpl3.ExecuteSQLQueryActionBuilderImpl4.ExecuteSQLQueryActionBuilderImpl5.ExecuteSQLQueryActionBuilderImpl6;14import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder.ExecuteSQLQueryActionBuilderSupportImpl.ExecuteSQLQueryActionBuilderImpl.ExecuteSQLQueryActionBuilderImpl1.ExecuteSQLQueryActionBuilderImpl2.ExecuteSQLQueryActionBuilderImpl3.ExecuteSQLQueryActionBuilderImpl4.ExecuteSQLQueryAction

Full Screen

Full Screen

setControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import java.util.ArrayList;3import java.util.List;4import org.testng.annotations.Test;5import com.consol.citrus.annotations.CitrusTest;6import com.consol.citrus.testng.CitrusParameters;7public class ExecuteSQLQueryActionJavaTest {8 @CitrusParameters("testName")9 @Test(dataProvider = "testDataProvider")10 public void executeSQLQueryActionJavaTest(String testName) {11 TestDesigner builder = new TestDesigner(applicationContext, testName) {12 public void configure() {13 executeSQLQuery().statement("SELECT * FROM CUSTOMER WHERE ID = 1").dataSource("myDataSource")14 .validateResultSet().row(0).column(0).value("1").column(1).value("John").row(1).column(0)15 .value("2").column(1).value("Jane");16 }17 };18 builder.run();19 }20 public Object[][] testDataProvider() {21 return new Object[][] { new Object[] { "executeSQLQueryActionJavaTest" } };22 }23}24package com.consol.citrus.actions;25import java.util.ArrayList;26import java.util.List;27import org.testng.annotations.Test;28import com.consol.citrus.annotations.CitrusTest;29import com.consol.citrus.testng.CitrusParameters;30public class ExecuteSQLQueryActionJavaTest {31 @CitrusParameters("testName")32 @Test(dataProvider = "testDataProvider")33 public void executeSQLQueryActionJavaTest(String testName) {34 TestDesigner builder = new TestDesigner(applicationContext, testName) {35 public void configure() {36 executeSQLQuery().statement("SELECT * FROM CUSTOMER WHERE ID = 1").dataSource("myDataSource")37 .validateResultSet().row(0).column(0).value("1").column(1).value("John").row(1).column(0)

Full Screen

Full Screen

setControlResultSet

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.UnitTestSupport;5import com.consol.citrus.dsl.builder.ExecuteSQLQueryActionBuilder;6import com.consol.citrus.dsl.builder.PurgeJdbcActionBuilder;7import com.consol.citrus.dsl.builder.SendActionBuilder;8import com.consol.citrus.dsl.builder.VariableBuilder;9import com.consol.citrus.dsl.builder.VariablesBuilder;10import com.consol.citrus.exceptions.CitrusRuntimeException;11import com.consol.citrus.jdbc.message.JdbcMessage;12import com.consol.citrus.message.MessageType;13import com.consol.citrus.testng.AbstractTestNGUnitTest;14import org.mockito.Mockito;15import org.springframework.jdbc.core.JdbcTemplate;16import org.springframework.jdbc.datasource.DriverManagerDataSource;17import org.springframework.jdbc.support.rowset.SqlRowSet;18import org.testng.Assert;19import org.testng.annotations.Test;20import java.util.ArrayList;21import java.util.List;22import static org.mockito.Mockito.*;23public class ExecuteSQLQueryActionTest extends AbstractTestNGUnitTest {24 private JdbcTemplate jdbcTemplate = Mockito.mock(JdbcTemplate.class);25 public void testExecuteSQLQueryBuilder() {26 MockTestDesigner builder = new MockTestDesigner(applicationContext) {27 public void configure() {28 executeSQLQuery(new ExecuteSQLQueryActionBuilder()29 .statement("SELECT * FROM CUSTOMERS")30 .rowMapper(new TestRowMapper())31 .validateResultSet("result", "CUSTOMER_ID", "1")32 .validateResultSet("result", "CUSTOMER_NAME", "John Doe")33 .validateResultSet("result", "CUSTOMER_ADDRESS", "1234 Main Street")34 .validateResultSet("result", "CUSTOMER_CITY", "Anytown")35 .validateResultSet("result", "CUSTOMER_STATE", "CA")36 .validateResultSet("result", "CUSTOMER_ZIP", "98765")37 .validateResultSet("result", "CUSTOMER_COUNTRY", "USA")38 .validateResultSet("result", "CUSTOMER_PHONE", "123-555-1212")39 .validateResultSet("result", "CUSTOMER_FAX", "123-555-1213")40 .validateResultSet("result", "CUSTOMER_EMAIL", "

Full Screen

Full Screen

setControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import java.sql.ResultSet;3import java.sql.SQLException;4import java.util.ArrayList;5import java.util.List;6import javax.sql.DataSource;7import org.springframework.jdbc.core.JdbcTemplate;8import org.springframework.jdbc.core.RowMapper;9import org.springframework.util.StringUtils;10import com.consol.citrus.context.TestContext;11import com.consol.citrus.exceptions.CitrusRuntimeException;12import com.consol.citrus.message.Message;13import com.consol.citrus.message.MessageType;14import com.consol.citrus.message.MessageTypeResolver;15import com.consol.citrus.message.MessageTypeUtils;16import com.consol.citrus.util.FileUtils;17import com.consol.citrus.validation.context.ValidationContext;18import com.consol.citrus.validation.context.ValidationContextUtils;19public class ExecuteSQLQueryAction extends AbstractSQLAction {20 public static final String DEFAULT_RESULT_VARIABLE = "sqlQueryResult";21 private String resultVariable = DEFAULT_RESULT_VARIABLE;22 private String sqlQuery;23 private List<String> parameters = new ArrayList<String>();24 private ResultSet resultSet;25 public ExecuteSQLQueryAction() {26 super("query");27 }28 public ExecuteSQLQueryAction(Builder builder) {29 super("query", builder);30 this.resultVariable = builder.resultVariable;31 this.sqlQuery = builder.sqlQuery;32 this.parameters = builder.parameters;33 }34 public void doExecute(TestContext context) {35 if (resultSet == null) {36 if (StringUtils.hasText(sqlQuery)) {37 resultSet = new JdbcTemplate(getDataSource(context)).queryForRowSet(context.replaceDynamicContentInString(sqlQuery), context.replaceDynamicContentInCollection(parameters));38 } else {39 throw new CitrusRuntimeException("Neither sqlQuery nor resultSet is set for SQL query action - unable to execute query");40 }41 }42 context.setVariable(resultVariable, resultSet);43 log.info("Executed SQL query: " + sqlQuery);44 }

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