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.Fingerprint;
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 FingerprintDaoTest extends TestCase {
23
24 private ClassPathXmlApplicationContext ctx;
25 private FingerprintDao fd;
26
27
28 protected void setUp() throws Exception {
29 ctx = new ClassPathXmlApplicationContext(new String[] {
30 "applicationContext-hibernate.xml"});
31
32 fd = (FingerprintDao)ctx.getBean("fingerprintDao");
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 Fingerprint f = new Fingerprint();
84 f.setFingerprint(fd
85 .saveFingerprint("/home/anderson/documentos/xicara_java.png"));
86 f.setIdRegister(r);
87 f.setComment("Comentario");
88
89 fd.save(f);
90
91 assertNotNull(f);
92 }
93
94
95
96
97
98
99
100 @SuppressWarnings("unchecked")
101 public void testGet() {
102 List<Fingerprint> l = fd.getAll();
103
104 Fingerprint f = fd.get(l.get(0).getId());
105
106 assertNotNull(f);
107 }
108
109
110
111
112
113
114
115 @SuppressWarnings("unchecked")
116 public void testGetFingerprint() {
117 List<Fingerprint> l = fd.getAll();
118
119 boolean ret = fd.getFingerprint(l.get(0).getId());
120
121 assertEquals(true, ret);
122 }
123
124
125
126
127
128
129
130 @SuppressWarnings("unchecked")
131 public void testUpdate() {
132 List<Fingerprint> l = fd.getAll();
133
134 Fingerprint f = (Fingerprint)fd.get(l.get(0).getId());
135 f.setComment("Comentario Atualizado!");
136
137 fd.update(f);
138
139 assertNotNull(f);
140 }
141
142
143
144
145
146
147
148 @SuppressWarnings("unchecked")
149 public void testGetAll() {
150 List<Fingerprint> all = fd.getAll();
151 assertNotNull(all.get(0));
152 }
153
154
155
156
157
158
159
160 @SuppressWarnings("unchecked")
161 public void testDelete() {
162 List<Fingerprint> l = fd.getAll();
163
164 Fingerprint f = fd.get(l.get(0).getId());
165
166
167
168 assertNotNull(f);
169 }
170 }