diff options
Diffstat (limited to 'juick-www/src/test/java/com/juick/www')
-rw-r--r-- | juick-www/src/test/java/com/juick/www/WebAppTests.java | 20 |
1 files changed, 12 insertions, 8 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 464e9416..c5e9eb6a 100644 --- a/juick-www/src/test/java/com/juick/www/WebAppTests.java +++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java @@ -26,7 +26,6 @@ import com.juick.Message; import com.juick.Tag; import com.juick.User; import com.juick.configuration.MockDataConfiguration; -import com.juick.server.configuration.BaseWebConfiguration; import com.juick.service.MessagesService; import com.juick.service.UserService; import com.juick.test.util.MockUtils; @@ -41,6 +40,7 @@ import org.apache.commons.text.StringEscapeUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.test.context.ContextConfiguration; @@ -48,6 +48,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder; import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; import javax.inject.Inject; import java.io.IOException; @@ -73,8 +74,10 @@ import static org.mockito.Mockito.when; @ContextConfiguration public class WebAppTests { @Configuration + @EnableWebMvc + @ComponentScan(basePackages = "com.juick.www.controllers") @Import(value = { - BaseWebConfiguration.class, WwwServletConfiguration.class, WwwAppConfiguration.class, SapeConfiguration.class, + WwwServletConfiguration.class, WwwAppConfiguration.class, SapeConfiguration.class, MockDataConfiguration.class }) static class Config {} @@ -201,10 +204,9 @@ public class WebAppTests { assertThat(output, equalTo("<a href=\"/ugnich/?tag=%26gt%3B_%26lt%3B\">>_<</a>")); } - public DomElement fetchMeta(String url, String name) throws IOException { - HtmlPage threadPage = webClient.getPage(url); + public DomElement fetchMeta(HtmlPage page, String name) throws IOException { DomElement emptyMeta = new DomElement("", "meta", null, null); - return threadPage.getElementsByTagName("meta").stream() + return page.getElementsByTagName("meta").stream() .filter(t -> t.getAttribute("name").equals(name)).findFirst().orElse(emptyMeta); } @Test @@ -235,12 +237,14 @@ public class WebAppTests { when(messagesService.canViewThread(1, 0)).thenReturn(true); when(messagesService.getMessage(1)).thenReturn(msg); - assertThat(fetchMeta("http://localhost:8080/ugnich/1", "twitter:card") + HtmlPage threadPage = webClient.getPage("http://localhost:8080/ugnich/1"); + + assertThat(fetchMeta(threadPage, "twitter:card") .getAttribute("content"), equalTo("summary")); msg.setAttachmentType("png"); - assertThat(fetchMeta("http://localhost:8080/ugnich/1", "twitter:card") + assertThat(fetchMeta(threadPage, "twitter:card") .getAttribute("content"), equalTo("summary_large_image")); - assertThat(fetchMeta("http://localhost:8080/ugnich/1", "og:description") + assertThat(fetchMeta(threadPage, "og:description") .getAttribute("content"), startsWith(StringEscapeUtils.escapeHtml4(MessageUtils.getMessageHashTags(msg)))); |