Concordion-returning-multivalueresult
提供:Dev Guides
一致-MultiValueResultを返す
Concordion executeコマンドを使用して、ビヘイビアの結果をMapの形式で取得できます。これを使用して、ビヘイビアの複数の出力を取得できます。 たとえば、次の要件を考慮してください-
The full name Robert De is to be broken into its first name Robert and last name De.
ここでは、ユーザー名を受け入れ、firstNameとlastNameをキーとして対応する値を持つMapオブジェクトを返すsplit関数を使用して、それらを使用できるようにする必要があります。
ユーザー名を受け入れ、結果オブジェクトを出力するような分割関数の仕様を記述したい場合、仕様は次のようになります-
<p>The full name <span concordion:execute = "#result = split(#TEXT)">Robert
De</span> is to be broken into first name
<span concordion:assertEquals = "#result.firstName">Robert</span> and last name
<span concordion:assertEquals = "#result.lastName">De</span>.</p>
Concordionはドキュメントを解析するときに、特別な変数#TEXTの値を「Robert De」として現在の要素の値に設定し、それをsplit関数に渡します。 次に、executeコマンドを使用して#TEXTとしてパラメーターを指定してsplit()メソッドを実行し、結果を#result変数に設定し、結果マップを使用して、firstNameとlastNameの値を出力として出力します。
例
動作するEclipse IDEを用意し、以下の手順に従ってConcordionアプリケーションを作成します-
Step | Description |
---|---|
1 | Create a project with the name concordion and create a package com.finddevguides under the src folder in the created project. |
2 | Add the required Concordion libraries using Add External JARs option as explained in the Concordion - First Application chapter. |
3 | Create Java class System under the com.finddevguides package. |
4 | Create Fixture class SystemFixture under the specs.finddevguides package. |
5 | Create Specification html Systeml under the specs.finddevguides package. |
6 | The final step is to create the content of all the Java files and specification file and run the application as explained below. |
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
import org.concordion.api.MultiValueResult;
public class System {
public MultiValueResult split(String userName){
MultiValueResult result = new MultiValueResult();
String[] words = userName.split(" ");
result.with("firstName", words[0]).with("lastName", words[1]);
return result;
}
}
SystemFixture.javaファイルの内容は次のとおりです-
package specs.finddevguides;
import org.concordion.api.MultiValueResult;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.finddevguides.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public MultiValueResult split(String userName){
return system.split(userName);
}
}
以下はSystemlファイルの内容です-
<html xmlns:concordion = "http://www.concordion.org/2007/concordion">
<head>
<link href = "../concordion.css" rel = "stylesheet" type = "text/css"/>
</head>
<body>
<h1>System Specifications</h1>
<p>We are building specifications for our online order tracking application.</p>
<p>Following is the requirement to split full name of a logged in
user to its constituents by splitting name by whitespace:</p>
<div class = "example">
<h3>Example</h3>
<p>The full name <span concordion:execute = "#result = split(#TEXT)">Robert De</span>
is to be broken into first name <span
concordion:assertEquals = "#result.firstName">Robert</span> and last name <span
concordion:assertEquals = "#result.lastName">De</span>.</p>
</div>
</body>
</html>
ソースファイルと仕様ファイルの作成が完了したら、JUnitテストとしてアプリケーションを実行します。 すべてがあなたのアプリケーションでうまくいけば、それは次の結果を生成します-
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\finddevguides\Systeml
Successes: 2, Failures: 0
システムは、Concordionテスト実行の出力です。