-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackEndDeveloperTests.java
More file actions
203 lines (189 loc) · 7.94 KB
/
Copy pathBackEndDeveloperTests.java
File metadata and controls
203 lines (189 loc) · 7.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//--== CS400 File Header Information ==--
//Name: Gabriela Nawangsari Setyawan
//Email: gsetyawan@wisc.edu
//Team: Blue
//Role: Backend developer
//TA: Daniel Finer
//Lecturer: Gary Dahl
//Notes to Grader: n/a
import static org.junit.jupiter.api.Assertions.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.zip.DataFormatException;
import org.junit.jupiter.api.Test;
public class BackEndDeveloperTests {
/**
* Test to see if a BackEnd object is created correctly (check to see if size is
* correct based on the data input and BackEnd is not null)
*
* @throws FileNotFoundException if csv file is not found
* @throws NullPointerException if BackEnd object is not created
*/
@Test
public void testBackEndObject() throws NullPointerException, FileNotFoundException {
Reader filePathInput;
String dataInput = "name,check-in date,check-out date,room number\n"
+ "Leslie Smith,07/09/2020,7/11/2020,2019\n" + "Guntur Rashik,06/05/2020,06/07/2020,2015\n"
+ "Sarah Smith,08/20/2020,8/29/2020,1000";
filePathInput = new FileReader("Reservations.csv");
BackEnd backEnd1;
BackEnd backEnd2;
int expectedSizeForBE1 = 41;
int expectedSizeForBE2 = 3;
try {
backEnd1 = new BackEnd(filePathInput); // backEnd object using the csv file as the data input
backEnd2 = new BackEnd(dataInput); // backEnd object constructed using the
if (backEnd1.getSize() != expectedSizeForBE1) { // test to check if the size corresponds to the number of rows in the csv file (41)
fail("Did not successfully add reservations to the tree");
}
if (backEnd2.getSize() != expectedSizeForBE2) { // test to check if the size corresponds to the number of elements from the dataInput (3)
fail("Did not successfully add reservations to the tree");
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (DataFormatException e1) {
e1.printStackTrace();
} catch (NullPointerException e) {
fail("The backEnd object is still null");
}
}
/**
* Add 2 Reservations and check if the number of size return using getSize() is
* as expected every time we add a reservation
*
* @throws FileNotFoundException is thrown if csv file is not found
*/
@Test
public void testAddingReservation() throws FileNotFoundException {
// Initializing all the required fields to make the HotelReservation objects in order to add it
String nameRes1 = "Michael Jordan";
String nameRes2 = "Sandra Bullock";
String checkInDate1 = "08/08/2020";
String checkInDate2 = "08/10/2020";
String checkOutDate1 = "08/18/2020";
String checkOutDate2 = "08/14/2020";
int roomNumberRes1 = 3124;
int roomNumberRes2 = 3125;
Reader filePathInput;
filePathInput = new FileReader("Reservations.csv");
BackEnd backEnd;
try {
backEnd = new BackEnd(filePathInput);
backEnd.add(nameRes1, checkInDate1, checkOutDate1, roomNumberRes1); // add a new reservation
assertEquals(42, backEnd.getSize()); // see if the size increases by 1
backEnd.selectByOccupant("Michael Jordan");
backEnd.add(nameRes2, checkInDate2, checkOutDate2, roomNumberRes2); // add a new Reservation
assertEquals(43, backEnd.getSize()); // see if the size increases by 1
assertEquals(nameRes1 + ", " + checkInDate1 + "-" + checkOutDate1 + ", room " + roomNumberRes1,
backEnd.selectByDate(checkInDate1, checkOutDate1).get(0).toString());
} catch (IOException | DataFormatException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
System.out.print("We cannot have identical checkInDate and room number");
}
}
/**
* Tests if the correct node is returned if we try to find a reservation by
* passing in the checkIn and checkOut dates
*
* @throws FileNotFoundException if Reservations.csv is not found
*/
@Test
public void testSelectByDate() throws FileNotFoundException {
Reader filePathInput;
filePathInput = new FileReader("Reservations.csv");
BackEnd backEnd;
try {
backEnd = new BackEnd(filePathInput);
backEnd.selectByDate("06/27/2020", "07/01/2020"); // first attempt to look for a HotelReservationObject by checkIn and checkOut date
if (!backEnd.reservationListBasedOnDate.get(0).toString()
.equals("Denis Villeneuve, 06/27/2020-07/01/2020, room 2049")) {
fail("Did not get correct reservation");
}
backEnd.selectByDate("06/01/2020", "06/07/2020"); // second attempt
if (!backEnd.reservationListBasedOnDate.get(1).toString()
.equals("Barack Obama, 06/01/2020-06/07/2020, room 4128")) {
fail("Did not get correct reservation");
}
} catch (NullPointerException e) {
System.out.print("Tried to check an invalid reservation");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (DataFormatException e) {
e.printStackTrace();
}
}
/**
* Tests if the correct node is returned when we try to find a reservation by
* passing the occupant's name
*
* @throws DataFormatException if there are any incorrect data format when we try to read the data from the user
* @throws IOException if there is an error when trying to input/output data
* @throws FileNotFoundException if the csv file is not found
*/
@Test
public void testSelectByOccupant() throws FileNotFoundException {
Reader filePathInput;
filePathInput = new FileReader("Reservations.csv");
BackEnd backEnd;
String expectedFirst;
String expectedSecond;
try {
backEnd = new BackEnd(filePathInput);
backEnd.selectByOccupant("Martin Garrix");
expectedFirst = "Martin Garrix, 07/22/2020-07/31/2020, room 2044";
if (!backEnd.reservationListBasedOnName.get(0).toString().equals(expectedFirst)) {
fail("Did not get the correct reservation");
}
expectedSecond = "Barack Obama, 06/01/2020-06/07/2020, room 4128";
backEnd.selectByOccupant("Barack Obama");
if (!backEnd.reservationListBasedOnName.get(1).toString().equals(expectedSecond)) {
fail("Did not get the correct reservation");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException | DataFormatException e) {
e.printStackTrace();
}
}
/**
* Adds nodes with same dates and checks if the order is correct (based on room
* number, larger room number should be on the right side of parent while
* smaller room number should be on the left side)
* @throws DataFormatException if there are any incorrect data format when we try to read the data from the user
* @throws IOException if there is an error when trying to input/output data
* @throws FileNotFoundException if the csv file is not found
*/
@Test
public void testOrder() throws FileNotFoundException, IOException, DataFormatException {
Reader filePathInput;
filePathInput = new FileReader("Reservations.csv");
BackEnd backEnd;
backEnd = new BackEnd(filePathInput);
String expected = "[ Matthew McConaughey, 06/01/2020-06/12/2020, room 2020,"
+ " Calvin Johnson, 06/01/2020-06/15/2020, room 2137, "
+ "Mitchell Trubisky, 06/01/2020-08/30/2020, "
+ "room 3079, Barack Obama, 06/01/2020-06/07/2020, room 4128, "
+ "Gaby Setyawan, 06/02/2020-06/11/2020, room 3149, "
+ "Jennifer Lawrence, 06/04/2020-06/10/2020, room 1010, "
+ "Paul Atreides, 06/11/2020-06/29/2020, room 3122,"
+ " Zion Williamson, 06/12/2020-06/25/2020, room 1111, "
+ "Davis Mills, 06/20/2020-06/23/2020, room 4079, "
+ "Meghan Markle, 06/23/2020-07/10/2020, room 2021, "
+ "Damian Lillard, 06/24/2020-07/07/2020, room 5132, "
+ "Denis Villeneuve, 06/27/2020-07/01/2020, room 2049, "
+ "Jessica Xu, 06/28/2020-06/30/2020, room 5099, "
+ "Sandra Day-O'Connor , 06/29/2020-07/06/2020, room 1141, "
+ "Kevin Faulconer, 06/29/2020-07/05/2020, room 4044, "
+ "Ryan Gosling, 06/30/2020-07/06/2020, room 1010 ]";
if(!backEnd.june.toString().equals(expected)) {
fail("Didn't get the correct order, need to check red black tree again");
}
}
}