Skip to content

MockMvc.perform with the TestContext framework causes additional perform invocations to be "polluted" [SPR-13260] #17851

@spring-projects-issues

Description

@spring-projects-issues

Rob Winch opened SPR-13260 and commented

The following has worked in prior versions of Spring Framework and the 4.2.0.BUILD-SNAPSHOT up until today. To be clear I believe this bug is a regression that is in 4.2.0.BUILD-SNAPSHOT.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@WebAppConfiguration
public class MockMvcPerformTwiceTests {
	@Autowired
	WebApplicationContext context;

	@Test
	public void mockMvcPerformTwice() throws Exception {
		final String SESSION_ATTR = "mockMvcPerformTwice";
		MockMvc mvc = MockMvcBuilders
				.webAppContextSetup(context)
				.build();

		mvc
			.perform(get("/").sessionAttr(SESSION_ATTR, "value"))
			.andExpect(request().sessionAttribute(SESSION_ATTR, not(nullValue())));

		mvc
			.perform(get("/"))
			.andExpect(request().sessionAttribute(SESSION_ATTR, nullValue()));
	}

	@Configuration
	@EnableWebMvc
	static class Config {
		@Bean
		public MyController myController() {
			return new MyController();
		}
	}

	@RestController
	static class MyController {
		@RequestMapping("/")
		public String hello() {
			return "hello";
		}
	}
}

I believe this is related to the changes in #17803 but do not have time investigate further. I wanted to log this issue to ensure we figure out what is going on before GA.


Affects: 4.2 GA

Issue Links:

Referenced from: commits 3c799e6

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions