From bebe7c159f00e6d5a83bb786824d5f32e4de9270 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 24 Feb 2018 16:54:28 +0300 Subject: spring boot wip --- .../src/test/java/com/juick/www/WebAppTests.java | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'juick-www/src/test/java/com') 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 726a4612..73cec17a 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() { @@ -102,13 +106,13 @@ 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); -- cgit v1.2.3