SELF
- このランナーの「自己」型 C
- コンテキスト型 A
- アプリケーションコンテキストアサーションプロバイダー public abstract class AbstractApplicationContextRunner<SELF extends AbstractApplicationContextRunner<SELF,C,A>,C extends org.springframework.context.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 class | AbstractApplicationContextRunner.BeanRegistration<T> コンテキストのロード時に適用される Bean 登録。 |
修飾子 | コンストラクターと説明 |
---|---|
protected | AbstractApplicationContextRunner(SupplierSE<C> contextFactory) 新しい AbstractApplicationContextRunner インスタンスを作成します。 |
protected | AbstractApplicationContextRunner(SupplierSE<C> contextFactory, ListSE<org.springframework.context.ApplicationContextInitializer<? super C>> initializers, TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoaderSE classLoader, org.springframework.context.ApplicationContext parent, ListSE<AbstractApplicationContextRunner.BeanRegistration<?>> beanRegistrations, ListSE<Configurations> configurations) 新しい AbstractApplicationContextRunner インスタンスを作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
protected abstract SELF | newInstance(SupplierSE<C> contextFactory, ListSE<org.springframework.context.ApplicationContextInitializer<? super C>> initializers, TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoaderSE classLoader, org.springframework.context.ApplicationContext parent, ListSE<AbstractApplicationContextRunner.BeanRegistration<?>> beanRegistrations, ListSE<Configurations> configurations) |
SELF | run(ContextConsumer<? super A> consumer) このローダーの現在の状態に基づいて、新しい ApplicationContext を作成してリフレッシュします。 |
SELF | with(FunctionSE<SELF, SELF> customizer) このランナーにカスタマイズを適用します。 |
<T> SELF | withBean(ClassSE<T> type, ObjectSE... constructorArgs) 指定されたユーザー Bean を ApplicationContext に登録します。 |
<T> SELF | withBean(ClassSE<T> type, SupplierSE<T> supplier, org.springframework.beans.factory.config.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, org.springframework.beans.factory.config.BeanDefinitionCustomizer... customizers) 指定されたユーザー Bean を ApplicationContext に登録します。 |
SELF | withClassLoader(ClassLoaderSE classLoader) ApplicationContext がリソースのロードと Bean クラスのロードに使用する ClassLoader SE をカスタマイズします。 |
SELF | withConfiguration(Configurations configurations) 指定された構成クラスを ApplicationContext に登録します。 |
SELF | withInitializer(org.springframework.context.ApplicationContextInitializer<? super C> initializer) コンテキストの作成時に呼び出される ApplicationContextInitializer を追加します。 |
SELF | withParent(org.springframework.context.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
protected AbstractApplicationContextRunner(SupplierSE<C> contextFactory)
AbstractApplicationContextRunner
インスタンスを作成します。contextFactory
- 実際のコンテキストの作成に使用されるファクトリ protected AbstractApplicationContextRunner(SupplierSE<C> contextFactory, ListSE<org.springframework.context.ApplicationContextInitializer<? super C>> initializers, TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoaderSE classLoader, org.springframework.context.ApplicationContext parent, ListSE<AbstractApplicationContextRunner.BeanRegistration<?>> beanRegistrations, ListSE<Configurations> configurations)
AbstractApplicationContextRunner
インスタンスを作成します。contextFactory
- 実際のコンテキストの作成に使用されるファクトリ initializers
- イニシャライザー environmentProperties
- 環境プロパティ systemProperties
- システムのプロパティ classLoader
- クラスローダー parent
- 親 beanRegistrations
- Bean の登録 configurations
- 構成 public SELF withInitializer(org.springframework.context.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(org.springframework.context.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, org.springframework.beans.factory.config.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, org.springframework.beans.factory.config.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
- 呼び出すカスタマイザ protected abstract SELF newInstance(SupplierSE<C> contextFactory, ListSE<org.springframework.context.ApplicationContextInitializer<? super C>> initializers, TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoaderSE classLoader, org.springframework.context.ApplicationContext parent, ListSE<AbstractApplicationContextRunner.BeanRegistration<?>> beanRegistrations, ListSE<Configurations> configurations)
public SELF run(ContextConsumer<? super A> consumer)
ApplicationContext
を作成してリフレッシュします。コンテキストは指定された consumer
によって消費され、完了時に閉じられます。consumer
- 作成された ApplicationContext
のコンシューマー Copyright © 2019 Pivotal Software, Inc.. All rights reserved.