Merge /pub/main
[educational.data.git] / Dr.NO / src / drno / tests / RegressionTest.java
blobb878072d3530099ba19a8f63510ac71c5bf3baed
1 /*
2 * Oprettet 2005-05-12 af tobibobi
3 */
4 package drno.tests;
6 import java.rmi.RemoteException;
7 import java.rmi.registry.LocateRegistry;
8 import java.rmi.registry.Registry;
9 import java.sql.Timestamp;
10 import java.util.Vector;
12 import drno.exception.ConsistanceException;
13 import drno.exception.ObjectLockException;
14 import drno.exception.SecurityDisallowedException;
15 import drno.exception.UnkErrException;
16 import drno.interfaces.EmployeeHandler;
17 import drno.interfaces.IEmployee;
18 import drno.interfaces.IEmployeeEditable;
19 import drno.interfaces.IPatient;
20 import drno.interfaces.IPatientEditable;
21 import drno.interfaces.ITidsreservation;
22 import drno.interfaces.ITidsreservationEditable;
23 import drno.interfaces.LoginHandler;
24 import drno.interfaces.PatientHandler;
25 import drno.interfaces.TidsreservationsHandler;
26 import drno.server.Server;
29 import junit.framework.TestCase;
31 /**
32 * @author tobibobi
34 * TODO To change the template for this generated type comment go to Window -
35 * Preferences - Java - Code Style - Code Templates
37 public class RegressionTest extends TestCase {
38 private EmployeeHandler employeeHandler;
40 private PatientHandler patientHandler;
42 private LoginHandler loginHandler;
44 private TidsreservationsHandler tidsreservationsHandler;
46 /**
47 * @param fornavn
48 * @param login
49 * @param pw
50 * @param efternavn
51 * @param tlf
52 * @return
53 * @throws RemoteException
54 * @throws SecurityDisallowedException
55 * @throws ConsistanceException
56 * @throws UnkErrException
57 * @throws ObjectLockException
59 private IEmployee createEmployee(String fornavn, String login, String pw,
60 String efternavn, String tlf) throws RemoteException,
61 SecurityDisallowedException, ConsistanceException, UnkErrException,
62 ObjectLockException {
63 IEmployeeEditable employee = employeeHandler.createNewEmployee();
64 employee.setFornavn(fornavn);
65 employee.setEfternavn(efternavn);
66 employee.setLogin(login);
67 employee.setPassword(pw);
68 employee.setTelefonNummer(tlf);
69 employee.setTidsOpdeling(10);
70 employee.setType(IEmployee.TYPE_DOCTOR);
71 IEmployee empl = employeeHandler.saveEmployee(employee);
72 return empl;
75 /**
76 * @param fornavn
77 * @param efternavn
78 * @param adresse
79 * @param postnr
80 * @param cpr
81 * @param sex
82 * @param tlf
83 * @return
84 * @throws RemoteException
85 * @throws ConsistanceException
86 * @throws ObjectLockException
87 * @throws UnkErrException
89 private IPatient createPatient(String fornavn, String efternavn,
90 String adresse, int postnr, String cpr, int sex, String tlf)
91 throws RemoteException, ConsistanceException, ObjectLockException,
92 UnkErrException {
93 IPatientEditable pat = patientHandler.createNewPatient();
94 pat.setFornavn(fornavn);
95 pat.setEfternavn(efternavn);
96 pat.setAdresse(adresse);
97 pat.setPostnummer(new Integer(postnr));
98 pat.setCpr(cpr);
99 pat.setSex(sex);
100 pat.setDoctor(loginHandler.getUser());
101 pat.setTlf(tlf);
102 IPatient pat2 = patientHandler.savePatient(pat);
103 return pat2;
107 * @param pat2
108 * @param empl
109 * @param start
110 * @param slut
111 * @param emne
112 * @return
113 * @throws RemoteException
114 * @throws ConsistanceException
115 * @throws ObjectLockException
116 * @throws UnkErrException
118 private ITidsreservation createTidsReservation(IPatient pat2,
119 IEmployee empl, Timestamp start, Timestamp slut, String emne)
120 throws RemoteException, ConsistanceException, ObjectLockException,
121 UnkErrException {
122 ITidsreservationEditable tidsr = tidsreservationsHandler.createNewTidsReservation();
123 tidsr.setEmployee(empl);
124 tidsr.setEmne(emne);
125 tidsr.setPatient(pat2);
126 tidsr.setTidStart(start);
127 tidsr.setTidSlut(slut);
128 tidsr.setType(ITidsreservation.TYPE_CONSULTATION);
129 ITidsreservation reservation = tidsreservationsHandler.saveTidsreservation(tidsr);
130 return reservation;
134 * @param empl
135 * @throws ObjectLockException
136 * @throws RemoteException
137 * @throws SecurityDisallowedException
138 * @throws UnkErrException
140 private void deleteEmployee(IEmployee empl) throws ObjectLockException,
141 RemoteException, SecurityDisallowedException, UnkErrException {
142 employeeHandler.deleteEmployee(employeeHandler.editEmployee(empl));
146 * @param pat2
147 * @throws ObjectLockException
148 * @throws UnkErrException
149 * @throws RemoteException
151 private void deletePatient(IPatient pat2) throws ObjectLockException,
152 UnkErrException, RemoteException {
153 patientHandler.deletePatient(patientHandler.editPatient(pat2));
157 * @param reservation
158 * @throws ConsistanceException
159 * @throws ObjectLockException
160 * @throws UnkErrException
161 * @throws RemoteException
163 private void deleteTidsReservation(ITidsreservation reservation)
164 throws ConsistanceException, ObjectLockException, UnkErrException,
165 RemoteException {
166 tidsreservationsHandler.deleteTidsreservation(tidsreservationsHandler
167 .editTidsreservation(reservation));
170 public void setUp() {
171 try {
173 Server.instance();
174 Registry reg = LocateRegistry.getRegistry("localhost");
175 loginHandler = ((LoginHandler) reg.lookup("DrNOServer")).login(
176 "admin", "admin");
177 patientHandler = loginHandler.getPatientHandler();
178 employeeHandler = loginHandler.getEmployeeHandler();
179 tidsreservationsHandler = loginHandler.getTidsreservationsHandler();
181 } catch (Exception ex) {
182 ex.printStackTrace();
183 fail();
187 public void tearDown() {
190 public final void testCreateAndDeleteEmployee() {
191 try {
192 String fornavn = "Albertawdgwaref";
193 String login = "DummyLogIn";
194 String pw = "DummyPassWord";
195 String efternavn = "Einstein";
196 String tlf = "12345678";
197 IEmployee empl = createEmployee(fornavn, login, pw, efternavn, tlf);
199 Vector eVec = employeeHandler.searchEmployeesByName(fornavn);
200 assertEquals("Der er for mange employees", 1, eVec.size());
201 assertEquals(fornavn, ((IEmployee) eVec.get(0)).getFornavn());
203 deleteEmployee(empl);
205 eVec = employeeHandler.searchEmployeesByName(fornavn);
206 assertEquals("Der er for mange employees", 0, eVec.size());
207 } catch (RemoteException e) {
209 e.printStackTrace();
210 } catch (SecurityDisallowedException e) {
212 e.printStackTrace();
213 } catch (ConsistanceException e) {
215 e.printStackTrace();
216 } catch (UnkErrException e) {
218 e.printStackTrace();
219 } catch (ObjectLockException e) {
221 e.printStackTrace();
226 public final void testCreateAndDeletePatient() throws Exception {
227 try {
229 String fornavn = "Albert";
230 String efternavn = "Åberg";
231 String adresse = "Lansgade";
232 int postnr = 1000;
233 String cpr = "122456-1233";
234 int sex = IPatient.SEX_MALE;
235 String tlf = "12345678";
236 IPatient pat2 = createPatient(fornavn, efternavn, adresse, postnr,
237 cpr, sex, tlf);
239 Vector vPat = patientHandler.searchPatientsByCPR(cpr);
240 assertEquals("Patienten er ikke fundet", 1, vPat.size());
241 IPatient p = (IPatient) vPat.get(0);
243 assertEquals("Fornavn er ikke ens", fornavn, p.getFornavn());
244 assertEquals("Efternavn er ikke ens", efternavn, p.getEfternavn());
246 deletePatient(pat2);
247 } catch (RemoteException e) {
248 e.printStackTrace();
249 fail();
250 } catch (ConsistanceException e) {
251 e.printStackTrace();
252 fail();
253 } catch (ObjectLockException e) {
254 e.printStackTrace();
255 fail();
256 } catch (UnkErrException e) {
257 e.printStackTrace();
258 fail();
259 } catch (Exception e) {
260 e.printStackTrace();
261 throw e;
265 public final void testCreateAndDeleteTidsreservation() {
266 try {
268 IPatient pat2 = createPatient("A", "B", "C", 1000, "123456-4321",
269 IPatient.SEX_MALE, "12345678");
270 IEmployee empl = createEmployee("A", "Berta", "QWERTY", "C", "12345678");
272 Timestamp start = Timestamp.valueOf("2004-1-1 12:00:00");
273 Timestamp slut = Timestamp.valueOf("2004-1-1 12:10:00");
274 String emne = "Rektalundersøgelse med tilhørende højtryks puling";
276 ITidsreservation reservation = createTidsReservation(pat2, empl,
277 start, slut, emne);
279 Vector v = tidsreservationsHandler.getFromDate(start);
281 assertEquals("Der er flere reservationer den enkelte dag",1,v.size());
283 deleteTidsReservation(reservation);
285 deleteEmployee(empl);
286 deletePatient(pat2);
287 } catch (RemoteException re) {
288 re.printStackTrace();
289 fail();
290 } catch (ConsistanceException e) {
291 e.printStackTrace();
292 fail();
293 } catch (ObjectLockException e) {
294 e.printStackTrace();
295 fail();
296 } catch (UnkErrException e) {
297 e.printStackTrace();
298 fail();
299 } catch (SecurityDisallowedException e) {
300 e.printStackTrace();
301 fail();