forked from ucsd-cse15l-w23/docsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestDocSearch.java
45 lines (43 loc) · 2.07 KB
/
TestDocSearch.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
import static org.junit.Assert.*;
import org.junit.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.io.IOException;
public class TestDocSearch {
@Test
public void testIndex() throws URISyntaxException, IOException {
Handler h = new Handler("./written_2/");
URI rootPath = new URI("http://localhost/");
assertEquals("There are 224 total files to search.", h.handleRequest(rootPath));
}
@Test
public void testSearch() throws URISyntaxException, IOException {
Handler h = new Handler("./written_2/");
URI rootPath = new URI("http://localhost/search?q=sushi");
String expect = "Found 3 paths:\n./written_2/travel_guides/berlitz1/WhatToJapan.txt\n./written_2/travel_guides/berlitz1/WhereToJapan.txt\n./written_2/travel_guides/berlitz2/California-WhereToGo.txt";
assertEquals(expect, h.handleRequest(rootPath));
}
@Test
public void testSearch2() throws URISyntaxException, IOException {
Handler h = new Handler("./written_2/");
URI rootPath = new URI("http://localhost/search?q=kingpin");
String expect = "Found 1 paths:\n./written_2/travel_guides/berlitz2/Crete-History.txt";
assertEquals(expect, h.handleRequest(rootPath));
}
@Test
public void testSearch3() throws URISyntaxException, IOException {
Handler h = new Handler("./written_2/");
URI rootPath = new URI("http://localhost/search?q=insipid");
String expect = "Found 1 paths:\n./written_2/travel_guides/berlitz1/WhereToItaly.txt";
assertEquals(expect, h.handleRequest(rootPath));
}
@Test
public void testSearch4() throws URISyntaxException, IOException {
Handler h = new Handler("./written_2/");
URI rootPath = new URI("http://localhost/search?q=kerosene");
String expect = "Found 3 paths:\n./written_2/non-fiction/OUP/Berk/ch1.txt\n" +
"./written_2/travel_guides/berlitz2/Bahamas-WhereToGo.txt\n" +
"./written_2/travel_guides/berlitz2/Nepal-WhatToDo.txt";
assertEquals(expect, h.handleRequest(rootPath));
}
}