クラス MockServletContext
- 実装されたすべてのインターフェース:
ServletContextEE
ServletContext
EE インターフェースのモック実装。Spring 6.0 以降、このモックのセットは Servlet 6.0 ベースラインに基づいて設計されています。
Servlet 3.1 と互換性がありますが、setMajorVersion(int)
/setMinorVersion(int)
を介して特定のバージョンを公開するように構成できます。デフォルトは 3.1 です。Servlet 3.1 のサポートは制限されていることに注意してください。サーブレット、フィルター、リスナーの登録方法はサポートされていません。どちらも JSP 構成ではありません。通常、これらの登録方法が使用される ServletContainerInitializers および WebApplicationInitializers を単体テストすることはお勧めしません。
テスト環境で完全な WebApplicationContext
をセットアップするには、AnnotationConfigWebApplicationContext
、XmlWebApplicationContext
、GenericWebApplicationContext
を使用して、対応する MockServletContext
インスタンスを渡すことができます。リソースパスを相対的なファイルシステムの場所として解釈するために、MockServletContext
を FileSystemResourceLoader
で構成することを検討してください。
- 導入:
- 1.0.2
- 作成者:
- Rod Johnson, Juergen Hoeller, Sam Brannen
- 関連事項:
フィールドサマリー
インターフェース jakarta.servlet.ServletContextEE から継承されたフィールド
ORDERED_LIBSEE, TEMPDIREE
コンストラクターのサマリー
コンストラクターコンストラクター説明ベースパスとDefaultResourceLoader
を使用して、新しいMockServletContext
を作成します(つまりMockServletContext
(StringSE resourceBasePath) DefaultResourceLoader
を使用して、新しいMockServletContext
を作成します。MockServletContext
(StringSE resourceBasePath, ResourceLoader resourceLoader) 提供されたリソースベースパスとリソースローダーを使用して、新しいMockServletContext
を作成します。MockServletContext
(ResourceLoader resourceLoader) 指定されたResourceLoader
を使用し、ベースパスを使用せずに、新しいMockServletContext
を作成します。方法の概要
修飾子と型メソッド説明void
addFilterRegistration
(FilterRegistrationEE registration) FilterRegistration
EE を追加します。void
addInitParameter
(StringSE name, StringSE value) addJspFile
(StringSE servletName, StringSE jspFile) void
addListener
(ClassSE<? extends EventListenerSE> listenerClass) void
addListener
(StringSE className) <T extends EventListenerSE>
voidaddListener
(T t) void
addMimeType
(StringSE fileExtension, MediaType mimeType) getMimeType(String)
が使用する MIME 型マッピングを追加します。addServlet
(StringSE servletName, ServletEE servlet) addServlet
(StringSE servletName, ClassSE<? extends ServletEE> servletClass) addServlet
(StringSE servletName, StringSE className) <T extends FilterEE>
TcreateFilter
(ClassSE<T> c) <T extends EventListenerSE>
TcreateListener
(ClassSE<T> c) <T extends ServletEE>
TcreateServlet
(ClassSE<T> c) void
declareRoles
(StringSE... roleNames) getAttribute
(StringSE name) getContext
(StringSE contextPath) デフォルトのServlet
の名前を取得します。int
int
getFilterRegistration
(StringSE filterName) MapSE<StringSE,
? extends FilterRegistrationEE> getInitParameter
(StringSE name) int
getMimeType
(StringSE filePath) int
getNamedDispatcher
(StringSE path) getRealPath
(StringSE path) getRequestDispatcher
(StringSE path) getResource
(StringSE path) getResourceAsStream
(StringSE path) protected StringSE
getResourceLocation
(StringSE path) 指定されたパスの完全なリソースの場所を作成し、このMockServletContext
のリソースベースパスを先頭に追加します。getResourcePaths
(StringSE path) getServletRegistration
(StringSE servletName) このメソッドは常にnull
を返します。MapSE<StringSE,
? extends ServletRegistrationEE> このメソッドは常に空のマップを返します。int
void
void
log
(StringSE message, ThrowableSE ex) void
registerContext
(StringSE contextPath, ServletContextEE context) void
registerNamedDispatcher
(StringSE name, RequestDispatcherEE requestDispatcher) 名前付きサーブレットのラッパーとして機能するRequestDispatcher
EE(通常はMockRequestDispatcher
)を登録します。void
removeAttribute
(StringSE name) void
setAttribute
(StringSE name, ObjectSE value) void
setContextPath
(StringSE contextPath) void
setDefaultServletName
(StringSE defaultServletName) デフォルトのServlet
の名前を設定します。void
setEffectiveMajorVersion
(int effectiveMajorVersion) void
setEffectiveMinorVersion
(int effectiveMinorVersion) boolean
setInitParameter
(StringSE name, StringSE value) void
setMajorVersion
(int majorVersion) void
setMinorVersion
(int minorVersion) void
setRequestCharacterEncoding
(StringSE requestCharacterEncoding) void
setResponseCharacterEncoding
(StringSE responseCharacterEncoding) void
setServletContextName
(StringSE servletContextName) void
setSessionTimeout
(int sessionTimeout) void
setSessionTrackingModes
(SetSE<SessionTrackingModeEE> sessionTrackingModes) void
指定された名前でRequestDispatcher
EE の登録を解除します。
コンストラクターの詳細
MockServletContext
public MockServletContext()ベースパスとDefaultResourceLoader
(つまり、WAR ルートとしてのクラスパスルート)を使用せずに、新しいMockServletContext
を作成します。MockServletContext
DefaultResourceLoader
を使用して、新しいMockServletContext
を作成します。- パラメーター:
resourceBasePath
- WAR のルートディレクトリ (スラッシュで終わらないでください)- 関連事項:
MockServletContext
指定されたResourceLoader
を使用し、ベースパスを使用せずに、新しいMockServletContext
を作成します。- パラメーター:
resourceLoader
- 使用する ResourceLoader (またはデフォルトの場合は null)
MockServletContext
提供されたリソースベースパスとリソースローダーを使用して、新しいMockServletContext
を作成します。'default' という名前のサーブレットの
MockRequestDispatcher
を登録します。- パラメーター:
resourceBasePath
- WAR のルートディレクトリ (スラッシュで終わらないでください)resourceLoader
- 使用する ResourceLoader (またはデフォルトの場合は null)- 関連事項:
メソッドの詳細
getResourceLocation
指定されたパスの完全なリソースの場所を作成し、このMockServletContext
のリソースベースパスを先頭に追加します。- パラメーター:
path
- 指定されたパス- 戻り値:
- 完全なリソースパス
setContextPath
getContextPath
- 次で指定:
- インターフェース
ServletContextEE
のgetContextPathEE
registerContext
getContext
- 次で指定:
- インターフェース
ServletContextEE
のgetContextEE
setMajorVersion
public void setMajorVersion(int majorVersion) getMajorVersion
public int getMajorVersion()- 次で指定:
- インターフェース
ServletContextEE
のgetMajorVersionEE
setMinorVersion
public void setMinorVersion(int minorVersion) getMinorVersion
public int getMinorVersion()- 次で指定:
- インターフェース
ServletContextEE
のgetMinorVersionEE
setEffectiveMajorVersion
public void setEffectiveMajorVersion(int effectiveMajorVersion) getEffectiveMajorVersion
public int getEffectiveMajorVersion()- 次で指定:
- インターフェース
ServletContextEE
のgetEffectiveMajorVersionEE
setEffectiveMinorVersion
public void setEffectiveMinorVersion(int effectiveMinorVersion) getEffectiveMinorVersion
public int getEffectiveMinorVersion()- 次で指定:
- インターフェース
ServletContextEE
のgetEffectiveMinorVersionEE
getMimeType
- 次で指定:
- インターフェース
ServletContextEE
のgetMimeTypeEE
addMimeType
getMimeType(String)
が使用する MIME 型マッピングを追加します。- パラメーター:
fileExtension
-txt
、gif
などのファイル拡張子mimeType
- MIME 型
getResourcePaths
- 次で指定:
- インターフェース
ServletContextEE
のgetResourcePathsEE
getResource
- 次で指定:
- インターフェース
ServletContextEE
のgetResourceEE
- 例外:
MalformedURLExceptionSE
getResourceAsStream
- 次で指定:
- インターフェース
ServletContextEE
のgetResourceAsStreamEE
getRequestDispatcher
- 次で指定:
- インターフェース
ServletContextEE
のgetRequestDispatcherEE
getNamedDispatcher
- 次で指定:
- インターフェース
ServletContextEE
のgetNamedDispatcherEE
registerNamedDispatcher
名前付きサーブレットのラッパーとして機能するRequestDispatcher
EE(通常はMockRequestDispatcher
)を登録します。- パラメーター:
name
- ラップされたサーブレットの名前requestDispatcher
- 名前付きサーブレットをラップするディスパッチャー- 関連事項:
unregisterNamedDispatcher
指定された名前でRequestDispatcher
EE の登録を解除します。- パラメーター:
name
- 登録を解除するディスパッチャーの名前- 関連事項:
getDefaultServletName
デフォルトのServlet
の名前を取得します。デフォルトは 'default' です。
setDefaultServletName
デフォルトのServlet
の名前を設定します。また、
unregisters
は現在のデフォルトのRequestDispatcher
EE であり、replaces
は提供されたdefaultServletName
のMockRequestDispatcher
を使用します。- パラメーター:
defaultServletName
- デフォルトのServlet
の名前。null
または空にしない- 関連事項:
log
- 次で指定:
- インターフェース
ServletContextEE
のlogEE
log
- 次で指定:
- インターフェース
ServletContextEE
のlogEE
getRealPath
- 次で指定:
- インターフェース
ServletContextEE
のgetRealPathEE
getServerInfo
- 次で指定:
- インターフェース
ServletContextEE
のgetServerInfoEE
getInitParameter
- 次で指定:
- インターフェース
ServletContextEE
のgetInitParameterEE
getInitParameterNames
- 次で指定:
- インターフェース
ServletContextEE
のgetInitParameterNamesEE
setInitParameter
- 次で指定:
- インターフェース
ServletContextEE
のsetInitParameterEE
addInitParameter
getAttribute
- 次で指定:
- インターフェース
ServletContextEE
のgetAttributeEE
getAttributeNames
- 次で指定:
- インターフェース
ServletContextEE
のgetAttributeNamesEE
setAttribute
- 次で指定:
- インターフェース
ServletContextEE
のsetAttributeEE
removeAttribute
- 次で指定:
- インターフェース
ServletContextEE
のremoveAttributeEE
setServletContextName
getServletContextName
- 次で指定:
- インターフェース
ServletContextEE
のgetServletContextNameEE
getClassLoader
- 次で指定:
- インターフェース
ServletContextEE
のgetClassLoaderEE
declareRoles
- 次で指定:
- インターフェース
ServletContextEE
のdeclareRolesEE
getDeclaredRoles
setSessionTrackingModes
public void setSessionTrackingModes(SetSE<SessionTrackingModeEE> sessionTrackingModes) throws IllegalStateExceptionSE, IllegalArgumentExceptionSE getDefaultSessionTrackingModes
- 次で指定:
- インターフェース
ServletContextEE
のgetDefaultSessionTrackingModesEE
getEffectiveSessionTrackingModes
- 次で指定:
- インターフェース
ServletContextEE
のgetEffectiveSessionTrackingModesEE
getSessionCookieConfig
- 次で指定:
- インターフェース
ServletContextEE
のgetSessionCookieConfigEE
setSessionTimeout
public void setSessionTimeout(int sessionTimeout) - 次で指定:
- インターフェース
ServletContextEE
のsetSessionTimeoutEE
getSessionTimeout
public int getSessionTimeout()- 次で指定:
- インターフェース
ServletContextEE
のgetSessionTimeoutEE
setRequestCharacterEncoding
- 次で指定:
- インターフェース
ServletContextEE
のsetRequestCharacterEncodingEE
getRequestCharacterEncoding
- 次で指定:
- インターフェース
ServletContextEE
のgetRequestCharacterEncodingEE
setResponseCharacterEncoding
- 次で指定:
- インターフェース
ServletContextEE
のsetResponseCharacterEncodingEE
getResponseCharacterEncoding
- 次で指定:
- インターフェース
ServletContextEE
のgetResponseCharacterEncodingEE
addFilterRegistration
FilterRegistration
EE を追加します。- 導入:
- 6.2
getFilterRegistration
- 次で指定:
- インターフェース
ServletContextEE
のgetFilterRegistrationEE
getFilterRegistrations
- 次で指定:
- インターフェース
ServletContextEE
のgetFilterRegistrationsEE
getJspConfigDescriptor
- 次で指定:
- インターフェース
ServletContextEE
のgetJspConfigDescriptorEE
addJspFile
- 次で指定:
- インターフェース
ServletContextEE
のaddJspFileEE
addServlet
- 次で指定:
- インターフェース
ServletContextEE
のaddServletEE
addServlet
- 次で指定:
- インターフェース
ServletContextEE
のaddServletEE
addServlet
public ServletRegistration.DynamicEE addServlet(StringSE servletName, ClassSE<? extends ServletEE> servletClass) - 次で指定:
- インターフェース
ServletContextEE
のaddServletEE
createServlet
- 次で指定:
- インターフェース
ServletContextEE
のcreateServletEE
- 例外:
ServletExceptionEE
getServletRegistration
このメソッドは常にnull
を返します。getServletRegistrations
このメソッドは常に空のマップを返します。- 次で指定:
- インターフェース
ServletContextEE
のgetServletRegistrationsEE
- 関連事項:
addFilter
- 次で指定:
- インターフェース
ServletContextEE
のaddFilterEE
addFilter
- 次で指定:
- インターフェース
ServletContextEE
のaddFilterEE
addFilter
public FilterRegistration.DynamicEE addFilter(StringSE filterName, ClassSE<? extends FilterEE> filterClass) - 次で指定:
- インターフェース
ServletContextEE
のaddFilterEE
createFilter
- 次で指定:
- インターフェース
ServletContextEE
のcreateFilterEE
- 例外:
ServletExceptionEE
addListener
- 次で指定:
- インターフェース
ServletContextEE
のaddListenerEE
addListener
- 次で指定:
- インターフェース
ServletContextEE
のaddListenerEE
addListener
- 次で指定:
- インターフェース
ServletContextEE
のaddListenerEE
createListener
- 次で指定:
- インターフェース
ServletContextEE
のcreateListenerEE
- 例外:
ServletExceptionEE
getVirtualServerName
- 次で指定:
- インターフェース
ServletContextEE
のgetVirtualServerNameEE