1 package org.kuali.ole.deliver.drools;
2
3 import org.apache.commons.io.FileUtils;
4 import org.junit.Test;
5 import org.kuali.ole.deliver.bo.drools.DroolsRuleBo;
6 import org.kuali.ole.deliver.bo.drools.FinesAndLimitsBo;
7 import org.kuali.ole.deliver.drools.rules.GeneralChecksDroolFileGenerator;
8
9 import java.io.File;
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import static junit.framework.TestCase.assertNotNull;
14
15
16
17
18 public class GeneralChecksFileGenerator_UT {
19
20 @Test
21 public void generateGeneralChecksDroolsFile() throws Exception {
22 GeneralChecksDroolFileGenerator droolFileGenerator = new GeneralChecksDroolFileGenerator();
23 droolFileGenerator.setFileDir(System.getProperty("java.io.tmpdir") + "/general-checks.drl");
24
25 List<DroolsRuleBo> droolsRuleBoList = new ArrayList<>();
26
27 setupIsActive(droolsRuleBoList);
28 setupIsAddressVerfied(droolsRuleBoList);
29 setupActivationDate(droolsRuleBoList);
30 setupIsGeneralBlock(droolsRuleBoList);
31 setupIsPatronExpired(droolsRuleBoList);
32 setupAllCharges(droolsRuleBoList);
33 setupReplacementFineAmout(droolsRuleBoList);
34 setupOverDueCheck(droolsRuleBoList);
35 setupRecallAndOverDueDays(droolsRuleBoList);
36 setupOverdueFineAmount(droolsRuleBoList);
37
38 File generateFile = droolFileGenerator.generateFile(droolsRuleBoList,"general-checks-test");
39 assertNotNull(generateFile);
40 String readFileToString = FileUtils.readFileToString(generateFile);
41 System.out.println(readFileToString);
42 }
43
44 private void setupActivationDate(List<DroolsRuleBo> droolsRuleBoList) {
45 DroolsRuleBo setupActivationDate = new DroolsRuleBo();
46 setupActivationDate.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.ACTIVATION_DATE);
47 setupActivationDate.setAgendaGroup("general-checks");
48 setupActivationDate.setRuleName("Patron's Activation date");
49 setupActivationDate.setErrorMessage("Patron has an invalid activation date.");
50 droolsRuleBoList.add(setupActivationDate);
51 }
52
53 private void setupOverdueFineAmount(List<DroolsRuleBo> droolsRuleBoList) {
54 DroolsRuleBo overdueFineAmount = new DroolsRuleBo();
55 overdueFineAmount.setBorrowerTypes("STFQTR,ALUM25");
56 overdueFineAmount.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.OVERDUE_FINE_AMOUNT);
57 overdueFineAmount.setAgendaGroup("general-checks");
58 overdueFineAmount.setRuleName("Patron Has Atleast One Item which has exceeded the overdue limit");
59 overdueFineAmount.setErrorMessage("Patron Has Atleast One Item which has exceeded overdue fine limit.");
60 FinesAndLimitsBo finesAndLimitsBo = new FinesAndLimitsBo();
61 finesAndLimitsBo.setLimitAmount("300");
62 overdueFineAmount.setFinesAndLimitsBo(finesAndLimitsBo);
63 droolsRuleBoList.add(overdueFineAmount);
64 }
65
66 private void setupRecallAndOverDueDays(List<DroolsRuleBo> droolsRuleBoList) {
67 DroolsRuleBo recallAndOverdueDaysRule = new DroolsRuleBo();
68 recallAndOverdueDaysRule.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.RECALL_AND_OVERDUE_DAYS);
69 recallAndOverdueDaysRule.setAgendaGroup("general-checks");
70 recallAndOverdueDaysRule.setRuleName("Patron Has Atleast One Item which has been recalled and has exceeded the overdue limit");
71 recallAndOverdueDaysRule.setErrorMessage("Patron Has Atleast One Item which has been recalled and is overdue");
72 FinesAndLimitsBo finesAndLimitsBo = new FinesAndLimitsBo();
73 finesAndLimitsBo.setOverDueLimits("3");
74 recallAndOverdueDaysRule.setFinesAndLimitsBo(finesAndLimitsBo);
75 droolsRuleBoList.add(recallAndOverdueDaysRule);
76 }
77
78 private void setupOverDueCheck(List<DroolsRuleBo> droolsRuleBoList) {
79 DroolsRuleBo overdueRule = new DroolsRuleBo();
80 overdueRule.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.OVERDUE_CHECK);
81 overdueRule.setAgendaGroup("general-checks");
82 overdueRule.setRuleName("Patron Has Atleast One Item which is over the allow due limit");
83 overdueRule.setErrorMessage("Patron Has Atleast One Item which is over the allowed due limit");
84 FinesAndLimitsBo finesAndLimitsBo = new FinesAndLimitsBo();
85 finesAndLimitsBo.setOverDueLimits("3");
86 overdueRule.setFinesAndLimitsBo(finesAndLimitsBo);
87 droolsRuleBoList.add(overdueRule);
88 }
89
90 private void setupReplacementFineAmout(List<DroolsRuleBo> droolsRuleBoList) {
91
92 DroolsRuleBo replacementFineRule = new DroolsRuleBo();
93 replacementFineRule.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.REPLACEMENT_FEE_AMOUNT);
94 replacementFineRule.setAgendaGroup("general-checks");
95 replacementFineRule.setRuleName("Check Replacement fine");
96 replacementFineRule.setErrorMessage("Patron has replacement fees of $150 or more");
97 FinesAndLimitsBo finesAndLimitsBo = new FinesAndLimitsBo();
98 finesAndLimitsBo.setLimitAmount("150");
99 finesAndLimitsBo.setOperator(">");
100 finesAndLimitsBo.setBorrowerType("ALUM25,UGRAD");
101 replacementFineRule.setFinesAndLimitsBo(finesAndLimitsBo);
102 droolsRuleBoList.add(replacementFineRule);
103 }
104
105 private void setupIsGeneralBlock(List<DroolsRuleBo> droolsRuleBoList) {
106 DroolsRuleBo generalBlock = new DroolsRuleBo();
107 generalBlock.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.IS_BLOCKED);
108 generalBlock.setAgendaGroup("general-checks");
109 generalBlock.setEditorId("general-checks");
110 generalBlock.setRuleName("Patron Block check");
111 generalBlock.setErrorMessage("Patron has a general block");
112 generalBlock.setOverridePermission("Patron has a general block");
113 droolsRuleBoList.add(generalBlock);
114 }
115
116 private void setupIsAddressVerfied(List<DroolsRuleBo> droolsRuleBoList) {
117 DroolsRuleBo addressVerified = new DroolsRuleBo();
118 addressVerified.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.ADDRESS_VERIFIED);
119 addressVerified.setAgendaGroup("general-checks");
120 addressVerified.setEditorId("general-checks");
121 addressVerified.setRuleName("Is Address Verified");
122 addressVerified.setErrorMessage("Is Address Verified");
123 droolsRuleBoList.add(addressVerified);
124 }
125
126 private void setupIsActive(List<DroolsRuleBo> droolsRuleBoList) {
127 DroolsRuleBo isActiveRule = new DroolsRuleBo();
128 isActiveRule.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.IS_ACTIVE);
129 isActiveRule.setAgendaGroup("general-checks");
130 isActiveRule.setEditorId("general-checks");
131 isActiveRule.setRuleName("Is Patron Active");
132 isActiveRule.setErrorMessage("Patron is InActive");
133 droolsRuleBoList.add(isActiveRule);
134 }
135
136 private void setupIsPatronExpired(List<DroolsRuleBo> droolsRuleBoList) {
137 DroolsRuleBo patronExpired = new DroolsRuleBo();
138 patronExpired.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.IS_PATRON_EXPIRED);
139 patronExpired.setAgendaGroup("general-checks");
140 patronExpired.setEditorId("general-checks");
141 patronExpired.setRuleName("Is Patron Expired");
142 patronExpired.setErrorMessage("Patron is Expired");
143 droolsRuleBoList.add(patronExpired);
144 }
145
146 public void setupAllCharges(List<DroolsRuleBo> droolsRuleBoList) {
147 DroolsRuleBo allChargesRule = new DroolsRuleBo();
148 allChargesRule.setRuleType(DroolsConstants.GENERAL_CHECK_RULE_TYPE.ALL_CHARGES);
149 allChargesRule.setAgendaGroup("general-checks");
150 allChargesRule.setRuleName("Patron All Charges");
151 allChargesRule.setErrorMessage("Patron's overall charges are $200 or more.");
152
153
154 FinesAndLimitsBo finesAndLimitsBo = new FinesAndLimitsBo();
155 finesAndLimitsBo.setLimitAmount("200");
156 finesAndLimitsBo.setOperator(">");
157 finesAndLimitsBo.setBorrowerType("QGRAD,UGRAD,ALUM25");
158
159 allChargesRule.setFinesAndLimitsBo(finesAndLimitsBo);
160 droolsRuleBoList.add(allChargesRule);
161 }
162 }