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