-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataWriterTest.java
324 lines (291 loc) · 14.4 KB
/
DataWriterTest.java
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import java.util.ArrayList;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.*;
public class DataWriterTest {
private SearchableDatabase searchableDatabase = SearchableDatabase.getInstance();
private ArrayList<User> userList = searchableDatabase.getUsers();
private ArrayList<JobListing> jobList = searchableDatabase.getJobListings();
private ArrayList<CompanyProfile> profileList = searchableDatabase.getCompanyProfiles();
@BeforeEach
public void setup() {
userList.clear();
jobList.clear();
profileList.clear();
searchableDatabase.getUsers().clear();
searchableDatabase.getJobListings().clear();
searchableDatabase.getCompanyProfiles().clear();
DataWriter.saveUsers();
DataWriter.saveJobListings();
DataWriter.saveCompanyProfiles();
}
@AfterEach
public void tearDown() {
userList.clear();
jobList.clear();
profileList.clear();
searchableDatabase.getUsers().clear();
searchableDatabase.getJobListings().clear();
searchableDatabase.getCompanyProfiles().clear();
DataWriter.saveUsers();
DataWriter.saveJobListings();
DataWriter.saveCompanyProfiles();
}
@Test
public void testWritingZeroUsers() {
userList = searchableDatabase.getUsers();
assertEquals(0, userList.size());
}
@Test
public void testWritingOneStudentNoResumeOrReviews() {
Student s1 = new Student("Baba","Booey","[email protected]","password","junior");
s1.setUserUUID(UUID.randomUUID());
searchableDatabase.addUser(s1);
DataWriter.saveUsers();
assertEquals("Booey", DataLoader.loadData().getUsers().get(0).getLastName());
}
@Test
public void testWritingThreeStudentsNoResumesOrReviews() {
Student s1 = new Student("Baba","Booey","[email protected]","password","junior");
Student s2 = new Student("Daba","Twooey","[email protected]","password2","freshman");
Student s3 = new Student("Gaba","Three-ey","[email protected]","password3","senior");
s1.setUserUUID(UUID.randomUUID());
s2.setUserUUID(UUID.randomUUID());
s3.setUserUUID(UUID.randomUUID());
searchableDatabase.addUser(s1);
searchableDatabase.addUser(s2);
searchableDatabase.addUser(s3);
DataWriter.saveUsers();
assertEquals("Three-ey", DataLoader.loadData().getUsers().get(2).getLastName());
}
@Test
public void testWritingOneStudentWithEmptyResume() {
Student s1 = new Student("Student","1","[email protected]","password!","senior");
s1.setUserUUID(UUID.randomUUID());
s1.createResume(new ArrayList<Integer>(), new ArrayList<Integer>(), new ArrayList<WorkExperience>(), new ArrayList<Education>());
searchableDatabase.addUser(s1);
DataWriter.saveUsers();
Student testStudent = (Student) DataLoader.loadData().getUsers().get(0);
assertEquals(s1.getResume().getEmail(), testStudent.getResume().getEmail());
}
@Test
public void testWritingOneStudentWithFilledResume() {
Student s1 = new Student("Student","1","[email protected]","password!","senior");
s1.setUserUUID(UUID.randomUUID());
s1.addSkill("Java");
s1.addClass("Intro to Science");
ArrayList<Integer> skillIndexes = new ArrayList<>();
skillIndexes.add(0);
ArrayList<Integer> classIndexes = new ArrayList<>();
classIndexes.add(0);
ArrayList<WorkExperience> workExperiences = new ArrayList<>();
workExperiences.add(new WorkExperience("Job 323","Real Inc","7/7/21-7/7/22","Some programming experience"));
ArrayList<Education> educations = new ArrayList<>();
educations.add(new Education("UofSA","Comp. Sci.",3.55,"Spring 2020"));
s1.createResume(skillIndexes, classIndexes,workExperiences, educations);
searchableDatabase.addUser(s1);
DataWriter.saveUsers();
Student testStudent = (Student) DataLoader.loadData().getUsers().get(0);
assertEquals(s1.getResume().getClass(), testStudent.getResume().getClass());
}
@Test
public void testWritingOneStudentWithReview() {
Student s1 = new Student("Student","1","[email protected]","password!","senior");
s1.setUserUUID(UUID.randomUUID());
Review review = new Review("IGN","", 0.78, "Too much water");
s1.addReview(review);
searchableDatabase.addUser(s1);
DataWriter.saveUsers();
Student testStudent = (Student) DataLoader.loadData().getUsers().get(0);
assertEquals(review.getRating(), testStudent.getReviews().get(0).getRating());
}
@Test
public void testWritingOneEmployerNoCompany() {
Employer e1 = new Employer("Guy","McReal","[email protected]","yeppers");
e1.setUserUUID(UUID.randomUUID());
searchableDatabase.addUser(e1);
DataWriter.saveUsers();
assertEquals("McReal", DataLoader.loadData().getUsers().get(0).getLastName());
}
@Test
public void testWritingOneEmployerWithCompanyAndID() {
CompanyProfile compProfile = new CompanyProfile("Walter's Rock Candy", "12345 Street Road", "Say My Name.");
compProfile.setUUID(UUID.randomUUID());
Employer e1 = new Employer("Walter","White","[email protected]","weHaveToCook", compProfile, UUID.randomUUID());
e1.setUserUUID(UUID.randomUUID());
searchableDatabase.addUser(e1);
DataWriter.saveUsers();
assertEquals("[email protected]", DataLoader.loadData().getUsers().get(0).getEmail());
}
@Test
public void testWritingThreeEmployers() {
Employer e1 = new Employer("Guy","McReal","[email protected]","yeppers");
e1.setUserUUID(UUID.randomUUID());
CompanyProfile compProfile = new CompanyProfile("Walter's Rock Candy", "12345 Street Road", "Say My Name.");
compProfile.setUUID(UUID.randomUUID());
Employer e2 = new Employer("Walter","White","[email protected]","weHaveToCook", compProfile, UUID.randomUUID());
Employer e3 = new Employer("Jesse","James","[email protected]","passwords");
e3.setUserUUID(UUID.randomUUID());
searchableDatabase.addUser(e1);
searchableDatabase.addUser(e2);
searchableDatabase.addUser(e3);
DataWriter.saveUsers();
assertEquals("James", DataLoader.loadData().getUsers().get(2).getLastName());
}
@Test
public void testWritingOneAdmin() {
Administrator a1 = new Administrator("Admin", "Istrator", "admin@admin", "admin", UUID.randomUUID());
a1.setUserUUID(UUID.randomUUID());
searchableDatabase.addUser(a1);
DataWriter.saveUsers();
assertEquals("Istrator", DataLoader.loadData().getUsers().get(0).getLastName());
}
@Test
public void testWritingThreeAdmins() {
Administrator a1 = new Administrator("Admin", "Istrator", "admin@admin", "admin", UUID.randomUUID());
Administrator a2 = new Administrator("Adam", "Inistrator", "admin2@admin2", "12345678", UUID.randomUUID());
Administrator a3 = new Administrator("First", "McLast", "admin3@admin3", "hehehehe", UUID.randomUUID());
searchableDatabase.addUser(a1);
searchableDatabase.addUser(a2);
searchableDatabase.addUser(a3);
DataWriter.saveUsers();
assertEquals("McLast", DataLoader.loadData().getUsers().get(2).getLastName());
}
@Test
public void testWritingOneOfEachUser() {
Administrator a1 = new Administrator("Admin", "Istrator", "admin@admin", "admin", UUID.randomUUID());
Employer e1 = new Employer("Guy","McReal","[email protected]","yeppers");
e1.setUserUUID(UUID.randomUUID());
Student s1 = new Student("Baba","Booey","[email protected]","password","junior");
s1.setUserUUID(UUID.randomUUID());
searchableDatabase.addUser(a1);
searchableDatabase.addUser(e1);
searchableDatabase.addUser(s1);
DataWriter.saveUsers();
assertEquals("McReal", DataLoader.loadData().getUsers().get(2).getLastName());
}
@Test
public void testWritingOneJobListingNoSkillsNoApplicants() {
JobListing j1 = new JobListing("New Job","It's a job","Right Here",true,12.00,"Testers United");
j1.setUUID(UUID.randomUUID());
CompanyProfile c1 = new CompanyProfile("Testers United", "4444 Four Drive", "It's a company");
c1.setUUID(UUID.randomUUID());
c1.addListing(j1);
searchableDatabase.addProfile(c1);
DataWriter.saveCompanyProfiles();
DataWriter.saveJobListings();
assertEquals(12.00, DataLoader.loadData().getJobListings().get(0).getPayRate());
}
@Test
public void testWritingThreeJobListingsNoSkillsNoApplicants() {
JobListing j1 = new JobListing("New Job","It's a job","Right Here",true,12.00,"My Company");
JobListing j2 = new JobListing("Part-time Server","You get to serve pizza!","NYC",true,15.50,"Pete's Pizza");
JobListing j3 = new JobListing("Assistant Clerk","You'll be paid in experience","Online",false,0.00,"Help Desk Inc");
j1.setUUID(UUID.randomUUID());
j2.setUUID(UUID.randomUUID());
j3.setUUID(UUID.randomUUID());
jobList.add(j1);
jobList.add(j2);
jobList.add(j3);
CompanyProfile c1 = new CompanyProfile("Testers United", "4444 Four Drive", "It's a company");
c1.setUUID(UUID.randomUUID());
c1.addListing(j1);
c1.addListing(j2);
c1.addListing(j3);
searchableDatabase.addProfile(c1);
DataWriter.saveCompanyProfiles();
DataWriter.saveJobListings();
assertFalse(DataLoader.loadData().getJobListings().get(2).getPaid());
}
@Test
public void testWritingOneJobListingWithSkillsAndApplicants() {
ArrayList<Student> applicants = new ArrayList<>();
Student s1 = new Student("Student","1","[email protected]","password!","senior");
s1.setUserUUID(UUID.randomUUID());
Student s2 = new Student("Student","2","[email protected]","password12345!","junior");
s2.setUserUUID(UUID.randomUUID());
applicants.add(s1);
applicants.add(s2);
userList.add(s1);
userList.add(s2);
DataWriter.saveUsers();
ArrayList<String> requiredSkills = new ArrayList<>();
requiredSkills.add("Java Programmer");
requiredSkills.add("Great communicator");
JobListing j1 = new JobListing("New Job","It's a job","Right Here",true,12.00,"My Company",
UUID.randomUUID(),applicants,requiredSkills,true);
CompanyProfile c1 = new CompanyProfile("Testers United", "4444 Four Drive", "It's a company");
c1.setUUID(UUID.randomUUID());
c1.addListing(j1);
searchableDatabase.addProfile(c1);
DataWriter.saveCompanyProfiles();
DataWriter.saveJobListings();
assertEquals("2", DataLoader.loadData().getJobListings().get(0).getApplicants().get(1).getLastName());
}
@Test
public void testWritingOneEmptyJobListing() {
JobListing j1 = new JobListing();
j1.setUUID(UUID.randomUUID());
CompanyProfile c1 = new CompanyProfile("Testers United", "4444 Four Drive", "It's a company");
c1.setUUID(UUID.randomUUID());
c1.addListing(j1);
searchableDatabase.addProfile(c1);
DataWriter.saveCompanyProfiles();
DataWriter.saveJobListings();
assertTrue(DataLoader.loadData().getJobListings().get(0).getVisibility());
}
@Test
public void testWritingOneCompanyProfile() {
CompanyProfile c1 = new CompanyProfile("Real Company INC", "12321 Street", "We are real and very employment");
c1.setUUID(UUID.randomUUID());
searchableDatabase.addProfile(c1);
DataWriter.saveCompanyProfiles();
assertEquals("12321 Street", DataLoader.loadData().getCompanyProfiles().get(0).getAddress());
}
@Test
public void testWritingThreeCompanyProfiles() {
CompanyProfile c1 = new CompanyProfile("Real Company INC", "12321 Street", "We are real and very employment");
c1.setUUID(UUID.randomUUID());
CompanyProfile c2 = new CompanyProfile("Java the Hutt's Coding Corp", "Galaxy Far, Far Away", "Code, you must.");
c2.setUUID(UUID.randomUUID());
CompanyProfile c3 = new CompanyProfile("Almost Bankrupt Company", "555 Desperation Avenue", "Please, we need new workers");
c3.setUUID(UUID.randomUUID());
searchableDatabase.addProfile(c1);
searchableDatabase.addProfile(c2);
searchableDatabase.addProfile(c3);
DataWriter.saveCompanyProfiles();
assertEquals("555 Desperation Avenue", DataLoader.loadData().getCompanyProfiles().get(2).getAddress());
}
@Test
public void testWritingCompanyProfileWithListings() {
JobListing j1 = new JobListing("New Job","It's a job","Right Here",true,12.00,"My Company");
j1.setUUID(UUID.randomUUID());
jobList.add(j1);
ArrayList<JobListing> c1Listings = new ArrayList<>();
c1Listings.add(j1);
CompanyProfile c1 = new CompanyProfile("Real Company INC", "12321 Street", "We are real and very employment", UUID.randomUUID(),
new ArrayList<Review>(), c1Listings);
searchableDatabase.addProfile(c1);
DataWriter.saveJobListings();
DataWriter.saveCompanyProfiles();
assertEquals(c1Listings.get(0).getDescription(), DataLoader.loadData().getCompanyProfiles().get(0).getListings().get(0).getDescription());
}
@Test
public void testWritingCompanyProfileWithListingsAndReviews() {
JobListing j1 = new JobListing("New Job","It's a job","Right Here",true,12.00,"My Company");
j1.setUUID(UUID.randomUUID());
ArrayList<JobListing> c1Listings = new ArrayList<>();
c1Listings.add(j1);
Review r1 = new Review("Johnny","Cash",2.00,"I focus on the pain, the only thing that's real");
ArrayList<Review> c1Reviews = new ArrayList<>();
c1Reviews.add(r1);
CompanyProfile c1 = new CompanyProfile("Real Company INC", "12321 Street", "We are real and very employment", UUID.randomUUID(),
c1Reviews, c1Listings);
c1.setUUID(UUID.randomUUID());
searchableDatabase.addProfile(c1);
DataWriter.saveCompanyProfiles();
assertEquals(c1Reviews.get(0).getRating(), DataLoader.loadData().getCompanyProfiles().get(0).getReviews().get(0).getRating());
}
}