|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2024 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
79 | 79 | import org.springframework.format.support.FormattingConversionService;
|
80 | 80 | import org.springframework.http.CacheControl;
|
81 | 81 | import org.springframework.http.HttpHeaders;
|
| 82 | +import org.springframework.http.MediaType; |
82 | 83 | import org.springframework.http.converter.HttpMessageConverter;
|
83 | 84 | import org.springframework.mock.web.MockHttpServletRequest;
|
84 | 85 | import org.springframework.test.util.ReflectionTestUtils;
|
85 | 86 | import org.springframework.util.StringUtils;
|
86 | 87 | import org.springframework.validation.Validator;
|
87 | 88 | import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
88 | 89 | import org.springframework.web.accept.ContentNegotiationManager;
|
| 90 | +import org.springframework.web.accept.FixedContentNegotiationStrategy; |
89 | 91 | import org.springframework.web.accept.ParameterContentNegotiationStrategy;
|
90 | 92 | import org.springframework.web.bind.annotation.ControllerAdvice;
|
91 | 93 | import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
@@ -577,6 +579,22 @@ void customMediaTypes() {
|
577 | 579 | });
|
578 | 580 | }
|
579 | 581 |
|
| 582 | + @Test |
| 583 | + void defaultContentTypes() { |
| 584 | + this.contextRunner |
| 585 | + .withPropertyValues("spring.mvc.contentnegotiation.default-content-types:application/json,application/xml") |
| 586 | + .run((context) -> { |
| 587 | + RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class); |
| 588 | + ContentNegotiationManager contentNegotiationManager = (ContentNegotiationManager) ReflectionTestUtils |
| 589 | + .getField(adapter, "contentNegotiationManager"); |
| 590 | + assertThat(contentNegotiationManager).isNotNull(); |
| 591 | + assertThat(contentNegotiationManager.getStrategy(FixedContentNegotiationStrategy.class)) |
| 592 | + .extracting(FixedContentNegotiationStrategy::getContentTypes) |
| 593 | + .asInstanceOf(InstanceOfAssertFactories.list(MediaType.class)) |
| 594 | + .containsExactly(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML); |
| 595 | + }); |
| 596 | + } |
| 597 | + |
580 | 598 | @Test
|
581 | 599 | void formContentFilterIsAutoConfigured() {
|
582 | 600 | this.contextRunner.run((context) -> assertThat(context).hasSingleBean(OrderedFormContentFilter.class));
|
|
0 commit comments