@Before public void setUp() throws Exception { brlPersistence = BRDRLPersistence.getInstance(); }
buf.append( "not (\n" ); LHSPatternVisitor visitor = getLHSPatternVisitor( isDSLEnhanced, buf, nestedIndentation,
private void marshalRHS( StringBuilder buf, RuleModel model, boolean isDSLEnhanced ) { String indentation = "\t\t"; if ( model.rhs != null ) { //Add boiler-plate for actions operating on Dates Map<String, List<ActionFieldValue>> classes = getRHSClassDependencies( model ); if ( classes.containsKey( SuggestionCompletionEngine.TYPE_DATE ) ) { buf.append( indentation ); buf.append( "java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"" + System.getProperty( "drools.dateformat" ) + "\");\n" ); } //Add boiler-plate for actions operating on WorkItems if ( !getRHSWorkItemDependencies( model ).isEmpty() ) { buf.append( indentation ); buf.append( "org.drools.process.instance.WorkItemManager wim = (org.drools.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();\n" ); } //Marshall the model itself RHSActionVisitor actionVisitor = getRHSActionVisitor( isDSLEnhanced, buf, indentation ); for ( IAction action : model.rhs ) { actionVisitor.visit( action ); } } }
protected String marshalRule( RuleModel model ) { boolean isDSLEnhanced = model.hasDSLSentences(); bindingsPatterns = new HashMap<String, IFactPattern>(); bindingsFields = new HashMap<String, FieldConstraint>(); StringBuilder buf = new StringBuilder(); this.marshalHeader( model, buf ); this.marshalMetadata( buf, model ); this.marshalAttributes( buf, model ); buf.append( "\twhen\n" ); this.marshalLHS( buf, model, isDSLEnhanced ); buf.append( "\tthen\n" ); this.marshalRHS( buf, model, isDSLEnhanced ); this.marshalFooter( buf ); return buf.toString(); }
protected String marshalRule( RuleModel model ) { boolean isDSLEnhanced = model.hasDSLSentences(); bindingsPatterns = new HashMap<String, IFactPattern>(); bindingsFields = new HashMap<String, FieldConstraint>(); StringBuilder buf = new StringBuilder(); this.marshalHeader( model, buf ); this.marshalMetadata( buf, model ); this.marshalAttributes( buf, model ); buf.append( "\twhen\n" ); this.marshalLHS( buf, model, isDSLEnhanced ); buf.append( "\tthen\n" ); this.marshalRHS( buf, model, isDSLEnhanced ); this.marshalFooter( buf ); return buf.toString(); }
public Reader getKnowledgeReader(Resource ruleResource) throws IOException { String brl = loadBrlFile(ruleResource.getReader()); RuleModel model = BRXMLPersistence.getInstance().unmarshal(brl); this.hasDSLSentences=model.hasDSLSentences(); return new StringReader(BRDRLPersistence.getInstance().marshal(model)); }
private void marshalRHS( StringBuilder buf, RuleModel model, boolean isDSLEnhanced ) { String indentation = "\t\t"; if ( model.rhs != null ) { //Add boiler-plate for actions operating on Dates Map<String, List<ActionFieldValue>> classes = getRHSClassDependencies( model ); if ( classes.containsKey( SuggestionCompletionEngine.TYPE_DATE ) ) { buf.append( indentation ); buf.append( "java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"" + System.getProperty( "drools.dateformat" ) + "\");\n" ); } //Add boiler-plate for actions operating on WorkItems if ( !getRHSWorkItemDependencies( model ).isEmpty() ) { buf.append( indentation ); buf.append( "org.drools.process.instance.WorkItemManager wim = (org.drools.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();\n" ); } //Marshall the model itself RHSActionVisitor actionVisitor = getRHSActionVisitor( isDSLEnhanced, buf, indentation ); for ( IAction action : model.rhs ) { actionVisitor.visit( action ); } } }
buf.append( "not (\n" ); LHSPatternVisitor visitor = getLHSPatternVisitor( isDSLEnhanced, buf, nestedIndentation,
public Reader getKnowledgeReader(Resource ruleResource) throws IOException { String brl = loadBrlFile(ruleResource.getReader()); RuleModel model = BRXMLPersistence.getInstance().unmarshal(brl); this.hasDSLSentences=model.hasDSLSentences(); return new StringReader(BRDRLPersistence.getInstance().marshal(model)); }
@Test public void testDefaultMVEL() { RuleModel m = new RuleModel(); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "mvel" ) > -1 ); m.addAttribute( new RuleAttribute( "dialect", "goober" ) ); s = BRDRLPersistence.getInstance().marshal( m ); assertFalse( s.indexOf( "mvel" ) > -1 ); assertTrue( s.indexOf( "goober" ) > -1 ); }
@Test public void testFieldBindingWithNoConstraints() { // to satisfy JBRULES-850 RuleModel m = getModelWithNoConstraints(); String s = BRDRLPersistence.getInstance().marshal( m ); // System.out.println(s); assertTrue( s.indexOf( "Person( f1 : age)" ) != -1 ); }
@Test public void testLockOnActive() { RuleModel m = new RuleModel(); m.addAttribute( new RuleAttribute( "lock-on-active", "true" ) ); m.addAttribute( new RuleAttribute( "auto-focus", "true" ) ); m.addAttribute( new RuleAttribute( "duration", "42" ) ); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "lock-on-active true" ) > -1 ); assertTrue( s.indexOf( "auto-focus true" ) > -1 ); assertTrue( s.indexOf( "duration 42" ) > -1 ); }
@Test public void testInvalidComposite() throws Exception { RuleModel m = new RuleModel(); CompositeFactPattern com = new CompositeFactPattern( "not" ); m.addLhsItem( com ); String s = BRDRLPersistence.getInstance().marshal( m ); assertNotNull( s ); m.addLhsItem( new CompositeFactPattern( "or" ) ); m.addLhsItem( new CompositeFactPattern( "exists" ) ); s = BRDRLPersistence.getInstance().marshal( m ); assertNotNull( s ); }
rm ); String drl = BRDRLPersistence.getInstance().marshal( rm ); assertTrue( drl.indexOf( "age > \"42\"" ) > 0 );
@Test public void textIsNullOperator() { final RuleModel m = new RuleModel(); m.name = "IsNullOperator"; final FactPattern pat = new FactPattern( "Person" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldName( "age" ); con.setOperator( "== null" ); pat.addConstraint( con ); m.addLhsItem( pat ); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "Person( age == null )" ) != -1 ); }
@Test public void testFieldsDeclaredButNoConstraints() { RuleModel m = new RuleModel(); m.name = "boo"; FactPattern p = new FactPattern( "Person" ); // this isn't an effective constraint, so it should be ignored. p.addConstraint( new SingleFieldConstraint( "field1" ) ); m.addLhsItem( p ); String actual = BRDRLPersistence.getInstance().marshal( m ); String expected = "rule \"boo\" \tdialect \"mvel\"\n when Person() then end"; assertEqualsIgnoreWhitespace( expected, actual ); SingleFieldConstraint con = (SingleFieldConstraint) p.constraintList.constraints[ 0 ]; con.setFieldBinding( "q" ); // now it should appear, as we are binding a var to it actual = BRDRLPersistence.getInstance().marshal( m ); expected = "rule \"boo\" dialect \"mvel\" when Person(q : field1) then end"; assertEqualsIgnoreWhitespace( expected, actual ); }
@Test public void textIsNotNullOperator() { final RuleModel m = new RuleModel(); m.name = "IsNotNullOperator"; final FactPattern pat = new FactPattern( "Person" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldName( "age" ); con.setOperator( "!= null" ); pat.addConstraint( con ); m.addLhsItem( pat ); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "Person( age != null )" ) != -1 ); }
m.addRhsItem( ai ); String result = BRDRLPersistence.getInstance().marshal( m );
m.addRhsItem( au ); String result = BRDRLPersistence.getInstance().marshal( m );
m.addRhsItem( am ); String result = BRDRLPersistence.getInstance().marshal( m );