Skip to content

Commit

Permalink
[DROOLS-210] Prevent trait proxies from being traited
Browse files Browse the repository at this point in the history
  • Loading branch information
sotty committed Aug 2, 2013
1 parent fa7588e commit 3c2ae93
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4470,4 +4470,63 @@ public void traitDonLegacyClassWithoutEmptyConstructor( ) {




@Test
public void testMapCoreManyTraits( ) {
String source = "package org.drools.test;\n" +
"\n" +
"import java.util.*;\n" +
"global List list;\n " +
"\n" +
"declare org.drools.factmodel.MapCore \n" +
"end\n" +
"\n" +
"global List list; \n" +
"\n" +
"declare trait PersonMap\n" +
"@propertyReactive \n" +
" name : String \n" +
" age : int \n" +
" height : Double \n" +
"end\n" +
"\n" +
"declare trait StudentMap\n" +
"@propertyReactive\n" +
" ID : String\n" +
" GPA : Double = 3.0\n" +
"end\n" +
"\n" +
"rule Don \n" +
"no-loop \n" +
"when \n" +
" $m : Map( this[ \"age\"] == 18 )\n" +
"then \n" +
" Object obj1 = don( $m, PersonMap.class );\n" +
" Object obj2 = don( obj1, StudentMap.class );\n" +
" System.out.println( \"done: PersonMap\" );\n" +
"\n" +
"end\n" +
"\n";

StatefulKnowledgeSession ks = getSessionFromString( source );
TraitFactory.setMode( TraitFactory.VirtualPropertyMode.MAP, ks.getKnowledgeBase() );

List list = new ArrayList();
ks.setGlobal( "list", list );

Map<String,Object> map = new HashMap<String, Object>( );
map.put( "name", "john" );
map.put( "age", 18 );
ks.insert( map );

ks.fireAllRules();

for ( Object o : ks.getObjects() ) {
System.err.println( o );
}

assertEquals( 3.0, map.get( "GPA" ) );
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ public <T> T getContext(Class<T> contextClass) {


public <T, K> T don( K core, Class<T> trait, boolean logical ) {
if ( core instanceof Thing && ( (Thing) core ).getCore() != core ) {
return don( ((Thing) core).getCore(), trait, logical );
}
try {
BitSet currentType = core instanceof TraitableBean ? ( (TraitableBean) core ).getCurrentTypeCode() : null;
BitSet veto = currentType != null ? (BitSet) currentType.clone() : null;
Expand Down

0 comments on commit 3c2ae93

Please sign in to comment.