|
| 1 | +/* |
| 2 | + * Copyright 2012-2018 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.boot.test.autoconfigure.web.servlet; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | +import org.junit.runner.RunWith; |
| 21 | + |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; |
| 23 | +import org.springframework.boot.test.context.TestConfiguration; |
| 24 | +import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| 25 | +import org.springframework.context.annotation.Bean; |
| 26 | +import org.springframework.test.context.junit4.SpringRunner; |
| 27 | +import org.springframework.test.web.servlet.MockMvc; |
| 28 | + |
| 29 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 30 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; |
| 31 | + |
| 32 | +/** |
| 33 | + * Tests for {@link WebMvcTest} with a disabled filter registration. |
| 34 | + * |
| 35 | + * @author Andy Wilkinson |
| 36 | + */ |
| 37 | +@RunWith(SpringRunner.class) |
| 38 | +@WebMvcTest |
| 39 | +public class WebMvcTestServletFilterRegistrationDisabledIntegrationTests { |
| 40 | + |
| 41 | + @Autowired |
| 42 | + private MockMvc mvc; |
| 43 | + |
| 44 | + @Test |
| 45 | + public void shouldApplyFilter() throws Exception { |
| 46 | + this.mvc.perform(get("/one")).andExpect(header().string("x-test", (String) null)); |
| 47 | + } |
| 48 | + |
| 49 | + @TestConfiguration |
| 50 | + static class DisabledRegistrationConfiguration { |
| 51 | + |
| 52 | + @Bean |
| 53 | + public FilterRegistrationBean exampleFilterRegistration(ExampleFilter filter) { |
| 54 | + FilterRegistrationBean registration = new FilterRegistrationBean(filter); |
| 55 | + registration.setEnabled(false); |
| 56 | + return registration; |
| 57 | + } |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments