Clover Coverage Report - kew-test 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
200   498   43   8.33
32   319   0.22   8
24     1.79  
3    
 
  RuleTemplateXmlParserTest       Line # 40 192 0% 41 246 0% 0.0
  RuleTemplateXmlParserTest.TemplateParserGeneralFixture       Line # 49 6 0% 1 7 0% 0.0
  RuleTemplateXmlParserTest.TemplateParserAttributeActivationFixture       Line # 456 2 0% 1 3 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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    * This is a Test class to test the rule template xml parser
36    *
37    * @author Kuali Rice Team (rice.collab@kuali.org)
38    *
39    */
 
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   
 
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    // below has allowOverwrite=true
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   
 
70  0 toggle 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   
 
80  0 toggle protected void loadTestData() throws Exception {
81  0 loadXmlFile("RuleTemplateConfig.xml");
82    }
83   
 
84  0 toggle 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   
 
101  0 toggle 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   
 
122  0 toggle 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   
 
141  0 toggle 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    * Loads valid template definitions
158    */
 
159  0 toggle @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    * Loads a "minimal" template definition and then updates/overwrites it
172    */
 
173  0 toggle @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); // allowOverwrite=true
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    * Loads a "full" template definition and then updates/overwrites it
186    */
 
187  0 toggle @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); // allowOverwrite=true
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    * Tests attempting to overwrite a template without the allowOverwrite flag set to true
200    */
 
201  0 toggle @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); // no allowOverwrite specified
204  0 testTemplate(TemplateParserGeneralFixture.INVALID_TEMPLATE_OVERWRITE.fileNameParameter, RuntimeException.class); // allowOverwrite=false
205    }
206   
207    /**
208    * Tests loading a template with a full ruleDefaults section
209    */
 
210  0 toggle @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    // test the rule template options
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    // test those set in the default/template rule
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    * Tests loading a template with a partial ruleDefaults section
236    */
 
237  0 toggle @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    // test the rule template options
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    // test those set in the default/template rule
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    * Tests loading a template with a partial ruleDefaults section and then updating/overwriting it
266    */
 
267  0 toggle @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    // test the rule template options
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    // test those set in the default/template rule
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    // we overwrite the template and specify a new subset of defaults...any setting omitted should be removed, i.e. reset to a default
295    // value
296  0 options = template.getRuleTemplateOptions();
297  0 assertEquals(1, options.size());
298  0 assertOptionValue(template, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, "true");
299   
300    // test those set in the default/template rule
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    // activation date defaults to current time
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    * Tests loading a template with a partial ruleDefaults section, and then updating/overwriting it with one with no ruleDefaults
316    * section defined at all
317    */
 
318  0 toggle @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    // test the rule template options
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    // test those set in the default/template rule
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    // we have removed all defaults, make sure they are gone...
346    // specifically that the default/template rule is GONE
347  0 assertNoDefaultsSpecified(template);
348    }
349   
350    /**
351    * Tests loading a template with the minimal required ruleDefaults
352    */
 
353  0 toggle @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    // test the rule template options; this one just has the instructions, nothing else
359  0 List<RuleTemplateOption> options = template.getRuleTemplateOptions();
360  0 assertEquals(0, options.size());
361   
362    // test those set in the default/template rule; everything default exception description which is specified
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    // activation date defaults to current time
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    * Asserts that if the defaults element is omitted, the correct defaults are set
378    * @param template the RuleTemplate to check
379    */
 
380  0 toggle protected void assertNoDefaultsSpecified(RuleTemplate template) {
381    // test the rule template options
382  0 assertDefaultTemplateOptions(template);
383    // test those set in the default/template rule
384  0 assertDefaultRuleDefaults(template);
385    }
386   
387    /**
388    * Asserts that if the defaults element is omitted, the correct RuleTemplateOptions are set (or not set)
389    * @param template the RuleTemplate to check
390    */
 
391  0 toggle protected void assertDefaultTemplateOptions(RuleTemplate template) {
392  0 List<RuleTemplateOption> options = template.getRuleTemplateOptions();
393  0 assertEquals(0, options.size());
394    }
395   
396    /**
397    * Asserts that if the defaults element is omitted, the correct template rule defaults are set
398    * @param template the RuleTemplate to check
399    */
 
400  0 toggle protected void assertDefaultRuleDefaults(RuleTemplate template) {
401  0 RuleBaseValues ruleDefaults = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(template.getRuleTemplateId());
402    // if ruleDefaults were not specified, then the defaults/template rule should not have been created, or should have been deleted
403  0 assertNull(ruleDefaults);
404    }
405   
406    /**
407    * Tests that the rule default template options are present. Must be kept in sync with defaults
408    * defined in RuleTemplate object
409    * @param ruleTemplate the ruleTemplate to check
410    * @param present whether the option should be present or not
411    */
 
412  0 toggle 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    * Tests that the rule default template options are present and set to null. Must be kept in sync with defaults
420    * defined in RuleTemplate object
421    * @param ruleTemplate the ruleTemplate to check
422    */
 
423  0 toggle 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    * Asserts that the rule template has a specific rule template option defined (with any value)
431    * @param template the rule template
432    * @param key the RuleTemplateOption key
433    * @param present whether the option should be present
434    */
 
435  0 toggle 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    * Asserts that the rule template has a specific rule template option defined with a specific value
446    * @param template the rule template
447    * @param key the RuleTemplateOption key
448    * @param value the RuleTemplateOption value
449    */
 
450  0 toggle 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   
 
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   
 
469  0 toggle private TemplateParserAttributeActivationFixture(String[] activeAttributeNames, String[] inactiveAttributeNames) {
470  0 this.activeAttributeNames = activeAttributeNames;
471  0 this.inactiveAttributeNames = inactiveAttributeNames;
472    }
473    }
474   
 
475  0 toggle @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    // test for ingesting active attribute
491   
492    // test for ingesting inactive attribute
493   
494    // test for ingesting active attribute and then reingest to test manual inactivation
495   
496    // test for ingesting active attribute and then reingest to test automatic inactivation
497   
498    }