From 8094d66534f47ed302d271da4dba1147fe6b2a3c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 6 Sep 2017 14:23:07 +0300 Subject: www: cleanup and fix configuration --- .../src/test/java/com/juick/www/WebAppTests.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'juick-www/src/test') 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(">_<")); } - 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)))); } -- cgit v1.2.3