Best Citrus code snippet using com.consol.citrus.dsl.builder.ExecuteSQLBuilder
Source:ExecuteSQLBuilder.java
...28 *29 * @author Christoph Deppisch30 * @since 2.331 */32public class ExecuteSQLBuilder extends AbstractTestActionBuilder<ExecuteSQLAction> {33 /**34 * Constructor using action field.35 * @param action36 */37 public ExecuteSQLBuilder(ExecuteSQLAction action) {38 super(action);39 }40 /**41 * Default constructor.42 */43 public ExecuteSQLBuilder() {44 super(new ExecuteSQLAction());45 }46 /**47 * Sets the Spring JDBC template to use.48 * @param jdbcTemplate49 * @return50 */51 public ExecuteSQLBuilder jdbcTemplate(JdbcTemplate jdbcTemplate) {52 action.setJdbcTemplate(jdbcTemplate);53 return this;54 }55 /**56 * Sets the transaction manager to use.57 * @param transactionManager58 * @return59 */60 public ExecuteSQLBuilder transactionManager(PlatformTransactionManager transactionManager) {61 action.setTransactionManager(transactionManager);62 return this;63 }64 /**65 * Sets the transaction timeout to use.66 * @param transactionTimeout67 * @return68 */69 public ExecuteSQLBuilder transactionTimeout(int transactionTimeout) {70 action.setTransactionTimeout(String.valueOf(transactionTimeout));71 return this;72 }73 /**74 * Sets the transaction timeout to use.75 * @param transactionTimeout76 * @return77 */78 public ExecuteSQLBuilder transactionTimeout(String transactionTimeout) {79 action.setTransactionTimeout(transactionTimeout);80 return this;81 }82 /**83 * Sets the transaction isolation level to use.84 * @param isolationLevel85 * @return86 */87 public ExecuteSQLBuilder transactionIsolationLevel(String isolationLevel) {88 action.setTransactionIsolationLevel(isolationLevel);89 return this;90 }91 /**92 * Sets the SQL data source.93 * @param dataSource94 * @return95 */96 public ExecuteSQLBuilder dataSource(DataSource dataSource) {97 action.setDataSource(dataSource);98 return this;99 }100 /**101 * List of statements to execute. Declared inline in the test case.102 * @param statements103 */104 public ExecuteSQLBuilder statements(List<String> statements) {105 action.getStatements().addAll(statements);106 return this;107 }108 /**109 * Adds a new statement to the list of SQL executions.110 * @param sql111 * @return112 */113 public ExecuteSQLBuilder statement(String sql) {114 action.getStatements().add(sql);115 return this;116 }117 /**118 * Setter for external file resource containing the SQL statements to execute.119 * @param sqlResource120 */121 public ExecuteSQLBuilder sqlResource(Resource sqlResource) {122 statements(SqlUtils.createStatementsFromFileResource(sqlResource));123 return this;124 }125 /**126 * Setter for external file resource containing the SQL statements to execute.127 * @param filePath128 */129 public ExecuteSQLBuilder sqlResource(String filePath) {130 action.setSqlResourcePath(filePath);131 return this;132 }133 /**134 * Ignore errors during execution.135 * @param ignoreErrors boolean flag to set136 */137 public ExecuteSQLBuilder ignoreErrors(boolean ignoreErrors) {138 action.setIgnoreErrors(ignoreErrors);139 return this;140 }141}...
Source:ExecuteQueryIT.java
1/*2 * Copyright 2006-2016 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.samples.todolist;17import com.consol.citrus.annotations.CitrusTest;18import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;19import com.consol.citrus.jdbc.message.JdbcMessage;20import com.consol.citrus.jdbc.server.JdbcServer;21import com.consol.citrus.message.MessageType;22import javax.sql.DataSource;23import org.springframework.beans.factory.annotation.Autowired;24import org.springframework.core.io.ClassPathResource;25import org.testng.annotations.Test;26/**27 * @author Christoph Deppisch28 */29public class ExecuteQueryIT extends TestNGCitrusTestRunner {30 @Autowired31 private JdbcServer jdbcServer;32 @Autowired33 private DataSource dataSource;34 @Test35 @CitrusTest36 public void testCreateTable() {37 async()38 .actions(sql(executeSQLbuilder -> executeSQLbuilder39 .dataSource(dataSource)40 .statement("CREATE TABLE IF NOT EXISTS todo_entries (id VARCHAR(50), title VARCHAR(255), description VARCHAR(255), done BOOLEAN)")));41 receive(receiveMessageBuilder -> receiveMessageBuilder42 .endpoint(jdbcServer)43 .messageType(MessageType.JSON)44 .message(JdbcMessage.execute("CREATE TABLE IF NOT EXISTS todo_entries (id VARCHAR(50), title VARCHAR(255), description VARCHAR(255), done BOOLEAN)")));45 send(sendMessageBuilder -> sendMessageBuilder46 .endpoint(jdbcServer)47 .message(JdbcMessage.success()));48 }49 @Test50 @CitrusTest51 public void testSelect() {52 variable("todoId", "citrus:randomUUID()");53 variable("todoName", "citrus:concat('todo_', citrus:randomNumber(4))");54 variable("todoDescription", "Description: ${todoName}");55 async()56 .actions(query(exeucteSQLBuilder-> exeucteSQLBuilder57 .dataSource(dataSource)58 .statement("SELECT id, title, description FROM todo_entries")59 .validate("id", "${todoId}")60 .validate("title", "${todoName}")61 .validate("description", "${todoDescription}")));62 receive(receiveMessageBuilder -> receiveMessageBuilder63 .endpoint(jdbcServer)64 .messageType(MessageType.JSON)65 .message(JdbcMessage.execute("SELECT id, title, description FROM todo_entries")));66 send(sendMessageBuilder -> sendMessageBuilder67 .endpoint(jdbcServer)68 .messageType(MessageType.JSON)69 .message(JdbcMessage.success()70 .dataSet(new ClassPathResource("dataset.json"))));71 }72 @Test73 @CitrusTest74 public void testDelete() {75 String sql = "DELETE FROM todo_entries";76 async()77 .actions(sql(executeSQLbuilder -> executeSQLbuilder78 .dataSource(dataSource)79 .statement(sql)));80 receive(receiveMessageBuilder -> receiveMessageBuilder81 .endpoint(jdbcServer)82 .messageType(MessageType.JSON)83 .message(JdbcMessage.execute(sql)));84 send(sendMessageBuilder -> sendMessageBuilder85 .endpoint(jdbcServer)86 .message(JdbcMessage.success().rowsUpdated(10)));87 }88 @Test89 @CitrusTest90 public void testDropTable() {91 String sql = "DROP TABLE todo_entries";92 async()93 .actions(sql(exeucteSQLBuilder -> exeucteSQLBuilder94 .dataSource(dataSource)95 .statement(sql)));96 receive(receiveMessageBuilder -> receiveMessageBuilder97 .endpoint(jdbcServer)98 .messageType(MessageType.JSON)99 .message(JdbcMessage.execute(sql)));100 send(sendMessageBuilder -> sendMessageBuilder101 .endpoint(jdbcServer)102 .message(JdbcMessage.success()));103 }104}...
Source:EndpointConfig.java
1/*2 * Copyright 2006-2017 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.samples.todolist;17import java.util.Collections;18import com.consol.citrus.container.SequenceAfterSuite;19import com.consol.citrus.container.SequenceBeforeSuite;20import com.consol.citrus.dsl.endpoint.CitrusEndpoints;21import com.consol.citrus.dsl.runner.TestRunner;22import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;23import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;24import com.consol.citrus.http.client.HttpClient;25import com.consol.citrus.xml.namespace.NamespaceContextBuilder;26import org.apache.commons.dbcp.BasicDataSource;27import org.springframework.context.annotation.Bean;28import org.springframework.context.annotation.Configuration;29import org.springframework.context.annotation.Import;30/**31 * @author Christoph Deppisch32 */33@Import(TodoAppAutoConfiguration.class)34@Configuration35public class EndpointConfig {36 @Bean37 public HttpClient todoClient() {38 return CitrusEndpoints39 .http()40 .client()41 .requestUrl("http://localhost:8080")42 .build();43 }44 @Bean45 public NamespaceContextBuilder namespaceContextBuilder() {46 NamespaceContextBuilder namespaceContextBuilder = new NamespaceContextBuilder();47 namespaceContextBuilder.setNamespaceMappings(Collections.singletonMap("xh", "http://www.w3.org/1999/xhtml"));48 return namespaceContextBuilder;49 }50 @Bean51 public SequenceBeforeSuite beforeSuite() {52 return new TestRunnerBeforeSuiteSupport() {53 @Override54 public void beforeSuite(TestRunner runner) {55 runner.sql(executeSQLBuilder -> executeSQLBuilder56 .dataSource(todoListDataSource())57 .statement("CREATE TABLE IF NOT EXISTS todo_entries (id VARCHAR(50), title VARCHAR(255), description VARCHAR(255), done BOOLEAN)"));58 }59 };60 }61 @Bean62 public SequenceAfterSuite afterSuite() {63 return new TestRunnerAfterSuiteSupport() {64 @Override65 public void afterSuite(TestRunner runner) {66 runner.sql(executeSQLBuilder -> executeSQLBuilder67 .dataSource(todoListDataSource())68 .statement("DELETE FROM todo_entries"));69 }70 };71 }72 @Bean(destroyMethod = "close")73 public BasicDataSource todoListDataSource() {74 BasicDataSource dataSource = new BasicDataSource();75 dataSource.setDriverClassName("org.hsqldb.jdbcDriver");76 dataSource.setUrl("jdbc:hsqldb:hsql://localhost:9099/testdb");77 dataSource.setUsername("sa");78 dataSource.setPassword("");79 dataSource.setInitialSize(1);80 dataSource.setMaxActive(5);81 dataSource.setMaxIdle(2);82 return dataSource;83 }84}...
ExecuteSQLBuilder
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import java.util.HashMap;3import org.testng.annotations.Test;4import com.consol.citrus.annotations.CitrusTest;5import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;6import com.consol.citrus.db.server.JdbcServer;7import com.consol.citrus.db.server.JdbcServerBuilder;8import com.consol.citrus.db.server.JdbcServerConfiguration;9import com.consol.citrus.db.server.JdbcServerConfigurationBuilder;10import com.consol.citrus.db.server.controller.QueryResultController;11import com.consol.citrus.db.server.controller.QueryResultControllerBuilder;12import com.consol.citrus.db.server.controller.ResultType;13import com.consol.citrus.db.server.controller.ResultSetController;14import com.consol.citrus.db.server.controller.ResultSetControllerBuilder;15public class ExecuteSQLBuilderTest extends TestNGCitrusTestRunner {16 public void testExecuteSQLBuilder() {17 .jdbcServer()18 .autoStart(true)19 .port(9999)20 .timeout(60000)21 .build();22 .queryResultController()23 .query("SELECT * FROM TEST")24 .resultType(ResultType.UPDATE_COUNT)25 .updateCount(1)26 .build();27 .resultSetController()28 .query("SELECT * FROM TEST")29 .columnNames(new String[] { "ID", "NAME" })30 .columnTypes(new String[] { "NUMBER", "VARCHAR2" })31 .data(new Object[][] { { 1, "Test" } })32 .build();33 .jdbcServer()34 .configuration(configuration)35 .controllers(new HashMap<String, QueryResultController>() {36 {37 put("queryResultController", queryResultController);38 put("resultSetController", resultSetController);39 }40 })41 .build();42 variable("jdbcServer", jdbcServer);43 executeSQLBuilder()44 .sql("SELECT * FROM TEST")45 .server("${jdbcServer}")46 .controller("queryResultController")47 .build();48 }49}
ExecuteSQLBuilder
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import java.util.HashMap;3import java.util.Map;4import com.consol.citrus.actions.ExecuteSQLAction;5import com.consol.citrus.container.SequenceBeforeTest;6import com.consol.citrus.dsl.testng.TestNGCitrusTest;7import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;8import com.consol.citrus.jdbc.message.JdbcMessageHeaders;9import com.consol.citrus.message.MessageType;10import org.springframework.jdbc.core.JdbcTemplate;11import org.springframework.jdbc.datasource.SingleConnectionDataSource;12import org.testng.annotations.Test;13public class ExecuteSQLBuilderTest extends TestNGCitrusTest {14 public void executeSQLBuilderTest() {15 run(new TestNGCitrusTestDesigner() {16 public void configure() {17 variable("tableName", "CITRUS_USER");18 variable("sqlQuery", "INSERT INTO ${tableName}(ID, NAME, LASTNAME) VALUES(1, 'John', 'Doe')");19 variable("sqlQuery2", "SELECT * FROM ${tableName}");20 singleConnectionDataSource("jdbcConnection", "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:db1", "sa", "");21 jdbcTemplate("jdbcTemplate", "jdbcConnection");22 executeSQL().sqlResource("classpath:com/consol/citrus/dsl/builder/create_table.sql");23 executeSQL()24 .sqlQuery("${sqlQuery}");25 executeSQL()26 .sqlQuery("${sqlQuery2}")27 .messageType(MessageType.PLAINTEXT)28 .header(JdbcMessageHeaders.SQL_RESULT_SET, "resultSet")29 .extractFromResultSet("resultSet", "id", "id")30 .extractFromResultSet("resultSet", "name", "name")31 .extractFromResultSet("resultSet", "lastname", "lastname");32 executeSQL()33 .sqlResource("classpath:com/consol/citrus/dsl/builder/delete_data.sql");34 executeSQL()35 .sqlResource("classpath:com/consol/citrus/dsl/builder/drop_table.sql");
ExecuteSQLBuilder
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.actions.ExecuteSQLAction;3import com.consol.citrus.dsl.builder.AbstractTestBuilder;4import com.consol.citrus.dsl.builder.BuilderSupport;5import com.consol.citrus.dsl.builder.DelegatingTestBuilder;6import com.consol.citrus.dsl.builder.SendBuilder;7import com.consol.citrus.dsl.builder.SendSoapMessageBuilder;8import com.consol.citrus.dsl.builder.VariableBuilder;9import com.consol.citrus.dsl.builder.VariablesBuilder;10import com.consol.citrus.dsl.builder.WhenBuilder;11import com.consol.citrus.dsl.builder.WhenConditionBuilder;12import com.consol.citrus.dsl.builder.WhenHttpActionBuilder;13import com.consol.citrus.dsl.builder.WhenSoapActionBuilder;14import com.consol.citrus.dsl.builder.WhenSoapResponseActionBuilder;15import com.consol.citrus.dsl.builder.WhenTimeoutActionBuilder;16import com.consol.citrus.dsl.builder.WhileBuilder;17import com.consol.citrus.exceptions.CitrusRuntimeException;18import com.consol.citrus.message.MessageType;19import com.consol.citrus.testng.AbstractTestNGUnitTest;20import org.springframework.core.io.Resource;21import org.testng.annotations.Test;22import java.util.ArrayList;23import java.util.List;24import static com.consol.citrus.actions.ExecuteSQLAction.Builder;25import static com.consol.citrus.actions.ExecuteSQLAction.Builder.sql;26import static com.consol.citrus.actions.ExecuteSQLAction.Builder.sqlResource;27import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statement;28import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statementData;29import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statementResource;30import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statementResourceData;31import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statementResourceDataBuilder;32import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statementResourceDataBuilderResource;33import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statementResourceDataResource;34import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statementResourceResource;35import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statementResourceBuilder;36import static com.consol.citrus.actions.ExecuteSQLAction.Builder.statementResourceBuilderResource;37import static com.consol
ExecuteSQLBuilder
Using AI Code Generation
1package com.consol.citrus.dsl;2import com.consol.citrus.dsl.builder.ExecuteSQLBuilder;3import com.consol.citrus.dsl.runner.TestRunner;4public class ExecuteSQLBuilderTest {5 public static void main(String[] args) {6 TestRunner runner = new TestRunner();7 runner.run(new ExecuteSQLBuilder()8 .statement("SELECT * FROM CUSTOMER")9 .validate("CUSTOMER_ID", "123")10 .validate("NAME", "John Doe")11 .validate("ADDRESS", "123 Main Street")12 .validate("CITY", "Anytown")13 .validate("STATE", "CA")14 .validate("ZIP", "12345")15 .validate("COUNTRY", "US"));16 }17}18package com.consol.citrus.dsl;19import com.consol.citrus.dsl.builder.ExecuteSQLBuilder;20import com.consol.citrus.dsl.runner.TestRunner;21public class ExecuteSQLBuilderTest {22 public static void main(String[] args) {23 TestRunner runner = new TestRunner();24 runner.run(new ExecuteSQLBuilder()25 .statement("SELECT * FROM CUSTOMER")26 .validate("CUSTOMER_ID", "123")27 .validate("NAME", "John Doe")28 .validate("ADDRESS", "123 Main Street")29 .validate("CITY", "Anytown")30 .validate("STATE", "CA")31 .validate("ZIP", "12345")32 .validate("COUNTRY", "US"));33 }34}35package com.consol.citrus.dsl;36import com.consol.citrus.dsl.builder.ExecuteSQLBuilder;37import com.consol.citrus.dsl.runner.TestRunner;38public class ExecuteSQLBuilderTest {39 public static void main(String[] args) {40 TestRunner runner = new TestRunner();41 runner.run(new ExecuteSQLBuilder()42 .statement("SELECT * FROM CUSTOMER")43 .validate("CUSTOMER_ID", "123")44 .validate("NAME", "John Doe")45 .validate("ADDRESS", "123 Main Street")46 .validate("CITY", "Anytown")47 .validate("STATE", "CA")48 .validate("ZIP", "12345")
ExecuteSQLBuilder
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.dsl.builder.AbstractTestContainerBuilder;3import com.consol.citrus.dsl.builder.BuilderSupport;4import com.consol.citrus.dsl.builder.DelegatingTestContainerBuilder;5import com.consol.citrus.dsl.builder.ExecuteSQLBuilder;6import com.consol.citrus.dsl.builder.TestActionBuilder;7import com.consol.citrus.dsl.builder.TestBehaviorBuilder;8import com.consol.citrus.dsl.builder.TestBuilder;9import com.consol.citrus.dsl.builder.TestRunner;10import com.consol.citrus.dsl.builder.TestRunnerAfterSuiteSupport;11import com.consol.citrus.dsl.builder.TestRunnerBeforeSuiteSupport;12import com.consol.citrus.dsl.builder.TestRunnerSupport;13import com.consol.citrus.dsl.builder.WhenTestBuilder;14import com.consol.citrus.dsl.design.TestDesigner;15import com.consol.citrus.dsl.design.TestDesignerAfterSuiteSupport;16import com.consol.citrus.dsl.design.TestDesignerBeforeSuiteSupport;17import com.consol.citrus.dsl.design.TestDesignerSupport;18import com.consol.citrus.dsl.runner.TestRunnerAfterSuite;19import com.consol.citrus.dsl.runner.TestRunnerBeforeSuite;20import com.consol.citrus.dsl.runner.TestRunnerImpl;21import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;22import com.consol.citrus.dsl.testng.TestNGCitrusTestDesignerSupport;23import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;24import com.consol.citrus.dsl.testng.TestNGCitrusTestRunnerSupport;25import com.consol.citrus.exceptions.CitrusRuntimeException;26import com.consol.citrus.functions.Function;27import com.consol.citrus.functions.FunctionLibrary;28import com.consol.citrus.report.TestActionListeners;29import com.consol.citrus.report.TestListeners;30import com.consol.citrus.report.TestSuiteListeners;31import com.consol.citrus.report.TestSuiteReporters;32import com.consol.citrus.report.TestSuiteReporter;33import com.consol.citrus.report.TestReporter;34import com.consol.citrus.report.TestListeners;35import com.consol.citrus.report.TestActionListeners;36import com.consol.citrus.report.TestSuiteListeners;37import com.consol.citrus.report.TestReporter;38import com.consol.citrus.report.TestSuiteReporters;39import
ExecuteSQLBuilder
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import org.testng.annotations.Test;3import org.testng.annotations.BeforeTest;4import org.testng.annotations.AfterTest;5import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;6public class ExecuteSQLBuilderTest extends TestNGCitrusTestDesigner {7 public void executeSQLBuilderTest() {8 executeSQLBuilder()9 .driver("com.mysql.jdbc.Driver")10 .username("root")11 .password("root")12 .statement("select * from employees");13 }14}15[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ 3 ---
ExecuteSQLBuilder
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.dsl.builder.ExecuteSQLBuilder;3import com.consol.citrus.dsl.builder.ExecuteSQLBuilderSupport;4import com.consol.citrus.dsl.builder.DelegatingTestActionBuilder;5import com.consol.citrus.dsl.runner.TestRunner;6import com.consol.citrus.sql.actions.ExecuteSQLAction;7public class ExecuteSQLBuilder extends DelegatingTestActionBuilder<ExecuteSQLAction, ExecuteSQLBuilderSupport> implements ExecuteSQLBuilderSupport {8 public ExecuteSQLBuilder(TestRunner runner) {9 super(new ExecuteSQLAction(), runner);10 }11 public ExecuteSQLBuilder sqlResource(String sqlResource) {12 action.setSqlResource(sqlResource);13 return this;14 }15 public ExecuteSQLBuilder dataSource(String dataSource) {16 action.setDataSource(dataSource);17 return this;18 }19 public ExecuteSQLBuilder sqlStatement(String sqlStatement) {20 action.setSqlStatement(sqlStatement);21 return this;22 }23 public ExecuteSQLBuilder statementParameter(String statementParameter) {24 action.setStatementParameter(statementParameter);25 return this;26 }27 public ExecuteSQLBuilder statementParameters(String statementParameters) {28 action.setStatementParameters(statementParameters);29 return this;30 }31 public ExecuteSQLBuilder statementParameters(String[] statementParameters) {32 action.setStatementParameters(statementParameters);33 return this;34 }35 public ExecuteSQLBuilder statementParameters(Object[] statementParameters) {36 action.setStatementParameters(statementParameters);37 return this;38 }
ExecuteSQLBuilder
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import java.util.HashMap;3import java.util.Map;4import com.consol.citrus.dsl.builder.ExecuteSQLBuilder;5import com.consol.citrus.dsl.runner.TestRunner;6import com.consol.citrus.message.MessageType;7import com.consol.citrus.testng.AbstractTestNGUnitTest;8import org.mockito.Mockito;9import org.springframework.jdbc.core.JdbcTemplate;10import org.springframework.jdbc.datasource.SingleConnectionDataSource;11import org.testng.Assert;12import org.testng.annotations.Test;13public class ExecuteSQLBuilderTest extends AbstractTestNGUnitTest {14 public void testExecuteSQLBuilder() {15 JdbcTemplate jdbcTemplate = Mockito.mock(JdbcTemplate.class);16 Mockito.when(jdbcTemplate.queryForList(Mockito.anyString())).thenReturn(new HashMap<String, Object>());17 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext) {18 public void execute() {19 sql(new ExecuteSQLBuilder() {20 public void configure() {21 jdbcTemplate(jdbcTemplate);22 statement("select * from test");23 variable("result", "test");24 messageType(MessageType.PLAINTEXT);25 }26 });27 }28 };29 Assert.assertEquals(builder.getTestActionCount(), 1);30 Assert.assertEquals(builder.getLastTestAction().getClass(), ExecuteSQLBuilder.ExecuteSQLAction.class);31 Assert.assertEquals(builder.getVariable("result"), "test");32 Assert.assertEquals(builder.getLastTestAction().getMessageType(), MessageType.PLAINTEXT);33 }34 public void testExecuteSQLBuilderWithDataSource() {35 JdbcTemplate jdbcTemplate = Mockito.mock(JdbcTemplate.class);36 Mockito.when(jdbcTemplate.queryForList(Mockito.anyString())).thenReturn(new HashMap<String, Object>());37 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext) {38 public void execute() {39 sql(new ExecuteSQLBuilder() {40 public void configure() {41 dataSource(new SingleConnectionDataSource());42 statement("select * from test");43 variable("result", "test");44 messageType(MessageType.PLAINTEXT);45 }46 });47 }48 };49 Assert.assertEquals(builder.getTestActionCount(), 1);50 Assert.assertEquals(builder.getLastTestAction().getClass(), ExecuteSQLBuilder.ExecuteSQLAction.class);51 Assert.assertEquals(builder.getVariable("result"), "test");52 Assert.assertEquals(builder.getLastTestAction().getMessageType(), MessageType.PLAINTEXT);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!