scorecardType.set(scorecard, "age", 10);
session.insert(scorecard);
session.fireAllRules();
assertEquals( 29.0, scorecardType.get( scorecard, "scorecard__calculatedScore" ) );
Object scorecardInternals = session.getObjects( new ClassObjectFilter( scorecardInternalsType.getFactClass() ) ).iterator().next();
assertEquals( 29.0, scorecardInternalsType.get( scorecardInternals, "score" ) );
Map reasonCodesMap = (Map) scorecardInternalsType.get( scorecardInternals, "ranking" );
assertNotNull( reasonCodesMap );
assertEquals( 2, reasonCodesMap.size() );
assertEquals( -16.0, reasonCodesMap.get( "VL002" ) );
assertEquals( 20.0, reasonCodesMap.get( "AGE02" ) );
Object scorecardOutput = session.getObjects( new ClassObjectFilter( scorecardOutputType.getFactClass() ) ).iterator().next();
assertEquals( 29.0, scorecardOutputType.get( scorecardOutput, "calculatedScore" ) );
assertEquals( "AGE02", scorecardOutputType.get( scorecardOutput, "reasonCode" ) );
session.dispose();
session = kbase.newKieSession();
scorecard = scorecardType.newInstance();
scorecardType.set( scorecard, "age", 0 );
scorecardType.set( scorecard, "occupation", "SKYDIVER" );
session.insert( scorecard );
session.fireAllRules();
assertEquals( -1.0, scorecardType.get( scorecard, "scorecard__calculatedScore" ) );
scorecardInternals = session.getObjects( new ClassObjectFilter( scorecardInternalsType.getFactClass() ) ).iterator().next();
System.out.println( scorecardInternals );
assertEquals( -1.0, scorecardInternalsType.get( scorecardInternals, "score" ) );
reasonCodesMap = (Map) scorecardInternalsType.get( scorecardInternals, "ranking" );
assertNotNull( reasonCodesMap );
assertEquals( 3, reasonCodesMap.size() );
assertEquals( -109.0, reasonCodesMap.get( "OCC01" ) );
assertEquals( -16.0, reasonCodesMap.get( "VL002" ) );
assertEquals( 0.0, reasonCodesMap.get( "AGE01" ) );
assertEquals( Arrays.asList( "AGE01", "VL002", "OCC01" ), new ArrayList( reasonCodesMap.keySet() ) );
scorecardOutput = session.getObjects( new ClassObjectFilter( scorecardOutputType.getFactClass() ) ).iterator().next();
assertEquals( -1.0, scorecardOutputType.get( scorecardOutput, "calculatedScore" ) );
assertEquals( "AGE01", scorecardOutputType.get( scorecardOutput, "reasonCode" ) );
session.dispose();
session = kbase.newKieSession();
scorecard = scorecardType.newInstance();
scorecardType.set( scorecard, "age", 20 );
scorecardType.set( scorecard, "occupation", "TEACHER" );
scorecardType.set( scorecard, "residenceState", "AP" );
scorecardType.set( scorecard, "validLicense", true );
session.insert( scorecard );
session.fireAllRules();
assertEquals( 41.0, scorecardType.get( scorecard, "scorecard__calculatedScore" ) );
scorecardInternals = session.getObjects( new ClassObjectFilter( scorecardInternalsType.getFactClass() ) ).iterator().next();
System.out.println( scorecardInternals );
assertEquals( 41.0, scorecardInternalsType.get( scorecardInternals, "score" ) );
reasonCodesMap = (Map) scorecardInternalsType.get( scorecardInternals, "ranking" );
assertNotNull( reasonCodesMap );
assertEquals( 4, reasonCodesMap.size() );
assertEquals( -89.0, reasonCodesMap.get( "OCC02" ) );
assertEquals( -22.0, reasonCodesMap.get( "RS001" ) );
assertEquals( -14.0, reasonCodesMap.get( "VL001" ) );
assertEquals( 30.0, reasonCodesMap.get( "AGE03" ) );
assertEquals( Arrays.asList( "AGE03", "VL001", "RS001", "OCC02" ), new ArrayList( reasonCodesMap.keySet() ) );
scorecardOutput = session.getObjects( new ClassObjectFilter( scorecardOutputType.getFactClass() ) ).iterator().next();
assertEquals( 41.0, scorecardOutputType.get( scorecardOutput, "calculatedScore" ) );
assertEquals( "AGE03", scorecardOutputType.get( scorecardOutput, "reasonCode" ) );
session.dispose();