Package nablarch.test.core.http
Class HttpRequestTestSupport
java.lang.Object
nablarch.test.event.TestEventDispatcher
nablarch.test.core.http.HttpRequestTestSupport
- Direct Known Subclasses:
- AbstractHttpRequestTestTemplate
HTTPリクエストテスト用の基底クラス。
- Author:
- hisaaki sioiri, Masato Inoue
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected classコピー対象となるHTMLリソースの拡張子。
- 
Field SummaryFieldsFields inherited from class nablarch.test.event.TestEventDispatchertestName
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedコンストラクタ
 本メソッドはサブクラスから使用されることを想定している。HttpRequestTestSupport(Class<?> testClass) コンストラクタ。
- 
Method SummaryModifier and TypeMethodDescriptionvoidassertApplicationMessageId(String[] expected, nablarch.fw.ExecutionContext actual) メッセージIDのアサートを行う。voidassertApplicationMessageId(String msg, String[] expected, nablarch.fw.ExecutionContext actual) メッセージIDのアサートを行う。voidassertApplicationMessageId(String msg, String expectedCommaSeparated, nablarch.fw.ExecutionContext actual) メッセージIDのアサートを行う。voidassertApplicationMessageId(String expectedCommaSeparated, nablarch.fw.ExecutionContext actual) メッセージIDのアサートを行う。voidassertEntity(String sheetName, String id, Object actual) voidassertForward(String msg, String expectedUri) フォワード先URIが想定通りであることを表明する。voidassertObjectArrayPropertyEquals(String message, String sheetName, String id, Object[] actual) Object配列に設定されたプロパティをアサートする。
 チェック条件の詳細はAssertion.assertProperties(java.util.Map, Object)を参照。voidassertObjectListPropertyEquals(String message, String sheetName, String id, List<?> actual) Object に設定されたプロパティをアサートする。
 チェック条件の詳細はAssertion.assertProperties(java.util.Map, Object)を参照。voidassertObjectPropertyEquals(String message, String sheetName, String id, Object actual) Object に設定されたプロパティをアサートする。
 チェック条件の詳細はAssertion.assertProperties(java.util.Map, Object)を参照。voidassertSqlResultSetEquals(String message, String sheetName, String id, nablarch.core.db.statement.SqlResultSet actual) voidassertSqlRowEquals(String message, String sheetName, String id, nablarch.core.db.statement.SqlRow actual) protected voidassertStatusCode(String message, int expected, nablarch.fw.web.HttpResponse response) ステータスコードが想定通りであることを表明する。voidassertTableEquals(String sheetName) voidassertTableEquals(String sheetName, String groupId) voidassertTableEquals(String message, String sheetName, String groupId) protected voidcopyHtmlResourceToDumpDir(HttpTestConfiguration config, File destDir, nablarch.fw.web.ResourceLocator warBaseLocator) HTMLリソースをダンプファイルの出力ディレクトリへコピーする。nablarch.fw.ExecutionContextcreateExecutionContext(String userId) ExecutionContextを生成する。nablarch.fw.web.HttpRequestリクエストパラメータを作成する。nablarch.fw.web.HttpRequestcreateHttpRequest(String requestUri, Map<String, String[]> params) リクエストパラメータを作成する。nablarch.fw.web.HttpRequestcreateHttpRequestWithConversion(String requestUri, String httpMethod, Map<String, String> commaSeparated, Map<String, String> cookie) リクエストパラメータを作成する。nablarch.fw.web.HttpRequestcreateHttpRequestWithConversion(String requestUri, String httpMethod, Map<String, String> commaSeparated, Map<String, String> cookie, Map<String, String> queryParams) リクエストパラメータを作成する。nablarch.fw.web.HttpRequestcreateHttpRequestWithConversion(String requestUri, Map<String, String> commaSeparated, Map<String, String> cookie) リクエストパラメータを作成する。protected HttpServerHttpServerのインスタンスを生成する。protected HttpServerHttpServerを生成する。protected voiddeleteHtmlResourceFile(File srcDir, File destDir) ダンプディレクトリのHTMLリソースファイルを削除する。nablarch.fw.web.HttpResponseexecute(Class<?> testClass, String caseName, nablarch.fw.web.HttpRequest req, nablarch.fw.ExecutionContext ctx) 自動テスト用HTTPサーバを使用して、リクエスト単体テストを実現する。protected nablarch.fw.web.HttpResponse自動テスト用HTTPサーバを使用して、リクエスト単体テストを実現する。protected StringgetAbsoluteCssUriPrefix(String uri, String replaceAbsolutePath) URI型の絶対パス参照文字列から、URIのプレフィックスを取得する。protected FilegetDumpFile(nablarch.fw.ExecutionContext ctx) HTTPレスポンスボディが出力されたファイルを取得する。protected FileFiltergetFileFilter(HttpTestConfiguration config) FileFilterを取得する。getListMap(String sheetName, String id) getListParamMap(String sheetName, String id) getParamMap(String sheetName, String id) サポートハンドラを取得する。protected voidinitializeIfNotYet(HttpTestConfiguration config, File dumpDir, String className) 初回時のみ初期化を実行する。booleanis3XXStatusCode(int statusCode) 300系の HTTP ステータスコードかどうか判定するprotected voidprepareHandlerQueue(List<nablarch.fw.Handler> handlerQueue) ハンドラキューの準備を行う。static voidキャッシュした HttpServer をリセットする。protected StringrewritePath(String text, String replaceAbsolutePath) 静的リソース内のパスを置き換える。protected voidrewriteResourceFile(HttpTestConfiguration config, File dumpDir, nablarch.fw.web.ResourceLocator warBaseLocator) HTMLリソースディレクトリ内のCSSファイルを置換する。protected voidsetDumpFile(nablarch.fw.ExecutionContext ctx, File file) HTTPレスポンスボディが出力されたファイルを設定する。protected static voidsetHttpHeader(nablarch.fw.web.HttpRequest req, HttpTestConfiguration config) HTTPHeaderを設定する。
 すでにHttpRequestに設定されている項目は、設定しない。voidsetToken(nablarch.fw.web.HttpRequest request, nablarch.fw.ExecutionContext context, boolean valid) トークンをリクエストパラメータとセッションスコープに設定する。
 引数validが真の場合、有効なトークンを設定する。偽の場合はトークンを無効にする。voidDbAccessTestSupport.setUpDb(String)への委譲メソッド。voidvoidsetValidToken(nablarch.fw.web.HttpRequest request, nablarch.fw.ExecutionContext context) 有効なトークンをリクエストパラメータとセッションスコープに設定する。
 二重サブミットを防止しているアクションのメソッドをテストする場合は、このメソッドを呼び出しトークンを設定する。Methods inherited from class nablarch.test.event.TestEventDispatcherdispatchEventOfAfterTestClass, dispatchEventOfAfterTestMethod, dispatchEventOfBeforeTestClassAndBeforeSuit, dispatchEventOfBeforeTestMethod, getMethodName
