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
16
17
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
35
36
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
65
66
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
80
81
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
98
99
100
101 @SuppressWarnings("unchecked")
102 public void testGetAll() {
103 List<Office> all = od.getAll();
104 assertNotNull(all.get(0));
105 }
106
107
108
109
110
111
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
120
121 assertNotNull(o);
122 }
123 }