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.Establishment;
11 import br.org.articulus.domain.Office;
12 import br.org.articulus.domain.Register;
13 import br.org.articulus.domain.Sector;
14 import br.org.articulus.domain.Vacation;
15
16
17
18
19
20
21
22 public class VacationDaoTest extends TestCase {
23
24 private ClassPathXmlApplicationContext ctx;
25 private VacationDao vd;
26
27
28 protected void setUp() throws Exception {
29 ctx = new ClassPathXmlApplicationContext(new String[] {
30 "applicationContext-hibernate.xml"});
31
32 vd = (VacationDao)ctx.getBean("vacationDao");
33 }
34
35
36
37
38
39
40
41 public void testSave() {
42 Establishment e = new Establishment();
43 e.setName("Empresa");
44
45 EstablishmentDao ed = (EstablishmentDao)ctx.getBean("establishmentDao");
46 ed.save(e);
47
48 Sector s = new Sector();
49 s.setName("Setor");
50 s.setIdEstablishment(e);
51
52 SectorDao sd = (SectorDao)ctx.getBean("sectorDao");
53 sd.save(s);
54
55 Office o = new Office();
56 o.setName("Cargo");
57 o.setIdEstablishment(e);
58 o.setIdSector(s);
59
60 OfficeDao od = (OfficeDao)ctx.getBean("officeDao");
61 od.save(o);
62
63 Register r = new Register();
64 r.setActive(true);
65 r.setAddress("Endereco tal");
66 r.setBirthday(new Date());
67 r.setCity("Maringá");
68 r.setComment("comentario");
69 r.setEmail("andersonajx@gmail.com");
70 r.setIdEstablishment(e);
71 r.setIdOffice(o);
72 r.setIdSector(s);
73 r.setName("anderson clayton");
74 r.setNeighborhood("Zona 3");
75 r.setPhone(99468400);
76 r.setPhoneScrap(30268266);
77 r.setState("PR");
78 r.setZipcode(87050190);
79
80 RegisterDao rd = (RegisterDao)ctx.getBean("registerDao");
81 rd.save(r);
82
83 Vacation v = new Vacation();
84 v.setComment("comentario");
85 v.setEnd(new Date());
86 v.setIdRegister(r);
87 v.setStart(new Date());
88
89 vd.save(v);
90
91 assertNotNull(v);
92 }
93
94
95
96
97
98
99
100 @SuppressWarnings("unchecked")
101 public void testGet() {
102 List<Vacation> l = vd.getAll();
103
104 Vacation v = vd.get(l.get(0).getId());
105
106 assertNotNull(v);
107 }
108
109
110
111
112
113
114
115 @SuppressWarnings("unchecked")
116 public void testUpdate() {
117 List<Vacation> l = vd.getAll();
118
119 Vacation v = (Vacation)vd.get(l.get(0).getId());
120 v.setComment("Comentario Atualizado!");
121
122 vd.update(v);
123
124 assertNotNull(v);
125 }
126
127
128
129
130
131
132
133 @SuppressWarnings("unchecked")
134 public void testGetAll() {
135 List<Vacation> all = vd.getAll();
136 assertNotNull(all.get(0));
137 }
138
139
140
141
142
143
144
145 @SuppressWarnings("unchecked")
146 public void testDelete() {
147 List<Vacation> l = vd.getAll();
148
149 Vacation v = vd.get(l.get(0).getId());
150
151
152
153 assertNotNull(v);
154 }
155 }