2025-09-15 11:08:45 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* license: GPLv3
|
|
|
|
|
|
* lodge.reservationsystem
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2025-08-28 21:08:16 -04:00
|
|
|
|
package lodge;
|
|
|
|
|
|
|
2025-09-03 08:56:57 -04:00
|
|
|
|
import java.time.ZoneId;
|
|
|
|
|
|
import java.time.ZonedDateTime;
|
2025-09-24 16:51:48 -04:00
|
|
|
|
import java.time.temporal.ChronoUnit;
|
2025-09-03 08:56:57 -04:00
|
|
|
|
|
2025-09-18 12:18:33 -04:00
|
|
|
|
import lodge.data.Account;
|
|
|
|
|
|
import lodge.data.Address;
|
|
|
|
|
|
import lodge.data.DuplicateObjectException;
|
|
|
|
|
|
import lodge.data.EmailAddress;
|
|
|
|
|
|
import lodge.data.ReservationStatusEnum;
|
2025-09-24 16:51:48 -04:00
|
|
|
|
import lodge.reservation.IReservation;
|
|
|
|
|
|
import lodge.reservation.Reservation;
|
2025-08-28 21:08:16 -04:00
|
|
|
|
import lodge.reservationsystem.AccomodationManager;
|
2025-08-31 18:59:49 -04:00
|
|
|
|
import lodge.reservationsystem.CabinReservation;
|
|
|
|
|
|
import lodge.reservationsystem.HotelReservation;
|
2025-09-05 09:16:57 -04:00
|
|
|
|
import lodge.reservationsystem.HouseReservation;
|
2025-08-28 21:08:16 -04:00
|
|
|
|
|
2025-09-24 16:51:48 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* The Tests for the ReservationSystem Module
|
|
|
|
|
|
*
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
* This class main function acts as a driver function to run the test functions.
|
|
|
|
|
|
* </p>
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author Sherwin Price
|
|
|
|
|
|
* @version 1.0
|
|
|
|
|
|
* @since 2025
|
|
|
|
|
|
*/
|
2025-08-28 21:08:16 -04:00
|
|
|
|
public final class TestReservations {
|
2025-09-24 16:51:48 -04:00
|
|
|
|
// Request that Manager updates specific account’s files with data stored in
|
|
|
|
|
|
static void Test_AddAccount(AccomodationManager mgr, Account acct) throws Exception {
|
|
|
|
|
|
mgr.AddAccount(acct);
|
|
|
|
|
|
|
|
|
|
|
|
// 4. Request that Manager updates specific account’s files with data stored in
|
|
|
|
|
|
// memory
|
|
|
|
|
|
mgr.UpdateAccount(acct);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Test_AddReservation(AccomodationManager mgr, Account acct, Reservation rsrv, Address mlAddr,
|
|
|
|
|
|
ZonedDateTime zdtStrt)
|
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
rsrv.setMailing_address(mlAddr);
|
|
|
|
|
|
rsrv.setNumberOfBeds(2);
|
|
|
|
|
|
rsrv.setNumberOfFloors(1);
|
|
|
|
|
|
rsrv.setNumberOfBedRooms(1);
|
|
|
|
|
|
rsrv.setSquareFeet(450);
|
|
|
|
|
|
rsrv.setReservation_start_date(zdtStrt);
|
|
|
|
|
|
rsrv.setReservation_end_date(zdtStrt.plus(4, ChronoUnit.DAYS));
|
|
|
|
|
|
|
|
|
|
|
|
mgr.addReservation(acct, rsrv);
|
|
|
|
|
|
|
|
|
|
|
|
mgr.UpdateAccount(acct);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-28 21:08:16 -04:00
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
|
|
2025-09-24 16:51:48 -04:00
|
|
|
|
// Configure data repository
|
2025-09-05 10:26:49 -04:00
|
|
|
|
AccomodationManager mgr = new AccomodationManager(getRepositoryConfig.getPath());
|
2025-08-28 21:08:16 -04:00
|
|
|
|
|
2025-09-24 16:51:48 -04:00
|
|
|
|
// 1. Get the list of loaded accounts from Manager
|
2025-08-28 21:08:16 -04:00
|
|
|
|
mgr.loadAll();
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Retrieve a loaded account object that matches a specific account number
|
2025-09-06 19:21:01 -04:00
|
|
|
|
mgr.retrieveAccount("A1450981765");
|
2025-08-28 21:08:16 -04:00
|
|
|
|
|
|
|
|
|
|
// 3. Add new account object to the list managed by Manager (if account object
|
|
|
|
|
|
// already exists on add action with the same account number, it is considered
|
|
|
|
|
|
// an error)
|
|
|
|
|
|
|
2025-09-24 16:51:48 -04:00
|
|
|
|
Test_AddAccount(mgr, mgr.newAccount("701-456-7890",
|
2025-09-03 08:56:57 -04:00
|
|
|
|
new Address("10 wilco ave", "wilco", "WY", "82801"),
|
2025-09-24 16:51:48 -04:00
|
|
|
|
new EmailAddress("wilco@wyommin.net")));
|
2025-09-10 19:32:19 -04:00
|
|
|
|
|
2025-09-24 16:51:48 -04:00
|
|
|
|
Test_AddAccount(mgr, mgr.newAccount("301-356-3890",
|
2025-09-10 19:32:19 -04:00
|
|
|
|
new Address("30 Amstadam ave", "New York", "NY", "12010"),
|
2025-09-24 16:51:48 -04:00
|
|
|
|
new EmailAddress("newbee952@aol.com")));
|
|
|
|
|
|
|
2025-08-28 21:08:16 -04:00
|
|
|
|
// 5. Add draft lodging reservation to an account (if reservation object already
|
|
|
|
|
|
// exists with the same reservation number, it is considered an error)
|
2025-09-24 16:51:48 -04:00
|
|
|
|
Account acct2 = mgr.retrieveLoadedAccounts().get(1);
|
|
|
|
|
|
Test_AddReservation(mgr, acct2,
|
|
|
|
|
|
new HotelReservation(
|
|
|
|
|
|
new Address("400 hotel ave", "Maryland City", "MD", "20723")),
|
|
|
|
|
|
new Address("400 hotel ave", "Maryland City", "MD", "20723"),
|
|
|
|
|
|
ZonedDateTime.of(2025, 9, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
|
|
|
|
|
|
|
|
|
|
|
Account acct1 = mgr.retrieveLoadedAccounts().get(0);
|
|
|
|
|
|
Test_AddReservation(mgr, acct2,
|
|
|
|
|
|
new CabinReservation(new Address("30 cabin ave", "Carnelian", "CA", "96140")),
|
|
|
|
|
|
new Address("30 cabin ave", "Carnelian Bay", "CA", "96140"),
|
|
|
|
|
|
ZonedDateTime.of(2025, 9, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
|
|
|
|
|
|
|
|
|
|
|
Test_AddReservation(mgr, acct1,
|
|
|
|
|
|
new CabinReservation(new Address("40 cabin ave", "Carnelian", "CA", "96140")),
|
|
|
|
|
|
new Address("40 cabin ave", "Carnelian Bay", "CA", "96140"),
|
|
|
|
|
|
ZonedDateTime.of(2025, 9, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
|
|
|
|
|
|
|
|
|
|
|
Test_AddReservation(mgr, acct1,
|
|
|
|
|
|
new HouseReservation(new Address("3000 Osage ave", "GreenBelt", "MD", "20740")),
|
|
|
|
|
|
new Address("40012 College ave", "College Park", "MD", "20740"),
|
|
|
|
|
|
ZonedDateTime.of(2025, 9, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
2025-09-03 12:25:10 -04:00
|
|
|
|
|
2025-09-03 08:56:57 -04:00
|
|
|
|
try {
|
2025-09-24 16:51:48 -04:00
|
|
|
|
IReservation irsrv = acct1.getAllReservations().next();
|
|
|
|
|
|
if (mgr.addReservation(acct1, acct1.findReservation(irsrv.getReservation_number()))) {
|
|
|
|
|
|
mgr.UpdateAccount(mgr.retrieveAccount(irsrv.getAccountNumber()));
|
2025-09-18 12:18:33 -04:00
|
|
|
|
}
|
2025-09-10 13:06:54 -04:00
|
|
|
|
} catch (DuplicateObjectException e) {
|
2025-09-03 12:25:10 -04:00
|
|
|
|
System.out.println(e.getMessage());
|
2025-09-03 08:56:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-18 12:18:33 -04:00
|
|
|
|
Account account = mgr.retrieveLoadedAccounts().get(0);
|
2025-08-31 18:59:49 -04:00
|
|
|
|
|
2025-08-29 07:26:53 -04:00
|
|
|
|
// 6. Complete reservation that is associated with an account
|
2025-09-24 16:51:48 -04:00
|
|
|
|
IReservation irsrv = account.getAllReservations().next();
|
|
|
|
|
|
Reservation rsrv = account.findReservation(irsrv.getReservation_number());
|
|
|
|
|
|
rsrv.Change(rsrv, ReservationStatusEnum.Completed);
|
|
|
|
|
|
mgr.UpdateAccount(mgr.retrieveAccount(account.getAccount_number()));
|
2025-08-29 10:32:10 -04:00
|
|
|
|
|
|
|
|
|
|
// 7. Cancel reservation that is associated with an account
|
2025-09-18 12:18:33 -04:00
|
|
|
|
account = mgr.retrieveLoadedAccounts().getLast();
|
|
|
|
|
|
IReservation ir = account.getAllReservations().next();
|
2025-09-24 16:51:48 -04:00
|
|
|
|
rsrv = (Reservation) ir;
|
2025-09-18 12:18:33 -04:00
|
|
|
|
rsrv.Change(rsrv, ReservationStatusEnum.Canceled);
|
|
|
|
|
|
mgr.UpdateAccount(mgr.retrieveAccount(rsrv.getAccountNumber()));
|
2025-09-10 17:54:48 -04:00
|
|
|
|
|
|
|
|
|
|
// 8. Change reservation values that can be changed (if reservation is
|
|
|
|
|
|
// cancelled, completed, or for past date, it is considered an error)
|
2025-09-18 12:18:33 -04:00
|
|
|
|
rsrv.Change(rsrv, ReservationStatusEnum.Completed);
|
2025-09-24 16:51:48 -04:00
|
|
|
|
rsrv.update(rsrv);
|
2025-09-10 17:54:48 -04:00
|
|
|
|
|
|
|
|
|
|
// 9. Request for price per night to be calculated and returned for a
|
|
|
|
|
|
// per night
|
|
|
|
|
|
// reservation
|
2025-09-26 23:38:25 -04:00
|
|
|
|
System.out.println(String.format("%s Per Night Rate: %f",
|
|
|
|
|
|
rsrv.ReservationType().replace("Reservation", ""), rsrv.getPricePerNight()));
|
2025-09-10 17:54:48 -04:00
|
|
|
|
|
|
|
|
|
|
// 10. Request for total reservation price to be calculated and returned for
|
|
|
|
|
|
// specific reservation
|
2025-09-24 16:51:48 -04:00
|
|
|
|
rsrv = account.findReservation(rsrv.getReservation_number());
|
|
|
|
|
|
rsrv.calculatePrice();
|
2025-09-10 17:54:48 -04:00
|
|
|
|
|
2025-09-14 11:56:57 -04:00
|
|
|
|
mgr.showReservationList();
|
|
|
|
|
|
|
2025-08-28 21:08:16 -04:00
|
|
|
|
System.out.println("Program Completed.");
|
|
|
|
|
|
}
|
2025-09-10 17:54:48 -04:00
|
|
|
|
|
|
|
|
|
|
public final static class getRepositoryConfig {
|
|
|
|
|
|
public final static String getPath() {
|
|
|
|
|
|
String home = System.getenv("HOME") != null ? System.getenv("HOME")
|
|
|
|
|
|
: System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH");
|
|
|
|
|
|
return home.replace('\\', '/') + "/workspace/reservationsystem/src/resources";
|
2025-09-05 09:16:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-28 21:08:16 -04:00
|
|
|
|
}
|