| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.rice.kew.xml; |
| 17 |
|
|
| 18 |
|
import org.junit.Test; |
| 19 |
|
import org.kuali.rice.kew.rule.RuleBaseValues; |
| 20 |
|
import org.kuali.rice.kew.rule.RuleTemplateOption; |
| 21 |
|
import org.kuali.rice.kew.rule.bo.RuleTemplate; |
| 22 |
|
import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute; |
| 23 |
|
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 24 |
|
import org.kuali.rice.kew.test.KEWTestCase; |
| 25 |
|
import org.kuali.rice.kew.util.KEWConstants; |
| 26 |
|
|
| 27 |
|
import java.util.Date; |
| 28 |
|
import java.util.Iterator; |
| 29 |
|
import java.util.List; |
| 30 |
|
|
| 31 |
|
import static org.junit.Assert.*; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@author |
| 38 |
|
|
| 39 |
|
|
|
|
|
| 0% |
Uncovered Elements: 246 (246) |
Complexity: 41 |
Complexity Density: 0.21 |
|
| 40 |
|
public class RuleTemplateXmlParserTest extends KEWTestCase { |
| 41 |
|
private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RuleTemplateXmlParserTest.class); |
| 42 |
|
|
| 43 |
|
private static final String RULE_ATTRIBUTE_ONE = "TemplateTestRuleAttribute1"; |
| 44 |
|
private static final String RULE_ATTRIBUTE_TWO = "TemplateTestRuleAttribute2"; |
| 45 |
|
private static final String RULE_ATTRIBUTE_THREE = "TemplateTestRuleAttribute3"; |
| 46 |
|
private static final String RULE_ATTRIBUTE_FOUR = "TemplateTestRuleAttribute4"; |
| 47 |
|
private static final String RULE_ATTRIBUTE_FIVE = "TemplateTestRuleAttribute5"; |
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 49 |
|
private enum TemplateParserGeneralFixture { |
| 50 |
|
VALID_TEMPLATE_MIN_XML("ValidRuleTemplate", "RuleTemplate_Valid", new String[]{RULE_ATTRIBUTE_ONE}, new String[0], new String[]{RULE_ATTRIBUTE_ONE}, new String[0]), |
| 51 |
|
VALID_TEMPLATE_FULL_XML("ValidRuleTemplate_Full", "RuleTemplate_Valid_Full", new String[]{RULE_ATTRIBUTE_ONE}, new String[0], new String[]{RULE_ATTRIBUTE_ONE}, new String[0]), |
| 52 |
|
|
| 53 |
|
VALID_TEMPLATE_OVERWRITE("ValidRuleTemplateOverwrite", "RuleTemplate_Valid", new String[]{RULE_ATTRIBUTE_ONE}, new String[]{RULE_ATTRIBUTE_FOUR}, new String[]{RULE_ATTRIBUTE_FOUR}, new String[]{RULE_ATTRIBUTE_ONE}), |
| 54 |
|
VALID_TEMPLATE_FULL_OVERWRITE("ValidRuleTemplateFullOverwrite", "RuleTemplate_Valid_Full", new String[]{RULE_ATTRIBUTE_ONE}, new String[]{RULE_ATTRIBUTE_FOUR}, new String[]{RULE_ATTRIBUTE_FOUR}, new String[]{RULE_ATTRIBUTE_ONE}), |
| 55 |
|
INVALID_TEMPLATE_OVERWRITE("InvalidRuleTemplateOverwrite", "RuleTemplate_Valid", new String[]{RULE_ATTRIBUTE_ONE}, new String[0], new String[]{RULE_ATTRIBUTE_ONE}, new String[0]), |
| 56 |
|
VALID_TEMPLATE_WITH_FULL_DEFAULTS("ValidRuleTemplateWithFullDefaults", "RuleTemplate_Valid_Defaults", new String[]{RULE_ATTRIBUTE_TWO}, new String[0], new String[]{RULE_ATTRIBUTE_TWO}, new String[0]), |
| 57 |
|
VALID_TEMPLATE_WITH_LIMITED_DEFAULTS("ValidRuleTemplateWithSomeDefaults", "RuleTemplate_Valid_Some_Defaults", new String[]{RULE_ATTRIBUTE_THREE}, new String[0], new String[0], new String[]{RULE_ATTRIBUTE_THREE}), |
| 58 |
|
VALID_TEMPLATE_WITH_LIMITED_DEFAULTS_OVERWRITE("ValidRuleTemplateWithSomeDefaultsOverwrite", "RuleTemplate_Valid_Some_Defaults", new String[]{RULE_ATTRIBUTE_THREE}, new String[0], new String[0], new String[]{RULE_ATTRIBUTE_THREE}), |
| 59 |
|
VALID_TEMPLATE_WITH_DESCRIPTION_DEFAULT("ValidRuleTemplateWithDefaultsDescriptionOnly", "RuleTemplate_Valid_Description_Default", new String[]{RULE_ATTRIBUTE_TWO}, new String[0], new String[]{RULE_ATTRIBUTE_TWO}, new String[0]), |
| 60 |
|
VALID_TEMPLATE_WITH_LIMITED_DEFAULTS_REMOVED("ValidRuleTemplateWithSomeRemovedDefaultsOverwrite", "RuleTemplate_Valid_Some_Defaults", new String[]{RULE_ATTRIBUTE_THREE}, new String[0], new String[0], new String[]{RULE_ATTRIBUTE_THREE}) |
| 61 |
|
; |
| 62 |
|
|
| 63 |
|
public String fileNameParameter; |
| 64 |
|
public String ruleTemplateName; |
| 65 |
|
public String[] activeAttributeNames; |
| 66 |
|
public String[] inactiveAttributeNames; |
| 67 |
|
public String[] requiredAttributeNames; |
| 68 |
|
public String[] nonRequiredAttributeNames; |
| 69 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 70 |
0
|
private TemplateParserGeneralFixture(String fileNameParameter, String ruleTemplateName, String[] activeAttributeNames, String[] inactiveAttributeNames, String[] requiredAttributeNames, String[] nonRequiredAttributeNames) {... |
| 71 |
0
|
this.fileNameParameter = fileNameParameter; |
| 72 |
0
|
this.ruleTemplateName = ruleTemplateName; |
| 73 |
0
|
this.activeAttributeNames = activeAttributeNames; |
| 74 |
0
|
this.inactiveAttributeNames = inactiveAttributeNames; |
| 75 |
0
|
this.requiredAttributeNames = requiredAttributeNames; |
| 76 |
0
|
this.nonRequiredAttributeNames = nonRequiredAttributeNames; |
| 77 |
|
} |
| 78 |
|
} |
| 79 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 80 |
0
|
protected void loadTestData() throws Exception {... |
| 81 |
0
|
loadXmlFile("RuleTemplateConfig.xml"); |
| 82 |
|
} |
| 83 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 84 |
0
|
private void testTemplate(String docName, Class expectedException) throws Exception {... |
| 85 |
0
|
RuleTemplateXmlParser parser = new RuleTemplateXmlParser(); |
| 86 |
0
|
String filename = "RT_" + docName + ".xml"; |
| 87 |
0
|
try { |
| 88 |
0
|
parser.parseRuleTemplates(getClass().getResourceAsStream(filename)); |
| 89 |
0
|
if (expectedException != null) { |
| 90 |
0
|
fail(filename + " successfully loaded. Expected exception of class '" + expectedException + "'"); |
| 91 |
|
} |
| 92 |
|
} catch (Exception e) { |
| 93 |
0
|
if (expectedException == null || !(expectedException.isAssignableFrom(e.getClass()))) { |
| 94 |
0
|
throw e; |
| 95 |
|
} else { |
| 96 |
0
|
log.error(filename + " exception: " + e); |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 101 |
0
|
private void testListOfTemplateAttributes(List ruleTemplateAttributes, String[] activeRuleTemplateAttributeNames, String[] requiredRuleTemplateAttributeNames) {... |
| 102 |
0
|
for (Iterator iterator = ruleTemplateAttributes.iterator(); iterator.hasNext();) { |
| 103 |
0
|
RuleTemplateAttribute templateAttribute = (RuleTemplateAttribute) iterator.next(); |
| 104 |
0
|
String ruleAttributeName = templateAttribute.getRuleAttribute().getName(); |
| 105 |
|
|
| 106 |
0
|
LOG.info("Attribute name '" + ruleAttributeName +"' active indicator is " + templateAttribute.isActive()); |
| 107 |
0
|
if (activeRuleTemplateAttributeNames == null) { |
| 108 |
0
|
assertEquals("Active indicator should be false for all attributes but is not for attribute '" + ruleAttributeName + "'",Boolean.FALSE, templateAttribute.getActive()); |
| 109 |
|
} else { |
| 110 |
0
|
runTestsOnTemplateAttributeField(ruleAttributeName, templateAttribute.isActive(), activeRuleTemplateAttributeNames, "active"); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
0
|
LOG.info("Attribute name '" + ruleAttributeName +"' required indicator is " + templateAttribute.isRequired()); |
| 114 |
0
|
if (requiredRuleTemplateAttributeNames == null) { |
| 115 |
0
|
assertEquals("Required indicator should be false for all attributes but is not for attribute '" + ruleAttributeName + "'",Boolean.FALSE, templateAttribute.getRequired()); |
| 116 |
|
} else { |
| 117 |
0
|
runTestsOnTemplateAttributeField(ruleAttributeName, templateAttribute.isRequired(), requiredRuleTemplateAttributeNames, "required"); |
| 118 |
|
} |
| 119 |
|
} |
| 120 |
|
} |
| 121 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
| 122 |
0
|
private void testAllAttributesActive(List activeRuleTemplateAttributes, String[] activeRuleTemplateAttributeNames) {... |
| 123 |
0
|
for (Iterator iterator = activeRuleTemplateAttributes.iterator(); iterator.hasNext();) { |
| 124 |
0
|
RuleTemplateAttribute activeTemplateAttribute = (RuleTemplateAttribute) iterator.next(); |
| 125 |
0
|
String ruleAttributeName = activeTemplateAttribute.getRuleAttribute().getName(); |
| 126 |
0
|
assertEquals("Template Attribute with name '" + ruleAttributeName + "' has invalid active value", Boolean.TRUE, activeTemplateAttribute.getActive()); |
| 127 |
0
|
boolean foundAttribute = false; |
| 128 |
0
|
for (int i = 0; i < activeRuleTemplateAttributeNames.length; i++) { |
| 129 |
0
|
String shouldBeActiveAttributeName = activeRuleTemplateAttributeNames[i]; |
| 130 |
0
|
if (shouldBeActiveAttributeName.equals(ruleAttributeName)) { |
| 131 |
0
|
foundAttribute = true; |
| 132 |
0
|
break; |
| 133 |
|
} |
| 134 |
|
} |
| 135 |
0
|
if (!foundAttribute) { |
| 136 |
0
|
fail("Template Attribute with name '" + ruleAttributeName + "' should have been in active template name list but was not found"); |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
| 141 |
0
|
private void runTestsOnTemplateAttributeField(String ruleAttributeName, boolean valueToConfirm, String[] attributeNamesShouldBeTrue, String errorMessageIdentifier) {... |
| 142 |
0
|
boolean foundAttribute = false; |
| 143 |
0
|
for (String attributeNameThatShouldPass : attributeNamesShouldBeTrue) { |
| 144 |
0
|
if (ruleAttributeName.equals(attributeNameThatShouldPass)) { |
| 145 |
0
|
foundAttribute = true; |
| 146 |
0
|
if (!valueToConfirm) { |
| 147 |
0
|
fail("Attribute with name '" + ruleAttributeName + "' should have been " + errorMessageIdentifier + " but is not"); |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
|
} |
| 151 |
0
|
if ( (!foundAttribute) && (valueToConfirm) ) { |
| 152 |
0
|
fail("Attribute with name '" + ruleAttributeName + "' should not be " + errorMessageIdentifier + " but is"); |
| 153 |
|
} |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
4
-
|
|
| 159 |
0
|
@Test public void testLoadValidTemplate() throws Exception {... |
| 160 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_FULL_XML.fileNameParameter, null); |
| 161 |
|
|
| 162 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_MIN_XML.fileNameParameter, null); |
| 163 |
0
|
RuleTemplate template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_MIN_XML.ruleTemplateName); |
| 164 |
0
|
testListOfTemplateAttributes(template.getRuleTemplateAttributes(), TemplateParserGeneralFixture.VALID_TEMPLATE_MIN_XML.activeAttributeNames, TemplateParserGeneralFixture.VALID_TEMPLATE_MIN_XML.requiredAttributeNames); |
| 165 |
0
|
testAllAttributesActive(template.getActiveRuleTemplateAttributes(), TemplateParserGeneralFixture.VALID_TEMPLATE_MIN_XML.activeAttributeNames); |
| 166 |
|
|
| 167 |
0
|
assertNoDefaultsSpecified(template); |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
4
-
|
|
| 173 |
0
|
@Test public void testLoadValidTemplateWithOverwrite() throws Exception {... |
| 174 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_MIN_XML.fileNameParameter, null); |
| 175 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_OVERWRITE.fileNameParameter, null); |
| 176 |
|
|
| 177 |
0
|
RuleTemplate template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_OVERWRITE.ruleTemplateName); |
| 178 |
0
|
testListOfTemplateAttributes(template.getRuleTemplateAttributes(), TemplateParserGeneralFixture.VALID_TEMPLATE_OVERWRITE.activeAttributeNames, TemplateParserGeneralFixture.VALID_TEMPLATE_OVERWRITE.requiredAttributeNames); |
| 179 |
0
|
testAllAttributesActive(template.getActiveRuleTemplateAttributes(), TemplateParserGeneralFixture.VALID_TEMPLATE_OVERWRITE.activeAttributeNames); |
| 180 |
|
|
| 181 |
0
|
assertNoDefaultsSpecified(template); |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
4
-
|
|
| 187 |
0
|
@Test public void testLoadValidTemplateFullWithOverwrite() throws Exception {... |
| 188 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_FULL_XML.fileNameParameter, null); |
| 189 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_FULL_OVERWRITE.fileNameParameter, null); |
| 190 |
|
|
| 191 |
0
|
RuleTemplate template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_FULL_OVERWRITE.ruleTemplateName); |
| 192 |
0
|
testListOfTemplateAttributes(template.getRuleTemplateAttributes(), TemplateParserGeneralFixture.VALID_TEMPLATE_FULL_OVERWRITE.activeAttributeNames, TemplateParserGeneralFixture.VALID_TEMPLATE_FULL_OVERWRITE.requiredAttributeNames); |
| 193 |
0
|
testAllAttributesActive(template.getActiveRuleTemplateAttributes(), TemplateParserGeneralFixture.VALID_TEMPLATE_FULL_OVERWRITE.activeAttributeNames); |
| 194 |
|
|
| 195 |
0
|
assertNoDefaultsSpecified(template); |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
4
-
|
|
| 201 |
0
|
@Test public void testLoadInvalidTemplateWithOverwrite() throws Exception {... |
| 202 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_MIN_XML.fileNameParameter, null); |
| 203 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_MIN_XML.fileNameParameter, RuntimeException.class); |
| 204 |
0
|
testTemplate(TemplateParserGeneralFixture.INVALID_TEMPLATE_OVERWRITE.fileNameParameter, RuntimeException.class); |
| 205 |
|
} |
| 206 |
|
|
| 207 |
|
|
| 208 |
|
|
| 209 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
4
-
|
|
| 210 |
0
|
@Test public void testLoadValidTemplateWithFullDefaults() throws Exception {... |
| 211 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_FULL_DEFAULTS.fileNameParameter, null); |
| 212 |
|
|
| 213 |
0
|
RuleTemplate template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_FULL_DEFAULTS.ruleTemplateName); |
| 214 |
|
|
| 215 |
|
|
| 216 |
0
|
List<RuleTemplateOption> options = template.getRuleTemplateOptions(); |
| 217 |
0
|
assertEquals(5, options.size()); |
| 218 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, "false"); |
| 219 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_APPROVE_REQ, "true"); |
| 220 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_COMPLETE_REQ, "false"); |
| 221 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_FYI_REQ, "false"); |
| 222 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_DEFAULT_CD, "A"); |
| 223 |
|
|
| 224 |
|
|
| 225 |
0
|
RuleBaseValues ruleDefaults = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(template.getRuleTemplateId()); |
| 226 |
0
|
assertTrue(ruleDefaults.getTemplateRuleInd()); |
| 227 |
0
|
assertEquals("Testy Me A Template", ruleDefaults.getDescription()); |
| 228 |
0
|
assertEquals("01/11/2006", ruleDefaults.getFromDateString()); |
| 229 |
0
|
assertEquals("01/01/2100", ruleDefaults.getToDateString()); |
| 230 |
0
|
assertTrue(ruleDefaults.getForceAction()); |
| 231 |
0
|
assertFalse(ruleDefaults.getActiveInd()); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
|
| 235 |
|
|
| 236 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
4
-
|
|
| 237 |
0
|
@Test public void testLoadValidTemplateWithSomeDefaults() throws Exception {... |
| 238 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS.fileNameParameter, null); |
| 239 |
|
|
| 240 |
0
|
RuleTemplate template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS.ruleTemplateName); |
| 241 |
|
|
| 242 |
|
|
| 243 |
0
|
List<RuleTemplateOption> options = template.getRuleTemplateOptions(); |
| 244 |
0
|
assertEquals(5, options.size()); |
| 245 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, "false"); |
| 246 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_APPROVE_REQ, "true"); |
| 247 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_COMPLETE_REQ, "false"); |
| 248 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_FYI_REQ, "false"); |
| 249 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_DEFAULT_CD, "A"); |
| 250 |
|
|
| 251 |
|
|
| 252 |
0
|
RuleBaseValues ruleDefaults = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(template.getRuleTemplateId()); |
| 253 |
0
|
assertTrue(ruleDefaults.getTemplateRuleInd()); |
| 254 |
0
|
assertEquals("a rule based on RuleTemplate_Valid_Some_Defaults", ruleDefaults.getDescription()); |
| 255 |
0
|
assertFalse(ruleDefaults.getForceAction()); |
| 256 |
0
|
assertFalse(ruleDefaults.getActiveInd()); |
| 257 |
0
|
assertEquals("01/11/2006", ruleDefaults.getFromDateString()); |
| 258 |
0
|
assertEquals("01/01/2100", ruleDefaults.getToDateString()); |
| 259 |
0
|
assertNotNull(ruleDefaults.getActivationDate()); |
| 260 |
0
|
assertTrue(new Date(System.currentTimeMillis() - 10000).before(ruleDefaults.getActivationDate()) && new Date(System.currentTimeMillis() + 100).after(ruleDefaults.getActivationDate())); |
| 261 |
0
|
assertNull(ruleDefaults.getDeactivationDate()); |
| 262 |
|
} |
| 263 |
|
|
| 264 |
|
|
| 265 |
|
|
| 266 |
|
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 1 |
Complexity Density: 0.03 |
4
-
|
|
| 267 |
0
|
@Test public void testLoadValidTemplateWithSomeDefaultsOverwrite() throws Exception {... |
| 268 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS.fileNameParameter, null); |
| 269 |
|
|
| 270 |
0
|
RuleTemplate template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS.ruleTemplateName); |
| 271 |
|
|
| 272 |
|
|
| 273 |
0
|
List<RuleTemplateOption> options = template.getRuleTemplateOptions(); |
| 274 |
0
|
assertEquals(5, options.size()); |
| 275 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, "false"); |
| 276 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_APPROVE_REQ, "true"); |
| 277 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_COMPLETE_REQ, "false"); |
| 278 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_FYI_REQ, "false"); |
| 279 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_DEFAULT_CD, "A"); |
| 280 |
|
|
| 281 |
|
|
| 282 |
0
|
RuleBaseValues ruleDefaults = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(template.getRuleTemplateId()); |
| 283 |
0
|
assertTrue(ruleDefaults.getTemplateRuleInd()); |
| 284 |
0
|
assertEquals("a rule based on RuleTemplate_Valid_Some_Defaults", ruleDefaults.getDescription()); |
| 285 |
0
|
assertFalse(ruleDefaults.getForceAction()); |
| 286 |
0
|
assertFalse(ruleDefaults.getActiveInd()); |
| 287 |
0
|
assertEquals("01/11/2006", ruleDefaults.getFromDateString()); |
| 288 |
0
|
assertEquals("01/01/2100", ruleDefaults.getToDateString()); |
| 289 |
|
|
| 290 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS_OVERWRITE.fileNameParameter, null); |
| 291 |
|
|
| 292 |
0
|
template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS_OVERWRITE.ruleTemplateName); |
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| 296 |
0
|
options = template.getRuleTemplateOptions(); |
| 297 |
0
|
assertEquals(1, options.size()); |
| 298 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, "true"); |
| 299 |
|
|
| 300 |
|
|
| 301 |
0
|
ruleDefaults = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(template.getRuleTemplateId()); |
| 302 |
0
|
assertTrue(ruleDefaults.getTemplateRuleInd()); |
| 303 |
0
|
assertEquals("a rule based on (updated) RuleTemplate_Valid_Some_Defaults", ruleDefaults.getDescription()); |
| 304 |
0
|
assertFalse(ruleDefaults.getForceAction()); |
| 305 |
0
|
assertFalse(ruleDefaults.getActiveInd()); |
| 306 |
|
|
| 307 |
0
|
assertNull(ruleDefaults.getFromDate()); |
| 308 |
0
|
assertNotNull(ruleDefaults.getActivationDate()); |
| 309 |
0
|
assertTrue(new Date(System.currentTimeMillis() - 10000).before(ruleDefaults.getActivationDate()) && new Date(System.currentTimeMillis() + 100).after(ruleDefaults.getActivationDate())); |
| 310 |
0
|
assertNull(ruleDefaults.getToDateString()); |
| 311 |
0
|
assertNull(ruleDefaults.getDeactivationDate()); |
| 312 |
|
} |
| 313 |
|
|
| 314 |
|
|
| 315 |
|
|
| 316 |
|
|
| 317 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
4
-
|
|
| 318 |
0
|
@Test public void testLoadValidTemplateWithSomeRemovedDefaults() throws Exception {... |
| 319 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS.fileNameParameter, null); |
| 320 |
|
|
| 321 |
0
|
RuleTemplate template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS.ruleTemplateName); |
| 322 |
|
|
| 323 |
|
|
| 324 |
0
|
List<RuleTemplateOption> options = template.getRuleTemplateOptions(); |
| 325 |
0
|
assertEquals(5, options.size()); |
| 326 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, "false"); |
| 327 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_APPROVE_REQ, "true"); |
| 328 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_COMPLETE_REQ, "false"); |
| 329 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_FYI_REQ, "false"); |
| 330 |
0
|
assertOptionValue(template, KEWConstants.ACTION_REQUEST_DEFAULT_CD, "A"); |
| 331 |
|
|
| 332 |
|
|
| 333 |
0
|
RuleBaseValues ruleDefaults = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(template.getRuleTemplateId()); |
| 334 |
0
|
assertTrue(ruleDefaults.getTemplateRuleInd()); |
| 335 |
0
|
assertEquals("a rule based on RuleTemplate_Valid_Some_Defaults", ruleDefaults.getDescription()); |
| 336 |
0
|
assertFalse(ruleDefaults.getForceAction()); |
| 337 |
0
|
assertFalse(ruleDefaults.getActiveInd()); |
| 338 |
0
|
assertEquals("01/11/2006", ruleDefaults.getFromDateString()); |
| 339 |
0
|
assertEquals("01/01/2100", ruleDefaults.getToDateString()); |
| 340 |
|
|
| 341 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS_REMOVED.fileNameParameter, null); |
| 342 |
|
|
| 343 |
0
|
template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_LIMITED_DEFAULTS_REMOVED.ruleTemplateName); |
| 344 |
|
|
| 345 |
|
|
| 346 |
|
|
| 347 |
0
|
assertNoDefaultsSpecified(template); |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
|
| 351 |
|
|
| 352 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
4
-
|
|
| 353 |
0
|
@Test public void testLoadValidTemplateWithDescriptionDefault() throws Exception {... |
| 354 |
0
|
testTemplate(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_DESCRIPTION_DEFAULT.fileNameParameter, null); |
| 355 |
|
|
| 356 |
0
|
RuleTemplate template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserGeneralFixture.VALID_TEMPLATE_WITH_DESCRIPTION_DEFAULT.ruleTemplateName); |
| 357 |
|
|
| 358 |
|
|
| 359 |
0
|
List<RuleTemplateOption> options = template.getRuleTemplateOptions(); |
| 360 |
0
|
assertEquals(0, options.size()); |
| 361 |
|
|
| 362 |
|
|
| 363 |
0
|
RuleBaseValues ruleDefaults = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(template.getRuleTemplateId()); |
| 364 |
0
|
assertTrue(ruleDefaults.getTemplateRuleInd()); |
| 365 |
0
|
assertEquals("a description", ruleDefaults.getDescription()); |
| 366 |
0
|
assertFalse(ruleDefaults.getForceAction()); |
| 367 |
0
|
assertFalse(ruleDefaults.getActiveInd()); |
| 368 |
|
|
| 369 |
0
|
assertNull(ruleDefaults.getFromDate()); |
| 370 |
0
|
assertNotNull(ruleDefaults.getActivationDate()); |
| 371 |
0
|
assertTrue(new Date(System.currentTimeMillis() - 10000).before(ruleDefaults.getActivationDate()) && new Date(System.currentTimeMillis() + 100).after(ruleDefaults.getActivationDate())); |
| 372 |
0
|
assertNull(ruleDefaults.getToDateString()); |
| 373 |
0
|
assertNull(ruleDefaults.getDeactivationDate()); |
| 374 |
|
} |
| 375 |
|
|
| 376 |
|
|
| 377 |
|
|
| 378 |
|
@param |
| 379 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 380 |
0
|
protected void assertNoDefaultsSpecified(RuleTemplate template) {... |
| 381 |
|
|
| 382 |
0
|
assertDefaultTemplateOptions(template); |
| 383 |
|
|
| 384 |
0
|
assertDefaultRuleDefaults(template); |
| 385 |
|
} |
| 386 |
|
|
| 387 |
|
|
| 388 |
|
|
| 389 |
|
@param |
| 390 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 391 |
0
|
protected void assertDefaultTemplateOptions(RuleTemplate template) {... |
| 392 |
0
|
List<RuleTemplateOption> options = template.getRuleTemplateOptions(); |
| 393 |
0
|
assertEquals(0, options.size()); |
| 394 |
|
} |
| 395 |
|
|
| 396 |
|
|
| 397 |
|
|
| 398 |
|
@param |
| 399 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 400 |
0
|
protected void assertDefaultRuleDefaults(RuleTemplate template) {... |
| 401 |
0
|
RuleBaseValues ruleDefaults = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(template.getRuleTemplateId()); |
| 402 |
|
|
| 403 |
0
|
assertNull(ruleDefaults); |
| 404 |
|
} |
| 405 |
|
|
| 406 |
|
|
| 407 |
|
|
| 408 |
|
|
| 409 |
|
@param |
| 410 |
|
@param |
| 411 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 412 |
0
|
protected void assertRuleDefaultsArePresent(RuleTemplate template, boolean present) {... |
| 413 |
0
|
for (String key: RuleTemplate.DEFAULT_OPTION_KEYS) { |
| 414 |
0
|
assertOptionPresence(template, key, present); |
| 415 |
|
} |
| 416 |
|
} |
| 417 |
|
|
| 418 |
|
|
| 419 |
|
|
| 420 |
|
|
| 421 |
|
@param |
| 422 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 423 |
0
|
protected void assertRuleDefaultsAreNull(RuleTemplate template) {... |
| 424 |
0
|
for (String key: RuleTemplate.DEFAULT_OPTION_KEYS) { |
| 425 |
0
|
assertOptionValue(template, key, null); |
| 426 |
|
} |
| 427 |
|
} |
| 428 |
|
|
| 429 |
|
|
| 430 |
|
|
| 431 |
|
@param |
| 432 |
|
@param |
| 433 |
|
@param |
| 434 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 435 |
0
|
protected void assertOptionPresence(RuleTemplate template, String key, boolean present) {... |
| 436 |
0
|
RuleTemplateOption option = template.getRuleTemplateOption(key); |
| 437 |
0
|
if (present) { |
| 438 |
0
|
if (option == null) fail("Rule template option '" + key + "' is not defined on template: " + template); |
| 439 |
|
} else { |
| 440 |
0
|
if (option != null) fail("Rule template option '" + key + "' is defined on template: " + template); |
| 441 |
|
} |
| 442 |
|
} |
| 443 |
|
|
| 444 |
|
|
| 445 |
|
|
| 446 |
|
@param |
| 447 |
|
@param |
| 448 |
|
@param |
| 449 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 450 |
0
|
protected void assertOptionValue(RuleTemplate template, String key, String value) {... |
| 451 |
0
|
RuleTemplateOption option = template.getRuleTemplateOption(key); |
| 452 |
0
|
if (option == null) fail("Rule template option '" + key + "' not defined on template: " + template); |
| 453 |
0
|
assertEquals("Incorrect rule template option value for key '" + key + "'. Expected '" + value + "' but found '" + option.getValue() + "'", value, option.getValue()); |
| 454 |
|
} |
| 455 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 456 |
|
private enum TemplateParserAttributeActivationFixture { |
| 457 |
|
ATTRIBUTE_1(new String[]{RULE_ATTRIBUTE_ONE}, new String[]{RULE_ATTRIBUTE_TWO}), |
| 458 |
|
ATTRIBUTE_2(new String[]{}, new String[]{RULE_ATTRIBUTE_ONE,RULE_ATTRIBUTE_TWO}), |
| 459 |
|
ATTRIBUTE_3(new String[]{RULE_ATTRIBUTE_ONE,RULE_ATTRIBUTE_THREE}, new String[]{RULE_ATTRIBUTE_TWO}), |
| 460 |
|
ATTRIBUTE_4(new String[]{RULE_ATTRIBUTE_TWO,RULE_ATTRIBUTE_FIVE}, new String[]{RULE_ATTRIBUTE_ONE,RULE_ATTRIBUTE_THREE,RULE_ATTRIBUTE_FOUR,}), |
| 461 |
|
; |
| 462 |
|
|
| 463 |
|
public static final String RULE_TEMPLATE_XML_FILENAME_PARM = "ActivationAttributesTest_"; |
| 464 |
|
public static final String RULE_TEMPLATE_NAME = "RuleTemplate_Activation_Test"; |
| 465 |
|
|
| 466 |
|
public String[] activeAttributeNames; |
| 467 |
|
public String[] inactiveAttributeNames; |
| 468 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 469 |
0
|
private TemplateParserAttributeActivationFixture(String[] activeAttributeNames, String[] inactiveAttributeNames) {... |
| 470 |
0
|
this.activeAttributeNames = activeAttributeNames; |
| 471 |
0
|
this.inactiveAttributeNames = inactiveAttributeNames; |
| 472 |
|
} |
| 473 |
|
} |
| 474 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
4
-
|
|
| 475 |
0
|
@Test public void testAttributeActivationAndRemoval() throws Exception {... |
| 476 |
0
|
RuleTemplate template = null; |
| 477 |
0
|
int totalAttributes = -1; |
| 478 |
0
|
for (TemplateParserAttributeActivationFixture currentEnum : TemplateParserAttributeActivationFixture.values()) { |
| 479 |
0
|
String fileNameParameter = TemplateParserAttributeActivationFixture.RULE_TEMPLATE_XML_FILENAME_PARM + (currentEnum.ordinal() + 1); |
| 480 |
0
|
testTemplate(fileNameParameter, null); |
| 481 |
0
|
template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(TemplateParserAttributeActivationFixture.RULE_TEMPLATE_NAME); |
| 482 |
0
|
assertEquals("Total Number of Active Attributes from Rule Template is wrong",currentEnum.activeAttributeNames.length,template.getActiveRuleTemplateAttributes().size()); |
| 483 |
0
|
totalAttributes = currentEnum.activeAttributeNames.length + currentEnum.inactiveAttributeNames.length; |
| 484 |
0
|
assertEquals("Total Number of Attributes from Rule Template is wrong",totalAttributes,template.getRuleTemplateAttributes().size()); |
| 485 |
0
|
testListOfTemplateAttributes(template.getRuleTemplateAttributes(), currentEnum.activeAttributeNames, null); |
| 486 |
0
|
testAllAttributesActive(template.getActiveRuleTemplateAttributes(), currentEnum.activeAttributeNames); |
| 487 |
|
} |
| 488 |
|
} |
| 489 |
|
|
| 490 |
|
|
| 491 |
|
|
| 492 |
|
|
| 493 |
|
|
| 494 |
|
|
| 495 |
|
|
| 496 |
|
|
| 497 |
|
|
| 498 |
|
} |