- 
Field Details- 
testClassテストクラス
 
- 
- 
Constructor Details- 
HttpRequestTestSupportコンストラクタ。- Parameters:
- testClass- テストクラス
 
- 
HttpRequestTestSupportprotected HttpRequestTestSupport()コンストラクタ
 本メソッドはサブクラスから使用されることを想定している。
 
- 
- 
Method Details- 
executeprotected nablarch.fw.web.HttpResponse execute(String caseName, nablarch.fw.web.HttpRequest req, nablarch.fw.ExecutionContext ctx) 自動テスト用HTTPサーバを使用して、リクエスト単体テストを実現する。- Parameters:
- req- テスト対象のアクションを呼び出すためのHttpRequest
- caseName- テストケース名
- ctx- ExecutionContext
- Returns:
- HttpResponse
 
- 
initializeIfNotYet初回時のみ初期化を実行する。- Parameters:
- config- HttpTestConfiguration
- dumpDir- HTMLダンプ先のディレクトリ
- className- テストクラス
 
- 
executepublic nablarch.fw.web.HttpResponse execute(Class<?> testClass, String caseName, nablarch.fw.web.HttpRequest req, nablarch.fw.ExecutionContext ctx) 自動テスト用HTTPサーバを使用して、リクエスト単体テストを実現する。- Parameters:
- testClass- テストクラス
- req- テスト対象のアクションを呼び出すためのHttpRequest
- caseName- テストケース名
- ctx- ExecutionContext
- Returns:
- HttpResponse
 
