public void testSerializeReport()
{
InternalDemoHandler[] handlers = FunctionalityTestLib.getAllDemoHandlers();
for (int i = 0; i < handlers.length; i++)
{
final InternalDemoHandler handler = handlers[i];
try
{
if (handler instanceof OpenSourceXMLDemoHandler)
{
// contains a non-serializable image
continue;
}
logger.debug("Starting to read " + handler.getDemoName());
final MasterReport report = handler.createReport();
final DataFactory model = report.getDataFactory();
// we don't test whether our demo models are serializable :)
report.setDataFactory(new TableDataFactory
("default", new DefaultTableModel()));
// clear all report properties, which may cause trouble ...
final ReportProperties p = report.getProperties();
final Iterator keys = p.keys();
while (keys.hasNext())
{
String key = (String) keys.next();
if (p.get(key) instanceof Serializable == false)
{
p.put(key, null);
}
}
final ByteArrayOutputStream bo = new ByteArrayOutputStream();
try
{
final ObjectOutputStream oout = new ObjectOutputStream(bo);
oout.writeObject(report);
oout.close();
}
catch (Exception e)
{
logger.debug("Failed to write " + handler.getDemoName(), e);
fail();
}
try
{
final ByteArrayInputStream bin = new ByteArrayInputStream(bo.toByteArray());
final ObjectInputStream oin = new ObjectInputStream(bin);
final MasterReport report2 = (MasterReport) oin.readObject();
report2.setDataFactory(model);
assertTrue(FunctionalityTestLib.execGraphics2D(report2));
}
catch (Exception e)
{
logger.debug("Failed to read " + handler.getDemoName(), e);
fail();
}
}
catch (Exception e)
{
logger.debug("Failed to execute " + handler.getDemoName(), e);
fail();
}
}
}