-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestIOMachine.java
315 lines (265 loc) · 12.2 KB
/
testIOMachine.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
import javax.swing.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;
/**
* testIOMachine
*
* This class was made to test the methods in IOMachine.java. Each method is tested with inputs that
* will result in successful operation, as well as inputs that will result in failed operation. This
* is done through running this class alongside the server programs.
*
* @author Team 60, Section 11
* @version 5/03/2021
*
*/
public class testIOMachine implements Serializable {
public static void main(String[] args) throws IOException {
try { //runs client side stuff
// getting localhost ip
InetAddress ip = InetAddress.getByName("localhost");
// establish the connection with server port 1234
Socket s = new Socket(ip, 1234); //CHANGE FOR USE WITH UNITY TO 5555
// obtaining input and out streams
ObjectOutputStream dos = new ObjectOutputStream(s.getOutputStream());
ObjectInputStream dis = new ObjectInputStream(s.getInputStream());
//Confirm connection successful
JOptionPane.showMessageDialog(null, "Connection Established", "CampsGram",
JOptionPane.INFORMATION_MESSAGE);
//creates an IOMachine to easily access the server
IOMachine ioMachine = new IOMachine(dos, dis);
//initializing fields to create new profile and account objects
ArrayList<String> interests = new ArrayList<>(); //interests list
interests.add("running");
interests.add("gaming");
interests.add("tech");
ArrayList<String> friends = new ArrayList<>(); //friends list
friends.add("Joe");
friends.add("Jack");
friends.add("Nick");
ArrayList<String> requestsSent = new ArrayList<>(); //friend requests sent
requestsSent.add("1");
requestsSent.add("2");
ArrayList<String> requestsReceived = new ArrayList<>(); //friend requests received
requestsReceived.add("1");
requestsReceived.add("2");
//creating new profile objects to use in testing
Profile pf = new Profile("chen3801", interests, friends, "Purdue University",
"jchsda@gmail.com", 1231231234L, "jdsfhladhflajdshfladhflal " +
"dsfasdfhlahfl",
requestsSent, requestsReceived);
Profile pf1 = new Profile("chen380", interests, friends, "Purdue University",
"jchsda@gmail.com", 1231231234L, "jdsfhladhflajdshfladhflal " +
"dsfasdfhlahfl",
requestsSent, requestsReceived);
ArrayList<Profile> pfList = new ArrayList<>();
pfList.add(pf);
//creating new account objects to use in testing
Account newAccount = new Account("jchsda@gmail.com", "asahdlh@dahl123", pfList);
Account newAccount2 = new Account("jch000@gmail.com", "asahdlh@dahl123", pfList);
//Success Case: addAccount()
// adds account to server successfully
try {
ioMachine.addAccount(newAccount);
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: addAccount()
// fails to add account to server due to incorrect input
try {
ioMachine.addAccount(pf);
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: findAccount()
// finds account in server successfully
try {
Account account = ioMachine.findAccount("jchsda@gmail.com");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: findAccount()
// returns false due to failing to find account associated with this email
try {
Account account = ioMachine.findAccount("NaN@gmail.com");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: deleteAccount()
// deletes account from server successfully
try {
boolean accDeleted = ioMachine.deleteAccount(newAccount);
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: deleteAccount()
// fails to delete account due to invalid input
try {
boolean accDeleted = ioMachine.deleteAccount(pf);
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: addProfile()
// successfully adds a profile to the account associated with that email
try {
ioMachine.addProfile(pf1, "jchsda@gmail.com");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: addProfile()
// fails to add a profile to the account due to no account associated with the email
try {
ioMachine.addProfile(pf1, "NaN@gmail.com");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: findProfile()
// successfully finds profile
try {
Profile profile = ioMachine.findProfile("chen3801");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: findProfile()
// fails to find profile due to no such profile existing
try {
Profile profile = ioMachine.findProfile("NaN");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: deleteProfile()
// deletes profile successfully
try {
boolean deleted = ioMachine.deleteProfile("chen3801");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: deleteProfile()
//fails to delete profile due to invalid input
try {
boolean deleted = ioMachine.deleteProfile("NaN");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: editProfile()
// edits profile successfully
try {
boolean profileEdit = ioMachine.editProfile("chen3801",
"PhoneNumber", "2342342345");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: editProfile()
// fails to edit profile due to invalid input for the fields
try {
boolean profileEdit = ioMachine.editProfile("NaN",
"Address", "NaNNaNNaNNaN");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: editProfileList()
// edits list fields for specified profile successfully
try {
boolean profileEditList = ioMachine.editProfileList("Add",
"chen3801", "Interest", "sleeping");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: editProfileList()
// fails to edit list field due to invalid input
try {
boolean profileEditList = ioMachine.editProfileList("Pause",
"NaN", "NaN", "NaN");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: sendRequest()
// successfully sends a friend request to specified profile
try {
boolean requestSent = ioMachine.sendRequest("chen3801", "chen380");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: sendRequest()
// fails to send a friend request due to invalid input
try {
boolean requestSent = ioMachine.sendRequest("NaN", "NaNNaN");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: rescindRequest()
// successfully rescinds friend request
try {
boolean rescindRequest = ioMachine.rescindRequest("chen3801", "chen380");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: rescindRequest()
// fails to rescind friend request due to improper input
try {
boolean rescindRequest = ioMachine.rescindRequest("NaN", "NaNNaN");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: acceptFriend()
// successfully accepts specified friend request
try {
boolean friendAccepted = ioMachine.acceptFriend("chen3801", "chen380");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: acceptFriend()
// fails to accept
try {
boolean friendAccepted = ioMachine.acceptFriend("NaN", "NaNNaN");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: declineFriend()
// successfully declines friend request
try {
boolean friendDeclined = ioMachine.declineFriend("chen3801", "chen380");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: declineFriend()
// fails to decline friend request due to invalid input
try {
boolean friendDeclined = ioMachine.declineFriend("NaN", "NaNNaN");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: unfriend()
// successfully unfriends specified profile
try {
boolean unfriended = ioMachine.unfriend("chen3801", "chen380");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Failure Case: unfriend()
// fails to unfriend profile due to invalid input
try {
boolean unfriended = ioMachine.unfriend("NaN", "NaNNaN");
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
//Success Case: viewAllProfiles()
// successfully assigns arraylist of strings containing all usernames to variable
try {
ArrayList<String> viewAllProfiles = ioMachine.viewAllProfiles();
} catch (Exception e) {
System.out.println("Error: An Exception Has Occurred");
}
} catch (IOException e) { //display error message is connection not established
JOptionPane.showMessageDialog(null, "Error: Connection Cannot be Established",
"Campsgram", JOptionPane.ERROR_MESSAGE);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error: There was an Error in the code " +
"somewhere", "Campsgram", JOptionPane.ERROR_MESSAGE);
}
}
}