1 package com.germinus.merlin.dao;
2
3 import com.germinus.merlin.model.Course;
4 import com.germinus.merlin.model.assignment.Assignment;
5 import com.germinus.merlin.model.assignment.AssignmentOnline;
6
7 import java.util.List;
8
9
10
11
12
13 public class AssigmentDaoTest extends BaseDaoTestCase {
14 private AssignmentDao dao;
15
16 private final static int NUM_ASSIGNMENTS = 18;
17 private final static Long[] IDS_ASSIGNMENTS = {1L,2L};
18 @SuppressWarnings("unused")
19 private final static String [] NAMES_ASSIGNMENTS = {"assignment1","assignment2"};
20 @SuppressWarnings("unused")
21 private final static Long ID_COURSE = 10264L;
22
23
24
25
26
27
28 public void setAssignmentDao(AssignmentDao dao) {
29 this.dao = dao;
30 }
31
32
33
34
35
36
37 public void testRemoveAssignment() throws Exception {
38 dao.remove(IDS_ASSIGNMENTS[0]);
39 List<Assignment> assignments = dao.getAll();
40 assertEquals(NUM_ASSIGNMENTS-1, assignments.size());
41 }
42
43
44
45
46
47
48 public void testGetAllAssignmet() throws Exception {
49 List<Assignment> assignmentsList = dao.getAll();
50 String assertMsg= new String ("\n\t<Expected> "+NUM_ASSIGNMENTS+" <Actual> "+assignmentsList.size());
51 assertEquals(assertMsg,NUM_ASSIGNMENTS,assignmentsList.size());
52 }
53
54
55
56
57
58
59
60 public void testGetAssignmentInvalid() throws Exception {
61
62 try {
63 @SuppressWarnings("unused")
64 Assignment assignment = dao.get(1L);
65 } catch (Exception e) {
66 assertNotNull(e);
67 }
68 assertTrue(true);
69 }
70
71
72
73
74
75
76 public void testExistsAssignmentId() throws Exception {
77 String assertMsg;
78 for (int i=0; i<IDS_ASSIGNMENTS.length; i++){
79 assertMsg= new String ("\n\t<Expected> "+"Exist Assignment "+IDS_ASSIGNMENTS[i]+" <Actual> "+"Not exist");
80 assertTrue(assertMsg,dao.exists(IDS_ASSIGNMENTS[i]));
81 }
82
83 }
84
85
86
87
88
89
90 public void testGetAssignmentsInitials() throws Exception {
91 String assertMsg = null;
92 Assignment assignment = null;
93
94 for (int i=0; i<IDS_ASSIGNMENTS.length; i++)
95 {
96 try {
97 assertMsg= new String ("\n\t<Expected> "+"Exist Assignment "+IDS_ASSIGNMENTS[i]+" <Actual> "+"Not exist");
98 assignment = dao.get(IDS_ASSIGNMENTS[i]);
99 assertNotNull(assertMsg,assignment);
100 assignment = null;
101 } catch (Exception e) {
102 assertTrue(assertMsg,false);
103 }
104 }
105
106 }
107
108
109
110
111
112
113 public void testSaveAssignment() throws Exception {
114
115 Assignment assignmentAux = (Assignment) dao.getAll().toArray()[0];
116 Course courseAux = assignmentAux.getCourse();
117
118 Assignment newAssignment = new AssignmentOnline();
119 newAssignment.setName("Nuevo assignment a a�adir");
120 newAssignment.setDescription("Descripcion del nuevo assignment");
121 newAssignment.setCourse(courseAux);
122
123 dao.save(newAssignment);
124 flush();
125
126 List<Assignment> assignmentsList = dao.getAll();
127 String assertMsg = new String ("\n\t<Expected> "+(NUM_ASSIGNMENTS+1)+" <Actual> "+assignmentsList.size());
128 assertEquals(assertMsg,NUM_ASSIGNMENTS+1, assignmentsList.size());
129
130 }
131 }