1 package br.org.articulus.server.dao;
2
3 import java.util.List;
4
5 import junit.framework.TestCase;
6
7 import org.springframework.context.support.ClassPathXmlApplicationContext;
8
9 import br.org.articulus.domain.Establishment;
10 import br.org.articulus.domain.Sector;
11
12
13
14
15
16
17
18 public class SectorDaoTest extends TestCase {
19
20 private ClassPathXmlApplicationContext ctx;
21 private SectorDao sd;
22
23
24 protected void setUp() throws Exception {
25 ctx = new ClassPathXmlApplicationContext(new String[] {
26 "applicationContext-hibernate.xml"});
27
28 sd = (SectorDao)ctx.getBean("sectorDao");
29 }
30
31
32
33
34
35
36
37 public void testSave() {
38 Establishment e = new Establishment();
39 e.setName("Empresa");
40
41 EstablishmentDao ed = (EstablishmentDao)ctx.getBean("establishmentDao");
42 ed.save(e);
43
44 Sector s = new Sector();
45 s.setIdEstablishment(e);
46 s.setName("Setor");
47
48 sd.save(s);
49
50 assertNotNull(s);
51 }
52
53
54
55
56
57
58
59 @SuppressWarnings("unchecked")
60 public void testGet() {
61 List<Sector> l = sd.getAll();
62
63 Sector s = sd.get(l.get(0).getId());
64
65 assertNotNull(s);
66 }
67
68
69
70
71
72
73
74 @SuppressWarnings("unchecked")
75 public void testUpdate() {
76 List<Sector> l = sd.getAll();
77
78 Sector s = (Sector)sd.get(l.get(0).getId());
79 s.setName("Setor Atualizada!");
80
81 sd.update(s);
82
83 assertNotNull(s);
84 }
85
86
87
88
89
90
91
92 @SuppressWarnings("unchecked")
93 public void testGetAll() {
94 List<Sector> all = sd.getAll();
95 assertNotNull(all.get(0));
96 }
97
98
99
100
101
102
103
104 @SuppressWarnings("unchecked")
105 public void testDelete() {
106 List<Sector> l = sd.getAll();
107
108 Sector s = sd.get(l.get(0).getId());
109
110
111
112 assertNotNull(s);
113 }
114 }