aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java5
-rw-r--r--juick-www/src/test/java/com/juick/www/WebAppTests.java20
2 files changed, 15 insertions, 10 deletions
diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
index 6840d453..be21c3fc 100644
--- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
+++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
@@ -25,7 +25,6 @@ import com.juick.api.TGBot;
import com.juick.server.configuration.BaseWebConfiguration;
import com.juick.api.configuration.ApiSecurityConfig;
import com.juick.api.configuration.MessengerConfiguration;
-import com.juick.api.configuration.TelegramConfiguration;
import com.juick.configuration.MockDataConfiguration;
import com.juick.server.helpers.TagStats;
import com.juick.service.MessagesService;
@@ -48,6 +47,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.socket.client.WebSocketConnectionManager;
import javax.inject.Inject;
@@ -68,9 +68,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@WebAppConfiguration
public class MessagesTests {
@Configuration
+ @EnableWebMvc
@ComponentScan(basePackages = "com.juick.api.controllers")
@Import(value = {BaseWebConfiguration.class, ApiSecurityConfig.class,
- MockDataConfiguration.class, MessengerConfiguration.class, TelegramConfiguration.class})
+ MockDataConfiguration.class, MessengerConfiguration.class})
static class Config {
@Bean
WebSocketConnectionManager connectionManager() {
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\">&gt;_&lt;</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))));