This sample uses JDBC database connection to verify stored data in SQL query results sets.


The todo-list sample application stores data to a relational database. This sample shows the usage of database JDBC validation actions in Citrus. We are able to execute SQL statements on a database target. See the reference guide database chapter for details.

The database source is configured as Spring datasource in the application context citrus-context.xml.

public SingleConnectionDataSource dataSource() {
    SingleConnectionDataSource dataSource = new SingleConnectionDataSource();
    return dataSource;

As you can see we are using a special Citrus JDBC driver here. This driver connects to the Citrus JDBC server mock.

In the test case we can verify any JDBC operation on the datasource without having to actually create the data in the database.

        .message(JdbcMessage.execute("SELECT id, title, description FROM todo_entries"));

        .message(JdbcMessage.success().dataSet("[ {" +
                    "\"id\": \"" + UUID.randomUUID().toString() + "\"," +
                    "\"title\": \"${todoName}\"," +
                    "\"description\": \"${todoDescription}\"," +
                    "\"done\": \"false\"" +
                "} ]"));


You can run the sample on your localhost in order to see Citrus in action. Read the instructions how to run the sample.