diff options
author | 2018-02-24 16:54:28 +0300 | |
---|---|---|
committer | 2018-03-15 12:05:59 +0300 | |
commit | bebe7c159f00e6d5a83bb786824d5f32e4de9270 (patch) | |
tree | 151801a2e625d4952d12630da6a4aec6a37fb76d /juick-www/src/test/java | |
parent | 70f481e2fe39a9029b1896d7b351293fd5de4ef8 (diff) |
spring boot wip
Diffstat (limited to 'juick-www/src/test/java')
-rw-r--r-- | juick-www/src/test/java/com/juick/www/WebAppTests.java | 36 |
1 files changed, 18 insertions, 18 deletions
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() { @@ -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); |