Skip to content

Commit

Permalink
#8 PoliticanBusySchedule test
Browse files Browse the repository at this point in the history
  • Loading branch information
pethers committed Feb 26, 2018
1 parent a216184 commit 85247cd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public void afterMatchFired(AfterMatchFiredEvent event) {

private static final String politicianDrlFile2 = "rules/PoliticianTimeToRetire.drl";

private static final String politicianDrlFile3 = "rules/PoliticianBusySchedule.drl";



/** The Constant partyDrlFile. */
private static final String partyDrlFile = "rules/PartyNoGovernmentExperience.drl";
Expand Down Expand Up @@ -105,6 +108,7 @@ public void ruleEngineTest() throws Exception {
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write(ResourceFactory.newClassPathResource(politicianDrlFile));
kieFileSystem.write(ResourceFactory.newClassPathResource(politicianDrlFile2));
kieFileSystem.write(ResourceFactory.newClassPathResource(politicianDrlFile3));
kieFileSystem.write(ResourceFactory.newClassPathResource(partyDrlFile));

KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
Expand Down
41 changes: 41 additions & 0 deletions service.impl/src/test/resources/rules/PoliticianBusySchedule.drl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.hack23.cia.service.impl.rules

import com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician
import com.hack23.cia.service.api.action.kpi.Status
import com.hack23.cia.service.impl.rules.PoliticianComplianceCheckImpl
import java.util.Date
import java.util.concurrent.TimeUnit

function long busyFactor(Date firstAssignmentDate, long totalDaysServed){
return ( totalDaysServed / TimeUnit.MILLISECONDS.toDays(new Date().getTime() - firstAssignmentDate.getTime()) );
}

rule "We have an politician with busy schedule, at least on average more than 4 concurrent roles per day"
dialect "java"
when
$p : PoliticianComplianceCheckImpl( politician.active == true && ( busyFactor(politician.firstAssignmentDate, politician.totalDaysServed ) > 4 ))
then
modify( $p ) {
setStatus( Status.MINOR )
}
end

rule "We have an politician with busy schedule, at least on average more than 5 concurrent roles per day"
dialect "java"
when
$p : PoliticianComplianceCheckImpl( politician.active == true && ( busyFactor(politician.firstAssignmentDate, politician.totalDaysServed ) > 5 ))
then
modify( $p ) {
setStatus( Status.MAJOR )
}
end

rule "We have an politician with busy schedule, at least on average more than 7 concurrent roles per day"
dialect "java"
when
$p : PoliticianComplianceCheckImpl( politician.active == true && ( busyFactor(politician.firstAssignmentDate, politician.totalDaysServed ) > 6 ))
then
modify( $p ) {
setStatus( Status.CRITICAL )
}
end

0 comments on commit 85247cd

Please sign in to comment.