BAEL-1556

This commit is contained in:
lol
2018-02-16 22:31:53 +01:00
parent 49d880bf58
commit 9dd6ca9179
10 changed files with 177 additions and 4 deletions
@@ -0,0 +1,27 @@
package com.baeldung.springsecuritythymeleaf;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringSecurityThymeleafApplicationTests {
@Autowired
ViewController viewController;
@Autowired
WebApplicationContext wac;
@Test
public void whenConfigured_thenLoadsContext() {
assertNotNull(viewController);
assertNotNull(wac);
}
}
@@ -0,0 +1,27 @@
package com.baeldung.springsecuritythymeleaf;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
@RunWith(SpringRunner.class)
@WebMvcTest
public class ViewControllerIntegrationTest {
@Autowired
MockMvc mockMvc;
@Test
public void givenUser_whenPerformingGet_thenReturnsIndex() throws Exception {
mockMvc.perform(get("/index").with(user("user").password("password"))).andExpect(status().isOk()).andExpect(view().name("index"));
}
}