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   * TestCase to PointDao class
20   * @author anderson
21   * @version 2.0
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  	 * Test a null save method
39  	 * @author anderson
40  	 * @version 2.0 
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  	 * Test get method
97  	 * @author anderson
98  	 * @version 2.0
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 	 * Test update method
112 	 * @author anderson
113 	 * @version 2.0
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 	 * Test getAll method
130 	 * @author anderson
131 	 * @version 2.0
132 	 */
133 	@SuppressWarnings("unchecked")
134 	public void testGetAll() {
135 		List<Point> all = pd.getAll();
136 		assertNotNull(all.get(0));
137 	}
138 	
139 }