The main purpose of this example is to show you :
| Import |
| com.greenpepper.confluence.demo.collection |
| GreenPepper.Confluence.Demo.Collection |
Setup Example
Using the SetupInterpreter, we populate a list of province.
| Setup |
Canada Province Codes |
| Name |
Code |
| ALBERTA |
AB |
| BRITISH COLUMBIA |
BC |
| MANITOBA |
MB |
| NEW BRUNSWICK |
NB |
| NEWFOUNDLAND and LABRADOR |
NL |
| NOVA SCOTIA |
NS |
| NUNAVUT |
NU |
| ONTARIO |
ON |
| PRINCE EDWARD ISLAND |
PE |
| QUEBEC |
QC |
| SASKATCHEWAN |
SK |
From this list, we intentionnally omit the Yukon province to show the behavior of the DoSetupInterpreter.
Using the DoSetupInterpreter, the Yukon province will be inserted but others won't. This is because the insertProvinceWithCode method will throw an exception when we are trying to insert duplicate province data. From the row causing the exception, all the remaining rows will be skipped.
| Do Setup |
Canada Province Codes |
| insert province |
YUKON |
with code |
YT |
| insert province |
ALBERTA |
with code |
AB |
| insert province |
BRITISH COLUMBIA |
with code |
BC |
List Of
Using the ListOfInterpreter, the requirement list should be the same as the SUD list (order is important).
| list of |
Canada Province Codes |
| Name |
Code |
| ALBERTA |
AB |
| BRITISH COLUMBIA |
BC |
| MANITOBA |
MB |
| NEW BRUNSWICK |
NB |
| NEWFOUNDLAND and LABRADOR |
NL |
| NOVA SCOTIA |
NS |
| NUNAVUT |
NU |
| ONTARIO |
ON |
| PRINCE EDWARD ISLAND |
PE |
| QUEBEC |
QC |
| SASKATCHEWAN |
SK |
| YUKON |
YT |
Set Of
Using the SetOfInterpreter, the requirement set should be the same as the SUD set (order is NOT important).
| set of |
Canada Province Codes |
| Name |
Code |
| YUKON |
YT |
| ALBERTA |
AB |
| BRITISH COLUMBIA |
BC |
| MANITOBA |
MB |
| SASKATCHEWAN |
SK |
| NEWFOUNDLAND and LABRADOR |
NL |
| NOVA SCOTIA |
NS |
| NUNAVUT |
NU |
| PRINCE EDWARD ISLAND |
PE |
| QUEBEC |
QC |
| ONTARIO |
ON |
| NEW BRUNSWICK |
NB |
Subset Of
Using the SubsetOfInterpreter, the requirement set should be a subset of the SUD set (subset of the full list).
| subset of |
Canada Province Codes |
| Name |
Code |
| BRITISH COLUMBIA |
BC |
| QUEBEC |
QC |
Superset Of
Using the SupersetOfInterpreter, the requirement set should be a superset of the SUD set (all items in the list should be present, extra items are ignored).
| superset of |
Canada Province Codes |
| Name |
Code |
| ALBERTA |
AB |
| BRITISH COLUMBIA |
BC |
| MANITOBA |
MB |
| NEW BRUNSWICK |
NB |
| NEWFOUNDLAND and LABRADOR |
NL |
| NOVA SCOTIA |
NS |
| NUNAVUT |
NU |
| ONTARIO |
ON |
| PRINCE EDWARD ISLAND |
PE |
| QUEBEC |
QC |
| SASKATCHEWAN |
SK |
| YUKON |
YT |
| Other Province |
OP |
Source Code
CanadaProvinceCodesFixture.java
package com.greenpepper.confluence.demo.collection;
import java.util.Set;
import com.greenpepper.reflect.CollectionProvider;
import com.greenpepper.reflect.EnterRow;
public class CanadaProvinceCodesFixture
{
private static final Country country= new Country("CANADA");
private String name;
private String code;
public CanadaProvinceCodesFixture()
{
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getCode()
{
return code;
}
public void setCode(String code)
{
this.code = code;
}
public void insertProvinceWithCode(String name, String code)
{
country.addProvince(name, code);
}
@EnterRow
public void insertProvince()
{
country.addProvince(name, code);
}
@CollectionProvider
public Set<Province> getListOfProvinces()
{
return country.provinces();
}
}
Country.java
package com.greenpepper.confluence.demo.collection;
import java.util.Set;
import java.util.TreeSet;
public class Country
{
private String name;
private Set<Province> provinces = new TreeSet<Province>();
public Country(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void addProvince(String name, String code)
{
Province province = new Province(name, code);
if (provinces.contains(province))
{
throw new IllegalArgumentException(String.format("Province '%s' alread exist", name));
}
provinces.add(province);
}
public Set<Province> provinces()
{
return provinces;
}
}
Province.java
package com.greenpepper.confluence.demo.collection;
public class Province
implements Comparable<Province>
{
private String name;
private String code;
public Province(String name, String code)
{
this.name = name;
this.code = code;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getCode()
{
return code;
}
public void setCode(String code)
{
this.code = code;
}
public int compareTo(Province o)
{
return getName().compareTo(o.getName());
}
}