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