|
| 1 | +/* |
| 2 | + * Copyright 2002-2014 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.test.context.testng.web; |
| 18 | + |
| 19 | +import org.springframework.beans.factory.annotation.Autowired; |
| 20 | +import org.springframework.context.annotation.Configuration; |
| 21 | +import org.springframework.mock.web.MockHttpServletRequest; |
| 22 | +import org.springframework.test.context.ContextConfiguration; |
| 23 | +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; |
| 24 | +import org.springframework.test.context.web.ServletTestExecutionListener; |
| 25 | +import org.springframework.test.context.web.WebAppConfiguration; |
| 26 | +import org.springframework.web.context.request.RequestContextHolder; |
| 27 | +import org.springframework.web.context.request.ServletRequestAttributes; |
| 28 | +import org.testng.annotations.Test; |
| 29 | + |
| 30 | +import static org.junit.Assert.*; |
| 31 | + |
| 32 | +/** |
| 33 | + * TestNG-based integration tests for {@link ServletTestExecutionListener}. |
| 34 | + * |
| 35 | + * @author Sam Brannen |
| 36 | + * @since 3.2.9 |
| 37 | + * @see org.springframework.test.context.web.ServletTestExecutionListenerJUnitIntegrationTests |
| 38 | + */ |
| 39 | +@ContextConfiguration |
| 40 | +@WebAppConfiguration |
| 41 | +public class ServletTestExecutionListenerTestNGIntegrationTests extends AbstractTestNGSpringContextTests { |
| 42 | + |
| 43 | + @Configuration |
| 44 | + static class Config { |
| 45 | + /* no beans required for this test */ |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | + @Autowired |
| 50 | + private MockHttpServletRequest servletRequest; |
| 51 | + |
| 52 | + |
| 53 | + /** |
| 54 | + * Verifies bug fix for <a href="https://jira.spring.io/browse/SPR-11626">SPR-11626</a>. |
| 55 | + * |
| 56 | + * @see #ensureMocksAreReinjectedBetweenTests_2 |
| 57 | + */ |
| 58 | + @Test |
| 59 | + public void ensureMocksAreReinjectedBetweenTests_1() { |
| 60 | + assertInjectedServletRequestEqualsRequestInRequestContextHolder(); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Verifies bug fix for <a href="https://jira.spring.io/browse/SPR-11626">SPR-11626</a>. |
| 65 | + * |
| 66 | + * @see #ensureMocksAreReinjectedBetweenTests_1 |
| 67 | + */ |
| 68 | + @Test |
| 69 | + public void ensureMocksAreReinjectedBetweenTests_2() { |
| 70 | + assertInjectedServletRequestEqualsRequestInRequestContextHolder(); |
| 71 | + } |
| 72 | + |
| 73 | + private void assertInjectedServletRequestEqualsRequestInRequestContextHolder() { |
| 74 | + assertEquals("Injected ServletRequest must be stored in the RequestContextHolder", servletRequest, |
| 75 | + ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments