public ExpressionFormLine(ExpressionPart part) { appendPart( part ); }
public ExpressionFormLine(ExpressionPart part) { appendPart( part ); }
@Test public void testCopy() { ExpressionFormLine efl = new ExpressionFormLine(); FactPattern fp = new FactPattern(SuggestionCompletionEngine.TYPE_OBJECT); fp.setBoundName("$o"); efl.appendPart(new ExpressionVariable(fp)); ExpressionMethod em = new ExpressionMethod("aMethod", "aClass", "aType"); ExpressionFormLine param = new ExpressionFormLine(); param.appendPart(new ExpressionText("\"hello world\"")); em.putParam("hi", param); efl.appendPart(em); ExpressionCollectionIndex index = new ExpressionCollectionIndex("get", "aRetType", "aGeneric"); efl.appendPart(index); index = new ExpressionCollectionIndex("get2", "aRetType", "aGeneric"); efl.appendPart(index); System.out.println(efl.getText()); ExpressionFormLine copy = new ExpressionFormLine(efl); assertNotSame(efl, copy); assertEquals(efl.getText(), copy.getText()); for (ExpressionPart e1 = efl.getRootExpression(), e2 = copy.getRootExpression(); e1 != null; e1 = e1.getNext(), e2 = e2.getNext()) { assertNotSame(e1, e2); assertEquals(e1.getClass(), e2.getClass()); } }
@Test public void toStringText() { ExpressionFormLine efl = new ExpressionFormLine(); FactPattern fact = new FactPattern( "String" ); fact.setBoundName( "$v" ); efl.appendPart( new ExpressionVariable( fact ) ); efl.appendPart( new ExpressionMethod( "size", "int", SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ) ); assertEquals( "$v.size()", efl.getText() ); efl.setBinding( "$s" ); assertEquals( "$s: $v.size()", efl.getText( true ) ); } }
@Test public void testAllVariableBindings2() { final RuleModel model = new RuleModel(); model.lhs = new IPattern[1]; final FactPattern fp = new FactPattern( "Car" ); model.lhs[0] = fp; fp.setBoundName( "$c" ); SingleFieldConstraint sfc = new SingleFieldConstraintEBLeftSide( "make" ); sfc.getExpressionValue().appendPart( new ExpressionField( "make", "java.lang.String", SuggestionCompletionEngine.TYPE_STRING ) ); sfc.setFieldBinding( "$m" ); fp.addConstraint( sfc ); List<String> vars = model.getAllVariables(); assertEquals( 2, vars.size() ); assertEquals( "$c", vars.get( 0 ) ); assertEquals( "$m", vars.get( 1 ) ); }
@Test public void testLHSExpressionNestedJavaEnum() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedJavaEnum"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", SuggestionCompletionEngine.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "genericName", "CHEESE", SuggestionCompletionEngine.TYPE_COMPARABLE ) ); con.setOperator( "==" ); con.setValue( "CHEESE.Cheddar" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsNestedJavaEnum\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.genericName == CHEESE.Cheddar )" + " then " + "end", result ); }
@Test public void testLHSExpressionNestedDate() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedDate"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", SuggestionCompletionEngine.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "dateBrought", "java.util.Date", SuggestionCompletionEngine.TYPE_DATE ) ); con.setOperator( "==" ); con.setValue( "27-Jun-2011" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsNestedDate\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.dateBrought == \"27-Jun-2011\" )" + " then " + "end", result ); }
@Test public void testLHSExpressionNestedString() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedString"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", SuggestionCompletionEngine.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "name", "java.lang.String", SuggestionCompletionEngine.TYPE_STRING ) ); con.setOperator( "==" ); con.setValue( "Cheedar" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsNestedString\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.name == \"Cheedar\" )" + " then " + "end", result ); }
@Test public void testLHSExpressionNestedNumber() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedNumber"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", SuggestionCompletionEngine.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "age", "java.lang.Integer", SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ) ); con.setOperator( "==" ); con.setValue( "55" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsNestedNumber\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.age == 55 )" + " then " + "end", result ); }
@Test public void testLHSExpressionNestedBoolean() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedBoolean"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", SuggestionCompletionEngine.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "smelly", "java.lang.Boolean", SuggestionCompletionEngine.TYPE_BOOLEAN ) ); con.setOperator( "==" ); con.setValue( "true" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsNestedBoolean\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.smelly == true )" + " then " + "end", result ); }
@Test public void testLHSExpressionNumber() { RuleModel m = new RuleModel(); m.name = "test expressionsNumber"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "java.lang.Integer", SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ) ); con.setOperator( "==" ); con.setValue( "55" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsNumber\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == 55 )" + " then " + "end", result ); }
@Test public void testLHSExpressionBoolean() { RuleModel m = new RuleModel(); m.name = "test expressionsBoolean"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "java.lang.Boolean", SuggestionCompletionEngine.TYPE_BOOLEAN ) ); con.setOperator( "==" ); con.setValue( "true" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsBoolean\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == true )" + " then " + "end", result ); }
@Test public void testLHSExpressionString2() { RuleModel m = new RuleModel(); m.name = "test expressionsString2"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "java.lang.String", SuggestionCompletionEngine.TYPE_STRING ) ); con.setOperator( "==" ); con.setValue( "Cheddar" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsString2\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == \"Cheddar\" )" + " then " + "end", result ); }
@Test public void testLHSExpressionDate() { RuleModel m = new RuleModel(); m.name = "test expressionsDate"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "java.util.Date", SuggestionCompletionEngine.TYPE_DATE ) ); con.setOperator( "==" ); con.setValue( "27-Jun-2011" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsDate\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == \"27-Jun-2011\" )" + " then " + "end", result ); }
@Test public void testLHSExpressionJavaEnum() { RuleModel m = new RuleModel(); m.name = "test expressionsJavaEnum"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "CHEESE", SuggestionCompletionEngine.TYPE_COMPARABLE ) ); con.setOperator( "==" ); con.setValue( "CHEESE.Cheddar" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsJavaEnum\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == CHEESE.Cheddar )" + " then " + "end", result ); }
@Test public void testLHSExpressionString1() { RuleModel m = new RuleModel(); m.name = "test expressionsString1"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionText( "field1" ) ); con.setOperator( "==" ); con.setValue( "goo" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); assertEqualsIgnoreWhitespace( "rule \"test expressionsString1\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == \"goo\" )" + " then " + "end", result ); }
"sfc0p0class", SuggestionCompletionEngine.TYPE_STRING ); efl0sfc0p0.appendPart( ef0sfc0p0 ); sfc0p0.setExpressionLeftSide( efl0sfc0p0 ); "sfc1p0class", SuggestionCompletionEngine.TYPE_STRING ); efl0sfc1p0.appendPart( ef0sfc1p0 ); sfc1p0.setExpressionLeftSide( efl0sfc1p0 ); "sfc0p1class", SuggestionCompletionEngine.TYPE_STRING ); efl0sfc0p1.appendPart( ef0sfc0p1 ); sfc0p1.setExpressionLeftSide( efl0sfc0p1 ); "sfc1p1class", SuggestionCompletionEngine.TYPE_STRING ); efl0sfc1p1.appendPart( ef0sfc1p1 ); sfc1p1.setExpressionLeftSide( efl0sfc1p1 );
efl0.setBinding( "$efl0" ); ExpressionText efl0p0 = new ExpressionText( "efl0p0" ); efl0.appendPart( efl0p0 ); fp0.setExpression( efl0 ); FactPattern fp0FactPattern = new FactPattern( "fp0FactPattern" );
efl0.setBinding( "$efl0" ); ExpressionText efl0p0 = new ExpressionText( "efl0p0" ); efl0.appendPart( efl0p0 ); sfc0.setExpressionValue( efl0 ); fp0.addConstraint( sfc0 );
efl0.setBinding( "$efl0" ); ExpressionText efl0p0 = new ExpressionText( "efl0p0" ); efl0.appendPart( efl0p0 ); fp0.setExpression( efl0 ); FactPattern fp0FactPattern = new FactPattern( "fp0FactPattern" );