Concordion - Execute on List



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.

Consider the following requirement −

<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>
         <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 split function. Then it will execute the split() 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
1 Create a project with a name concordion and create a package com.tutorialspoint under the src folder in the created project.
2 Add required Concordion libraries using Add External JARs option as explained in the Concordion - First Application chapter.
3 Create Java class System under the com.tutorialspoint package.
4 Create Fixture class SystemFixture under the specs.tutorialspoint package.
5 Create Specification html System.html under the specs.tutorialspoint 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.

Here is the content of System.java file −

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;
   }
}

Following is the content of SystemFixture.java file −

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);
   }  
}

Following is the content of System.html file −

<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>
   </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: 4, Failures: 0

System.html is the output of Concordion test run.

concordion Execute on List Output
Advertisements