001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.xml.export;
018:
019: import java.io.BufferedInputStream;
020: import java.io.ByteArrayInputStream;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.junit.Test;
025:
026: import edu.iu.uis.eden.KEWServiceLocator;
027: import edu.iu.uis.eden.export.ExportDataSet;
028: import edu.iu.uis.eden.export.ExportFormat;
029: import edu.iu.uis.eden.help.HelpEntry;
030:
031: public class HelpEntryXmlExporterTest extends XmlExporterTestCase {
032:
033: public void testExportActionConfig() throws Exception {
034: // action config has no help entries
035: }
036:
037: public void testExportEngineConfig() throws Exception {
038: // engine config has no help entries
039: }
040:
041: /**
042: * This will test some rule attributes with routing and searching config.
043: */
044: @Test
045: public void testExport() throws Exception {
046: loadXmlFile("HelpEntryExportConfig.xml");
047: assertExport();
048: }
049:
050: protected void assertExport() throws Exception {
051: // export all existing rule attributes
052: HelpEntry entry = new HelpEntry();
053: entry.setHelpKey("");
054: entry.setHelpName("");
055: entry.setHelpText("");
056: List oldHelpEntries = KEWServiceLocator.getHelpService()
057: .search(entry);
058: ExportDataSet dataSet = new ExportDataSet(ExportFormat.XML);
059: dataSet.getHelp().addAll(oldHelpEntries);
060: byte[] xmlBytes = KEWServiceLocator.getXmlExporterService()
061: .export(ExportFormat.XML, dataSet);
062: assertTrue("XML should be non empty.", xmlBytes != null
063: && xmlBytes.length > 0);
064:
065: // import the exported xml
066: loadXmlStream(new BufferedInputStream(new ByteArrayInputStream(
067: xmlBytes)));
068:
069: List newHelpEntries = KEWServiceLocator.getHelpService()
070: .search(entry);
071: assertEquals(
072: "Should have same number of old and new RuleAttributes.",
073: oldHelpEntries.size(), newHelpEntries.size());
074: for (Iterator iterator = oldHelpEntries.iterator(); iterator
075: .hasNext();) {
076: HelpEntry oldHelpEntry = (HelpEntry) iterator.next();
077: boolean foundAttribute = false;
078: for (Iterator iterator2 = newHelpEntries.iterator(); iterator2
079: .hasNext();) {
080: HelpEntry newHelpEntry = (HelpEntry) iterator2.next();
081: if (oldHelpEntry.getHelpName().equals(
082: newHelpEntry.getHelpName())) {
083: assertHelpEntryExport(oldHelpEntry, newHelpEntry);
084: foundAttribute = true;
085: }
086: }
087: assertTrue("Could not locate the new HelpEntry for name "
088: + oldHelpEntry.getHelpName(), foundAttribute);
089: }
090: }
091:
092: private void assertHelpEntryExport(HelpEntry oldHelpEntry,
093: HelpEntry newHelpEntry) {
094: // ids should be the same because we don't version rule attributes, but thier version number should be different
095: assertEquals("Ids should be the same.", oldHelpEntry
096: .getHelpId(), newHelpEntry.getHelpId());
097: assertFalse("Version numbers should be different.",
098: oldHelpEntry.getLockVerNbr().equals(
099: newHelpEntry.getLockVerNbr()));
100: assertEquals(oldHelpEntry.getHelpName(), newHelpEntry
101: .getHelpName());
102: assertEquals(oldHelpEntry.getHelpKey(), newHelpEntry
103: .getHelpKey());
104: assertEquals(oldHelpEntry.getHelpText(), newHelpEntry
105: .getHelpText());
106: //assertEquals(StringUtils.deleteWhitespace(oldRuleAttribute.getXmlConfigData()), StringUtils.deleteWhitespace(newRuleAttribute.getXmlConfigData()));
107: //assertRuleTemplateAttributes(oldRuleAttribute.getRuleTemplateAttributes(), newRuleAttribute.getRuleTemplateAttributes());
108: }
109:
110: }
|