Concordion-returning-object
提供:Dev Guides
一致-オブジェクトを返す
Concordion executeコマンドを使用すると、ビヘイビアの複数の出力を取得できるオブジェクトの形でビヘイビアの結果を取得できます。 たとえば、次の要件を考慮してください-
The full name Robert De is to be broken into first name Robert and last name De.
ここでは、ユーザー名を受け入れ、プロパティとして名と姓を使用する結果オブジェクトを返す分割関数を用意する必要があります。
私たちは、ユーザー名を期待し、結果オブジェクトを出力するような分割関数の仕様を書きたい場合は、次の仕様になります-
<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 the Add External JARs option as explained in the Concordion - First Application chapter. |
3 | Create Java class System, Result 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. |
ここにResult.javaファイルの内容があります-
package com.finddevguides;
public class Result {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
System.javaファイルの内容は次のとおりです-
package com.finddevguides;
public class System {
public Result split(String userName){
Result result = new Result();
String[] words = userName.split(" ");
result.setFirstName(words[0]);
result.setLastName(words[1]);
return result;
}
}
SystemFixture.javaファイルの内容は次のとおりです。
package specs.finddevguides;
import com.finddevguides.Result;
import com.finddevguides.System;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public Result 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: 1, Failures: 0
システムは、Concordionテスト実行の出力です。