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

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

Source:AbstractDatabaseConnectingTestAction.java Github

copy

Full Screen

...31 * access to a {@link javax.sql.DataSource}.32 * 33 * @author Christoph Deppisch34 */35public abstract class AbstractDatabaseConnectingTestAction extends JdbcDaoSupport implements TestAction {36 /**37 * Logger38 */39 protected final Logger log = LoggerFactory.getLogger(this.getClass());40 41 /** Text describing the test action */42 private String description;43 /** TestAction name injected as spring bean name */44 private String name = this.getClass().getSimpleName();45 46 /** SQL file resource path */47 protected String sqlResourcePath;48 49 /** List of SQL statements */50 protected List<String> statements = new ArrayList<>();51 52 /** This actions explicit test actor */53 private TestActor actor;54 /** Optional transaction manager */55 private PlatformTransactionManager transactionManager;56 private String transactionTimeout = String.valueOf(TransactionDefinition.TIMEOUT_DEFAULT);57 private String transactionIsolationLevel = "ISOLATION_DEFAULT";58 /**59 * Do basic logging and delegate execution to subclass.60 */61 public void execute(TestContext context) {62 doExecute(context);63 }64 65 /**66 * Subclasses may add custom execution logic here.67 */68 public abstract void doExecute(TestContext context);69 /**70 * Checks if this test action is disabled. Delegates to test actor defined71 * for this test action by default. Subclasses may add additional disabled logic here.72 * 73 * @param context the current test context.74 * @return75 */76 public boolean isDisabled(TestContext context) {77 if (actor != null) {78 return actor.isDisabled();79 } else {80 return false;81 }82 }83 /**84 * Reads SQL statements from external file resource. File resource can hold several85 * multi-line statements and comments.86 *87 * @param context the current test context.88 * @return list of SQL statements.89 */90 protected List<String> createStatementsFromFileResource(TestContext context) {91 return SqlUtils.createStatementsFromFileResource(new PathMatchingResourcePatternResolver()92 .getResource(context.replaceDynamicContentInString(sqlResourcePath)));93 }94 /**95 * Reads SQL statements from external file resource. File resource can hold several96 * multi-line statements and comments.97 *98 * @param context the current test context.99 * @return list of SQL statements.100 */101 protected List<String> createStatementsFromFileResource(TestContext context, SqlUtils.LastScriptLineDecorator lineDecorator) {102 return SqlUtils.createStatementsFromFileResource(new PathMatchingResourcePatternResolver()103 .getResource(context.replaceDynamicContentInString(sqlResourcePath)), lineDecorator);104 }105 106 /**107 * Gets this action's description.108 * @return the description109 */110 public String getDescription() {111 return description;112 }113 /**114 * Sets this test action's description.115 * @param description the description to set116 */117 public AbstractDatabaseConnectingTestAction setDescription(String description) {118 this.description = description;119 return this;120 }121 /**122 * Gets the name of the test action.123 * @return the test action name.124 */125 public String getName() {126 return name;127 }128 /**129 * Sets this test action's name.130 */131 public AbstractDatabaseConnectingTestAction setName(String name) {132 this.name = name;133 return this;134 }135 136 /**137 * List of statements to execute. Declared inline in the test case. 138 * @param statements139 */140 public AbstractDatabaseConnectingTestAction setStatements(List<String> statements) {141 this.statements = statements;142 return this;143 }144 145 /**146 * Setter for external file resource containing the SQL statements to execute.147 * @param sqlResource148 */149 public AbstractDatabaseConnectingTestAction setSqlResourcePath(String sqlResource) {150 this.sqlResourcePath = sqlResource;151 return this;152 }153 /**154 * Gets the sqlResource.155 * @return the sqlResource156 */157 public String getSqlResourcePath() {158 return sqlResourcePath;159 }160 /**161 * Gets the statements.162 * @return the statements163 */164 public List<String> getStatements() {165 return statements;166 }167 /**168 * Gets the transactionManager.169 *170 * @return171 */172 public PlatformTransactionManager getTransactionManager() {173 return transactionManager;174 }175 /**176 * Sets the transactionManager.177 *178 * @param transactionManager179 */180 public void setTransactionManager(PlatformTransactionManager transactionManager) {181 this.transactionManager = transactionManager;182 }183 /**184 * Gets the transactionTimeout.185 *186 * @return187 */188 public String getTransactionTimeout() {189 return transactionTimeout;190 }191 /**192 * Sets the transactionTimeout.193 *194 * @param transactionTimeout195 */196 public void setTransactionTimeout(String transactionTimeout) {197 this.transactionTimeout = transactionTimeout;198 }199 /**200 * Gets the transactionIsolationLevel.201 *202 * @return203 */204 public String getTransactionIsolationLevel() {205 return transactionIsolationLevel;206 }207 /**208 * Sets the transactionIsolationLevel.209 *210 * @param transactionIsolationLevel211 */212 public void setTransactionIsolationLevel(String transactionIsolationLevel) {213 this.transactionIsolationLevel = transactionIsolationLevel;214 }215 /**216 * Gets the actor.217 * @return the actor the actor to get.218 */219 public TestActor getActor() {220 return actor;221 }222 /**223 * Sets the actor.224 * @param actor the actor to set225 */226 public AbstractDatabaseConnectingTestAction setActor(TestActor actor) {227 this.actor = actor;228 return this;229 }230}...