- 
createHttpServerHttpServerを生成する。- Parameters:
- config- HttpTestConfiguration
- Returns:
- HTTPサーバ
 
- 
getTestSupportHandlerサポートハンドラを取得する。- Returns:
- サポートハンドラ
 
- 
prepareHandlerQueueハンドラキューの準備を行う。- Parameters:
- handlerQueue- ハンドラキュー
 
- 
createHttpServerHttpServerのインスタンスを生成する。- Returns:
- HttpServerのインスタンス
 
- 
copyHtmlResourceToDumpDirprotected void copyHtmlResourceToDumpDir(HttpTestConfiguration config, File destDir, nablarch.fw.web.ResourceLocator warBaseLocator) HTMLリソースをダンプファイルの出力ディレクトリへコピーする。- Parameters:
- config- HttpTestConfiguration
- destDir- 出力ディレクトリ
- warBaseLocator- warベースディレクトリのリソースロケータ
 
- 
deleteHtmlResourceFileダンプディレクトリのHTMLリソースファイルを削除する。- Parameters:
- srcDir- HTMLリソースフォルダ
- destDir- HTMLリソースのコピーフォルダ
 
- 
rewriteResourceFileprotected void rewriteResourceFile(HttpTestConfiguration config, File dumpDir, nablarch.fw.web.ResourceLocator warBaseLocator) HTMLリソースディレクトリ内のCSSファイルを置換する。出力したCSSファイルのタイムスタンプには、出力元CSSファイルのタイムスタンプを設定する。 次回、出力時にはタイムスタンプに変更がない限り、出力は行わない。 - Parameters:
- config- HttpTestConfiguration
- dumpDir- 出力先ディレクトリ
- warBaseLocator- warベースのリソースロケータ
 
- 
rewritePath静的リソース内のパスを置き換える。- Parameters:
- text- 文字列
- replaceAbsolutePath- ファイルの絶対パスからwarのルートパスを取り除いたパス。
- Returns:
- 置換後の文字列
 
- 
getAbsoluteCssUriPrefixURI型の絶対パス参照文字列から、URIのプレフィックスを取得する。- Parameters:
- uri- URI型の絶対パス参照文字列
- replaceAbsolutePath- HTMLリソースの絶対パスからwarのルートパスを取り除いたパス。
- Returns:
- URIのプレフックス
 
- 
getFileFilterFileFilterを取得する。- Parameters:
- config- HttpTestConfiguration
- Returns:
- FileFilter
 
- 
setHttpHeaderHTTPHeaderを設定する。
 すでにHttpRequestに設定されている項目は、設定しない。- Parameters:
- req- HTTPHeaderを設定するHttpRequest
- config- HttpTestConfiguration
 
- 
assertForwardフォワード先URIが想定通りであることを表明する。- Parameters:
- msg- アサート失敗時のメッセージ
- expectedUri- 期待するフォワード先URI
 
- 
assertStatusCodeprotected void assertStatusCode(String message, int expected, nablarch.fw.web.HttpResponse response) ステータスコードが想定通りであることを表明する。
 内蔵サーバから戻り値で返却されたHTTPレスポンスがリダイレクトである場合、 ステータスコードが303または302であることを表明する。 このとき、内蔵サーバから返却されるHTTPレスポンスと比較しないのは、後方互換性を保つためである。 (内蔵サーバは、リダイレクト時のステータスコードに'302 FOUND'を使用する) 上記以外の場合は、 HttpRequestTestSupportHandler.getStatusCode()のステータスコードを比較対象とする。- Parameters:
- message- アサート失敗時のメッセージ
- expected- 期待するステータスコード値
- response- HTTPレスポンス
- See Also:
 
- 
is3XXStatusCodepublic boolean is3XXStatusCode(int statusCode) 300系の HTTP ステータスコードかどうか判定する- Parameters:
- statusCode- 判定対象のHTTPステータスコード
- Returns:
- 300系の HTTP ステータスコードであれば true
 
