Reorganize web related classes for better separation of concerns.
Mainly this involves moving classes from `o.s.b.context.embedded`
that aren't directly tied to embedded servlet containers to
`o.s.b.web` and relocating everything from `o.s.b.context.web`.
See gh-5822
When Spring Security and its spring-security-test module are on the
classpath, `@WebMvcTest` will now auto-configure Spring Security and
configure its MockMvc-based test support. This behaviour can be
disabled using the new secure attribute on `@WebMvcTest` and
`@AutoConfigureMockMvc`.
Closes gh-5476
Previously, when @AliasFor was used, the value of the mapped property
would be incorrect as the value of the canonical attribute would be
used, rather than the value of the alias.
This commit updates AnnotationsPropertySource to use a merged annotation
as the source of attribute values, thereby ensuring that any aliased
attributes are configured correctly.
Closes gh-5821
Previously, meta-annotations were not considered when looking for
annotations that may have property mappings but were considered when
looking for a `@PropertyMapping` annotation. This led to three
problems:
1. Properties that should have been included in the property source
were not included
2. Properties that were included may have had the wrong name
3. Properties were included when they should not have been
`@DataJpaTests` provided a concrete example of all three problems:
1. The `replace` and `connection` attributes from
`@AutoConfigureTestDatabase` were not included in the property
source
2. The `showSql` attribute from `@DataJpaTest` was mapped as
`spring.test.database.spring.jpa.show-sql`
3. The `useDefaultFilters` attribute from `@DataJpaTest` was included
in the property source.
This commit updates AnnotationsPropertySource to consider
meta-annotations when looking for attributes that should be mapped.
This addresses the first problem. Furthermore,
AnnotationsPropertySource has been updated to no longer consider
meta-annotations when looking for a type-level property mapping.
This addresses the second and third problems.
Closes gh-5794
This commit introduces a new annotation, @AutoConfigureRestDocs,
which can be used to enable auto-configuration of Spring REST Docs.
The auto-configuration removes the need to use Spring REST Docs' JUnit
rule and will automatically configure MockMvc. Combined with the new
auto-configuration for MockMvc it allows a test class to be free of
boilerplate configuration:
@RunWith(SpringRunner.class)
@WebMvcTest
@AutoConfigureRestDocs(outputDir = "target/generated-snippets",
uriScheme = "https", uriHost = "api.example.com",
uriPort = 443)
public class ExampleDocumentationTests {
@Autowired
private MockMvc mvc;
@Test
public void documentIndex() {
// …
}
}
For more advanced customization a RestDocsMockMvcConfigurationCustomizer
bean can be used.
If a RestDocumentationResultHandler is found in the context, it will
be passed to the ConfigurableMockMvcBuilder's alwaysDo method as part
of its customization.
Closes gh-5563
Add @PropertyMapping annotation which can be used to mark annotation
attributes that should contribute Environment properties.
Provides a quick way for tests to change auto-configuration behavior in
a structured way.
Fixes gh-4901