Package io.ebean.test

Class 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");
    
     
    • Method Detail

      • start

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

        public static List<Stringstop()
        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<Stringcollect()
        Collect and return the messages/sql that was captured since the call to start() or collect().

        Unlike stop() collection of messages will continue.