/
WebServerTest.java
55 lines (44 loc) · 1.72 KB
/
WebServerTest.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
package com.vtence.molecule;
import com.vtence.molecule.testing.http.HttpRequest;
import com.vtence.molecule.testing.http.HttpResponse;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.net.URI;
import java.security.GeneralSecurityException;
import java.util.logging.LogManager;
import static com.vtence.molecule.testing.ResourceLocator.locateOnClasspath;
import static com.vtence.molecule.testing.http.HttpResponseAssert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class WebServerTest {
WebServer server;
HttpRequest request = new HttpRequest(8080);
HttpResponse response;
@BeforeClass public static void
silenceLogging() {
LogManager.getLogManager().reset();
}
@After
public void stopServer() throws Exception {
server.stop();
}
@Test
public void runsServerOnPort8080ByDefault() throws IOException, GeneralSecurityException {
server = WebServer.create();
server.start((request, response) -> response.body("It works!").done());
response = request.get("/");
assertThat(response).hasBodyText("It works!");
}
@Test
public void knowsServerUri() throws IOException {
server = WebServer.create("0.0.0.0", 9000);
assertThat("server uri", server.uri(), equalTo(URI.create("http://0.0.0.0:9000")));
}
@Test
public void tellsWhenServerIsUsingSSL() throws Exception {
server = WebServer.create("0.0.0.0", 8443).enableSSL(locateOnClasspath("ssl/keystore"), "password", "password");
assertThat("server uri", server.uri(), equalTo(URI.create("https://0.0.0.0:8443")));
}
}