Skip to content

Commit

Permalink
[DROOLS-324][DROOLS-325] add test cases showing that conditional name…
Browse files Browse the repository at this point in the history
…d consequences are working as expected
  • Loading branch information
mariofusco committed Nov 7, 2013
1 parent 5729624 commit 4934b87
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drools-compiler/src/test/java/org/drools/compiler/Cheese.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Cheese

public static final String STILTON = "stilton";

public static final int BASE_PRICE = 10;

private static final long serialVersionUID = 510l;
private String type;
private int price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,56 @@ public void testIfElse1() {
assertTrue( results.contains( "STILTON" ) );
}

@Test
public void testIfElseWithConstant() {
// DROOLS-325
String str = "import org.drools.compiler.Cheese;\n " +
"global java.util.List results;\n" +
"\n" +
"rule R1 when\n" +
" $a: Cheese ( type == \"stilton\" )\n" +
" if ( price > Cheese.BASE_PRICE ) do[t1] else do[t2]\n" +
" $b: Cheese ( type == \"cheddar\" )\n" +
"then\n" +
" results.add( $b.getType() );\n" +
"then[t1]\n" +
" results.add( $a.getType() );\n" +
"then[t2]\n" +
" results.add( $a.getType().toUpperCase() );\n" +
"end\n";

List<String> results = executeTestWithDRL(str);

assertEquals( 2, results.size() );
assertTrue( results.contains( "cheddar" ) );
assertTrue( results.contains( "STILTON" ) );
}

@Test
public void testIfElseWithMvelAccessor() {
// DROOLS-324
String str = "import org.drools.compiler.Cheese;\n " +
"global java.util.List results;\n" +
"\n" +
"rule R1 dialect \"mvel\" when\n" +
" $a: Cheese ( type == \"stilton\" )\n" +
" if ( $a.price > Cheese.BASE_PRICE ) do[t1] else do[t2]\n" +
" $b: Cheese ( type == \"cheddar\" )\n" +
"then\n" +
" results.add( $b.getType() );\n" +
"then[t1]\n" +
" results.add( $a.getType() );\n" +
"then[t2]\n" +
" results.add( $a.getType().toUpperCase() );\n" +
"end\n";

List<String> results = executeTestWithDRL(str);

assertEquals( 2, results.size() );
assertTrue( results.contains( "cheddar" ) );
assertTrue( results.contains( "STILTON" ) );
}

@Test
public void testIfElse2() {
String str = "import org.drools.compiler.Cheese;\n " +
Expand Down

0 comments on commit 4934b87

Please sign in to comment.