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   * TestCase to ScheduleDao class
20   * @author anderson
21   * @version 2.0
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  	 * 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  		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  	 * Test get method
98  	 * @author anderson
99  	 * @version 2.0
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 	 * Test update method
113 	 * @author anderson
114 	 * @version 2.0
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 	 * Test getAll method
131 	 * @author anderson
132 	 * @version 2.0
133 	 */
134 	@SuppressWarnings("unchecked")
135 	public void testGetAll() {
136 		List<Schedule> all = scd.getAll();
137 		assertNotNull(all.get(0));
138 	}
139 	
140 	
141 	/**
142 	 * Test delete method
143 	 * @author anderson
144 	 * @version 2.0
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 		//ud.delete(u);
153 		
154 		assertNotNull(s);
155 	}
156 }