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  import br.org.articulus.domain.SubSession;
11  
12  
13  /**
14   * TestCase to SubSessionDao class
15   * @author anderson
16   * @version 2.0
17   */
18  public class SubSessionDaoTest extends TestCase {
19  	
20  	private ClassPathXmlApplicationContext ctx;
21  	private SubSessionDao ssd;
22  
23  	
24  	protected void setUp() throws Exception {
25  		ctx = new ClassPathXmlApplicationContext(new String[] {
26          	"applicationContext-hibernate.xml"});
27  		
28  		ssd = (SubSessionDao)ctx.getBean("subSessionDao");
29  	}
30  	
31  	
32  	/**
33  	 * Test save method testing FK
34  	 * @author anderson
35  	 * @version 2.0
36  	 */
37  	public void testSave() {
38  		Session s = new Session();
39  		s.setName("Test");
40  		s.setPage("testPage.jsp");
41  		s.setComment("Test Comment");
42  		
43  		SessionDao sd = (SessionDao)ctx.getBean("sessionDao");
44  		sd.save(s);
45  		
46  		SubSession ss = new SubSession();
47  		ss.setName("Test");
48  		ss.setPage("testPage.jsp");
49  		ss.setComment("test comment");
50  		ss.setIdSession(s);
51  		
52  		ssd.save(ss);
53  		
54  		assertNotNull(s);
55  	}
56  	
57  	
58  	/**
59  	 * Test get method
60  	 * @author anderson
61  	 * @version 2.0
62  	 */
63  	@SuppressWarnings("unchecked")
64  	public void testGet() {
65  		List<SubSession> l = ssd.getAll();
66  		
67  		SubSession ss = ssd.get(l.get(0).getId());
68  	
69  		assertNotNull(ss);
70  	}
71  	
72  	
73  	/**
74  	 * Test update method
75  	 * @author anderson
76  	 * @version 2.0
77  	 */
78  	@SuppressWarnings("unchecked")
79  	public void testUpdate() {
80  		List<SubSession> l = ssd.getAll();
81  		
82  		SubSession ss = (SubSession)ssd.get(l.get(0).getId());
83  		ss.setName("Subsessao Atualizado!");
84  		
85  		ssd.update(ss);
86  		
87  		assertNotNull(ss);
88  	}
89  	
90  	
91  	/**
92  	 * Test getAll method
93  	 * @author anderson
94  	 * @version 2.0
95  	 */
96  	@SuppressWarnings("unchecked")
97  	public void testGetAll() {
98  		List<SubSession> all = ssd.getAll();
99  		assertNotNull(all.get(0));
100 	}
101 	
102 	
103 	/**
104 	 * Test delete method
105 	 * @author anderson
106 	 * @version 2.0
107 	 */
108 	@SuppressWarnings("unchecked")
109 	public void testDelete() {
110 		List<SubSession> l = ssd.getAll();
111 		
112 		SubSession ss = ssd.get(l.get(0).getId());
113 		
114 		//ssd.delete(ss);
115 		
116 		assertNotNull(ss);
117 	}
118 }