forked from ucsd-cse15l-w23/skill-demo1-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileServerTests.java
27 lines (24 loc) · 882 Bytes
/
FileServerTests.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
import static org.junit.Assert.*;
import org.junit.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.io.IOException;
public class FileServerTests {
@Test
public void testIndex() throws URISyntaxException, IOException {
Handler h = new Handler("./test-data");
URI rootPath = new URI("http://localhost/");
assertEquals("Use /search?q=... to search the files!", h.handleRequest(rootPath));
}
@Test
public void testSearch() throws URISyntaxException, IOException {
Handler h = new Handler("./test-data/");
URI rootPath = new URI("http://localhost/search?q=abc");
String path1 = "./test-data/abc.txt";
String path2 = "./test-data/abcdef.txt";
String result = h.handleRequest(rootPath);
assertTrue(result.startsWith("Found 2 files"));
assertTrue(result.contains(path1));
assertTrue(result.contains(path2));
}
}