aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/test/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/test/java/com/juick')
-rw-r--r--juick-www/src/test/java/com/juick/www/WebAppTests.java19
1 files changed, 12 insertions, 7 deletions
diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java
index c5e9eb6a..0aba7e37 100644
--- a/juick-www/src/test/java/com/juick/www/WebAppTests.java
+++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java
@@ -37,6 +37,7 @@ import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
import org.apache.commons.text.StringEscapeUtils;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -101,6 +102,11 @@ public class WebAppTests {
public void setup() {
webClient = MockMvcWebClientBuilder.webAppContextSetup(this.wac).build();
webClient.getOptions().setJavaScriptEnabled(false);
+ webClient.getOptions().setCssEnabled(false);
+ }
+ @After
+ public void teardown() {
+ webClient.close();
}
@Test
@@ -204,7 +210,8 @@ public class WebAppTests {
assertThat(output, equalTo("<a href=\"/ugnich/?tag=%26gt%3B_%26lt%3B\">&gt;_&lt;</a>"));
}
- public DomElement fetchMeta(HtmlPage page, String name) throws IOException {
+ public DomElement fetchMeta(String url, String name) throws IOException {
+ HtmlPage page = webClient.getPage(url);
DomElement emptyMeta = new DomElement("", "meta", null, null);
return page.getElementsByTagName("meta").stream()
.filter(t -> t.getAttribute("name").equals(name)).findFirst().orElse(emptyMeta);
@@ -237,15 +244,13 @@ public class WebAppTests {
when(messagesService.canViewThread(1, 0)).thenReturn(true);
when(messagesService.getMessage(1)).thenReturn(msg);
- HtmlPage threadPage = webClient.getPage("http://localhost:8080/ugnich/1");
-
- assertThat(fetchMeta(threadPage, "twitter:card")
+ assertThat(fetchMeta("http://localhost:8080/ugnich/1", "twitter:card")
.getAttribute("content"), equalTo("summary"));
msg.setAttachmentType("png");
- assertThat(fetchMeta(threadPage, "twitter:card")
+ assertThat(fetchMeta("http://localhost:8080/ugnich/1", "twitter:card")
.getAttribute("content"), equalTo("summary_large_image"));
- assertThat(fetchMeta(threadPage, "og:description")
- .getAttribute("content"),
+ assertThat(fetchMeta("http://localhost:8080/ugnich/1", "og:description")
+ .getAttribute("content"),
startsWith(StringEscapeUtils.escapeHtml4(MessageUtils.getMessageHashTags(msg))));
}