            ------
            UnitTest Support
            ------
            Naoki Takezoe
            ------
            2011-01-01

UnitTest Support

* {MockSqlManager}

 Mirage provides <<{{{apidocs/jp/sf/amateras/mirage/test/MockSqlManager.html}MockSqlManager}}>> for unit testing of classes which use SqlManager.

 Using MockSqlManager instead of SqlManager, you can execute a your code which uses SqlManager without database.
 You can configure results of MockSqlManager and verify executed SQLs using <<{{{apidocs/jp/sf/amateras/mirage/test/MirageTestContext.html}MirageTestContext}}>>.

 An example of TestCase which uses MockSqlManager is below:

--------
@Test
public void testGetBookById(){
  // set MockSqlManager to the test target
  BookService bookService = new BookService();
  bookService.setSqlManager(new MockSqlManager());

  // configure results which would be returned by MockSqlManager.
  Book book = new Book();
  book.setBookName("Mirage in Action");

  MirageTestContext.addResult(book);

  // execute
  Book result = bookService.getBookById(new Long(100));

  // assert returned object
  assertEquals("Mirage in Action", book.getName);

  // verify the number of executed SQL
  MirageTestContext.verifySqlCount(1);

  // verify the executed SQL
  MirageTestContext.verifySql(0,
    "SELECT ID, BOOK_NAME, AUTHOR, PUBLISHER, PRICE, PUBLISH_DATE " +
    "FROM BOOK WHERE ID = ? ORDER BY ID ASC", // verify SQL
    new Long(100)); // verify Parameters
}
--------

 If returned values has been not configured, MockSqlManager returns following values as a result.

 * <<empty list>> for SqlManager#getResultList()

 * <<null>> for SqlManager#getSingleResult()

 * <<1>> for SqlManager#insertEntity(), SqlManager#updateEntity(), SqlManager#deleteEntity()

 []

 [Note] The current version of MockSqlManager does not support stored procedure / function.
        call() and callForList() throw UnsupportedOperationException.

