X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fmain%2FDefaultLoadersTest.java;h=dc51479382cda038deb42670acd079e9d6cc0543;hb=471f660aa3dde0669b67e30ded82b3691edcfb17;hp=220996d52b31dad537d475f82dc632ed1308c4e3;hpb=2f21e4a2402f1c7a55175f223118521dbd2d27d8;p=Sone.git
diff --git a/src/test/java/net/pterodactylus/sone/main/DefaultLoadersTest.java b/src/test/java/net/pterodactylus/sone/main/DefaultLoadersTest.java
index 220996d..dc51479 100644
--- a/src/test/java/net/pterodactylus/sone/main/DefaultLoadersTest.java
+++ b/src/test/java/net/pterodactylus/sone/main/DefaultLoadersTest.java
@@ -2,21 +2,38 @@ package net.pterodactylus.sone.main;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.startsWith;
+import static org.mockito.Mockito.mock;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateProvider;
+import net.pterodactylus.util.web.Method;
+import net.pterodactylus.util.web.Page;
+import net.pterodactylus.util.web.Response;
+
+import freenet.clients.http.SessionManager;
+import freenet.clients.http.ToadletContext;
+import freenet.l10n.BaseL10n;
+import freenet.support.api.HTTPRequest;
import org.junit.Test;
/**
* Unit test for {@link DefaultLoaders}.
- *
- * @author David âBombeâ Roden
*/
public class DefaultLoadersTest {
+ private final BaseL10n l10n = mock(BaseL10n.class);
private final Loaders loaders = new DefaultLoaders();
private final StringWriter stringWriter = new StringWriter();
private final TemplateContext templateContext = new TemplateContext();
@@ -28,4 +45,27 @@ public class DefaultLoadersTest {
assertThat(stringWriter.toString(), is("Template. bar\n"));
}
+ @Test
+ public void staticPageIsServedFromClasspath() throws IOException, URISyntaxException {
+ Page staticPage = loaders.loadStaticPage("text/", "/net/pterodactylus/sone/main/", "text/plain");
+ URI uri = new URI("http://some.host/text/template.txt");
+ Method method = Method.GET;
+ HTTPRequest httpRequest = mock(HTTPRequest.class);
+ ToadletContext toadletContext = mock(ToadletContext.class);
+ SessionManager sessionManager = mock(SessionManager.class);
+ FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager);
+ OutputStream outputStream = new ByteArrayOutputStream();
+ Response response = new Response(outputStream);
+ staticPage.handleRequest(request, response);
+ assertThat(response.getContentType(), startsWith("text/plain"));
+ assertThat(response.getStatusCode(), is(200));
+ }
+
+ @Test
+ public void templateIsLocatedInClasspath() {
+ TemplateProvider templateProvider = loaders.getTemplateProvider();
+ Template template = templateProvider.getTemplate(templateContext, "about.html");
+ assertThat(template, notNullValue());
+ }
+
}