p1.setBoundName( "p1" ); p1.setFactType( "Person" ); allPatterns.add( p1 );
@Test public void testNoConstraintLists() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); // add cols for LHS ConditionCol52 c1 = new ConditionCol52(); Pattern52 p1 = new Pattern52(); p1.setBoundName( "c1" ); p1.setFactType( "Driver" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); ConditionCol52 c2 = new ConditionCol52(); Pattern52 p2 = new Pattern52(); p2.setBoundName( "c2" ); p2.setFactType( "Driver" ); c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); c2.setValueList( "a,b,c" ); p2.getChildColumns().add( c2 ); dt.getConditions().add( p1 ); SuggestionCompletionEngine sce = new SuggestionCompletionEngine(); sce.putDataEnumList( "Driver.name", new String[]{"bob", "michael"} ); assertEquals( 0, dt.getValueList( c1 ).length ); assertEquals( 3, dt.getValueList( c2 ).length ); }
@Test public void testNoConstraints() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); Pattern52 p1 = new Pattern52(); p1.setBoundName( "x" ); p1.setFactType( "Context" ); ConditionCol52 c = new ConditionCol52(); c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c ); dt.getConditions().add( p1 ); ActionSetFieldCol52 asf = new ActionSetFieldCol52(); asf.setBoundName( "x" ); asf.setFactField( "age" ); asf.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( asf ); String[][] data = new String[][]{ new String[]{"1", "desc", "y", "old"} }; dt.setData( upgrader.makeDataLists( data ) ); String drl = GuidedDTDRLPersistence.getInstance().marshal( dt ); assertTrue( drl.indexOf( "Context( )" ) > -1 ); assertTrue( drl.indexOf( "x.setAge" ) > drl.indexOf( "Context( )" ) ); assertFalse( drl.indexOf( "update( x );" ) > -1 ); dt.setData( upgrader.makeDataLists( new String[][]{ new String[]{"1", "desc", "", "old"} } ) ); drl = GuidedDTDRLPersistence.getInstance().marshal( dt ); assertEquals( -1, drl.indexOf( "Context( )" ) ); }
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "x" ); p1.setFactType( "Context" );
@Test public void testOnlyDecisionTableColumns() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); Pattern52 p1 = new Pattern52(); p1.setFactType( "Driver" ); p1.setBoundName( "$p1" ); ConditionCol52 c1 = new ConditionCol52(); c1.setFactField( "name" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); c1.setBinding( "$c1" ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); ActionInsertFactCol52 ins = new ActionInsertFactCol52(); ins.setBoundName( "$ins" ); ins.setFactField( "rating" ); ins.setFactType( "Person" ); ins.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( ins ); BRLRuleModel model = new BRLRuleModel( dt ); assertNotNull( model.getAllVariables() ); assertEquals( 3, model.getAllVariables().size() ); assertTrue( model.getAllVariables().contains( "$p1" ) ); assertTrue( model.getAllVariables().contains( "$c1" ) ); assertTrue( model.getAllVariables().contains( "$ins" ) ); }
@Test public void testLimitedEntryConditionsNoConstraints() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat( TableFormat.LIMITED_ENTRY ); dt.setTableName( "limited-entry" ); Pattern52 p1 = new Pattern52(); p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 ); // This is a hack consistent with how the Expanded Form decision table // works. I wouldn't be too surprised if this changes at some time, but // GuidedDTDRLPersistence.marshal does not support empty patterns at // present. LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52(); cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc1.setValue( new DTCellValue52( "y" ) ); p1.getChildColumns().add( cc1 ); dt.setData( upgrader.makeDataLists( new Object[][]{ new Object[]{1l, "desc", true}, new Object[]{2l, "desc", false} } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); int index = -1; index = drl.indexOf( "Smurf( )" ); assertTrue( index > -1 ); index = drl.indexOf( "Smurf( )", index + 1 ); assertFalse( index > -1 ); }
@Test public void testLimitedEntryConditionsConstraints1() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat( TableFormat.LIMITED_ENTRY ); dt.setTableName( "limited-entry" ); Pattern52 p1 = new Pattern52(); p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 ); LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52(); cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); cc1.setFactField( "name" ); cc1.setOperator( "==" ); cc1.setValue( new DTCellValue52( "Pupa" ) ); p1.getChildColumns().add( cc1 ); dt.setData( upgrader.makeDataLists( new Object[][]{ new Object[]{1l, "desc", true}, new Object[]{2l, "desc", false} } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); int index = -1; index = drl.indexOf( "Smurf( name == \"Pupa\" )" ); assertTrue( index > -1 ); index = drl.indexOf( "Smurf( name == \"Pupa\" )", index + 1 ); assertFalse( index > -1 ); }
p1.setBoundName( "$p1" );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "c1" ); p1.setFactType( "Driver" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE );
p1.setBoundName( "$c" ); p1.setFactType( "CheeseLover" );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );