1   package br.org.articulus.server.dao;
2   
3   import java.util.List;
4   
5   import junit.framework.TestCase;
6   
7   import org.springframework.context.support.ClassPathXmlApplicationContext;
8   
9   import br.org.articulus.domain.Session;
10  
11  
12  /**
13   * TestCase to SessionDao class
14   * @author anderson
15   * @version 2.0
16   */
17  public class SessionDaoTest extends TestCase {
18  	
19  	private ClassPathXmlApplicationContext ctx;
20  	private SessionDao ssd;
21  
22  	
23  	protected void setUp() throws Exception {
24  		ctx = new ClassPathXmlApplicationContext(new String[] {
25          	"applicationContext-hibernate.xml"});
26  		
27  		ssd = (SessionDao)ctx.getBean("sessionDao");
28  	}
29  	
30  	
31  	/**
32  	 * Test save method
33  	 * @author anderson
34  	 * @version 2.0
35  	 */
36  	public void testSave() {
37  		Session s = new Session();
38  		s.setName("Cadastro");
39  		s.setPage("cadastro.jsp");
40  		s.setComment("Pagina de cadastro");
41  		
42  		ssd.save(s);
43  		
44  		assertNotNull(s);
45  	}
46  	
47  	
48  	/**
49  	 * Test get method
50  	 * @author anderson
51  	 * @version 2.0
52  	 */
53  	@SuppressWarnings("unchecked")
54  	public void testGet() {
55  		List<Session> l = ssd.getAll();
56  		
57  		Session s = ssd.get(l.get(0).getId());
58  	
59  		assertNotNull(s);
60  	}
61  	
62  	
63  	/**
64  	 * Test update method
65  	 * @author anderson
66  	 * @version 2.0
67  	 */
68  	@SuppressWarnings("unchecked")
69  	public void testUpdate() {
70  		List<Session> l = ssd.getAll();
71  		
72  		Session s = (Session)ssd.get(l.get(0).getId());
73  		s.setName("Cadastro Atualizado!");
74  		
75  		ssd.update(s);
76  		
77  		assertNotNull(s);
78  	}
79  	
80  	
81  	/**
82  	 * Test getAll method
83  	 * @author anderson
84  	 * @version 2.0
85  	 */
86  	@SuppressWarnings("unchecked")
87  	public void testGetAll() {
88  		List<Session> all = ssd.getAll();
89  		assertNotNull(all.get(0));
90  	}
91  	
92  	
93  	/**
94  	 * Test delete method
95  	 * @author anderson
96  	 * @version 2.0
97  	 */
98  	@SuppressWarnings("unchecked")
99  	public void testDelete() {
100 		List<Session> l = ssd.getAll();
101 		
102 		Session s = ssd.get(l.get(0).getId());
103 		
104 		//sd.delete(s);
105 		
106 		assertNotNull(s);
107 	}
108 }