- 
assertApplicationMessageIdpublic void assertApplicationMessageId(String expectedCommaSeparated, nablarch.fw.ExecutionContext actual) メッセージIDのアサートを行う。- Parameters:
- expectedCommaSeparated- 期待するメッセージID(カンマ区切り)
- actual- 実行結果(メッセージIDをリクエストスコープにもつExecutionContext)
 
- 
assertApplicationMessageIdpublic void assertApplicationMessageId(String msg, String expectedCommaSeparated, nablarch.fw.ExecutionContext actual) メッセージIDのアサートを行う。- Parameters:
- msg- 任意のメッセージ
- expectedCommaSeparated- 期待するメッセージID(カンマ区切り)
- actual- 実行結果(メッセージIDをリクエストスコープにもつExecutionContext)
 
- 
assertApplicationMessageIdメッセージIDのアサートを行う。- Parameters:
- expected- 期待するメッセージIDの配列
- actual- 実行結果(メッセージIDをリクエストスコープにもつExecutionContext)
 
- 
assertApplicationMessageIdpublic void assertApplicationMessageId(String msg, String[] expected, nablarch.fw.ExecutionContext actual) メッセージIDのアサートを行う。- Parameters:
- msg- 任意のメッセージ
- expected- 期待するメッセージIDの配列
- actual- 実行結果(メッセージIDをリクエストスコープにもつExecutionContext)
 
- 
setValidTokenpublic void setValidToken(nablarch.fw.web.HttpRequest request, nablarch.fw.ExecutionContext context) 有効なトークンをリクエストパラメータとセッションスコープに設定する。
 二重サブミットを防止しているアクションのメソッドをテストする場合は、このメソッドを呼び出しトークンを設定する。- Parameters:
- request- テスト対象のアクションを呼び出すためのHttpRequest
- context- ExecutionContext
 
- 
setTokenpublic void setToken(nablarch.fw.web.HttpRequest request, nablarch.fw.ExecutionContext context, boolean valid) トークンをリクエストパラメータとセッションスコープに設定する。
 引数validが真の場合、有効なトークンを設定する。偽の場合はトークンを無効にする。- Parameters:
- request- テスト対象のアクションを呼び出すためのHttpRequest
- context- ExecutionContext
- valid- 有効なトークンを設定するかどうか
 
- 
createHttpRequestpublic nablarch.fw.web.HttpRequest createHttpRequest(String requestUri, String httpMethod, Map<String, String[]> params) リクエストパラメータを作成する。- Parameters:
- requestUri- リクエストURI
- httpMethod- HTTPメソッド
- params- パラメータが格納されたMap
- Returns:
- リクエストパラメータ
 
- 
createHttpRequestpublic nablarch.fw.web.HttpRequest createHttpRequest(String requestUri, Map<String, String[]> params) リクエストパラメータを作成する。- Parameters:
- requestUri- リクエストURI
- params- パラメータが格納されたMap
- Returns:
- リクエストパラメータ
 
- 
createHttpRequestWithConversionpublic nablarch.fw.web.HttpRequest createHttpRequestWithConversion(String requestUri, String httpMethod, Map<String, String> commaSeparated, Map<String, String> cookie, Map<String, String> queryParams) リクエストパラメータを作成する。- Parameters:
- requestUri- リクエストURI
- httpMethod- HTTPメソッド
- commaSeparated- パラメータが格納されたMap
- cookie- Cookie情報が格納されたMap
- queryParams- クエリパラメータ情報が格納されたMap
- Returns:
- リクエストパラメータ
 
- 
createHttpRequestWithConversionpublic nablarch.fw.web.HttpRequest createHttpRequestWithConversion(String requestUri, Map<String, String> commaSeparated, Map<String, String> cookie) リクエストパラメータを作成する。- Parameters:
- requestUri- リクエストURI
- commaSeparated- パラメータが格納されたMap
- cookie- Cookie情報が格納されたMap
- Returns:
- リクエストパラメータ
 
- 
createHttpRequestWithConversionpublic nablarch.fw.web.HttpRequest createHttpRequestWithConversion(String requestUri, String httpMethod, Map<String, String> commaSeparated, Map<String, String> cookie) リクエストパラメータを作成する。- Parameters:
- requestUri- リクエストURI
- httpMethod- HTTPメソッド
- commaSeparated- パラメータが格納されたMap
- cookie- Cookie情報が格納されたMap
- Returns:
- リクエストパラメータ
 
