DataTestSlice class final

Removes the beans of an application that a @DataTest leaves out, before any bean is created: its repositories and the other data beans stay, its services, controllers and other components go.

A bean of the application stays when one of the types it is registered under is a dataTypes (a repository is a DataRepository, an AuditorAware bean is one), when its class carries @EnableDataAuditing, or when it is one of the include types. Two more stay with them: the configuration object that makes a kept @Bean method's bean (a factory needs its instance, without the other @Bean methods of it), and, for an include type that is a configuration class, all its @Bean methods. Only the beans the application's modules declare are judged: the auto-configurations of the starters and what a test adds (@TestBean) are left alone.

The removal happens in the context, after its modules were read, so the conditions of the beans (@ConditionalOnProperty...) were decided with the whole application: a repository a property switches off stays off. A kept bean that needs a left out one fails the start as it always does: the report names the missing bean, and include it.

Spring (Java): the TypeExcludeFilter of @DataJdbcTest (DataJdbcTypeExcludeFilter) in the component scan of a slice; here the beans are listed by the generator at build time, so the filter works on their types.

Implemented types

Constructors

DataTestSlice(Iterable<BeanModule> modules, {Iterable<Type> include = const []})
A slice of the application whose beans modules declare, with the beans of the include types added.

Properties

hashCode → int
The hash code for this object.
no setterinherited
include → List<Type>
The beans added to the slice by the types of their classes.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

keptNames(Map<String, BeanDefinition<Object>> definitions) → Set<String>
The names, among definitions (the application's, by bean name), of the beans the slice keeps.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) → void
Adds, removes or replaces definitions in registry. Runs before every BeanFactoryPostProcessor.postProcessBeanFactory, this processor's own included.
override
postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) → void
Inspects or changes the definitions in beanFactory (scope, lazy, primary, ...). Avoid creating beans here: they would be created before the bean post-processors exist and miss their processing.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

applicationDefinitions(Iterable<BeanModule> modules) → List<BeanDefinition<Object>>
Every definition of modules and of the modules they import, once.
isDataBean(BeanDefinition<Object> definition) → bool
Whether a bean registered as definition is a data bean: one of its types is a dataTypes or its class carries @EnableDataAuditing.

Constants

dataTypes → const Set<Type>
The types of the beans a slice keeps whatever the test says: the repositories, the entities' introspections, the database drivers, and the types the starter's auto-configuration looks up or replaces.