Query:employees hired before | 10-Dec-1980 | ||
employee number | first name | last name | hire date |
1429 | Bob | Martin | 10-Oct-1975 |
9924 | Bill | Mitchell | 19-Dec-1966 |
The code for the fixture is:
package fitnesse.slim.test;
import static fitnesse.util.ListUtility.list;
import java.util.Date;
import java.util.List;
public class EmployeesHiredBefore {
private Date date;
public EmployeesHiredBefore(Date date) {
this.date = date;
}
public void table(List<List<String>> table) {
//optional function
}
public List<Object> query() {
return
list(
list(
list("employee number", "1429"),
list("first name", "Bob"),
list("last name", "Martin"),
list("hire date", "10-Oct-1974")
),
list(
list("employee number", "8832"),
list("first name", "James"),
list("last name", "Grenning"),
list("hire date", "15-Dec-1979")
)
);
}
}
Note the list function simply builds an ArrayList from it's arguments. It's in the ListUtility class
The first thing to notice is the Query: in the first cell of the table. This tells the Slim table processor that this is a query table. Next notice the constructor argument. (See ConstructorArguments). The column headers are field names. The fixture class must have a query method that returns a list of rows. Each row is a list of fields. Each field is a two-element list composed of the field name and it's string value.
Each row in the table is checked to see if there is a match in the query response. The fields are matched left to right. If the leftmost field matches, then the row is considered to be "found". Fields that don't matche are marked in error as in the 10-Oct-1974 field above. If the first cell of a row cannot be matched, then the row is considered missing. If there is an unmatched row remaining in the query response, it is added to the table and marked surplus. The order of the rows is irrelevant.
If a table method is declared in the fixture it will be called before the query function is called. It will be passed a list of rows which are themselves lists of cells. The rows and cells represent the all but the first row of the table. This is the same format at the doTable method of Table table, and the table method of Decision table.
Add Child Page to QueryTable