1   package br.org.articulus.server.dao;
2   
3   import java.util.Date;
4   import java.util.List;
5   
6   import junit.framework.TestCase;
7   
8   import org.springframework.context.support.ClassPathXmlApplicationContext;
9   
10  import br.org.articulus.domain.Log;
11  
12  
13  /**
14   * TestCase to LogDao class
15   * @author anderson
16   * @version 2.0
17   */
18  public class LogDaoTest extends TestCase {
19  	
20  	private static final int ID = 1;
21  	private ClassPathXmlApplicationContext ctx;
22  	
23  	protected void setUp() throws Exception {
24  		ctx = new ClassPathXmlApplicationContext(new String[] {
25  				"applicationContext-hibernate.xml"});
26  	}
27  	
28  	
29  	/**
30  	 * Test save method
31  	 * @author anderson
32  	 * @version 2.0
33  	 */
34  	public void testSave() {
35  		Log l = new Log();
36  		l.setIdUser(ID);
37  		l.setDate(new Date());
38  		l.setTime(new Date());
39  		l.setAction("User logged");
40  		
41  		LogDao ld = (LogDao)ctx.getBean("logDao");
42  		ld.save(l);
43  		
44  		assertNotNull(l);
45  	}
46  	
47  	
48  	/**
49  	 * Test get method
50  	 * @author anderson
51  	 * @version 2.0
52  	 */
53  	@SuppressWarnings("unchecked")
54  	public void testGet() {
55  		LogDao ld = (LogDao)ctx.getBean("logDao");
56  		List<Log> l = ld.getAll();
57  	
58  		assertNotNull(ld.get(l.get(0).getId()));
59  	}
60  	
61  	
62  	/**
63  	 * Test get all method
64  	 * @author anderson
65  	 * @version 2.0
66  	 */
67  	public void testGetAll() {
68  		LogDao ld = (LogDao)ctx.getBean("logDao");
69  		
70  		assertNotNull(ld.getAll());
71  	}
72  }