View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.xml.export;
18  
19  import java.io.BufferedInputStream;
20  import java.io.ByteArrayInputStream;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import org.junit.Test;
25  import org.kuali.rice.kew.export.ExportDataSet;
26  import org.kuali.rice.kew.help.HelpEntry;
27  import org.kuali.rice.kew.service.KEWServiceLocator;
28  
29  
30  
31  public class HelpEntryXmlExporterTest extends XmlExporterTestCase {
32      
33  	public void testExportActionConfig() throws Exception {
34  		// action config has no help entries
35      }
36      
37      public void testExportEngineConfig() throws Exception {
38      	// engine config has no help entries
39      }
40  	
41      /**
42       * This will test some rule attributes with routing and searching config.
43       */
44      @Test public void testExport() throws Exception {
45          loadXmlFile("HelpEntryExportConfig.xml");
46          assertExport();
47      }
48          
49      protected void assertExport() throws Exception {
50          // export all existing rule attributes
51      	HelpEntry entry=new HelpEntry();
52      	entry.setHelpKey("");
53      	entry.setHelpName("");
54      	entry.setHelpText("");
55          List oldHelpEntries = KEWServiceLocator.getHelpService().search(entry);
56          ExportDataSet dataSet = new ExportDataSet();
57          dataSet.getHelp().addAll(oldHelpEntries);
58          byte[] xmlBytes = KEWServiceLocator.getXmlExporterService().export(dataSet);
59          assertTrue("XML should be non empty.", xmlBytes != null && xmlBytes.length > 0);
60          
61          // import the exported xml
62          loadXmlStream(new BufferedInputStream(new ByteArrayInputStream(xmlBytes)));
63          
64          List newHelpEntries = KEWServiceLocator.getHelpService().search(entry);
65          assertEquals("Should have same number of old and new RuleAttributes.", oldHelpEntries.size(), newHelpEntries.size());
66          for (Iterator iterator = oldHelpEntries.iterator(); iterator.hasNext();) {
67              HelpEntry oldHelpEntry = (HelpEntry) iterator.next();
68              boolean foundAttribute = false;
69              for (Iterator iterator2 = newHelpEntries.iterator(); iterator2.hasNext();) {
70                  HelpEntry newHelpEntry = (HelpEntry) iterator2.next();
71                  if (oldHelpEntry.getHelpName().equals(newHelpEntry.getHelpName())) {
72                      assertHelpEntryExport(oldHelpEntry, newHelpEntry);
73                      foundAttribute = true;
74                  }
75              }
76              assertTrue("Could not locate the new HelpEntry for name " + oldHelpEntry.getHelpName(), foundAttribute);
77          }
78      }
79      
80      private void assertHelpEntryExport(HelpEntry oldHelpEntry, HelpEntry newHelpEntry) {
81          // ids should be the same because we don't version rule attributes, but thier version number should be different
82          assertEquals("Ids should be the same.", oldHelpEntry.getHelpId(), newHelpEntry.getHelpId());
83          assertFalse("Version numbers should be different.", oldHelpEntry.getLockVerNbr().equals(newHelpEntry.getLockVerNbr()));
84          assertEquals(oldHelpEntry.getHelpName(), newHelpEntry.getHelpName());
85          assertEquals(oldHelpEntry.getHelpKey(), newHelpEntry.getHelpKey());
86          assertEquals(oldHelpEntry.getHelpText(), newHelpEntry.getHelpText());
87          //assertEquals(StringUtils.deleteWhitespace(oldRuleAttribute.getXmlConfigData()), StringUtils.deleteWhitespace(newRuleAttribute.getXmlConfigData()));
88          //assertRuleTemplateAttributes(oldRuleAttribute.getRuleTemplateAttributes(), newRuleAttribute.getRuleTemplateAttributes());
89      }
90      
91  
92          
93  }