📜  Concordion-返回MultiValueResult

📅  最后修改于: 2020-12-07 04:44:14             🧑  作者: Mango


Concordion execute命令可用于以Map的形式获取行为的结果,通过该Map我们可以获取行为的多个输出。例如,考虑以下要求-

The full name Robert De is to be broken into its first name Robert and last name De.

在这里,我们需要一个split函数,该函数接受一个用户名并返回一个具有firstName和lastName作为其键及其相应值的Map对象,以便我们可以使用它们。

如果我们要为这样的拆分函数编写一个规范,该规范将接受用户名并输出结果对象,则该规范如下:

The full name Robert De is to be broken into first name Robert and last name De.

当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.tutorialspoint 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.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.

这是System.java文件的内容-

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

以下是SystemFixture.java文件的内容-

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

以下是System.html文件的内容-


   

   
      

System Specifications

We are building specifications for our online order tracking application.

Following is the requirement to split full name of a logged in user to its constituents by splitting name by whitespace:

Example

The full name Robert De is to be broken into first name Robert and last name De.

创建完源文件和规范文件后,让我们将应用程序作为JUnit Test运行。如果您的应用程序一切正常,则将产生以下结果-

C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\concordion\specs\tutorialspoint\System.html
Successes: 2, Failures: 0

System.html是Concordion测试运行的输出。

手风琴返回地图输出