public abstract class AbstractTestContextBootstrapper extends ObjectSE implements TestContextBootstrapper
TestContextBootstrapper
インターフェースの抽象的な実装。具象サブクラスは通常、次のメソッドの実装を提供するだけで済みます。
getDefaultContextLoaderClass(java.lang.Class<?>)
processMergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration)
カスタム ContextCache
サポートをプラグインするには、getCacheAwareContextLoaderDelegate()
をオーバーライドします。
コンストラクターと説明 |
---|
AbstractTestContextBootstrapper() |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public void setBootstrapContext(BootstrapContext bootstrapContext)
TestContextBootstrapper
BootstrapContext
を設定します。TestContextBootstrapper
の setBootstrapContext
public BootstrapContext getBootstrapContext()
TestContextBootstrapper
BootstrapContext
を取得します。TestContextBootstrapper
の getBootstrapContext
public TestContext buildTestContext()
BootstrapContext
のテストクラスSEを使用し、buildMergedContextConfiguration()
および getCacheAwareContextLoaderDelegate()
に委譲することにより、新しい DefaultTestContext
をビルドします。 具象サブクラスは、このメソッドをオーバーライドしてカスタム TestContext
実装を返すことを選択できます。
TestContextBootstrapper
の buildTestContext
TestContext
、決して null
TestContextBootstrapper.buildMergedContextConfiguration()
public final ListSE<TestExecutionListener> getTestExecutionListeners()
TestContextBootstrapper
BootstrapContext
のテストクラス用に新しくインスタンス化された TestExecutionListeners
のリストを取得します。@TestExecutionListeners
が BootstrapContext
のテストクラスに存在しない場合、デフォルトのリスナーが返されます。さらに、デフォルトのリスナーは AnnotationAwareOrderComparator
を使用してソートする必要があります。
具体的な実装は、デフォルトのリスナーのセットを構成するものを自由に決定できます。ただし、デフォルトでは、Spring TestContext フレームワークは SpringFactoriesLoader
メカニズムを使用して、クラスパス上のすべての META-INF/spring.factories
ファイルで構成されているすべての TestExecutionListener
クラス名を検索します。
@TestExecutionListeners
の inheritListeners
フラグを考慮する必要があります。具体的には、inheritListeners
フラグが true
に設定されている場合、特定のテストクラスに対して宣言されたリスナーは、スーパークラスで宣言されたリスナーのリストの最後に追加する必要があります。
TestContextBootstrapper
の getTestExecutionListeners
TestExecutionListener
インスタンスのリスト protected SetSE<ClassSE<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses()
TestExecutionListener
クラスを取得します。 このメソッドは getTestExecutionListeners()
によって呼び出され、クラス名を取得するために getDefaultTestExecutionListenerClassNames()
に委譲します。
特定のクラスをロードできない場合、DEBUG
メッセージがログに記録されますが、関連する例外は再スローされません。
protected ListSE<StringSE> getDefaultTestExecutionListenerClassNames()
TestExecutionListener
クラスの名前を取得します。 デフォルトの実装では、クラスパス上のすべての META-INF/spring.factories
ファイルで構成されているすべての org.springframework.test.context.TestExecutionListener
エントリを検索します。
このメソッドは getDefaultTestExecutionListenerClasses()
によって呼び出されます。
TestExecutionListener
クラスの名前の変更不可能なリスト SpringFactoriesLoader.loadFactoryNames(java.lang.Class<?>, java.lang.ClassLoader)
public final MergedContextConfiguration buildMergedContextConfiguration()
BootstrapContext
内のテストクラスのマージされたコンテキスト構成を構築します。マージされた構成を構築する場合、実装では次のことを考慮する必要があります。
@ContextHierarchy
および @ContextConfiguration
を介して宣言されたコンテキスト階層 @ActiveProfiles
を介して宣言されたアクティブな Bean 定義プロファイル ContextConfiguration.initializers()
を介して宣言されたコンテキスト初期化子 @TestPropertySource
を介して宣言されたプロパティソースのテスト 必要なセマンティクスの詳細については、前述のアノテーションについて Javadoc を参照してください。
TestContextBootstrapper.buildTestContext()
の実装は、通常、TestContext
を構築するときにこのメソッドに委譲する必要があることに注意してください。
特定のテストクラスに使用する ContextLoader
を決定するときは、次のアルゴリズムを使用する必要があります。
ContextLoader
クラスが ContextConfiguration.loader()
を介して明示的に宣言されている場合は、それを使用してください。ContextLoader
クラスを自由に決定できます。TestContextBootstrapper
の buildMergedContextConfiguration
null
TestContextBootstrapper.buildTestContext()
protected ListSE<ContextCustomizerFactory> getContextCustomizerFactories()
ContextCustomizerFactory
インスタンスを取得します。 デフォルトの実装では、SpringFactoriesLoader
メカニズムを使用して、クラスパス上のすべての META-INF/spring.factories
ファイルで構成されたファクトリをロードします。
protected ContextLoader resolveContextLoader(ClassSE<?> testClass, ListSE<ContextConfigurationAttributes> configAttributesList)
ContextConfigurationAttributes
の提供されたリストに使用する ContextLoader
SE クラスを解決してから、その ContextLoader
をインスタンス化して返します。 ユーザーが使用するローダーを明示的に宣言していない場合は、getDefaultContextLoaderClass(java.lang.Class<?>)
から返された値がデフォルトのコンテキストローダークラスとして使用されます。クラス解決プロセスの詳細については、resolveExplicitContextLoaderClass(java.util.List<org.springframework.test.context.ContextConfigurationAttributes>)
および getDefaultContextLoaderClass(java.lang.Class<?>)
を参照してください。
testClass
- ContextLoader
を解決する必要があるテストクラス。null
であってはならない configAttributesList
- 処理する構成属性のリスト。null
であってはなりません。ボトムアップで並べ替える必要があります (つまり、クラス階層を上に向かっているかのように)testClass
の解決された ContextLoader
(非 null
)IllegalStateExceptionSE
- getDefaultContextLoaderClass(Class)
が null
を返す場合 @Nullable protected ClassSE<? extends ContextLoader> resolveExplicitContextLoaderClass(ListSE<ContextConfigurationAttributes> configAttributesList)
ContextConfigurationAttributes
の提供されたリストに使用する ContextLoader
クラスを解決SEします。コンテキスト構成属性階層の最初のレベルから始めます。
ContextConfigurationAttributes
の contextLoaderClass
プロパティが明示的なクラスで構成されている場合、そのクラスが返されます。ContextLoader
クラスが階層の現在のレベルで指定されていない場合は、階層の次のレベルに移動して、ステップ #1 に戻ります。configAttributesList
- 処理する構成属性のリスト。null
であってはなりません。ボトムアップで並べ替える必要があります (つまり、クラス階層を上に向かっているかのように)ContextLoader
クラス、または明示的なローダーが見つからない場合は null
IllegalArgumentExceptionSE
- 指定された構成属性が null
または空の場合 protected CacheAwareContextLoaderDelegate getCacheAwareContextLoaderDelegate()
ContextCache
との透過的な相互作用に使用する CacheAwareContextLoaderDelegate
を取得します。 デフォルトの実装では、単に getBootstrapContext().getCacheAwareContextLoaderDelegate()
に委譲します。
具象サブクラスは、このメソッドをオーバーライドして、カスタム ContextCache
サポートを備えたカスタム CacheAwareContextLoaderDelegate
実装を返すことを選択できます。
null
)protected abstract ClassSE<? extends ContextLoader> getDefaultContextLoaderClass(ClassSE<?> testClass)
ContextLoader
クラスを決定SEします。 このメソッドによって返されるクラスは、ContextLoader
クラスが ContextConfiguration.loader()
を介して明示的に宣言されていない場合にのみ使用されます。
testClass
- デフォルトの ContextLoader
クラスを取得するテストクラス ContextLoader
クラス (非 null
)protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig)
MergedContextConfiguration
インスタンスを処理します。 返される MergedContextConfiguration
インスタンスは、元のラッパーまたはその代わりになる可能性があります。
デフォルトの実装は、指定されたインスタンスを変更せずに返すだけです。
具象サブクラスは、提供されたインスタンスのプロパティに基づいて、MergedContextConfiguration
の特殊なサブクラスを返すことを選択できます。
mergedConfig
- 処理する MergedContextConfiguration
。null
MergedContextConfiguration
; null