Package io.ebean.test

Class LoggedSql

java.lang.Object
io.ebean.test.LoggedSql

public class LoggedSql extends Object
Provides access to the messages logged to io.ebean.SQL.

This is here to allow easy access to the SQL that was executed during testing and if desired we can use that to perform asserts in tests.



     // start capturing SQL log messages
     LoggedSql.start();

     List<Customer> customers =
           Customer.find.where()
             .name.ilike("rob%")
             .findList();

       assertNotNull(customers);

     // perform an insert
     new Product("ad", "asd").save()


     // return the captured SQL log messages
     // since LoggedSql.start()
     List<String> sql = LoggedSql.stop();

     assertThat(sql).hasSize(2);
     assertThat(sql.get(0)).contains("from customer");
     assertThat(sql.get(1)).contains("into product");

 
  • Constructor Details

    • LoggedSql

      public LoggedSql()
  • Method Details

    • start

      public static List<String> start()
      Start the capture of the io.ebean.SQL messages.
    • stop

      public static List<String> stop()
      Stop the capture of the io.ebean.SQL messages and return the messages/sql that was captured since the call to start().
    • collect

      public static List<String> collect()
      Collect and return the messages/sql that was captured since the call to start() or collect().

      Unlike stop() collection of messages will continue.