use of alma.acs.logging.engine.io.IOHelper in project ACS by ACS-Community.
the class LoadSaveTest method testSaveLoadFields.
/**
* Save and Load the special logs then check their fields.
* <P>
* This test is performed comparing the fields of the special logs one by one
* instead of comparing the XMLs.
* The test does the following steps:
* <OL>
* <LI>build vector of logs to save from the XMLs in <code>specialLogs</code>
* <LI>save the vector of logs with an <code>IOHelper</code> object
* <LI>load the logs from file
* <LI>compare each field of the logs read from the file with those in <code>specialLogs</code>
* <LI>compare the additional data names and values
* </OL>
* <P>
* The test implicitly checks the conversion between XML and ILogEntry too.
*/
public void testSaveLoadFields() throws Exception {
ACSLogParser parser = ACSLogParserFactory.getParser();
assertNotNull(parser);
//Build the logs from the XML
Vector<ILogEntry> logsToCheck = new Vector<ILogEntry>();
for (int t = 0; t < specialLogs.length; t++) {
ILogEntry log = parser.parse(specialLogs[t]);
assertNotNull(log);
logsToCheck.add(log);
}
// Save the logs on disk
IOHelper ioHelper = new IOHelper();
assertNotNull(ioHelper);
ioHelper.saveLogs(fileName, logsToCheck, this, false, false);
assertEquals(logsToCheck.size(), numOfLogsWritten);
// Load the logs from disk
ioHelper.loadLogs(fileName, this, null, this, this, false);
assertEquals(logsRead.size(), logsToCheck.size());
// Iterate over the logs comparing each field
for (int t = 0; t < logsToCheck.size(); t++) {
ILogEntry originalLog = logsToCheck.elementAt(t);
assertNotNull(originalLog);
ILogEntry savedLog = logsRead.elementAt(t);
assertNotNull(savedLog);
// Check the fields
for (LogField f : LogField.values()) {
Object original = originalLog.getField(f);
Object saved = savedLog.getField(f);
assertEquals("Fields " + f + " differ", original, saved);
}
// Check additional data
assertEquals(originalLog.hasDatas(), savedLog.hasDatas());
if (originalLog.hasDatas()) {
Vector<AdditionalData> originalData = originalLog.getAdditionalData();
assertNotNull(originalData);
Vector<AdditionalData> savedData = savedLog.getAdditionalData();
assertNotNull(savedData);
assertEquals(originalData.size(), savedData.size());
for (int count = 0; count < originalData.size(); count++) {
AdditionalData originalDataItem = originalData.elementAt(count);
assertNotNull(originalDataItem);
AdditionalData savedDataItem = savedData.elementAt(count);
assertNotNull(savedDataItem);
assertEquals("Data names differ", originalDataItem.name, savedDataItem.name);
assertEquals("Data values differ", originalDataItem.value, savedDataItem.value);
}
}
}
}
use of alma.acs.logging.engine.io.IOHelper in project ACS by ACS-Community.
the class LoadSaveTest method testAppend.
/**
* Test the append switch while saving logs by saving the same
* collection twice in the same file but with the append switch set to
* <code>true</code>.
* @throws Exception
*/
public void testAppend() throws Exception {
IOHelper ioHelper = new IOHelper();
assertNotNull(ioHelper);
// First save with no append
ioHelper.saveLogs(fileName, logs, this, false, false);
// Second save with append
ioHelper.saveLogs(fileName, logs, this, true, false);
// Load the logs
ioHelper.loadLogs(fileName, this, null, this, this, false);
assertEquals(2 * logs.size(), logsRead.size());
assertEquals(2 * logs.size(), numOfLogsRead);
}
use of alma.acs.logging.engine.io.IOHelper in project ACS by ACS-Community.
the class LoadSaveTest method testSaveLoadCompressed.
/**
* Load and save a collection of logs in uncompressed files
* <P>
* The save is performed by passing the name of the file
*
* @throws Exception
*/
public void testSaveLoadCompressed() throws Exception {
IOHelper ioHelper = new IOHelper();
assertNotNull(ioHelper);
// Save the logs on file
ioHelper.saveLogs(gzipFileName, logs, this, false, true);
assertEquals(logs.size(), numOfLogsWritten);
// Read the logs
ioHelper.loadLogs(gzipFileName, this, null, this, this, true);
assertEquals(logs.size(), numOfLogsRead);
// Compare the 2 collections
assertEquals(logs.size(), logsRead.size());
// Compare the 2 collections
int t = 0;
for (ILogEntry log : logs) {
String logXML = log.toXMLString();
String logReadXML = logsRead.get(t++).toXMLString();
assertEquals(logXML, logReadXML);
}
}
use of alma.acs.logging.engine.io.IOHelper in project ACS by ACS-Community.
the class LoadSaveTest method testSaveLoadIterator.
/**
* Check the load and save of logs by passing an <code>Iterator</code>
*
* @throws Exception
*/
public void testSaveLoadIterator() throws Exception {
IOHelper ioHelper = new IOHelper();
assertNotNull(ioHelper);
Iterator<ILogEntry> iterator = logs.iterator();
long assumedLen = 0;
for (ILogEntry log : logs) {
char[] chars = (log.toXMLString() + "\n").toCharArray();
assumedLen += chars.length;
}
// Save the logs on file
ioHelper.saveLogs(fileName, iterator, this, false, false);
assertEquals(assumedLen, bytesWritten);
assertEquals(logs.size(), numOfLogsWritten);
// Read the logs
ioHelper.loadLogs(fileName, this, null, this, this, false);
assertEquals(logs.size(), numOfLogsRead);
}
use of alma.acs.logging.engine.io.IOHelper in project ACS by ACS-Community.
the class LoadSaveTest method testSaveLoad.
/**
* Load and save a collection of logs in uncompressed files
* <P>
* The save is performed by passing the name of the file
*
* @throws Exception
*/
public void testSaveLoad() throws Exception {
IOHelper ioHelper = new IOHelper();
assertNotNull(ioHelper);
long assumedLen = 0;
for (ILogEntry log : logs) {
char[] chars = (log.toXMLString() + "\n").toCharArray();
assumedLen += chars.length;
}
// Save the logs on file
ioHelper.saveLogs(fileName, logs, this, false, false);
assertEquals(assumedLen, bytesWritten);
assertEquals(logs.size(), numOfLogsWritten);
// Read the logs
ioHelper.loadLogs(fileName, this, null, this, this, false);
assertEquals(logs.size(), numOfLogsRead);
// bytes read includes the XML header
assertTrue(bytesRead > assumedLen);
// Compare the 2 collections
assertEquals(logs.size(), logsRead.size());
int t = 0;
for (ILogEntry log : logs) {
String logXML = log.toXMLString();
String logReadXML = logsRead.get(t++).toXMLString();
assertEquals(logXML, logReadXML);
}
}
Aggregations