/** * Create a new instance using the supplied {@link WebApplicationContext}. * @param context the {@code WebApplicationContext} to create a {@code MockMvc} * instance from; never {@code null} */ protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context) { this(MockMvcBuilders.webAppContextSetup(context).build()); }
/** * Create a new instance using the supplied {@link WebApplicationContext} * and {@link MockMvcConfigurer}. * @param context the {@code WebApplicationContext} to create a {@code MockMvc} * instance from; never {@code null} * @param configurer the MockMvcConfigurer to apply; never {@code null} */ protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context, MockMvcConfigurer configurer) { this(MockMvcBuilders.webAppContextSetup(context).apply(configurer).build()); }
@Before public void setup() { this.mockMvc = webAppContextSetup(this.wac).build(); }
@Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); }
@Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); }
@Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); }
@Before public void setUp() { this.mvc = webAppContextSetup(this.wac).build(); }
@Before public void setup() { this.mockMvc = webAppContextSetup(this.wac).dispatchOptions(true).build(); }
@Test public void mockMvc() throws Exception { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); WebConnection conn = new MockMvcWebConnectionBuilderSupport(mockMvc) {}.createConnection(this.client); assertMockMvcUsed(conn, "http://localhost/"); assertMockMvcNotUsed(conn, "http://example.com/"); }
@Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).alwaysExpect(status().isOk()).build(); }
@Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).alwaysExpect(status().isOk()).build(); }
@Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); given(this.personDao.getPerson(5L)).willReturn(new Person("Joe")); }
@Test public void chainMultiple() { MockMvcBuilders .webAppContextSetup(wac) .addFilter(new CharacterEncodingFilter() ) .defaultRequest(get("/").contextPath("/mywebapp")) .build(); }
@Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); verifyRootWacSupport(); given(this.personDao.getPerson(5L)).willReturn(new Person("Joe")); }
@Test void springMvcTest(WebApplicationContext wac) throws Exception { webAppContextSetup(wac).build() .perform(get("/person/42").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.name", is("Dilbert"))); }
@BeforeEach void setUpMockMvc(WebApplicationContext wac) { this.mockMvc = webAppContextSetup(wac) .alwaysExpect(status().isOk()) .alwaysExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) .build(); }
/** * See /SPR-14277 */ @Test public void dispatcherServletCustomizer() { StubWebApplicationContext root = new StubWebApplicationContext(this.servletContext); DefaultMockMvcBuilder builder = webAppContextSetup(root); builder.addDispatcherServletCustomizer(ds -> ds.setContextId("test-id")); builder.dispatchOptions(true); MockMvc mvc = builder.build(); DispatcherServlet ds = (DispatcherServlet) new DirectFieldAccessor(mvc) .getPropertyValue("servlet"); assertEquals("test-id", ds.getContextId()); }
@Before public void setup() { this.mockRequest.setAttribute(FROM_TCF_MOCK, FROM_TCF_MOCK); this.mockMvc = webAppContextSetup(this.wac) .addFilters(new RequestFilter(), new RequestAttributesFilter(), this.filterWithSessionScopedService) .defaultRequest(get("/").requestAttr(FROM_MVC_TEST_DEFAULT, FROM_MVC_TEST_DEFAULT)) .alwaysExpect(status().isOk()) .build(); }
@Test public void dispatcherServletCustomizerProcessedInOrder() { StubWebApplicationContext root = new StubWebApplicationContext(this.servletContext); DefaultMockMvcBuilder builder = webAppContextSetup(root); builder.addDispatcherServletCustomizer(ds -> ds.setContextId("test-id")); builder.addDispatcherServletCustomizer(ds -> ds.setContextId("override-id")); builder.dispatchOptions(true); MockMvc mvc = builder.build(); DispatcherServlet ds = (DispatcherServlet) new DirectFieldAccessor(mvc) .getPropertyValue("servlet"); assertEquals("override-id", ds.getContextId()); }
@Before public void setUp() { ServletContext servletContext = new MockServletContext(); MockHttpServletRequest mockRequest = new MockHttpServletRequest(servletContext); mockRequest.setAttribute(FROM_CUSTOM_MOCK, FROM_CUSTOM_MOCK); RequestContextHolder.setRequestAttributes(new ServletWebRequest(mockRequest, new MockHttpServletResponse())); this.wac.setServletContext(servletContext); new AnnotatedBeanDefinitionReader(this.wac).register(WebConfig.class); this.wac.refresh(); this.mockMvc = webAppContextSetup(this.wac) .defaultRequest(get("/").requestAttr(FROM_MVC_TEST_DEFAULT, FROM_MVC_TEST_DEFAULT)) .alwaysExpect(status().isOk()) .build(); }