How to use ExecuteSQLAction class of com.consol.citrus.actions package

Best Citrus code snippet using com.consol.citrus.actions.ExecuteSQLAction

Source:ExecuteSQLTestRunnerTest.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package com.consol.citrus.dsl.runner;17import com.consol.citrus.TestCase;18import com.consol.citrus.actions.ExecuteSQLAction;19import com.consol.citrus.testng.AbstractTestNGUnitTest;20import org.mockito.Mockito;21import org.springframework.core.io.ClassPathResource;22import org.springframework.core.io.Resource;23import org.springframework.jdbc.core.JdbcTemplate;24import org.springframework.transaction.PlatformTransactionManager;25import org.testng.Assert;26import org.testng.annotations.Test;27import java.io.File;28import java.io.IOException;29import static org.mockito.Mockito.reset;30import static org.mockito.Mockito.verify;31/**32 * @author Christoph Deppisch33 * @since 2.334 */35public class ExecuteSQLTestRunnerTest extends AbstractTestNGUnitTest {36 private JdbcTemplate jdbcTemplate = Mockito.mock(JdbcTemplate.class);37 private PlatformTransactionManager transactionManager = Mockito.mock(PlatformTransactionManager.class);38 private Resource resource = Mockito.mock(Resource.class);39 private File file = Mockito.mock(File.class);40 41 @Test42 public void testExecuteSQLBuilderWithStatement() {43 reset(jdbcTemplate);44 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {45 @Override46 public void execute() {47 sql(builder -> builder.jdbcTemplate(jdbcTemplate)48 .statement("TEST_STMT_1")49 .statement("TEST_STMT_2")50 .statement("TEST_STMT_3")51 .ignoreErrors(false));52 }53 };54 TestCase test = builder.getTestCase();55 Assert.assertEquals(test.getActionCount(), 1);56 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLAction.class);57 Assert.assertEquals(test.getActiveAction().getClass(), ExecuteSQLAction.class);58 ExecuteSQLAction action = (ExecuteSQLAction)test.getActions().get(0);59 Assert.assertEquals(action.getName(), "sql");60 Assert.assertEquals(action.getStatements().toString(), "[TEST_STMT_1, TEST_STMT_2, TEST_STMT_3]");61 Assert.assertEquals(action.isIgnoreErrors(), false);62 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);63 verify(jdbcTemplate).execute("TEST_STMT_1");64 verify(jdbcTemplate).execute("TEST_STMT_2");65 verify(jdbcTemplate).execute("TEST_STMT_3");66 }67 @Test68 public void testExecuteSQLBuilderWithTransaction() {69 reset(jdbcTemplate, transactionManager);70 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {71 @Override72 public void execute() {73 sql(builder -> builder.jdbcTemplate(jdbcTemplate)74 .transactionManager(transactionManager)75 .transactionTimeout(5000)76 .transactionIsolationLevel("ISOLATION_READ_COMMITTED")77 .statement("TEST_STMT_1")78 .statement("TEST_STMT_2")79 .statement("TEST_STMT_3")80 .ignoreErrors(false));81 }82 };83 TestCase test = builder.getTestCase();84 Assert.assertEquals(test.getActionCount(), 1);85 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLAction.class);86 Assert.assertEquals(test.getActiveAction().getClass(), ExecuteSQLAction.class);87 ExecuteSQLAction action = (ExecuteSQLAction)test.getActions().get(0);88 Assert.assertEquals(action.getName(), "sql");89 Assert.assertEquals(action.getStatements().toString(), "[TEST_STMT_1, TEST_STMT_2, TEST_STMT_3]");90 Assert.assertEquals(action.isIgnoreErrors(), false);91 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);92 Assert.assertEquals(action.getTransactionManager(), transactionManager);93 Assert.assertEquals(action.getTransactionTimeout(), "5000");94 Assert.assertEquals(action.getTransactionIsolationLevel(), "ISOLATION_READ_COMMITTED");95 verify(jdbcTemplate).execute("TEST_STMT_1");96 verify(jdbcTemplate).execute("TEST_STMT_2");97 verify(jdbcTemplate).execute("TEST_STMT_3");98 }99 @Test100 public void testExecuteSQLBuilderWithResource() throws IOException {101 reset(jdbcTemplate);102 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {103 @Override104 public void execute() {105 sql(builder -> builder.jdbcTemplate(jdbcTemplate)106 .sqlResource(new ClassPathResource("com/consol/citrus/dsl/runner/script.sql"))107 .ignoreErrors(true));108 }109 };110 TestCase test = builder.getTestCase();111 Assert.assertEquals(test.getActionCount(), 1);112 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLAction.class);113 Assert.assertEquals(test.getActiveAction().getClass(), ExecuteSQLAction.class);114 ExecuteSQLAction action = (ExecuteSQLAction)test.getActions().get(0);115 Assert.assertEquals(action.getName(), "sql");116 Assert.assertEquals(action.isIgnoreErrors(), true);117 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);118 Assert.assertEquals(action.getStatements().size(), 3);119 Assert.assertNull(action.getSqlResourcePath());120 verify(jdbcTemplate).execute("TEST_STMT_1");121 verify(jdbcTemplate).execute("TEST_STMT_2");122 verify(jdbcTemplate).execute("TEST_STMT_3");123 }124 @Test125 public void testExecuteSQLBuilderWithResourcePath() throws IOException {126 reset(jdbcTemplate);127 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {128 @Override129 public void execute() {130 sql(builder -> builder.jdbcTemplate(jdbcTemplate)131 .sqlResource("classpath:com/consol/citrus/dsl/runner/script.sql"));132 }133 };134 TestCase test = builder.getTestCase();135 Assert.assertEquals(test.getActionCount(), 1);136 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLAction.class);137 Assert.assertEquals(test.getActiveAction().getClass(), ExecuteSQLAction.class);138 ExecuteSQLAction action = (ExecuteSQLAction)test.getActions().get(0);139 Assert.assertEquals(action.getName(), "sql");140 Assert.assertEquals(action.isIgnoreErrors(), false);141 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);142 Assert.assertEquals(action.getSqlResourcePath(), "classpath:com/consol/citrus/dsl/runner/script.sql");143 verify(jdbcTemplate).execute("TEST_STMT_1");144 verify(jdbcTemplate).execute("TEST_STMT_2");145 verify(jdbcTemplate).execute("TEST_STMT_3");146 }147}...

Full Screen

Full Screen

Source:ExecuteSQLActionTest.java Github

copy

Full Screen

...27import static org.mockito.Mockito.*;28/**29 * @author Christoph Deppisch30 */31public class ExecuteSQLActionTest extends AbstractTestNGUnitTest {32 private static final String DB_STMT_1 = "DELETE * FROM ERRORS WHERE STATUS='resolved'";33 private static final String DB_STMT_2 = "DELETE * FROM CONFIGURATION WHERE VERSION=1";34 private ExecuteSQLAction executeSQLAction;35 36 private JdbcTemplate jdbcTemplate = Mockito.mock(JdbcTemplate.class);37 private PlatformTransactionManager transactionManager = Mockito.mock(PlatformTransactionManager.class);38 @BeforeMethod39 public void setUp() {40 executeSQLAction = new ExecuteSQLAction();41 executeSQLAction.setJdbcTemplate(jdbcTemplate);42 }43 44 @Test45 public void testSQLExecutionWithInlineStatements() {46 List<String> stmts = new ArrayList<>();47 stmts.add(DB_STMT_1);48 stmts.add(DB_STMT_2);49 50 executeSQLAction.setStatements(stmts);51 52 reset(jdbcTemplate);53 54 executeSQLAction.execute(context);...

Full Screen

Full Screen

Source:HealthcheckTest.java Github

copy

Full Screen

...7import org.testng.annotations.Test;8import com.consol.citrus.annotations.CitrusTest;9import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;10import static com.consol.citrus.actions.EchoAction.Builder.echo;11import static com.consol.citrus.actions.ExecuteSQLAction.Builder.sql;12import static com.consol.citrus.http.actions.HttpActionBuilder.http;13import static com.consol.citrus.validation.xml.XpathMessageValidationContext.Builder.xpath;14/**15 * This is a sample Java DSL Citrus integration test.16 *17 * @author Citrus18 */19@Test20public class HealthcheckTest extends TestNGCitrusSpringSupport {21 @Autowired22 private HttpClient secondHandApiEndpoint;23 @Autowired24 private BasicDataSource secondHandApiDataSource;25 @CitrusTest...

Full Screen

Full Screen

ExecuteSQLAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.springframework.beans.factory.annotation.Autowired;4import org.springframework.jdbc.core.JdbcTemplate;5import org.testng.annotations.Test;6public class ExecuteSQLActionIT extends TestNGCitrusTestDesigner {7 private JdbcTemplate jdbcTemplate;8 public void executeSQLActionIT() {9 executeSQL(jdbcTemplate)10 .statement("insert into person (id, name) values (1, 'John')")11 .statement("insert into person (id, name) values (2, 'Jane')")12 .statement("insert into person (id, name) values (3, 'Jack')")13 .statement("insert into person (id, name) values (4, 'Jill')");14 executeSQL(jdbcTemplate)15 .statement("select * from person where name like 'J%'")16 .validate("id", "1", "2", "3", "4")17 .validate("name", "John", "Jane", "Jack", "Jill");18 executeSQL(jdbcTemplate)19 .statement("select * from person where name like 'J%'")20 .extract("id", "name")21 .validate("id", "1", "2", "3", "4")22 .validate("name", "John", "Jane", "Jack", "Jill");23 }24}

Full Screen

Full Screen

ExecuteSQLAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.actions.ExecuteSQLAction;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import com.consol.citrus.jdbc.message.JdbcMessage;5import org.springframework.jdbc.core.JdbcTemplate;6import org.springframework.jdbc.datasource.DriverManagerDataSource;7import org.testng.annotations.Test;8public class ExecuteSQLActionSample extends TestNGCitrusTestDesigner {9 public void test() {10 DriverManagerDataSource dataSource = new DriverManagerDataSource();11 dataSource.setDriverClassName("org.hsqldb.jdbcDriver");12 dataSource.setUrl("jdbc:hsqldb:mem:testdb");13 dataSource.setUsername("sa");14 dataSource.setPassword("");15 JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);16 jdbcTemplate.execute("CREATE TABLE TEST_TABLE (ID INTEGER, NAME VARCHAR(255))");17 jdbcTemplate.execute("INSERT INTO TEST_TABLE (ID, NAME) VALUES (1, 'Foo')");18 jdbcTemplate.execute("INSERT INTO TEST_TABLE (ID, NAME) VALUES (2, 'Bar')");19 executeSQL(dataSource)20 .statement("SELECT * FROM TEST_TABLE")21 .validate("ID", "1")22 .validate("NAME", "Foo")23 .validate("ID", "2")24 .validate("NAME", "Bar")25 .extract("ID", "name")26 .message(JdbcMessage.resultSet());27 }28}29package com.consol.citrus.samples;30import com.consol.citrus.actions.ExecuteSQLQueryAction;31import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;32import com.consol.citrus.jdbc.message.JdbcMessage;33import org.springframework.jdbc.core.JdbcTemplate;34import org.springframework.jdbc.datasource.DriverManagerDataSource;35import org.testng.annotations.Test;36public class ExecuteSQLQueryActionSample extends TestNGCitrusTestDesigner {37 public void test() {38 DriverManagerDataSource dataSource = new DriverManagerDataSource();39 dataSource.setDriverClassName("org.hsqldb.jdbcDriver");40 dataSource.setUrl("jdbc:hsqldb:mem:testdb");41 dataSource.setUsername("sa");42 dataSource.setPassword("");43 JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);44 jdbcTemplate.execute("CREATE TABLE TEST_TABLE (ID INTEGER, NAME VARCHAR(255))");45 jdbcTemplate.execute("INSERT INTO TEST_TABLE (ID, NAME) VALUES (

Full Screen

Full Screen

ExecuteSQLAction

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.runner.TestRunner;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.testng.annotations.Test;4public class 4 extends TestNGCitrusTestDesigner {5public void 4() {6TestRunner runner = this.getTestRunner();7ExecuteSQLAction executeSQLAction = new ExecuteSQLAction();8executeSQLAction.setDataSource(dataSource);9executeSQLAction.setSqlResourcePath("classpath:sql/insert.sql");10executeSQLAction.setVariable("id", "citrus:randomNumber(10)");11executeSQLAction.setVariable("name", "citrus:concat('Name_', citrus:randomNumber(5))");12executeSQLAction.setVariable("description", "citrus:concat('Description_', citrus:randomNumber(5))");13runner.run(executeSQLAction);14}15}16import com.consol.citrus.dsl.runner.TestRunner;17import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;18import org.testng.annotations.Test;19public class 5 extends TestNGCitrusTestDesigner {20public void 5() {21TestRunner runner = this.getTestRunner();22ExecuteSQLAction executeSQLAction = new ExecuteSQLAction();23executeSQLAction.setDataSource(dataSource);24executeSQLAction.setSqlResourcePath("classpath:sql/insert.sql");25executeSQLAction.setVariable("id", "citrus:randomNumber(10)");26executeSQLAction.setVariable("name", "citrus:concat('Name_', citrus:randomNumber(5))");27executeSQLAction.setVariable("description", "citrus:concat('Description_', citrus:randomNumber(5))");28runner.run(executeSQLAction);29}30}31import com.consol.citrus.dsl.runner.TestRunner;32import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;33import org.testng.annotations.Test;34public class 6 extends TestNGCitrusTestDesigner {35public void 6() {

Full Screen

Full Screen

ExecuteSQLAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.actions.ExecuteSQLAction;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import org.springframework.beans.factory.annotation.Autowired;5import org.springframework.jdbc.core.JdbcTemplate;6import org.testng.annotations.Test;7public class ExecuteSQLActionDemo extends TestNGCitrusTestDesigner {8 private JdbcTemplate jdbcTemplate;9 public void executeSQLActionDemo() {10 variable("sqlQuery", "select * from user");11 echo("Executing SQL query: ${sqlQuery}");12 executeSQL(new ExecuteSQLAction.Builder()13 .jdbcTemplate(jdbcTemplate)14 .sqlQuery("${sqlQuery}")15 .build());16 echo("Execution of SQL query: ${sqlQuery} is done");17 }18}

Full Screen

Full Screen

ExecuteSQLAction

Using AI Code Generation

copy

Full Screen

1public class ExecuteSQLActionDemo {2 public static void main(String[] args) {3 Citrus citrus = Citrus.newInstance();4 TestCase testCase = citrus.createTestCase();5 ExecuteSQLAction executeSQLAction = new ExecuteSQLAction();6 executeSQLAction.setDriverClassName("com.mysql.jdbc.Driver");7 executeSQLAction.setUsername("root");8 executeSQLAction.setPassword("root");9 executeSQLAction.setSqlResourcePath("classpath:sql/create.sql");10 testCase.addTestAction(executeSQLAction);11 testCase.execute();12 }13}14Executing SQL statement: CREATE TABLE IF NOT EXISTS CUSTOMER ( ID INTEGER NOT NULL AUTO_INCREMENT, NAME VARCHAR(100) NOT NULL, AGE INTEGER, PRIMARY KEY (ID) );15Executing SQL statement: INSERT INTO CUSTOMER (NAME, AGE) VALUES ('John', 25);16Executing SQL statement: INSERT INTO CUSTOMER (NAME, AGE) VALUES ('Jane', 28);17Executing SQL statement: INSERT INTO CUSTOMER (NAME, AGE) VALUES ('Richard', 21);18Executing SQL statement: INSERT INTO CUSTOMER (NAME, AGE) VALUES ('Mark', 35);

Full Screen

Full Screen

ExecuteSQLAction

Using AI Code Generation

copy

Full Screen

1public class 4.java {2 public static void main(String[] args) {3 Citrus citrus = Citrus.newInstance();4 TestCase testCase = citrus.createTestCase("ExecuteSQLActionTest");5 testCase.add(new ExecuteSQLAction.Builder()6 .dataSource(dataSource)7 .statement("INSERT INTO CUSTOMER (ID, FIRSTNAME, LASTNAME) VALUES (1, 'John', 'Smith')")8 .build());9 citrus.run(testCase);10 }11}

Full Screen

Full Screen

ExecuteSQLAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import com.consol.citrus.testng.CitrusParameters;6import org.testng.annotations.Test;7public class ExecuteSQLActionJavaIT extends JUnit4CitrusTestDesigner {8 @CitrusParameters("param1")9 public void executeSQLActionJavaIT() {10 variable("query", "SELECT * FROM USERS WHERE ID = 1");11 variable("result", "empty");12 executeSQL(dataSource("myDataSource"), sql("query"), result("result"));13 echo("${result}");14 }15}16package com.consol.citrus.samples;17import com.consol.citrus.annotations.CitrusTest;18import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;19import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;20import com.consol.citrus.testng.CitrusParameters;21import org.testng.annotations.Test;22public class ExecuteSQLQueryActionJavaIT extends JUnit4CitrusTestDesigner {23 @CitrusParameters("param1")24 public void executeSQLQueryActionJavaIT() {25 variable("query", "SELECT * FROM USERS WHERE ID = 1");26 variable("result", "empty");27 executeSQLQuery(dataSource("myDataSource"), sql("query"), result("result"));28 echo("${result}");29 }30}31package com.consol.citrus.samples;32import com.consol.citrus.annotations.CitrusTest;33import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;34import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;35import com.consol.citrus.testng.Citrus

Full Screen

Full Screen

ExecuteSQLAction

Using AI Code Generation

copy

Full Screen

1public class 4 extends TestNGCitrusTestDesigner {2 public void configure() {3 executeSQL(dataSource)4 .statement("INSERT INTO CUSTOMER (CUSTOMER_ID, FIRSTNAME, LASTNAME) VALUES (1, 'John', 'Doe')")5 .statement("INSERT INTO CUSTOMER (CUSTOMER_ID, FIRSTNAME, LASTNAME) VALUES (2, 'Jane', 'Doe')")6 .statement("INSERT INTO CUSTOMER (CUSTOMER_ID, FIRSTNAME, LASTNAME) VALUES (3, 'James', 'Doe')")7 .statement("INSERT INTO CUSTOMER (CUSTOMER_ID, FIRSTNAME, LASTNAME) VALUES (4, 'Jack', 'Doe')")8 .statement("INSERT INTO CUSTOMER (CUSTOMER_ID, FIRSTNAME, LASTNAME) VALUES (5, 'Jill', 'Doe')");9 }10}

Full Screen

Full Screen

ExecuteSQLAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.actions.ExecuteSQLAction;3import com.consol.citrus.context.TestContext;4import com.consol.citrus.db.driver.JdbcConnection;5import com.consol.citrus.db.driver.Statement;6import com.consol.citrus.exceptions.TestCaseFailedException;7import com.consol.citrus.testng.AbstractTestNGUnitTest;8import org.mockito.Mockito;9import org.testng.annotations.Test;10import java.sql.SQLException;11import java.util.Arrays;12import java.util.Collections;13import static org.mockito.Mockito.*;14public class ExecuteSQLActionTest extends AbstractTestNGUnitTest {15 private JdbcConnection connection = Mockito.mock(JdbcConnection.class);16 private Statement statement = Mockito.mock(Statement.class);17 private TestContext context = new TestContext();18 public void testExecuteSQLAction() throws SQLException {19 when(connection.createStatement()).thenReturn(statement);20 ExecuteSQLAction executeSQLAction = new ExecuteSQLAction.Builder()21 .statements(Collections.singletonList("SELECT * FROM TEST"))22 .connection(connection)23 .build();24 executeSQLAction.execute(context);25 verify(statement).execute("SELECT * FROM TEST");26 }27 public void testExecuteSQLActionWithParameters() throws SQLException {28 when(connection.createStatement()).thenReturn(statement);29 ExecuteSQLAction executeSQLAction = new ExecuteSQLAction.Builder()30 .statements(Collections.singletonList("SELECT * FROM TEST WHERE ID = ?"))31 .connection(connection)32 .parameters(Collections.singletonList("123"))33 .build();34 executeSQLAction.execute(context);35 verify(statement).execute("SELECT * FROM TEST WHERE ID = ?", Collections.singletonList("123"));36 }37 public void testExecuteSQLActionWithParametersFromContext() throws SQLException {38 when(connection.createStatement()).thenReturn(statement);39 ExecuteSQLAction executeSQLAction = new ExecuteSQLAction.Builder()40 .statements(Collections.singletonList("SELECT * FROM TEST WHERE ID = ?"))41 .connection(connection)42 .parameters(Collections.singletonList("${id}"))43 .build();44 context.setVariable("id", "123");45 executeSQLAction.execute(context);46 verify(statement).execute("SELECT * FROM TEST WHERE ID = ?", Collections.singletonList("123"));47 }48 public void testExecuteSQLActionWithMultipleStatements() throws SQLException {49 when(connection.createStatement()).thenReturn(statement);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful