/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import com.ibatis.sqlmap.client.SqlMapClient; import ibatis.Account; import ibatis.SqlMap; import java.util.Iterator; import java.util.List; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; /** * * @author lane */ public class SingleSqlMapFactoryJUnitTest { private SqlMapClient sqlMap; private int i = 0; public SingleSqlMapFactoryJUnitTest() { } @BeforeClass public static void setUpClass() throws Exception { System.out.println("BeforeClass Event."); } @AfterClass public static void tearDownClass() throws Exception { System.out.println("AfterClass Event."); } @Before public void setUp() { System.out.println("setUp() is called: " + (i++)); sqlMap = SqlMap.getInstance(); } @After public void tearDown() { System.out.println("tearDown() is called: " + (i++)); sqlMap = null; } // TODO add test methods here. // The methods must be annotated with annotation @Test. For example: // // @Test // public void hello() {} @Test public void testGetAll() { try { System.out.println("testGetAll:\tselect * from account by ibatis sqlmap:"); List list = sqlMap.queryForList("getAccounts"); Iterator it=list.iterator(); while(it.hasNext()) { Account ac=(Account)it.next(); System.out.println("Username :" + ac.getUsername()); } }catch(Exception e) { e.printStackTrace(); throw new RuntimeException ("Error in selectAll. Cause: "+e); } } @Test public void testGetById() { try { System.out.println("testGetById:\tselect * from account where id=2 by ibatis sqlmap:"); Account person = (Account) sqlMap.queryForObject("getAccountById", "2"); System.out.println("username: " + person.getUsername()); }catch(Exception e) { e.printStackTrace(); throw new RuntimeException ("Error in selectById. Cause: "+e); } } }