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.Establishment;
10  import br.org.articulus.domain.Office;
11  import br.org.articulus.domain.Sector;
12  
13  
14  /**
15   * TestCase to OfficeDao class
16   * @author anderson
17   * @version 2.0
18   */
19  public class OfficeDaoTest extends TestCase {
20  	
21  	private ClassPathXmlApplicationContext ctx;
22  	private OfficeDao od;
23  
24  	
25  	protected void setUp() throws Exception {
26  		ctx = new ClassPathXmlApplicationContext(new String[] {
27          	"applicationContext-hibernate.xml"});
28  		
29  		od = (OfficeDao)ctx.getBean("officeDao");
30  	}
31  	
32  	
33  	/**
34  	 * Test a null save method
35  	 * @author anderson
36  	 * @version 2.0 
37  	 */
38  	public void testSave() {
39  		Establishment e = new Establishment();
40  		e.setName("Empresa");
41  		
42  		EstablishmentDao ed = (EstablishmentDao)ctx.getBean("establishmentDao");
43  		ed.save(e);
44  		
45  		Sector s = new Sector();
46  		s.setName("Setor");
47  		s.setIdEstablishment(e);
48  		
49  		SectorDao sd = (SectorDao)ctx.getBean("sectorDao");
50  		sd.save(s);
51  		
52  		Office o = new Office();
53  		o.setName("Cargo");
54  		o.setIdEstablishment(e);
55  		o.setIdSector(s);
56  		
57  		od.save(o);
58  		
59  		assertNotNull(o);
60  	}
61  	
62  	
63  	/**
64  	 * Test get method
65  	 * @author anderson
66  	 * @version 2.0
67  	 */
68  	@SuppressWarnings("unchecked")
69  	public void testGet() {
70  		List<Office> l = od.getAll();
71  		
72  		Office o = od.get(l.get(0).getId());
73  	
74  		assertNotNull(o);
75  	}
76  	
77  	
78  	/**
79  	 * Test update method
80  	 * @author anderson
81  	 * @version 2.0
82  	 */
83  	@SuppressWarnings("unchecked")
84  	public void testUpdate() {
85  		List<Office> l = od.getAll();
86  		
87  		Office o = (Office)od.get(l.get(0).getId());
88  		o.setName("Cargo Atualizado!");
89  		
90  		od.update(o);
91  		
92  		assertNotNull(o);
93  	}
94  	
95  	
96  	/**
97  	 * Test getAll method
98  	 * @author anderson
99  	 * @version 2.0
100 	 */
101 	@SuppressWarnings("unchecked")
102 	public void testGetAll() {
103 		List<Office> all = od.getAll();
104 		assertNotNull(all.get(0));
105 	}
106 	
107 	
108 	/**
109 	 * Test delete method
110 	 * @author anderson
111 	 * @version 2.0
112 	 */
113 	@SuppressWarnings("unchecked")
114 	public void testDelete() {
115 		List<Office> l = od.getAll();
116 		
117 		Office o = od.get(l.get(0).getId());
118 		
119 		//ud.delete(u);
120 		
121 		assertNotNull(o);
122 	}
123 }