From 346c39037d6e5e9c2d006ac43439f865f418a62c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 6 Sep 2017 12:04:40 +0300 Subject: api and www: cleanup tests and tests configuration --- .../src/test/java/com/juick/www/WebAppTests.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'juick-www/src/test/java/com/juick/www/WebAppTests.java') 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(">_<")); } - 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)))); -- cgit v1.2.3