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   * TestCase to FingerprintDao class
19   * @author anderson
20   * @version 2.0
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  	 * Test a null save method
38  	 * @author anderson
39  	 * @version 2.0 
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  	 * Test get method
97  	 * @author anderson
98  	 * @version 2.0
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 	 * Test getFingerprint method
112 	 * @author anderson
113 	 * @version 2.0
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 	 * Test update method
127 	 * @author anderson
128 	 * @version 2.0
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 	 * Test getAll method
145 	 * @author anderson
146 	 * @version 2.0
147 	 */
148 	@SuppressWarnings("unchecked")
149 	public void testGetAll() {
150 		List<Fingerprint> all = fd.getAll();
151 		assertNotNull(all.get(0));
152 	}
153 	
154 	
155 	/**
156 	 * Test delete method
157 	 * @author anderson
158 	 * @version 2.0
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 		//ud.delete(u);
167 		
168 		assertNotNull(f);
169 	}
170 }