aCiotola / ReservationSys

Software Dev 3 - Assignment
0 stars 0 forks source link

Code the ReservationListDB and ReservationListDBTest Classes #12

Closed aCiotola closed 7 years ago

aCiotola commented 7 years ago

The ReservationListDB class must be a member of the groupX.hotel.data package and it must implement the ReservationDAO interface.

It must declare the following instance fields and overloaded constructors.

private List<Reservation> database;
private List<Room> allRooms;
private final ListPersistenceObject listPersistenceObject;
private final HotelFactory factory; 

public CustomerListDB (ListPersistenceObject listPersistenceObject)
public CustomerListDB (ListPersistenceObject listPersistenceObject,
                    HotelFactory factory)

allrooms is set by the constructors from the listPersistenceObject’s getRoomDatabase method. In order to be able to override and test the methods specified by the ReservationDAO interface in the ReservationListDB class one at a time, stub all the ReservationListDB class methods. Once stubbed you will be able to override and test each method separately in the order specified below.

• Override the toString method so that when invoked, it returns a String representation of the contents of the database, one element per line as shown by the sample below:

Number of reservations in database: 8 raj@aa.ru20169102016915101 j@b.com20169152016920101 etc…

Add the methods required to test the ReservationListDB constructors and the toString method to your test application.

• Override and test the add (Reservation reserv) method

First check if the reservation overlaps with an existing reservation. If there is an overlap, throw a DuplicateReservationExcption. If the reservation does not overlap, adds a reference to a copy of the object referenced by the reserv and not the actual object being referenced by the parameter. In order to instantiate a Reservation object, use the factory class. Note that the reservation must be added in correct order to keep the database in sorted order. Implement a binary search private method to help. In your test class, verify that add works by invoking toString.

• Override and test the disconnect method

In order to make the database transactions persistent, the disconnect method must be implemented. This method must save the database to disk and assign null to the database field. In your test method, make certain that the changes to the database are persistent (i.e. add new reservation to the database, invoke the disconnect method to persist, reconnect by creating a new instance of the ReservationListDB class and display the string returned by the toString() method.

• Override and test the getReservations(Customer cust) method

Returns a copy of the Reservations belonging to the customer, or an empty arraylist..

• Override and test the cancel(Reservations reserv) method

Removes a reservation from the database if it is found; otherwise throw a NonExistingReservationException.

• Override and test the getReservedRooms(LocalDate checkin, LocalDate checkout) method

Returns an arraylist with all reserved Rooms overlapping during the time period. You must check if an existing reservation has a room that has been reserved with the checkin date of the reservation before the checkout date provided, and the checkout date of the reservation is after the checkin date provided: in this case the room is reserved. Only add a room once to the arraylist. You don’t need to make a defensive copy since Rooms are immutable.

• Override and test the getFreeRooms(LocalDate checkin, LocalDate checkout) method

Returns an arraylist with all unreserved Rooms overlapping during the time period - in otherwords, all rooms that are not returned by getReservedRooms. You don’t need to make a defensive copy since Rooms are immutable.

• Override and test the getFreeRooms(LocalDate checkin, LocalDate checkout, RoomType type) method

Returns an arraylist with all unreserved Rooms with the given room type overlapping during the time period. You don’t need to make a defensive copy since Rooms are immutable.

• Override and test the clearAllPast() method

This method removes all Reservations whose checkout date is before the current date, as returned by LocalDate.now()

aCiotola commented 7 years ago

completed by steven