Skip to content

Instantly share code, notes, and snippets.

@bijukunjummen
Created September 28, 2012 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bijukunjummen/3802254 to your computer and use it in GitHub Desktop.
Save bijukunjummen/3802254 to your computer and use it in GitHub Desktop.
Sample Web Config test - with pathvariables
package org.bk.webtest2;
import static org.springframework.test.web.server.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.server.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.server.setup.MockMvcBuilders.*;
import org.junit.Test;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.test.web.server.MockMvc;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
public class WebContextConfigurationTest {
@Test
public void testAWebFlow() throws Exception {
MockMvc mockMvc = annotationConfigSetup(WebContextConfigurationTest.TestConfiguration.class).build();
mockMvc.perform(get("/sample")).andExpect(view().name("sampleProperView"));
mockMvc.perform(get("/section")).andExpect(view().name("sectionView"));
}
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "org.bk.webtest2")
public static class TestConfiguration {
//
}
}
@Controller
class TestController {
@RequestMapping(value = "/sample")
public String sample() {
return "sampleProperView";
}
@RequestMapping(value = "/{section}")
public String section(@PathVariable("section") String section) {
return section + "View";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment