SELF
- このランナーの「自己」型 C
- コンテキスト型 A
- アプリケーションコンテキストアサーションプロバイダー public abstract class AbstractApplicationContextRunner<SELF extends AbstractApplicationContextRunner<SELF,C,A>,C extends ConfigurableApplicationContext,A extends ApplicationContextAssertProvider<C>> extends ObjectSE
ApplicationContext
を実行し、AssertJ スタイルのアサーションを提供するユーティリティ設計。テストは、テストに必要な共有構成を記述するテストクラスのフィールドとして最適に使用されます。public class MyContextTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withPropertyValues("spring.foo=bar") .withUserConfiguration(MyConfiguration.class); }
上記の初期化により、すべてのテストで MyConfiguration
を登録し、特に指定のない限り、spring.foo
プロパティを bar
に設定します。
上記の設定に基づいて、特定のテストは、おそらくオーバーライドされたプロパティ値を使用して、コンテキストの実行時に何が起こるかをシミュレートできます。
@Test public someTest() { this.contextRunner.withPropertyValues("spring.foo=biz").run((context) -> { assertThat(context).containsSingleBean(MyBean.class); // other assertions }); }
上記のテストは、spring.foo
プロパティを biz
に変更し、コンテキストに単一の MyBean
Bean が含まれることをアサートしています。run
メソッドは、アサーションをコンテキストに適用できる ContextConsumer
を取ります。完了すると、コンテキストは自動的に閉じられます。
アプリケーションコンテキストの起動に失敗すると、「失敗した」アプリケーションコンテキストで #run(ContextConsumer)
メソッドが呼び出されます。コンテキストの呼び出しは IllegalStateException
SE をスローし、実行中のコンテキストを予期するアサーションは失敗します。失敗の原因でさらにチェックが必要な場合は、getFailure()
アサーションを使用できます。
@Test public someTest() { this.context.withPropertyValues("spring.foo=fails").run((loaded) -> { assertThat(loaded).getFailure().hasCauseInstanceOf(BadPropertyException.class); // other assertions }); }
ApplicationContextRunner
, WebApplicationContextRunner
, ReactiveWebApplicationContextRunner
, ApplicationContextAssert
修飾子と型 | クラスと説明 |
---|---|
protected static class | AbstractApplicationContextRunner.BeanRegistration<T> コンテキストのロード時に適用される Bean 登録。 |
protected static class | AbstractApplicationContextRunner.RunnerConfiguration<C extends ConfigurableApplicationContext> |
修飾子と型 | メソッドと説明 |
---|---|
protected abstract SELF | newInstance(SupplierSE<C> contextFactory, boolean allowBeanDefinitionOverriding, ListSE<ApplicationContextInitializer<? super C>> initializers, TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoaderSE classLoader, ApplicationContext parent, ListSE<AbstractApplicationContextRunner.BeanRegistration<?>> beanRegistrations, ListSE<Configurations> configurations) 使用すべきではありません。 |
SELF | run(ContextConsumer<? super A> consumer) このローダーの現在の状態に基づいて、新しい ApplicationContext を作成およびリフレッシュします。 |
SELF | with(FunctionSE<SELF, SELF> customizer) このランナーにカスタマイズを適用します。 |
SELF | withAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding) 既存の定義と同じ名前で定義を登録することにより、Bean 定義のオーバーライドを許可するかどうかを指定します。 |
SELF | withAllowCircularReferences(boolean allowCircularReferences) Bean 間の循環参照を許可するかどうかを指定します。 |
<T> SELF | withBean(ClassSE<T> type, ObjectSE... constructorArgs) 指定されたユーザー Bean を ApplicationContext に登録します。 |
<T> SELF | withBean(ClassSE<T> type, SupplierSE<T> supplier, BeanDefinitionCustomizer... customizers) 指定されたユーザー Bean を ApplicationContext に登録します。 |
<T> SELF | withBean(StringSE name, ClassSE<T> type, ObjectSE... constructorArgs) 指定されたユーザー Bean を ApplicationContext に登録します。 |
<T> SELF | withBean(StringSE name, ClassSE<T> type, SupplierSE<T> supplier, BeanDefinitionCustomizer... customizers) 指定されたユーザー Bean を ApplicationContext に登録します。 |
SELF | withClassLoader(ClassLoaderSE classLoader) ApplicationContext がリソースのロードと Bean クラスのロードに使用する ClassLoader SE をカスタマイズします。 |
SELF | withConfiguration(Configurations configurations) 指定された構成クラスを ApplicationContext に登録します。 |
SELF | withInitializer(ApplicationContextInitializer<? super C> initializer) コンテキストの作成時に呼び出される ApplicationContextInitializer を追加します。 |
SELF | withParent(ApplicationContext parent) ApplicationContext の parent を構成します。 |
SELF | withPropertyValues(StringSE... pairs) 指定された Environment プロパティペアを追加します。 |
SELF | withSystemProperties(StringSE... pairs) 指定された System SE プロパティペアを追加します。 |
SELF | withUserConfiguration(ClassSE<?>... configurationClasses) 指定されたユーザー構成クラスを ApplicationContext に登録します。 |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
@DeprecatedSE protected AbstractApplicationContextRunner(SupplierSE<C> contextFactory)
AbstractApplicationContextRunner(Supplier, Function)
を推奨 AbstractApplicationContextRunner
インスタンスを作成します。contextFactory
- 実際のコンテキストの作成に使用されるファクトリ protected AbstractApplicationContextRunner(SupplierSE<C> contextFactory, FunctionSE<AbstractApplicationContextRunner.RunnerConfiguration<C>,SELF> instanceFactory)
AbstractApplicationContextRunner
インスタンスを作成します。contextFactory
- 実際のコンテキストの作成に使用されるファクトリ instanceFactory
- ランナーの新しいインスタンスを作成するために使用されるファクトリ protected AbstractApplicationContextRunner(AbstractApplicationContextRunner.RunnerConfiguration<C> configuration, FunctionSE<AbstractApplicationContextRunner.RunnerConfiguration<C>,SELF> instanceFactory)
AbstractApplicationContextRunner
インスタンスを作成します。configuration
- ランナーが使用する構成 instanceFactory
- ランナーの新しいインスタンスを作成するために使用されるファクトリ @DeprecatedSE protected AbstractApplicationContextRunner(SupplierSE<C> contextFactory, boolean allowBeanDefinitionOverriding, ListSE<ApplicationContextInitializer<? super C>> initializers, TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoaderSE classLoader, ApplicationContext parent, ListSE<AbstractApplicationContextRunner.BeanRegistration<?>> beanRegistrations, ListSE<Configurations> configurations)
AbstractApplicationContextRunner(Supplier, Function)
を推奨 AbstractApplicationContextRunner
インスタンスを作成します。contextFactory
- 実際のコンテキストの作成に使用されるファクトリ allowBeanDefinitionOverriding
- Bean 定義のオーバーライドを許可するかどうか initializers
- イニシャライザー environmentProperties
- 環境プロパティ systemProperties
- システムのプロパティ classLoader
- クラスローダー parent
- 親 beanRegistrations
- Bean の登録 configurations
- 構成 public SELF withAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
allowBeanDefinitionOverriding
- Bean オーバーライドが許可されている場合 DefaultListableBeanFactory.setAllowBeanDefinitionOverriding(boolean)
public SELF withAllowCircularReferences(boolean allowCircularReferences)
allowCircularReferences
- Bean 間の循環参照が許可されている場合 AbstractAutowireCapableBeanFactory.setAllowCircularReferences(boolean)
public SELF withInitializer(ApplicationContextInitializer<? super C> initializer)
ApplicationContextInitializer
を追加します。initializer
- 追加する初期化子 public SELF withPropertyValues(StringSE... pairs)
Environment
プロパティペアを追加します。キーと値のペアは、コロン(":")または等号("=")区切り文字で指定できます。以前に指定された可能性のある一致するキーをオーバーライドします。pairs
- 環境に追加する必要があるプロパティのキーと値のペア TestPropertyValues
, withSystemProperties(String...)
public SELF withSystemProperties(StringSE... pairs)
System
SE プロパティペアを追加します。キーと値のペアは、コロン(":")または等号("=")区切り文字で指定できます。コンテキストが run
になる前にシステムプロパティが追加され、コンテキストが閉じられると復元されます。pairs
- システムに追加する必要があるプロパティのキーと値のペア TestPropertyValues
, withSystemProperties(String...)
public SELF withClassLoader(ClassLoaderSE classLoader)
ApplicationContext
がリソースのロードと Bean クラスのロードに使用する ClassLoader
SE をカスタマイズします。classLoader
- 使用するクラスローダー (デフォルトを使用するために null にすることができます)FilteredClassLoader
public SELF withParent(ApplicationContext parent)
ApplicationContext
の parent
を構成します。parent
- 親 public <T> SELF withBean(ClassSE<T> type, ObjectSE... constructorArgs)
ApplicationContext
に登録します。Bean 名は、基礎となるコンテキストで構成された BeanNameGenerator
から生成されます。このような Bean は、通常のユーザー構成の後に登録順に登録されます。
T
- Bean の型 type
- Bean の型 constructorArgs
- Spring のコンストラクター解決アルゴリズムにフィードされるカスタム引数値。すべての引数または特定の引数のみを解決し、残りは通常のオートワイヤーによって解決されます (null
または空の場合があります)public <T> SELF withBean(StringSE name, ClassSE<T> type, ObjectSE... constructorArgs)
ApplicationContext
に登録します。このような Bean は、通常のユーザー構成の後に登録順に登録されます。
T
- Bean の型 name
- Bean 名または生成された名前を使用する null
type
- Bean の型 constructorArgs
- Spring のコンストラクター解決アルゴリズムにフィードされるカスタム引数値。すべての引数または特定の引数のみを解決し、残りは通常のオートワイヤーによって解決されます (null
または空の場合があります)public <T> SELF withBean(ClassSE<T> type, SupplierSE<T> supplier, BeanDefinitionCustomizer... customizers)
ApplicationContext
に登録します。Bean 名は、基礎となるコンテキストで構成された BeanNameGenerator
から生成されます。このような Bean は、通常のユーザー構成の後に登録順に登録されます。
T
- Bean の型 type
- Bean の型 supplier
- Bean のサプライヤー customizers
- ファクトリの BeanDefinition
をカスタマイズするための 1 つ以上のコールバック。lazy-init またはプライマリフラグの設定 public <T> SELF withBean(StringSE name, ClassSE<T> type, SupplierSE<T> supplier, BeanDefinitionCustomizer... customizers)
ApplicationContext
に登録します。Bean 名は、基礎となるコンテキストで構成された BeanNameGenerator
から生成されます。このような Bean は、通常のユーザー構成の後に登録順に登録されます。
T
- Bean の型 name
- Bean 名または生成された名前を使用する null
type
- Bean の型 supplier
- Bean のサプライヤー customizers
- ファクトリの BeanDefinition
をカスタマイズするための 1 つ以上のコールバック。lazy-init またはプライマリフラグの設定 public SELF withUserConfiguration(ClassSE<?>... configurationClasses)
ApplicationContext
に登録します。configurationClasses
- 追加するユーザー構成クラス public SELF withConfiguration(Configurations configurations)
ApplicationContext
に登録します。configurations
- 追加する構成 public SELF with(FunctionSE<SELF,SELF> customizer)
customizer
- 呼び出すカスタマイザ @DeprecatedSE protected abstract SELF newInstance(SupplierSE<C> contextFactory, boolean allowBeanDefinitionOverriding, ListSE<ApplicationContextInitializer<? super C>> initializers, TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoaderSE classLoader, ApplicationContext parent, ListSE<AbstractApplicationContextRunner.BeanRegistration<?>> beanRegistrations, ListSE<Configurations> configurations)
public SELF run(ContextConsumer<? super A> consumer)
ApplicationContext
を作成およびリフレッシュします。コンテキストは、指定された consumer
によって消費され、完了時に閉じられます。consumer
- 作成された ApplicationContext
のコンシューマー