2017-01-08 16:46:47 +01:00
|
|
|
package com.baeldung.handlermappings;
|
2017-01-04 13:10:02 +00:00
|
|
|
|
2017-01-09 16:47:27 +01:00
|
|
|
import com.baeldung.config.BeanNameUrlHandlerMappingConfig;
|
2017-01-04 13:10:02 +00:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.mockito.MockitoAnnotations;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
import org.springframework.test.context.web.WebAppConfiguration;
|
|
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
|
import org.springframework.web.context.WebApplicationContext;
|
|
|
|
|
2017-01-05 08:29:54 +01:00
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
2017-01-04 13:10:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
|
@WebAppConfiguration
|
2017-01-05 08:29:54 +01:00
|
|
|
@ContextConfiguration(classes = BeanNameUrlHandlerMappingConfig.class)
|
2017-02-04 21:56:11 +02:00
|
|
|
public class BeanNameMappingConfigIntegrationTest {
|
2017-01-04 13:10:02 +00:00
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private WebApplicationContext webAppContext;
|
|
|
|
private MockMvc mockMvc;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setup() {
|
|
|
|
MockitoAnnotations.initMocks(this);
|
|
|
|
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void whenBeanNameMapping_thenMappedOK() throws Exception {
|
|
|
|
mockMvc.perform(get("/beanNameUrl")).andExpect(status().isOk()).andExpect(view().name("welcome")).andDo(print());
|
|
|
|
}
|
|
|
|
}
|