diff options
Diffstat (limited to 'juick-www/src')
6 files changed, 38 insertions, 134 deletions
diff --git a/juick-www/src/main/java/com/juick/www/Application.java b/juick-www/src/main/java/com/juick/www/Application.java new file mode 100644 index 000000000..0e60e1d87 --- /dev/null +++ b/juick-www/src/main/java/com/juick/www/Application.java @@ -0,0 +1,12 @@ +package com.juick.www; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java index e04538e83..250197f76 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java @@ -17,6 +17,10 @@ package com.juick.www.configuration; +import com.juick.configuration.DataConfiguration; +import com.juick.configuration.SearchConfiguration; +import com.juick.server.configuration.BaseWebConfiguration; +import com.juick.server.configuration.StorageConfiguration; import com.juick.service.CloudflareCache; import com.juick.service.TagService; import com.juick.service.UserService; @@ -29,7 +33,7 @@ import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; +import org.springframework.context.annotation.Import; import javax.inject.Inject; import java.util.Collections; @@ -38,9 +42,10 @@ import java.util.Collections; * Created by aalexeev on 11/22/16. */ @Configuration -@PropertySource(value = "classpath:juick.conf", ignoreResourceNotFound = true) @EnableCaching -public class WwwAppConfiguration { +@Import({WwwServletConfiguration.class, WebSecurityConfig.class, SapeConfiguration.class, SearchConfiguration.class, + DataConfiguration.class, StorageConfiguration.class}) +public class WwwAppConfiguration extends BaseWebConfiguration { @Inject private UserService userService; @Inject 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 deleted file mode 100644 index 26beaee4a..000000000 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.www.configuration; - -import com.juick.configuration.DataConfiguration; -import com.juick.configuration.SearchConfiguration; -import com.juick.server.configuration.StorageConfiguration; -import org.apache.commons.codec.CharEncoding; -import org.springframework.web.filter.CharacterEncodingFilter; -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; - -import javax.servlet.FilterRegistration; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; - -/** - * Created by aalexeev on 11/20/16. - */ -public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - - @Override - protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{ - WwwServletConfiguration.class, - WwwAppConfiguration.class, - SearchConfiguration.class, - SapeConfiguration.class, - WebSecurityConfig.class, - DataConfiguration.class, - StorageConfiguration.class - }; - } - - @Override - protected Class<?>[] getServletConfigClasses() { - return null; - } - - @Override - protected String[] getServletMappings() { - return new String[]{"/"}; - } - - @Override - protected String getServletName() { - return "WWW-spring dispatcher servlet"; - } - - @Override - public void onStartup(ServletContext servletContext) throws ServletException { - super.onStartup(servletContext); - - FilterRegistration.Dynamic registration = servletContext.addFilter( - "encodingFilter", new CharacterEncodingFilter(CharEncoding.UTF_8, true)); - - registration.addMappingForUrlPatterns(null, true, "/*"); - } -} - diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwSecurityInitializer.java b/juick-www/src/main/java/com/juick/www/configuration/WwwSecurityInitializer.java deleted file mode 100644 index a977268f0..000000000 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwSecurityInitializer.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.www.configuration; - -/** - * Created by vitalyster on 25.11.2016. - */ - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; - -import javax.servlet.ServletContext; - -public class WwwSecurityInitializer extends AbstractSecurityWebApplicationInitializer { - private final Logger logger = LoggerFactory.getLogger(getClass()); - - @Override - protected void afterSpringSecurityFilterChain(ServletContext servletContext) { - logger.info("SpringSecurityFilterChain initialized"); - } -} 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 1654f2acd..a8dbad8ba 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 @@ -22,14 +22,12 @@ import com.mitchellbosecke.pebble.PebbleEngine; import com.mitchellbosecke.pebble.extension.FormatterExtension; import com.mitchellbosecke.pebble.loader.ClasspathLoader; import com.mitchellbosecke.pebble.loader.Loader; -import com.mitchellbosecke.pebble.loader.ServletLoader; import com.mitchellbosecke.pebble.spring4.PebbleViewResolver; import com.mitchellbosecke.pebble.spring4.extension.SpringExtension; import org.apache.commons.codec.CharEncoding; 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; 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 726a46129..73cec17a7 100644 --- a/juick-www/src/test/java/com/juick/www/WebAppTests.java +++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java @@ -44,14 +44,18 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureWebClient; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -77,16 +81,17 @@ import java.util.stream.StreamSupport; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; /** * Created by vitalyster on 12.01.2017. */ -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration +@RunWith(SpringRunner.class) +@AutoConfigureMockMvc +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@TestPropertySource(properties = {"xmpp_disabled=true"}) + @ContextConfiguration(classes = { DataConfiguration.class, WwwServletConfiguration.class, WwwAppConfiguration.class, SapeConfiguration.class, @@ -94,7 +99,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. }) public class WebAppTests { @Configuration - @ComponentScan(basePackages = "com.juick.www.controllers") static class Config { @Bean public ImagesService imagesService() { @@ -103,12 +107,12 @@ public class WebAppTests { } @Inject - private WebApplicationContext wac; - @Inject private WebApp webApp; - private static MockMvc mockMvc; - private static WebClient webClient; + @Inject + private MockMvc mockMvc; + @Inject + private WebClient webClient; @Inject private UserService userService; @@ -134,21 +138,17 @@ public class WebAppTests { @Before public void setup() throws IOException { if (!isSetUp) { - mockMvc = MockMvcBuilders.webAppContextSetup(wac) - .apply(springSecurity()) - .build(); - webClient = MockMvcWebClientBuilder.mockMvcSetup(mockMvc).build(); webClient.getOptions().setJavaScriptEnabled(false); webClient.getOptions().setCssEnabled(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); ugnichName = "ugnich"; - ugnichPassword = "MyPassw0rd!"; + ugnichPassword = "secret"; freefdName = "freefd"; freefdPassword = "MyPassw0rd!"; - int ugnichId = userService.createUser(ugnichName, ugnichPassword); - ugnich = userService.getUserByUID(ugnichId).orElseThrow(IllegalStateException::new); + userService.createUser(ugnichName, ugnichPassword); + ugnich = userService.getUserByName(ugnichName); int freefdId = userService.createUser(freefdName, freefdPassword); freefd = userService.getUserByUID(freefdId).orElseThrow(IllegalStateException::new); |