128 lines
6.2 KiB
Java
128 lines
6.2 KiB
Java
package lodge;
|
||
|
||
import java.time.ZoneId;
|
||
import java.time.ZonedDateTime;
|
||
|
||
import lodge.reservationsystem.AccomodationManager;
|
||
import lodge.reservationsystem.Account;
|
||
import lodge.reservationsystem.Address;
|
||
import lodge.reservationsystem.CabinReservation;
|
||
import lodge.reservationsystem.EmailAddress;
|
||
import lodge.reservationsystem.HotelReservation;
|
||
import lodge.reservationsystem.HouseReservation;
|
||
import lodge.reservationsystem.Reservation;
|
||
import lodge.reservationsystem.ReservationStatusEnum;
|
||
|
||
public final class TestReservations {
|
||
public static void main(String[] args) throws Exception {
|
||
|
||
AccomodationManager mgr = new AccomodationManager(getRepositoryConfig.getPath());
|
||
// 1. Get the list of loaded accounts from Manager
|
||
|
||
mgr.loadAll();
|
||
|
||
// 2. Retrieve a loaded account object that matches a specific account number
|
||
|
||
mgr.retrieveAccount("A1450981765");
|
||
|
||
// 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)
|
||
|
||
Account acct = mgr.newAccount("701-456-7890",
|
||
new Address("10 wilco ave", "wilco", "WY", "82801"),
|
||
new EmailAddress("wilco@wyommin.net"));
|
||
mgr.AddAccount(acct);
|
||
|
||
// 4. Request that Manager updates specific account’s files with data stored in
|
||
// memory
|
||
mgr.UpdateAccount(acct);
|
||
// 5. Add draft lodging reservation to an account (if reservation object already
|
||
// exists with the same reservation number, it is considered an error)
|
||
|
||
HotelReservation hotel = new HotelReservation(new Address("400 hotel ave", "Maryland City", "CA", "20723"));
|
||
hotel.setMailing_address(new Address("400 hotel ave", "Maryland City", "MD", "20723"));
|
||
hotel.setNumberOfBeds(2);
|
||
hotel.setNumberOfFloors(1);
|
||
hotel.setNumberOfBedRooms(1);
|
||
hotel.setSquareFeet(450);
|
||
hotel.setReservation_start_date(ZonedDateTime.of(2025, 07, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
||
hotel.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
|
||
boolean success1 = mgr.addReservation(acct, hotel);
|
||
assert success1;
|
||
|
||
mgr.UpdateAccount(acct);
|
||
|
||
CabinReservation cabin = new CabinReservation(new Address("30 cabin ave", "Carnelian", "CA", "96140"));
|
||
cabin.setMailing_address(new Address("40 cabin ave", "Carnelian Bay", "CA", "96140"));
|
||
cabin.setNumberOfBeds(4);
|
||
cabin.setNumberOfFloors(2);
|
||
cabin.setNumberOfBedRooms(3);
|
||
cabin.setSquareFeet(806);
|
||
cabin.setReservation_start_date(ZonedDateTime.of(2025, 9, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
||
cabin.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
|
||
boolean success2 = mgr.addReservation(acct, cabin);
|
||
assert success2;
|
||
|
||
mgr.UpdateAccount(acct);
|
||
|
||
HouseReservation house = new HouseReservation(new Address("3000 Osage ave", "GreenBelt", "MD", "20740"));
|
||
house.setMailing_address(new Address("40012 College ave", "College Park", "MD", "20740"));
|
||
house.setNumberOfBeds(4);
|
||
house.setNumberOfFloors(3);
|
||
house.setNumberOfBedRooms(3);
|
||
house.setSquareFeet(1400);
|
||
house.setReservation_start_date(ZonedDateTime.of(2025, 9, 5, 10, 0, 0, 0, ZoneId.of("UTC")));
|
||
house.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
|
||
boolean success3 = mgr.addReservation(acct, house);
|
||
assert success3;
|
||
|
||
mgr.UpdateAccount(acct);
|
||
|
||
|
||
try {
|
||
mgr.addReservation(acct, cabin);
|
||
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
||
} catch (Exception e) {
|
||
System.out.println(e.getMessage());
|
||
}
|
||
|
||
Account account = mgr.retrieveLoadedAccounts().getFirst();
|
||
Reservation rsrv = account.getReservation_list().getLast();
|
||
|
||
// 6. Complete reservation that is associated with an account
|
||
rsrv = mgr.retreiveReservation(cabin.getReservation_number());
|
||
rsrv.Change(rsrv, ReservationStatusEnum.Completed);
|
||
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
||
|
||
// 7. Cancel reservation that is associated with an account
|
||
rsrv = mgr.retreiveReservation(cabin.getReservation_number());
|
||
rsrv.Change(rsrv, ReservationStatusEnum.Canceled);
|
||
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
||
/*
|
||
*
|
||
* if (rsrv != null) {
|
||
* // 8. Change reservation values that can be changed (if reservation is
|
||
* // cancelled, completed, or for past date, it is considered an error)
|
||
* rsrv = Reservation.update(rsrv);
|
||
*
|
||
* // 9. Request for price per night to be calculated and returned for a
|
||
* specific
|
||
* // reservation
|
||
*
|
||
* rsrv = Reservation.calculatePricePerNight(rsrv);
|
||
* // 10. Request for total reservation price to be calculated and returned for
|
||
* a
|
||
* // specific reservation
|
||
* }
|
||
*/
|
||
System.out.println("Program Completed.");
|
||
}
|
||
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";
|
||
}
|
||
}
|
||
}
|