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.Justification;
12 import br.org.articulus.domain.Office;
13 import br.org.articulus.domain.Register;
14 import br.org.articulus.domain.Sector;
15
16
17
18
19
20
21
22 public class JustificationDaoTest extends TestCase {
23
24 private ClassPathXmlApplicationContext ctx;
25 private JustificationDao jd;
26
27
28 protected void setUp() throws Exception {
29 ctx = new ClassPathXmlApplicationContext(new String[] {
30 "applicationContext-hibernate.xml"});
31
32 jd = (JustificationDao)ctx.getBean("justificationDao");
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 Justification j = new Justification();
84 j.setComment("Comentario");
85 j.setDate(new Date());
86 j.setIdRegister(r);
87
88 jd.save(j);
89
90 assertNotNull(j);
91 }
92
93
94
95
96
97
98
99 @SuppressWarnings("unchecked")
100 public void testGet() {
101 List<Justification> l = jd.getAll();
102
103 Justification j = jd.get(l.get(0).getId());
104
105 assertNotNull(j);
106 }
107
108
109
110
111
112
113
114 @SuppressWarnings("unchecked")
115 public void testUpdate() {
116 List<Justification> l = jd.getAll();
117
118 Justification j = (Justification)jd.get(l.get(0).getId());
119 j.setComment("Comentario Atualizado!");
120
121 jd.update(j);
122
123 assertNotNull(j);
124 }
125
126
127
128
129
130
131
132 @SuppressWarnings("unchecked")
133 public void testGetAll() {
134 List<Justification> all = jd.getAll();
135 assertNotNull(all.get(0));
136 }
137
138
139
140
141
142
143
144 @SuppressWarnings("unchecked")
145 public void testDelete() {
146 List<Justification> l = jd.getAll();
147
148 Justification j = jd.get(l.get(0).getId());
149
150
151
152 assertNotNull(j);
153 }
154 }