2 * Oprettet 2005-05-12 af tobibobi
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
;
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
;
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
,
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
);
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
,
93 IPatientEditable pat
= patientHandler
.createNewPatient();
94 pat
.setFornavn(fornavn
);
95 pat
.setEfternavn(efternavn
);
96 pat
.setAdresse(adresse
);
97 pat
.setPostnummer(new Integer(postnr
));
100 pat
.setDoctor(loginHandler
.getUser());
102 IPatient pat2
= patientHandler
.savePatient(pat
);
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
,
122 ITidsreservationEditable tidsr
= tidsreservationsHandler
.createNewTidsReservation();
123 tidsr
.setEmployee(empl
);
125 tidsr
.setPatient(pat2
);
126 tidsr
.setTidStart(start
);
127 tidsr
.setTidSlut(slut
);
128 tidsr
.setType(ITidsreservation
.TYPE_CONSULTATION
);
129 ITidsreservation reservation
= tidsreservationsHandler
.saveTidsreservation(tidsr
);
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
));
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
));
158 * @throws ConsistanceException
159 * @throws ObjectLockException
160 * @throws UnkErrException
161 * @throws RemoteException
163 private void deleteTidsReservation(ITidsreservation reservation
)
164 throws ConsistanceException
, ObjectLockException
, UnkErrException
,
166 tidsreservationsHandler
.deleteTidsreservation(tidsreservationsHandler
167 .editTidsreservation(reservation
));
170 public void setUp() {
174 Registry reg
= LocateRegistry
.getRegistry("localhost");
175 loginHandler
= ((LoginHandler
) reg
.lookup("DrNOServer")).login(
177 patientHandler
= loginHandler
.getPatientHandler();
178 employeeHandler
= loginHandler
.getEmployeeHandler();
179 tidsreservationsHandler
= loginHandler
.getTidsreservationsHandler();
181 } catch (Exception ex
) {
182 ex
.printStackTrace();
187 public void tearDown() {
190 public final void testCreateAndDeleteEmployee() {
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
) {
210 } catch (SecurityDisallowedException e
) {
213 } catch (ConsistanceException e
) {
216 } catch (UnkErrException e
) {
219 } catch (ObjectLockException e
) {
226 public final void testCreateAndDeletePatient() throws Exception
{
229 String fornavn
= "Albert";
230 String efternavn
= "Åberg";
231 String adresse
= "Lansgade";
233 String cpr
= "122456-1233";
234 int sex
= IPatient
.SEX_MALE
;
235 String tlf
= "12345678";
236 IPatient pat2
= createPatient(fornavn
, efternavn
, adresse
, postnr
,
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());
247 } catch (RemoteException e
) {
250 } catch (ConsistanceException e
) {
253 } catch (ObjectLockException e
) {
256 } catch (UnkErrException e
) {
259 } catch (Exception e
) {
265 public final void testCreateAndDeleteTidsreservation() {
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
,
279 Vector v
= tidsreservationsHandler
.getFromDate(start
);
281 assertEquals("Der er flere reservationer den enkelte dag",1,v
.size());
283 deleteTidsReservation(reservation
);
285 deleteEmployee(empl
);
287 } catch (RemoteException re
) {
288 re
.printStackTrace();
290 } catch (ConsistanceException e
) {
293 } catch (ObjectLockException e
) {
296 } catch (UnkErrException e
) {
299 } catch (SecurityDisallowedException e
) {