- 
createExecutionContextExecutionContextを生成する。- Parameters:
- userId- セッションスコープに格納するユーザID
- Returns:
- 生成したExecutionContext
 
- 
getDumpFileHTTPレスポンスボディが出力されたファイルを取得する。- Parameters:
- ctx- ExecutionContext
- Returns:
- ファイル。HTTPダンプ出力が無効な場合はnull
 
- 
setDumpFileHTTPレスポンスボディが出力されたファイルを設定する。- Parameters:
- ctx- ExecutionContext
- file- ファイル
 
- 
setUpDbDbAccessTestSupport.setUpDb(String)への委譲メソッド。- Parameters:
- sheetName- シート名
- See Also:
 
- 
setUpDb- Parameters:
- sheetName- シート名
- groupId- グループID
- See Also:
 
- 
assertSqlResultSetEqualspublic void assertSqlResultSetEquals(String message, String sheetName, String id, nablarch.core.db.statement.SqlResultSet actual) - Parameters:
- message- 比較失敗時のメッセージ
- sheetName- 期待値を格納したシート名
- id- シート内のデータを特定するためのID
- actual- 実際の値
- See Also:
 
- 
assertSqlRowEqualspublic void assertSqlRowEquals(String message, String sheetName, String id, nablarch.core.db.statement.SqlRow actual) DbAccessTestSupport.assertSqlRowEquals(String, String, String, nablarch.core.db.statement.SqlRow)への委譲メソッド。- Parameters:
- message- 比較失敗時のメッセージ
- sheetName- 期待値を格納したシート名
- id- シート内のデータを特定するためのID
- actual- 実際の値
 
- 
getListMap- Parameters:
- sheetName- シート名
- id- ID
- Returns:
- List-Map形式のデータ
- See Also:
 
- 
getListParamMap- Parameters:
- sheetName- シート名
- id- ID
- Returns:
- List-Map<String, String[]>形式のデータ
- See Also:
 
- 
getParamMap- Parameters:
- sheetName- シート名
- id- ID
- Returns:
- Map<String,String[]>形式のデータ
- See Also:
 
- 
assertTableEquals- Parameters:
- sheetName- 期待値を格納したシート名
- See Also:
 
- 
assertTableEquals- Parameters:
- sheetName- 期待値を格納したシート名
- groupId- グループID(オプション)
- See Also:
 
- 
assertTableEquals- Parameters:
- message- 比較失敗時のメッセージ
- groupId- グループID(オプション)
- sheetName- 期待値を格納したシート名
- See Also:
 
- 
assertEntity- Parameters:
- sheetName- シート名
- id- ケース表のID(LIST_MAP=testの場合は、testを指定する。)
- actual- 実行結果のオブジェクト(Java Beansオブジェクト)
 
- 
assertObjectPropertyEqualsObject に設定されたプロパティをアサートする。
 チェック条件の詳細はAssertion.assertProperties(java.util.Map, Object)を参照。- Parameters:
- message- メッセージ
- sheetName- シート名
- id- ケース表のID(LIST_MAP=testの場合は、testを指定する。)
- actual- 実際の値
 
- 
assertObjectArrayPropertyEqualspublic void assertObjectArrayPropertyEquals(String message, String sheetName, String id, Object[] actual) Object配列に設定されたプロパティをアサートする。
 チェック条件の詳細はAssertion.assertProperties(java.util.Map, Object)を参照。- Parameters:
- message- メッセージ
- sheetName- シート名
- id- ケース表のID(LIST_MAP=testの場合は、testを指定する。)
- actual- 実際の値
 
- 
assertObjectListPropertyEqualspublic void assertObjectListPropertyEquals(String message, String sheetName, String id, List<?> actual) Object に設定されたプロパティをアサートする。
 チェック条件の詳細はAssertion.assertProperties(java.util.Map, Object)を参照。- Parameters:
- message- メッセージ
- sheetName- シート名
- id- ケース表のID(LIST_MAP=testの場合は、testを指定する。)
- actual- 実際の値
 
- 
resetHttpServerpublic static void resetHttpServer()キャッシュした HttpServer をリセットする。
 
-