Remove obsolete loading animation
[Sone.git] / src / test / java / net / pterodactylus / sone / main / DefaultLoadersTest.java
1 package net.pterodactylus.sone.main;
2
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.is;
5 import static org.hamcrest.Matchers.notNullValue;
6 import static org.hamcrest.Matchers.startsWith;
7 import static org.mockito.Mockito.mock;
8
9 import java.io.ByteArrayOutputStream;
10 import java.io.IOException;
11 import java.io.OutputStream;
12 import java.io.StringWriter;
13 import java.net.URI;
14 import java.net.URISyntaxException;
15
16 import net.pterodactylus.sone.web.page.FreenetRequest;
17 import net.pterodactylus.util.template.Template;
18 import net.pterodactylus.util.template.TemplateContext;
19 import net.pterodactylus.util.template.TemplateProvider;
20 import net.pterodactylus.util.web.Method;
21 import net.pterodactylus.util.web.Page;
22 import net.pterodactylus.util.web.Response;
23
24 import freenet.clients.http.ToadletContext;
25 import freenet.support.api.HTTPRequest;
26
27 import org.junit.Test;
28
29 /**
30  * Unit test for {@link DefaultLoaders}.
31  *
32  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33  */
34 public class DefaultLoadersTest {
35
36         private final Loaders loaders = new DefaultLoaders();
37         private final StringWriter stringWriter = new StringWriter();
38         private final TemplateContext templateContext = new TemplateContext();
39
40         @Test
41         public void templateCanBeLoadedFromTheClasspath() {
42                 Template template = loaders.loadTemplate("/net/pterodactylus/sone/main/template.txt");
43                 template.render(templateContext, stringWriter);
44                 assertThat(stringWriter.toString(), is("Template. bar\n"));
45         }
46
47         @Test
48         public void staticPageIsServedFromClasspath() throws IOException, URISyntaxException {
49                 Page<FreenetRequest> staticPage = loaders.loadStaticPage("text/", "/net/pterodactylus/sone/main/", "text/plain");
50                 URI uri = new URI("http://some.host/text/template.txt");
51                 Method method = Method.GET;
52                 HTTPRequest httpRequest = mock(HTTPRequest.class);
53                 ToadletContext toadletContext = mock(ToadletContext.class);
54                 FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext);
55                 OutputStream outputStream = new ByteArrayOutputStream();
56                 Response response = new Response(outputStream);
57                 staticPage.handleRequest(request, response);
58                 assertThat(response.getContentType(), startsWith("text/plain"));
59                 assertThat(response.getStatusCode(), is(200));
60         }
61
62         @Test
63         public void templateIsLocatedInClasspath() {
64                 TemplateProvider templateProvider = loaders.getTemplateProvider();
65                 Template template = templateProvider.getTemplate(templateContext, "about.html");
66                 assertThat(template, notNullValue());
67         }
68
69 }