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