diff options
author | Vitaly Takmazov | 2017-09-06 14:23:07 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-09-06 14:23:07 +0300 |
commit | 8094d66534f47ed302d271da4dba1147fe6b2a3c (patch) | |
tree | dcb2701d2462dd94f9964fa05e75ea02d6d06064 /juick-www | |
parent | 346c39037d6e5e9c2d006ac43439f865f418a62c (diff) |
www: cleanup and fix configuration
Diffstat (limited to 'juick-www')
3 files changed, 21 insertions, 11 deletions
diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java b/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java index d77bbdad..3a97c4be 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java @@ -19,7 +19,6 @@ package com.juick.www.configuration; import com.juick.configuration.DataConfiguration; import com.juick.configuration.SearchConfiguration; -import com.juick.server.configuration.BaseWebConfiguration; import org.apache.commons.codec.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -36,7 +35,7 @@ public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[]{ - BaseWebConfiguration.class, + WwwServletConfiguration.class, WwwAppConfiguration.class, DataConfiguration.class, SearchConfiguration.class, @@ -47,7 +46,7 @@ public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Class<?>[] getServletConfigClasses() { - return new Class<?>[]{WwwServletConfiguration.class}; + return null; } @Override diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 7a5de28c..cad8cfdb 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -29,8 +29,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; +import org.springframework.core.Ordered; import org.springframework.http.CacheControl; import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.resource.PathResourceResolver; @@ -50,7 +52,7 @@ public class WwwServletConfiguration extends BaseWebConfiguration { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.setOrder(0); + registry.setOrder(Ordered.HIGHEST_PRECEDENCE); registry.addResourceHandler( "/scripts*.js*", "/style*.css*", @@ -65,6 +67,10 @@ public class WwwServletConfiguration extends BaseWebConfiguration { .addResourceLocations("/static/") .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS).mustRevalidate().cachePublic()); } + @Override + public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { + configurer.enable(); + } @Inject private ServletContext servletContext; 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\">>_<</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)))); } |