public class GuidedDecisionTableTest {
@Test
public void testValueLists() {
final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
final PackageDataModelOracle oracle = PackageDataModelOracleBuilder.newPackageOracleBuilder()
.addEnum( "Driver",
"name",
new String[]{ "bob", "michael" } )
.addEnum( "Person",
"rating",
new String[]{ "1", "2" } )
.build();
final GuidedDecisionTableUtils utils = new GuidedDecisionTableUtils( oracle,
dt );
final Map<String, String> currentValueMap = new HashMap<String, String>();
// add cols for LHS
final ConditionCol52 c1 = new ConditionCol52();
final Pattern52 p1 = new Pattern52();
p1.setBoundName( "c1" );
p1.setFactType( "Driver" );
c1.setFactField( "name" );
c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
p1.getChildColumns().add( c1 );
dt.getConditions().add( p1 );
final ConditionCol52 c1_ = new ConditionCol52();
final Pattern52 p1_ = new Pattern52();
p1_.setBoundName( "c1" );
p1_.setFactType( "Driver" );
c1_.setFactField( "name" );
p1_.getChildColumns().add( c1_ );
c1_.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE );
dt.getConditions().add( p1_ );
final ConditionCol52 c1__ = new ConditionCol52();
c1__.setFactField( "sex" );
p1_.getChildColumns().add( c1__ );
c1__.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE );
c1__.setValueList( "Male,Female" );
dt.getConditions().add( p1_ );
final ConditionCol52 c1___ = new ConditionCol52();
final Pattern52 p1__ = new Pattern52();
p1__.setBoundName( "c1" );
p1__.setFactType( "Driver" );
c1___.setFactField( "name" );
c1___.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
c1___.setValueList( "one,two,three" );
p1__.getChildColumns().add( c1___ );
dt.getConditions().add( p1__ );
final ConditionCol52 c2 = new ConditionCol52();
final Pattern52 p2 = new Pattern52();
p2.setBoundName( "c2" );
p2.setFactType( "Driver" );
c2.setFactField( "nothing" );
c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
p2.getChildColumns().add( c2 );
dt.getConditions().add( p2 );
final ActionSetFieldCol52 asf = new ActionSetFieldCol52();
asf.setBoundName( "c1" );
asf.setFactField( "name" );
dt.getActionCols().add( asf );
final ActionInsertFactCol52 ins = new ActionInsertFactCol52();
ins.setBoundName( "x" );
ins.setFactField( "rating" );
ins.setFactType( "Person" );
dt.getActionCols().add( ins );
final ActionInsertFactCol52 ins_ = new ActionInsertFactCol52();
ins_.setBoundName( "x" );
ins_.setFactField( "rating" );
ins_.setFactType( "Person" );
ins_.setValueList( "one,two,three" );
dt.getActionCols().add( ins_ );
final ActionSetFieldCol52 asf_ = new ActionSetFieldCol52();
asf_.setBoundName( "c1" );
asf_.setFactField( "goo" );
dt.getActionCols().add( asf_ );
final ActionSetFieldCol52 asf__ = new ActionSetFieldCol52();
asf__.setBoundName( "c1" );
asf__.setFactField( "goo" );
asf__.setValueList( "one,two,three" );
dt.getActionCols().add( asf__ );
assertTrue( oracle.hasEnums( p1.getFactType(),
c1.getFactField() ) );
assertFalse( utils.hasValueList( c1 ) );
String[] r = oracle.getEnums( p1.getFactType(),
c1.getFactField(),
currentValueMap ).getFixedList();
assertEquals( 2,
r.length );
assertEquals( "bob",
r[ 0 ] );
assertEquals( "michael",
r[ 1 ] );
assertTrue( oracle.hasEnums( p1_.getFactType(),
c1_.getFactField() ) );
assertFalse( utils.hasValueList( c1_ ) );
r = oracle.getEnums( p1_.getFactType(),
c1_.getFactField(),
currentValueMap ).getFixedList();
assertEquals( 2,
r.length );
assertEquals( "bob",
r[ 0 ] );
assertEquals( "michael",
r[ 1 ] );
assertFalse( oracle.hasEnums( p1_.getFactType(),
c1__.getFactField() ) );
assertTrue( utils.hasValueList( c1__ ) );
r = utils.getValueList( c1__ );
assertEquals( 2,
r.length );
assertEquals( "Male",
r[ 0 ] );
assertEquals( "Female",
r[ 1 ] );
assertTrue( oracle.hasEnums( p1__.getFactType(),
c1___.getFactField() ) );
assertTrue( utils.hasValueList( c1___ ) );
r = utils.getValueList( c1___ );
assertEquals( 3,
r.length );
assertEquals( "one",
r[ 0 ] );
assertEquals( "two",
r[ 1 ] );
assertEquals( "three",
r[ 2 ] );
assertEquals( 0,
utils.getValueList( c2 ).length );
assertTrue( oracle.hasEnums( p1.getFactType(),
asf.getFactField() ) );
assertFalse( utils.hasValueList( asf ) );
r = oracle.getEnums( p1.getFactType(),
asf.getFactField(),
currentValueMap ).getFixedList();
assertEquals( 2,
r.length );
assertEquals( "bob",
r[ 0 ] );
assertEquals( "michael",
r[ 1 ] );
assertTrue( oracle.hasEnums( ins.getFactType(),
ins.getFactField() ) );
assertFalse( utils.hasValueList( ins ) );
r = oracle.getEnums( ins.getFactType(),
ins.getFactField(),
currentValueMap ).getFixedList();
assertEquals( 2,
r.length );
assertEquals( "1",
r[ 0 ] );
assertEquals( "2",
r[ 1 ] );
assertTrue( oracle.hasEnums( ins_.getFactType(),
ins_.getFactField() ) );
assertTrue( utils.hasValueList( ins_ ) );
r = utils.getValueList( ins_ );
assertEquals( 3,
r.length );
assertEquals( "one",
r[ 0 ] );
assertEquals( "two",
r[ 1 ] );
assertEquals( "three",
r[ 2 ] );
assertEquals( 0,
utils.getValueList( asf_ ).length );
assertFalse( oracle.hasEnums( p1.getFactType(),
asf__.getFactField() ) );
assertTrue( utils.hasValueList( asf__ ) );
r = utils.getValueList( asf__ );
assertEquals( 3,
r.length );
assertEquals( "one",
r[ 0 ] );
assertEquals( "two",
r[ 1 ] );
assertEquals( "three",
r[ 2 ] );
AttributeCol52 at = new AttributeCol52();
at.setAttribute( "no-loop" );
dt.getAttributeCols().add( at );
r = utils.getValueList( at );
assertEquals( 2,
r.length );
assertEquals( "true",