View Javadoc

1   /*
2    * Copyright 2006-2011 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.export;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertFalse;
20  import static org.junit.Assert.assertTrue;
21  
22  import java.io.BufferedInputStream;
23  import java.io.ByteArrayInputStream;
24  import java.util.Iterator;
25  import java.util.List;
26  
27  import org.junit.Test;
28  import org.kuali.rice.core.api.CoreApiServiceLocator;
29  import org.kuali.rice.kew.export.KewExportDataSet;
30  import org.kuali.rice.kew.help.HelpEntry;
31  import org.kuali.rice.kew.service.KEWServiceLocator;
32  import org.kuali.rice.test.BaselineTestCase;
33  
34  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
35  public class HelpEntryXmlExporterTest extends XmlExporterTestCase {
36      
37  	public void testExportActionConfig() throws Exception {
38  		// action config has no help entries
39      }
40      
41      public void testExportEngineConfig() throws Exception {
42      	// engine config has no help entries
43      }
44  	
45      /**
46       * This will test some rule attributes with routing and searching config.
47       */
48      @Test public void testExport() throws Exception {
49          loadXmlFile("HelpEntryExportConfig.xml");
50          assertExport();
51      }
52          
53      protected void assertExport() throws Exception {
54          // export all existing rule attributes
55      	HelpEntry entry=new HelpEntry();
56      	entry.setHelpKey("");
57      	entry.setHelpName("");
58      	entry.setHelpText("");
59          List oldHelpEntries = KEWServiceLocator.getHelpService().search(entry);
60          KewExportDataSet dataSet = new KewExportDataSet();
61          dataSet.getHelp().addAll(oldHelpEntries);
62          byte[] xmlBytes = CoreApiServiceLocator.getXmlExporterService().export(dataSet.createExportDataSet());
63          assertTrue("XML should be non empty.", xmlBytes != null && xmlBytes.length > 0);
64          
65          // import the exported xml
66          loadXmlStream(new BufferedInputStream(new ByteArrayInputStream(xmlBytes)));
67          
68          List newHelpEntries = KEWServiceLocator.getHelpService().search(entry);
69          assertEquals("Should have same number of old and new RuleAttributes.", oldHelpEntries.size(), newHelpEntries.size());
70          for (Iterator iterator = oldHelpEntries.iterator(); iterator.hasNext();) {
71              HelpEntry oldHelpEntry = (HelpEntry) iterator.next();
72              boolean foundAttribute = false;
73              for (Iterator iterator2 = newHelpEntries.iterator(); iterator2.hasNext();) {
74                  HelpEntry newHelpEntry = (HelpEntry) iterator2.next();
75                  if (oldHelpEntry.getHelpName().equals(newHelpEntry.getHelpName())) {
76                      assertHelpEntryExport(oldHelpEntry, newHelpEntry);
77                      foundAttribute = true;
78                  }
79              }
80              assertTrue("Could not locate the new HelpEntry for name " + oldHelpEntry.getHelpName(), foundAttribute);
81          }
82      }
83      
84      private void assertHelpEntryExport(HelpEntry oldHelpEntry, HelpEntry newHelpEntry) {
85          // ids should be the same because we don't version rule attributes, but thier version number should be different
86          assertEquals("Ids should be the same.", oldHelpEntry.getHelpId(), newHelpEntry.getHelpId());
87          assertFalse("Version numbers should be different.", oldHelpEntry.getLockVerNbr().equals(newHelpEntry.getLockVerNbr()));
88          assertEquals(oldHelpEntry.getHelpName(), newHelpEntry.getHelpName());
89          assertEquals(oldHelpEntry.getHelpKey(), newHelpEntry.getHelpKey());
90          assertEquals(oldHelpEntry.getHelpText(), newHelpEntry.getHelpText());
91          //assertEquals(StringUtils.deleteWhitespace(oldRuleAttribute.getXmlConfigData()), StringUtils.deleteWhitespace(newRuleAttribute.getXmlConfigData()));
92          //assertRuleTemplateAttributes(oldRuleAttribute.getRuleTemplateAttributes(), newRuleAttribute.getRuleTemplateAttributes());
93      }
94      
95  
96          
97  }