-
Notifications
You must be signed in to change notification settings - Fork 0
/
HandlerTests.java
52 lines (47 loc) · 1.85 KB
/
HandlerTests.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
import static org.junit.Assert.*;
import org.junit.*;
import java.net.URI;
public class HandlerTests {
@Test
public void handleRequest1() throws Exception {
ChatHandler h = new ChatHandler();
String url = "http://localhost:4000/chat?user=joe&message=hi";
URI input = new URI(url);
String expected = "joe: hi\n\n";
assertEquals(expected, h.handleRequest(input));
}
@Test
public void handleRequest2() throws Exception {
ChatHandler h = new ChatHandler();
// NOTE: %20 is the way to put a space in the parameters of a URL
String url = "http://localhost:4000/chat?user=edwin&message=happy%20friday!";
URI input = new URI(url);
String expected = "edwin: happy friday!\n\n";
assertEquals(expected, h.handleRequest(input));
}
@Test
public void handleRequestMulti() throws Exception {
ChatHandler h = new ChatHandler();
String url1 = "http://localhost:4000/chat?user=onat&message=good%20luck";
String url2 = "http://localhost:4000/chat?user=edwin&message=with%20your%20demo!";
URI input1 = new URI(url1);
URI input2 = new URI(url2);
String expected = "onat: good luck\n\nedwin: with your demo!\n\n";
h.handleRequest(input1);
assertEquals(expected, h.handleRequest(input2));
}
@Test
public void handleRequestSemanticAnalysis() throws Exception {
ChatHandler h = new ChatHandler();
String url1 = "http://localhost:4000/chat?user=onat&message=😂";
// String url2 = "http://localhost:4000/chat?user=onat&message=doggy🥹!!!";
String url3 = "http://localhost:4000/semantic-analysis?user=onat";
URI input1 = new URI(url1);
// URI input2 = new URI(url2);
URI input3 = new URI(url3);
String expected = "onat: 😂 This message has a LOL vibe.\n\n";
h.handleRequest(input1);
// h.handleRequest(input2);
assertEquals(expected, h.handleRequest(input3));
}
}