Full Screen

Full Screen

Source:AbstractDatabaseConnectingTestActionFactoryBean.java Github

copy

Full Screen

1package com.consol.citrus.config.xml;2import javax.sql.DataSource;3import java.util.List;4import com.consol.citrus.actions.AbstractDatabaseConnectingTestAction;5import org.springframework.jdbc.core.JdbcTemplate;6import org.springframework.transaction.PlatformTransactionManager;7/**8 * @author Christoph Deppisch9 */10public abstract class AbstractDatabaseConnectingTestActionFactoryBean<T extends AbstractDatabaseConnectingTestAction, B extends AbstractDatabaseConnectingTestAction.Builder<T, B>> extends AbstractTestActionFactoryBean<T, B> {11 /**12 * Sets the Jdbc template.13 * @param jdbcTemplate14 */15 public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {16 getBuilder().jdbcTemplate(jdbcTemplate);17 }18 /**19 * Sets the data source.20 * @param dataSource21 */22 public void setDataSource(DataSource dataSource) {23 getBuilder().dataSource(dataSource);24 }...

Full Screen

Full Screen

AbstractDatabaseConnectingTestAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.actions.AbstractDatabaseConnectingTestAction;3import com.consol.citrus.context.TestContext;4import com.consol.citrus.exceptions.CitrusRuntimeException;5import com.consol.citrus.jdbc.actions.JdbcAction;6import com.consol.citrus.jdbc.actions.JdbcExecuteAction;7import com.consol.citrus.jdbc.actions.JdbcQueryAction;8import com.consol.citrus.jdbc.message.JdbcMessage;9import com.consol.citrus.message.Message;10import com.consol.citrus.message.MessageType;11import com.consol.citrus.util.FileUtils;12import com.consol.citrus.validation.MessageValidator;13import com.consol.citrus.validation.context.ValidationContext;14import com.consol.citrus.validation.script.ScriptValidationContext;15import com.consol.citrus.validation.script.ScriptValidationContextBuilder;16import com.consol.citrus.validation.xml.XmlMessageValidationContext;17import com.consol.citrus.validation.xml.XmlMessageValidationContextBuilder;18import org.slf4j.Logger;19import org.slf4j.LoggerFactory;20import org.springframework.core.io.Resource;21import org.springframework.jdbc.core.JdbcTemplate;22import org.springframework.jdbc.datasource.SimpleDriverDataSource;23import org.springframework.util.StringUtils;24import javax.sql.DataSource;25import java.io.IOException;26import java.sql.Driver;27import java.util.HashMap;28import java.util.Map;

Full Screen

Full Screen

AbstractDatabaseConnectingTestAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.testng.CitrusParameters;4import com.consol.citrus.testng.CitrusXmlTestNG;5import org.testng.annotations.Test;6public class AbstractDatabaseConnectingTestActionTest extends CitrusXmlTestNG {7 @CitrusParameters({"name","age"})8 public void testAction() {9 executeTest();10 }11}12package com.consol.citrus.actions;13import com.consol.citrus.annotations.CitrusTest;14import com.consol.citrus.testng.CitrusParameters;15import com.consol.citrus.testng.CitrusXmlTestNG;16import org.testng.annotations.Test;17public class AbstractTestActionTest extends CitrusXmlTestNG {18 @CitrusParameters({"name","age"})19 public void testAction() {20 executeTest();21 }22}

Full Screen

Full Screen

AbstractDatabaseConnectingTestAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.testng.CitrusParameters;4import org.springframework.beans.factory.annotation.Autowired;5import org.springframework.core.io.ClassPathResource;6import org.springframework.jdbc.core.JdbcTemplate;7import org.springframework.jdbc.datasource.SimpleDriverDataSource;8import org.springframework.test.context.ContextConfiguration;9import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;10import org.testng.annotations.Test;11import javax.sql.DataSource;12import java.sql.Driver;13import java.util.List;14import java.util.Map;15@ContextConfiguration(classes = AbstractDatabaseConnectingTestActionTest.TestConfig.class)16public class AbstractDatabaseConnectingTestActionTest extends AbstractTestNGSpringContextTests {17 private DataSource dataSource;18 public void testAbstractDatabaseConnectingTestAction() {19 AbstractDatabaseConnectingTestAction abstractDatabaseConnectingTestAction = new AbstractDatabaseConnectingTestAction() {20 protected void executeTest() {21 JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);22 List<Map<String, Object>> result = jdbcTemplate.queryForList("SELECT * FROM test_table");23 System.out.println(result);24 }25 };26 abstractDatabaseConnectingTestAction.setDataSource(dataSource);27 abstractDatabaseConnectingTestAction.execute();28 }29 public static class TestConfig {30 private DataSource dataSource;31 @CitrusParameters(name = "driver")32 public Driver driver() throws ClassNotFoundException {33 return (Driver) Class.forName("org.hsqldb.jdbcDriver").newInstance();34 }35 @CitrusParameters(name = "url")36 public String url() {37 return "jdbc:hsqldb:mem:testdb";38 }39 @CitrusParameters(name = "username")40 public String username() {41 return "SA";42 }43 @CitrusParameters(name = "password")44 public String password() {45 return "";46 }47 @CitrusParameters(name = "schema")48 public ClassPathResource schema() {49 return new ClassPathResource("com/consol/citrus/actions/AbstractDatabaseConnectingTestActionTest.sql");50 }51 @CitrusParameters(name = "dataSet")52 public ClassPathResource dataSet() {53 return new ClassPathResource("com/consol/citrus/actions

Full Screen

Full Screen

AbstractDatabaseConnectingTestAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import java.sql.SQLException;3import org.testng.annotations.Test;4import com.consol.citrus.actions.AbstractDatabaseConnectingTestAction;5import com.consol.citrus.actions.ExecuteSQLQueryAction;6import com.consol.citrus.testng.AbstractTestNGUnitTest;7public class AbstractDatabaseConnectingTestActionTest extends AbstractTestNGUnitTest {8 public void testExecuteSQLQueryAction() {9 ExecuteSQLQueryAction action = new ExecuteSQLQueryAction();10 action.setDataSource(new AbstractDatabaseConnectingTestAction.DataSource() {11 public void close() throws SQLException {12 }13 public java.sql.Connection getConnection() throws SQLException {14 return null;15 }16 });17 action.setSqlResourcePath("classpath:com/consol/citrus/actions/ExecuteSQLQueryActionTest.sql");18 action.setSql("SELECT * FROM CUSTOMERS WHERE ID = 1");19 action.setValidateQueryResult(true);20 action.setValidateQueryResultColumnCount(2);21 action.setValidateQueryResultColumnNames(new String[] {"ID", "NAME"});22 action.setValidateQueryResultData(new String[][] {{"1", "John Doe"}});23 action.setVariable("result", "citrus:row(0)");24 action.setRow(0);25 action.setRowName("citrus:row(0)");26 action.setRowNames(new String[] {"citrus:row(0)", "citrus:row(1)"});27 action.setRowValue(0);28 action.setRowValues(new int[] {0, 1});29 action.setRowValueName("citrus:row(0)");30 action.setRowValueNames(new String[] {"citrus:row(0)", "citrus:row(1)"});31 action.setRowValueExpression("citrus:row(0)");32 action.setRowValueExpressions(new String[] {"citrus:row(0)", "citrus:row(1)"});33 action.setRowData("citrus:row(0)");34 action.setRowDataList(new String[] {"citrus:row(0)", "citrus:row(1)"});35 action.setRowDataExpression("citrus:row(0)");36 action.setRowDataExpressionList(new String[] {"citrus:row(

Full Screen

Full Screen

AbstractDatabaseConnectingTestAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import com.consol.citrus.Citrus;3import com.consol.citrus.annotations.CitrusTest;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.beans.factory.annotation.Qualifier;7import org.springframework.jdbc.core.JdbcTemplate;8import org.springframework.test.context.ContextConfiguration;9import org.testng.annotations.Test;10@ContextConfiguration(classes = Citrus.class)11public class AbstractDatabaseConnectingTestActionIT extends TestNGCitrusTestDesigner {12 @Qualifier("jdbcTemplate")13 private JdbcTemplate jdbcTemplate;14 public void testAbstractDatabaseConnectingTestAction() {15 variable("id", "citrus:randomNumber(10)");16 echo("Inserting new record into database using JDBC template");17 execute(new AbstractDatabaseConnectingTestAction() {18 public void execute() {19 jdbcTemplate.update("INSERT INTO CITRUS_TEST (ID, NAME, DESCRIPTION) VALUES (?, 'Citrus', 'Citrus Framework')", getVariable("id"));20 }21 });22 echo("Deleting record from database using JDBC template");23 execute(new AbstractDatabaseConnectingTestAction() {24 public void execute() {25 jdbcTemplate.update("DELETE FROM CITRUS_TEST WHERE ID = ?", getVariable("id"));26 }27 });28 }29}30package com.consol.citrus.actions;31import com.consol.citrus.Citrus;32import com.consol.citrus.annotations.CitrusTest;33import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;34import org.springframework.beans.factory.annotation.Autowired;35import org.springframework.beans.factory.annotation.Qualifier;36import org.springframework.jdbc.core.JdbcTemplate;37import org.springframework.test.context.ContextConfiguration;38import org.testng.annotations.Test;39@ContextConfiguration(classes = Citrus.class)40public class AbstractTestActionIT extends TestNGCitrusTestDesigner {41 @Qualifier("jdbcTemplate")42 private JdbcTemplate jdbcTemplate;43 public void testAbstractTestAction() {44 variable("id", "citrus:randomNumber(10)");45 echo("Inserting new record into database using JDBC template");46 execute(new AbstractTestAction

Full Screen

Full Screen

AbstractDatabaseConnectingTestAction

Using AI Code Generation

copy

Full Screen

1public class AbstractDatabaseConnectingTestActionTest extends AbstractTestNGCitrusTest {2 public void abstractDatabaseConnectingTestActionTest() {3 AbstractDatabaseConnectingTestActionTest action = new AbstractDatabaseConnectingTestActionTest();4 action.setDatabaseConnection(new JdbcConnection());5 action.setDataSource(new DriverManagerDataSource());6 action.setSqlResource(new ClassPathResource("classpath:com/consol/citrus/actions/jdbc.sql"));7 action.setSqlResourcePath("classpath:com/consol/citrus/actions/jdbc.sql");8 action.setSqlResourceUri("classpath:com/consol/citrus/actions/jdbc.sql");9 action.setSqlString("SELECT * FROM TEST");10 action.setSqlResourceCharset("UTF-8");11 action.setSqlResourceVariables(Collections.singletonMap("key", "value"));

Full Screen

Full Screen

AbstractDatabaseConnectingTestAction

Using AI Code Generation

copy

Full Screen

1public class 4 extends AbstractDatabaseConnectingTestAction {2 public void doExecute(TestContext context) {3 JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());4 jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS CUSTOMER(ID INT PRIMARY KEY, NAME VARCHAR(255))");5 jdbcTemplate.execute("INSERT INTO CUSTOMER(ID, NAME) VALUES(1, 'John')");6 jdbcTemplate.execute("INSERT INTO CUSTOMER(ID, NAME) VALUES(2, 'Jane')");7 }8}9public class 5 extends AbstractDatabaseConnectingTestAction {10 public void doExecute(TestContext context) {11 JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());12 jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS CUSTOMER(ID INT PRIMARY KEY, NAME VARCHAR(255))");13 jdbcTemplate.execute("INSERT INTO CUSTOMER(ID, NAME) VALUES(1, 'John')");14 jdbcTemplate.execute("INSERT INTO CUSTOMER(ID, NAME) VALUES(2, 'Jane')");15 }16}17public class 6 extends AbstractDatabaseConnectingTestAction {18 public void doExecute(TestContext context) {19 JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());20 jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS CUSTOMER(ID INT PRIMARY KEY, NAME VARCHAR(255))");21 jdbcTemplate.execute("INSERT INTO CUSTOMER(ID, NAME) VALUES(1, 'John')");22 jdbcTemplate.execute("INSERT INTO CUSTOMER(ID, NAME) VALUES(2, 'Jane')");23 }24}25public class 7 extends AbstractDatabaseConnectingTestAction {26 public void doExecute(TestContext context) {27 JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

Full Screen

Full Screen

AbstractDatabaseConnectingTestAction

Using AI Code Generation

copy

Full Screen

1public class 4 extends AbstractDatabaseConnectingTestAction {2 public 4() {3 super();4 setConnection(connection);5 setSqlResourcePath("classpath:sql/4.sql");6 setResultSetHandler(resultSetHandler);7 setDataSource(dataSource);8 }9}10package com.consol.citrus.actions;11import java.util.List;12import javax.sql.DataSource;13import org.springframework.jdbc.core.JdbcTemplate;14import org.springframework.jdbc.core.ResultSetExtractor;15import com.consol.citrus.exceptions.CitrusRuntimeException;16import com.consol.citrus.util.FileUtils;17public class AbstractDatabaseConnectingTestAction extends AbstractTestAction {18 private DataSource dataSource;19 private JdbcTemplate jdbcTemplate;20 private String sqlResourcePath;21 private ResultSetExtractor<List<List<String>>> resultSetHandler;22 public AbstractDatabaseConnectingTestAction() {23 }24 public void doExecute(TestContext context) {25 if (sqlResourcePath == null) {26 throw new CitrusRuntimeException("Missing sql resource path");27 }28 if (resultSetHandler == null) {29 throw new CitrusRuntimeException("Missing result set handler");30 }31 if (dataSource == null) {32 throw new CitrusRuntimeException("Missing data source");33 }34 jdbcTemplate = new JdbcTemplate(dataSource);35 String sql = FileUtils.readToString(FileUtils.getFileResource(sqlResourcePath, context));36 List<List<String>> result = jdbcTemplate.query(sql, resultSetHandler);37 context.setVariable("result", result);38 }39 public String getSqlResourcePath() {40 return sqlResourcePath;41 }42 public void setSqlResourcePath(String sqlResourcePath) {43 this.sqlResourcePath = sqlResourcePath;44 }45 public ResultSetExtractor<List<List<String>>> getResultSetHandler() {46 return resultSetHandler;47 }48 public void setResultSetHandler(49 ResultSetExtractor<List<List<String>>> resultSetHandler) {50 this.resultSetHandler = resultSetHandler;51 }52 public DataSource getDataSource() {

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