"Imp" );
TraitableBean imp = (TraitableBean) impClass.newInstance();
FactType traitClass = kb.getFactType( "org.drools.compiler.trait.test",
"Student" );
Class trait = traitClass.getFactClass();
TraitProxy proxy = (TraitProxy) tFactory.getProxy( imp,
trait );
Map<String, Object> virtualFields = imp._getDynamicProperties();
Map<String, Object> wrapper = proxy.getFields();
assertEquals( 3,
wrapper.size() );
assertEquals( 1,
virtualFields.size() );
impClass.set(imp,
"name",
"john");
assertEquals( 3,
wrapper.size() );
assertEquals( 1,
virtualFields.size() );
proxy.getFields().put( "school",
"skol" );
assertEquals( 3,
wrapper.size() );
assertEquals( 1,
virtualFields.size() );
proxy.getFields().put( "surname",
"xxx" );
assertEquals( 4,
wrapper.size() );
assertEquals( 2,
virtualFields.size() );
// FactType indClass = kb.getFactType("org.drools.compiler.trait.test","Entity");
// TraitableBean ind = (TraitableBean) indClass.newInstance();
TraitableBean ind = new Entity();
TraitProxy proxy2 = (TraitProxy) tFactory.getProxy( ind,
trait );
Map virtualFields2 = ind._getDynamicProperties();
Map wrapper2 = proxy2.getFields();
assertEquals( 3,
wrapper2.size() );
assertEquals( 3,
virtualFields2.size() );
traitClass.set( proxy2,
"name",
"john" );
assertEquals( 3,
wrapper2.size() );
assertEquals( 3,
virtualFields2.size() );
proxy2.getFields().put( "school",
"skol" );
assertEquals( 3,
wrapper2.size() );
assertEquals( 3,
virtualFields2.size() );
proxy2.getFields().put( "surname",
"xxx" );
assertEquals( 4,
wrapper2.size() );
assertEquals( 4,
virtualFields2.size() );
FactType traitClass2 = kb.getFactType( "org.drools.compiler.trait.test",
"Role" );
Class trait2 = traitClass2.getFactClass();
// TraitableBean ind2 = (TraitableBean) indClass.newInstance();
TraitableBean ind2 = new Entity();
TraitProxy proxy99 = (TraitProxy) tFactory.getProxy( ind2,
trait2 );
proxy99.getFields().put( "surname",
"xxx" );
proxy99.getFields().put( "name",
"xyz" );
proxy99.getFields().put( "school",
"skol" );
assertEquals( 3,
proxy99.getFields().size() );
TraitProxy proxy100 = (TraitProxy) tFactory.getProxy( ind2,
trait );
assertEquals( 4,
proxy100.getFields().size() );
} catch ( Exception e ) {
e.printStackTrace();
fail( e.getMessage() );
}