Concordion Tutorial
Concordion Tutorial
Audience
This tutorial has been prepared for beginners to help them understand the basic
functionality of Concordion tool.
Prerequisites
Before proceeding with this tutorial, one needs to have a good understanding of Java
programming language and basic HTML.
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at [email protected]
i
Concordion
Table of Contents
About the Tutorial .................................................................................................................................... i
Audience .................................................................................................................................................. i
Prerequisites ............................................................................................................................................ i
1. CONCORDION – OVERVIEW................................................................................................. 1
2. CONCORDION – ENVIRONMENT.......................................................................................... 3
ii
Concordion
iii
1. CONCORDION – OVERVIEW Concordion
What is Concordion?
Concordion is a powerful tool to write and manage automated acceptance tests in Java
based projects. It directly integrates with JUnit framework, making it ready to be used
with all popular Java based IDEs like Netbeans, Eclipse, IntelliJ IDEA.
2. Acceptance tests are written in Java language called fixture code. Using a
Concordion extension of a standard JUnit test case, tests are implemented. It is the
responsibility of the Fixture Code to find the example's data marked by tag and use
them to verify the software under development.
Output of Concordion
When Concordion active specification tests are run, the output XHTML files show the
original specification and test results. Successful tests are highlighted using "green" color
and failed tests are highlighted using "red". Any change in the system will result in failing
the test, which ensures that the specifications are always up-to-date. Concordion terms
these specifications as active specifications.
Key Features
Following are the key features of Concordion:
1
Concordion
Simple to learn - Concordion library is very concise. It has very few commands
to learn and examples are automated using JUnit tests so that tests can be run
easily and can be integrated with existing projects easily.
2
2. CONCORDION – ENVIRONMENT Concordion
Here we will see how to prepare a development environment to make use of Concordion.
Before using Concordion, you need to set up JDK, Tomcat, and Eclipse on your system.
Let's go step by step.
If you are running Windows and you have installed the JDK in C:\jdk1.7.0_75, you would
have to put the following line in your C:\autoexec.bat file.
set PATH=C:\jdk1.7.0_75\bin;%PATH%
set JAVA_HOME=C:\jdk1.7.0_75
On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk1.7.0_75 and you use
the C shell, you would put the following into your .cshrc file.
Alternatively, if you are using an Integrated Development Environment (IDE) like Borland
JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, then compile and run a simple program
to confirm that the IDE knows where you installed Java, otherwise do proper setup as
given in the document of the IDE.
3
Concordion
%C:\eclipse\eclipse.exe
Eclipse can be started by executing the following commands on a Unix (Solaris, Linux,
etc.) machine:
$/usr/local/eclipse/eclipse
After a successful startup, if everything is fine, then it should display the following result:
OS Archive name
Windows junit4.10.jar
Linux junit4.10.jar
Mac junit4.10.jar
4
Concordion
OS Action
OS Action
o hamcrest-core-1.3.jar
o junit-4.12.jar
o ognl-2.6.9.jar
5
Concordion
o xom-1.2.5.jar
o main
o test
o test-dummies
Concordion-1.5.1.jar
You will find all the Concordion dependency libraries in the directory E:\Concordion\lib.
Make sure you set your CLASSPATH variable on this directory properly, otherwise you will
face problems while running your application. If you are using Eclipse, then it is not
required to set CLASSPATH because all the setting will be done through Eclipse.
Once you are done with this last step, you are ready to proceed for your first Concordion
Example which you will see in the next chapter.
6
3. CONCORDION – FIRST APPLICATION Concordion
Let us start programming with Concordion. Before you start writing your first example
using Concordion, you have to make sure that you have set up your Concordion
environment properly as explained in Concordion - Environment Setup tutorial. We also
assume that you have a little bit working knowledge of Eclipse IDE.
So let us proceed to write a simple Concordion application which will print the following
acceptance test:
Example
When Robert logs in the system, a greeting "Hello Robert!" is displayed.
7
Concordion
Once your project is created successfully, you will have the following content in
yourProject Explorer:
8
Concordion
Now use Add External JARs button available under Libraries tab to add the following
core JAR from the Concordion folder.
concordion-1.5.1
hamcrest-core-1.3
junit-4.12
ognl-2.6.9
xom-1.2.5
9
Concordion
package com.tutorialspoint;
public class System {
public String getGreeting(String userName){
return "Hello " + userName + "!";
}
}
10
Concordion
<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 show greeting to logged in user:</p>
<div class="example">
<h3>Example</h3>
<p>When <span concordion:set="#userName">Robert</span> logs in the
system, a greeting "<span
concordion:assertEquals="getGreeting(#userName)">Hello Robert!</span>" is
displayed.</p>
</div>
</body>
</html>
package specs.tutorialspoint;
import com.tutorialspoint.System;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public String getGreeting(String userName){
return system.getGreeting(userName);
}
}
* {
font-family: Arial;
}
body {
11
Concordion
padding: 32px;
}
pre {
padding: 6px 28px 6px 28px;
background-color: #E8EEF7;
}
pre, pre *, code, code *, kbd {
font-family: Courier New, Courier;
font-size: 10pt;
}
h1, h1 * {
font-size: 24pt;
}
p, td, th, li, .breadcrumbs {
font-size: 10pt;
}
p, li {
line-height: 140%;
}
table {
border-collapse: collapse;
empty-cells: show;
margin: 8px 0px 8px 0px;
}
th, td {
border: 1px solid black;
padding: 3px;
}
td {
background-color: white;
vertical-align: top;
}
th {
background-color: #C3D9FF;
}
li {
margin-top: 6px;
margin-bottom: 6px;
}
12
Concordion
.example {
padding: 6px 16px 6px 16px;
border: 1px solid #D7D7D7;
margin: 6px 0px 28px 0px;
background-color: #F7F7F7;
}
.example h3 {
margin-top: 8px;
margin-bottom: 8px;
font-size: 12pt;
}
.special {
font-style: italic;
}
.idea {
font-size: 9pt;
color: #888;
font-style: italic;
}
.tight li {
margin-top: 1px;
margin-bottom: 1px;
}
.commentary {
float: right;
width: 200px;
background-color: #ffffd0;
padding:8px;
border: 3px solid #eeeeb0;
margin: 10px 0px 10px 10px;
}
.commentary, .commentary * {
font-size: 8pt;
}
There are two important points to note about the specification html file and the Test
Fixture:
System.html is the specification html file that uses the concordion namespace.
13
Concordion
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
@RunWith(ConcordionRunner.class)
public class SystemFixture {
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 1, Failures: 0
14
Concordion
Congratulations, you have created your first Concordion Acceptance test successfully.
Further, let us start doing something more interesting in the next few chapters.
15
4. CONCORDION – SET COMMAND Concordion
Concordian set command is used to store temporary variables that can be used in other
concordian commands.
If we want the numbers 2 and 3 to be as parameters and pass them to the sum function
as parameters so that they can be verified against the result returned by the system, then
we can use concordian:set command within the span tags around the numbers.
When Concordion parses the document, it will set a temporary variable #firstNumber to
be the value "2" and #secondNumber to be the value "3" and then call the sum() method
with parameters as #firstNumber and #secondNumber and check that the result is equal
to "5".
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add the required concordian libraries using Add External JARs option as explained
in the Concordian - First Example chapter.
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
16
Concordion
package com.tutorialspoint;
public class System {
public int sum(int firstNumber, int secondNumber) {
return firstNumber + secondNumber;
}
}
package specs.tutorialspoint;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.tutorialspoint.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public int sum(int firstNumber, int secondNumber) {
return system.sum(firstNumber, secondNumber);
}
}
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<head>
<link href="../concordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Calculator Specifications</h1>
<p>We are building online calculator support in our website.</p>
<p>Following is the requirement to add two numbers:</p>
<div class="example">
<h3>Example</h3>
<p>The Sum of two numbers <span concordion:set="#firstNumber">2</span>
and <span concordion:set="#secondNumber">3</span> will be <span
concordion:execute="#result = sum(#firstNumber, #secondNumber)"></span><span
concordion:assertEquals="#result">5</span>.</p>
</div>
17
Concordion
</body>
</html>
Once you are done with creating source and specification files, let us run the application
as JUnit test. If everything is fine with your application, it will produce the following result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 1, Failures: 0
18
5. CONCORDION – ASSERTEQUALS COMMAND Concordion
Concordion assertEquals command is used to check java bean property or method result
against a specified value.
When Concordion parses the document, it will set a temporary variable #firstNumber to
be the value "2" and #secondNumber to be the value "3" using set command and then
call the sum() method with parameters as #firstNumber and #secondNumber and check
that the result is equal to "5" using assertEquals command.
Example
Let us have working Eclipse IDE in place and follow the following steps to create a
Concordion application:
Step Description
6 The final step is to create the content of all the Java files and specificiation
file and run the application as explained below.
19
Concordion
package com.tutorialspoint;
public class System {
public int sum(int firstNumber, int secondNumber) {
return firstNumber + secondNumber;
}
}
package specs.tutorialspoint;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.tutorialspoint.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public int sum(int firstNumber, int secondNumber) {
return system.sum(firstNumber, secondNumber);
}
}
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<head>
<link href="../concordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Calculator Specifications</h1>
<p>We are building online calculator support in our website.</p>
<p>Following is the requirement to add two numbers:</p>
<div class="example">
<h3>Example</h3>
<p>The Sum of two numbers <span concordion:set="#firstNumber">2</span>
and <span concordion:set="#secondNumber">3</span> will be
<span concordion:assertEquals="sum(#firstNumber,
#secondNumber)">5</span>.</p>
</div>
20
Concordion
</body>
</html>
Once you are done with creating source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, this will show the following result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 1, Failures: 0
Successes: 1, Failures: 0
21
6. CONCORDION – ASSERTTRUE COMMAND Concordion
Concordion assertTrue command is used when the fixture needs to know the expected
result in order to perform a test.
If we want a test to be executed on the User Name and check whether the user name
starts with R or not.
When Concordion parses the document, it will set a temporary variable #userName to be
the value "Robert De". Then it will check if the userName starts with the letter specified
by #letter variable set in next command.
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add the required Concordion libraries using Add External JARs option as explained
in the Concordion - First Application chapter.
22
Concordion
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
package com.tutorialspoint;
public class System {
}
package specs.tutorialspoint;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
}
<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>User Name :<span concordion:set="#userName">Robert De</span></p>
<p>The User name <span
concordion:assertTrue="#userName.startsWith(#letter)">starts
with <b concordion:set="#letter">R</b></span>.</p>
<p>The User name <span
concordion:assertTrue="#userName.startsWith(#letter)">starts
with <b concordion:set="#letter">S</b></span>.</p>
</div>
23
Concordion
</body>
</html>
Once you are done with creating source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 1, Failures: 1
24
7. CONCORDION – ASSERTFALSE COMMAND Concordion
Concordion assertFalse command is used when the fixture needs to know the expected
result in order to perform a test.
If we want a test to be executed on the User Name and check that the user name does
not start with S.
When Concordion parses the document, it will set a temporary variable #userName to be
the value "Robert De". Then, it will check if the userName starts with the letter specified
by #letter variable set in next command.
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add the required Concordion libraries using Add External JARs option as explained
in the Concordion - First Application chapter.
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
25
Concordion
package com.tutorialspoint;
public class System {
}
package specs.tutorialspoint;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
}
<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>User Name :<span concordion:set="#userName">Robert De</span></p>
<p>The User name <span
concordion:assertFalse="#userName.startsWith(#letter)">does not start
with <b concordion:set="#letter">S</b></span>.</p>
</div>
</body>
</html>
Once you are done with creating source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
26
Concordion
Successes: 1, Failures: 0
27
8. CONCORDION – EXECUTE COMMAND Concordion
Concordion execute command is used run the operation of concordion fixture. Consider
the following requirement:
If we want to write a specification for a sum function which will accept two numbers and
output their sum, then the specification will be as follows:
When Concordion parses the document, it will set a temporary variable #firstNumber to
be the value "2" and #secondNumber to be the value "3" and then execute the sum()
method with parameters as #firstNumber and #secondNumber using the execute
command and set the result into #result variable and check that the #result variable is
equal to "5".
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add required Concordion libraries using Add External JARs option as explained in
the Concordion - First Application chapter.
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
28
Concordion
package com.tutorialspoint;
public class System {
public int sum(int firstNumber, int secondNumber) {
return firstNumber + secondNumber;
}
}
package specs.tutorialspoint;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.tutorialspoint.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public int sum(int firstNumber, int secondNumber) {
return system.sum(firstNumber, secondNumber);
}
}
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<head>
<link href="../concordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Calculator Specifications</h1>
<p>We are building online calculator support in our website.</p>
<p>Following is the requirement to add two numbers:</p>
<div class="example">
<h3>Example</h3>
<p>The Sum of two numbers <span concordion:set="#firstNumber">2</span>
and <span concordion:set="#secondNumber">3</span> will be <span
concordion:execute="#result = sum(#firstNumber, #secondNumber)"></span><span
concordion:assertEquals="#result">5</span>.</p>
</div>
29
Concordion
</body>
</html>
Once you are done with creating source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 1, Failures: 0
30
9. CONCORDION – RETURNING OBJECT Concordion
Concordion execute command can be used to get the result of a behavior in the form of
object using which we can get multiple outputs of a behavior. For example, consider the
following requirement:
The full name Robert De is to be broken into first name Robert and last name
De.
Here we need to have a spilt function which accepts a user name and returns a result
object having the first name and the last name as its properties so that we can use them.
If we want to write a specification for such a split function which will expect a user name
and output a result object, then the following will be the specification:
When Concordion parses the document, it will set the value of the special variable #TEXT
as the value of the current element as "Robert De" and pass it to the spilt function. Then
it will execute the spilt() method with parameters as #TEXT using the execute command
and set the result into the #result variable and using the result object, print the firstName
and the lastName properties as the output.
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add the required Concordion libraries using the Add External JARs option as
explained in the Concordion - First Application chapter.
31
Concordion
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
package com.tutorialspoint;
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;
}
}
package com.tutorialspoint;
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;
}
}
32
Concordion
package specs.tutorialspoint;
import com.tutorialspoint.Result;
import com.tutorialspoint.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);
}
}
<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>
Once you are done with creating the source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
33
Concordion
Successes: 1, Failures: 0
34
10. CONCORDION – RETURNING MAP Concordion
Concordion execute command can be used to get the result of a behavior in the form of a
Map using which we can get multiple outputs of a behavior. For example, consider the
following requirement:
The full name Robert De is to be broken into its first name Robert and last
name De.
Here we need to have a spilt function which accepts a user name and returns a Map object
having the firstName and the lastName as its keys having corresponding values so that
we can use them.
If we want to write a specification for such a split function which will accept a user name
and output a result object, then the following will be the specification:
When Concordion parses the document, it will set the value of the special variable #TEXT
to be the value of the current element as "Robert De" and pass it to the spilt function.
Then it will execute the spilt() method with parameters as #TEXT using the execute
command and set the result into the #result variable and using result map, print the
firstName and lastName values as output.
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add the required Concordion libraries using Add External JARs option as explained
in the Concordion - First Application chapter.
35
Concordion
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
package com.tutorialspoint;
import java.util.HashMap;
import java.util.Map;
public class System {
public Map split(String userName){
Map<String, String> result = new HashMap<String, String>();
String[] words = userName.split(" ");
result.put("firstName", words[0]);
result.put("lastName", words[1]);
return result;
}
}
package specs.tutorialspoint;
import java.util.Map;
import com.tutorialspoint.Result;
import com.tutorialspoint.System;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public Map<String, String> split(String userName){
return system.split(userName);
}
}
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<head>
<link href="../concordion.css" rel="stylesheet" type="text/css" />
36
Concordion
</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>
Once you are done with creating the source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 1, Failures: 0
37
11. CONCORDION – RETURNING MULTIVALUERESULT Concordion
Concordion execute command can be used to get the result of a behavior in the form of a
Map using which we can get multiple outputs of a behavior. For example, consider the
following requirement:
The full name Robert De is to be broken into its first name Robert and last
name De.
Here we need to have a spilt function which accepts a user name and returns a Map object
having firstName and lastName as its keys with their corresponding values so that we can
use them.
If we want write a specification for such a split function which will accept a user name and
output a result object, then the specification would be as follows:
When Concordion parses the document, it will set the value of the special variable #TEXT
to be the value of current element as "Robert De" and pass it to the spilt function. Then it
will execute the spilt() method with parameters as #TEXT using execute command and
set the result into the #result variable and using result map, print the firstName and
lastName values as the output.
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add the required Concordion libraries using Add External JARs option as explained
in the Concordion - First Application chapter.
38
Concordion
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
package com.tutorialspoint;
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;
}
}
package specs.tutorialspoint;
import org.concordion.api.MultiValueResult;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.tutorialspoint.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public MultiValueResult split(String userName){
return system.split(userName);
}
}
<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>
39
Concordion
Once you are done with creating the source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 2, Failures: 0
40
12. CONCORDION – EXECUTE ON TABLE Concordion
Concordion execute command can be used to run the operation of concordion fixture in a
repeating manner. For example, it will be useful if we want to illustrate a requirement with
multiple examples in the form of a table.
<table>
<tr><th>First Number</th><th>Second Number</th><th>Sum</th></tr>
<tr><td>2</td><td>3</td><td>5</td></tr>
<tr><td>4</td><td>5</td><td>9</td></tr>
</table>
If we want to write a specification for a sum function which will accept two numbers and
output their sum, then the specification would be as follows:
<table>
<tr><th>First Number</th><th>Second Number</th><th>Sum</th></tr>
<tr concordion:execute="#result = sum(#fullName)">
<td concordion:set="#firstNumber">2</td>
<td concordion:set="#secondNumber">3</td>
<td concordion:assertEquals="#result">5</td>
</tr>
<tr concordion:execute="#result = sum(#fullName)">
<td concordion:set="#firstNumber">4</td>
<td concordion:set="#secondNumber">5</td>
<td concordion:assertEquals="#result">9</td>
</tr>
</table>
When Concordion parses the document, it will set a temporary variable #firstNumber to
be the value "2" and #secondNumber to be the value "3". Then it will execute the sum()
method with parameters as #firstNumber and #secondNumber using execute command
and set the result into the #result variable and check that the #result variable is equal to
"5". This process is repeated for each table row element.
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
41
Concordion
Step Description
2 Add required Concordion libraries using Add External JARs option as explained in
the Concordion - First Application chapter.
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
package com.tutorialspoint;
public class System {
public int sum(int firstNumber, int secondNumber) {
return firstNumber + secondNumber;
}
}
package specs.tutorialspoint;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.tutorialspoint.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public int sum(int firstNumber, int secondNumber) {
return system.sum(firstNumber, secondNumber);
}
}
42
Concordion
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<head>
<link href="../concordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Calculator Specifications</h1>
<p>We are building online calculator support in our website.</p>
<p>Following is the requirement to add two numbers:</p>
<div class="example">
<h3>Example</h3>
<table>
<tr>
<th>First Number</th>
<th>Second Number</th>
<th>Sum</th>
</tr>
<tr concordion:execute="#result = sum(#firstNumber, #secondNumber)">
<td concordion:set="#firstNumber">2</td>
<td concordion:set="#secondNumber">3</td>
<td concordion:assertEquals="#result">5</td>
</tr>
<tr concordion:execute="#result = sum(#firstNumber, #secondNumber)">
<td concordion:set="#firstNumber">4</td>
<td concordion:set="#secondNumber">5</td>
<td concordion:assertEquals="#result">9</td>
</tr>
</table>
</div>
</body>
</html>
Once you are done with creating the source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 2, Failures: 0
43
Concordion
44
13. CONCORDION – EXECUTE ON LIST Concordion
Concordion execute command can be used to run the operation of concordion fixture in a
repeating manner. For example, it will be useful if we want to illustrate a requirement with
multiple examples in the form of a list.
<ul>
<li>The full name Robert De is to be split as
<ul>
<li>Robert</li>
<li>De</li>
</ul>
</li>
<li>The full name John Diere is to be split as
<ul>
<li>John</li>
<li>Diere</li>
</ul>
</li>
</ul>
If we want write a specification for a split function which will split a name into its first
name and last name, then the specification would be as follows:
<ul>
<li>The full name <span concordion:execute="#result = split(#TEXT)">Robert
De</span> is to be splited as
<ul>
<li><span
concordion:assertEquals="#result.firstName">Robert</span></li>
<li><span concordion:assertEquals="#result.lastName">De</span></li>
</ul>
</li>
<li>The full name <span concordion:execute="#result = split(#TEXT)">John
Diere</span> is to be splited as
<ul>
<li><span concordion:assertEquals="#result.firstName">John</span></li>
45
Concordion
<li><span concordion:assertEquals="#result.lastName">Diere</span></li>
</ul>
</li>
</ul>
When Concordion parses the document, it will set the value of the special variable #TEXT
to be the value of the current element as "Robert De" and pass it to the spilt function.
Then it will execute the spilt() method with parameters as #TEXT using execute command
and set the result into #result variable and using result, print the firstName and lastName
values as the output.
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add required Concordion libraries using Add External JARs option as explained in
the Concordion - First Application chapter.
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
package com.tutorialspoint;
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;
46
Concordion
}
}
package specs.tutorialspoint;
import org.concordion.api.MultiValueResult;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.tutorialspoint.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public MultiValueResult split(String userName){
return system.split(userName);
}
}
<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>
<ul>
<li>The full name <span concordion:execute="#result =
split(#TEXT)">Robert De</span> is to be splited as
<ul>
<li><span
concordion:assertEquals="#result.firstName">Robert</span></li>
<li><span
concordion:assertEquals="#result.lastName">De</span></li>
47
Concordion
</ul>
</li>
Once you are done with creating source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 4, Failures: 0
48
14. CONCORDION – VERIFYROWS COMMAND Concordion
Concordion verifyRows command can be used to check the content of a collection returned
as a result by the system. For example, if we set up a set of users in the system and do a
partial search on them, then the system should return the matching elements, otherwise
our acceptance tests should fail.
<table>
<tr><th>Users</th></tr>
<tr><td>Robert De</td></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
<p>Search for J should return:</p>
<table>
<tr><th>Matching Users</th></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
If we want write a specification for such a search function which will search and return a
collection, then the specification will be as follows:
<table concordion:execute="addUser(#username)">
<tr><th concordion:set="#username">Username</th></tr>
<tr><td>Robert De</td></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
<p>Search for "<b concordion:set="#searchString">J</b>" should return:</p>
<table concordion:verifyRows="#username : search(#searchString)">
<tr><th concordion:assertEquals="#username">Matching Usernames</th></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
When Concordion parses the document, it will execute addUser() on each row of the first
table and then set the searchString to be J. Next, Concordion will execute the search
49
Concordion
function which should return a Iterable object with a predictable iteration order, (e.g. a
List, LinkedHashSet or a TreeSet), verifyRows runs for each item of the collection and runs
the assertEquals command.
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add the required Concordion libraries using Add External JARs option as explained
in the Concordion - First Application chapter.
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
package com.tutorialspoint;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
public class System {
private Set<String> users = new HashSet<String>();
public void addUser(String username) {
users.add(username);
}
public Iterable<String> search(String searchString) {
SortedSet<String> matches = new TreeSet<String>();
for (String username : users) {
if (username.contains(searchString)) {
50
Concordion
matches.add(username);
}
}
return matches;
}
}
package specs.tutorialspoint;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.tutorialspoint.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public void addUser(String username) {
system.addUser(username);
}
public Iterable<String> search(String searchString) {
return system.search(searchString);
}
}
<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 add a partial search capability on user
names:</p>
<div class="example">
<h3>Example</h3>
<table concordion:execute="addUser(#username)">
51
Concordion
<tr><th concordion:set="#username">Username</th></tr>
<tr><td>Robert De</td></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
<p>Search for "<b concordion:set="#searchString">J</b>" should
return:</p>
<table concordion:verifyRows="#username : search(#searchString)">
<tr><th concordion:assertEquals="#username">Matching
Usernames</th></tr>
<tr><td>John Diere</td></tr>
<tr><td>Julie Re</td></tr>
</table>
</div>
</body>
</html>
Once you are done with creating the source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 2, Failures: 0
52
Concordion
53
15. CONCORDION – RUN COMMAND Concordion
Concordion run command can be used to link multiple specifications together and display
them at one central page. This command can run all the specifications, while displaying
the link's background in green / red / gray as appropriate.
Now we are going to create two specifications and link them together. We'll be reusing the
specifications created in Concordion - Execute on List and Concordion - Execute on Table
chapters as System Specifications and Calculator Specifications.
Example
Let us have a working Eclipse IDE in place and follow the steps given below to create a
Concordion application:
Step Description
2 Add the required Concordion libraries using Add External JARs option as explained
in the Concordion - First Application chapter.
6 The final step is to create the content of all the Java files and specification file
and run the application as explained below.
package com.tutorialspoint;
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]);
54
Concordion
return result;
}
public int sum(int firstNumber, int secondNumber) {
return firstNumber + secondNumber;
}
}
package specs.tutorialspoint;
import org.concordion.api.MultiValueResult;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.tutorialspoint.System;
@RunWith(ConcordionRunner.class)
public class SystemFixture {
System system = new System();
public MultiValueResult split(String userName){
return system.split(userName);
}
}
package specs.tutorialspoint;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;
import com.tutorialspoint.System;
@RunWith(ConcordionRunner.class)
public class CalculatorFixture {
System system = new System();
public int sum(int firstNumber, int secondNumber) {
return system.sum(firstNumber, secondNumber);
}
}
55
Concordion
<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>
<ul>
<li>The full name <span concordion:execute="#result =
split(#TEXT)">Robert De</span> is to be splited as
<ul>
<li><span
concordion:assertEquals="#result.firstName">Robert</span></li>
<li><span
concordion:assertEquals="#result.lastName">De</span></li>
</ul>
</li>
<li>The full name <span concordion:execute="#result =
split(#TEXT)">John Diere</span> is to be splited as
<ul>
<li><span
concordion:assertEquals="#result.firstName">John</span></li>
<li><span
concordion:assertEquals="#result.lastName">Diere</span></li>
</ul>
</li>
</ul>
</div>
<a concordion:run="concordion" href="Calculator.html">Calculator Service
Specifications</a>
</body>
</html>
56
Concordion
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<head>
<link href="../concordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Calculator Specifications</h1>
<p>We are building online calculator support in our website.</p>
<p>Following is the requirement to add two numbers:</p>
<div class="example">
<h3>Example</h3>
<table>
<tr>
<th>First Number</th>
<th>Second Number</th>
<th>Sum</th>
</tr>
<tr concordion:execute="#result = sum(#firstNumber, #secondNumber)">
<td concordion:set="#firstNumber">2</td>
<td concordion:set="#secondNumber">3</td>
<td concordion:assertEquals="#result">5</td>
</tr>
<tr concordion:execute="#result = sum(#firstNumber, #secondNumber)">
<td concordion:set="#firstNumber">4</td>
<td concordion:set="#secondNumber">5</td>
<td concordion:assertEquals="#result">9</td>
</tr>
</table>
</div>
</body>
</html>
Once you are done with creating source and specification files, let us run the application
as JUnit Test. If everything is fine with your application, then it will produce the following
result:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 2, Failures: 0
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
57
Concordion
Successes: 6, Failures: 0
Click on the link Calculator Service Specifications. You will see the following output:
58