DissectionURLManager urlManager = new MyDissectionURLManager();
DocumentInformationImpl docInfo = new DocumentInformationImpl();
docInfo.setDocumentURL(new MarinerURL("common1.xml"));
Dissector dissector = new Dissector();
DissectedDocumentImpl dissected = (DissectedDocumentImpl)
dissector.createDissectedDocument(context, characteristics,
document, urlManager, docInfo);
// Check the characteristics of the dissected document.
NodeCounts expectedDocumentNodeCounts
= expectedDocumentStats.nodeCounts;
int dissectableAreaCount
= expectedDocumentNodeCounts.dissectableAreaCount;
assertEquals(failures,
"Incorrect number of dissectable areas,",
dissectableAreaCount,
dissected.getDissectableAreaCount());
// Check the node counts.
NodeCounts actualNodeCounts = null;
// Gather statistics by visiting all the nodes.
VisitingStatisticsGatherer visitor = new VisitingStatisticsGatherer();
document.visitDocument(visitor);
NodeCounts visitorStatistics = visitor.getStatistics().nodeCounts;
// Gather statistics by iterating over all the nodes.
IteratingStatisticsGatherer iterator = new IteratingStatisticsGatherer();
document.visitDocument(iterator);
NodeCounts iteratorStatistics = iterator.getStatistics().nodeCounts;
// Make sure that all the different methods of gathering statistics
// agree.
assertEquals("Discrepancy between statistics gatherers",
visitorStatistics, iteratorStatistics);
// Set the actualStatistics value so they can be output later.
actualNodeCounts = visitorStatistics;
// Check that the statistics match the expectation.
checkNodeCount(failures,
expectedDocumentStats.nodeCounts,
actualNodeCounts);
// Check the shared content usages.
checkSharedContentUsages(failures,
"Total Cost",
details,
expectedDocumentStats.getTotalContentUsages(),
dissected.getTotalContentUsages());
checkSharedContentUsages(failures,
"Fixed Cost",
details,
expectedDocumentStats.getFixedContentUsages(),
dissected.getFixedContentUsages());
// Check that the dissectable areas are correct.
for (int i = 0; i < dissectableAreaCount; i += 1) {
DissectableArea area = dissected.getDissectableArea(i);
DissectableAreaStats expectedDAStats
= expectedDocumentStats.getDissectableAreaStats(i);
checkDissectableArea(failures, details, context, area,
expectedDAStats);
}
OutputDocument output = createOutputDocument();
DissectedContentHandler outputHandler
= createDissectedContentHandler(output);
RequestedShards requestedShards = dissected.createRequestedShards();
dissector.serialize(context, dissected,
requestedShards, outputHandler);
int totalCost = dissected.getTotalCost();
int outputSize = output.getSize();
// Check output size is reasonable; we allow explicit output size to
// be greater than the total cost to handle WBDOM generating WML.
if (expectedDocumentStats.outputSize > 0) {
int expectedOutputSize = expectedDocumentStats.outputSize +
expectedDocumentStats.totalCostMimasAdjust;
// check that
if (outputSize != expectedOutputSize) {
failures.append("Output size (" + outputSize
+ ") is not equal to expected output size ("
+ expectedOutputSize + ")\n");
}
} else {
if (outputSize > totalCost) {
failures.append("Output size (" + outputSize
+ ") is greater than total cost ("
+ totalCost + ")\n");
}
}
// Make sure that the total cost matches what we have set.
assertEquals(failures,
"Total cost did not match,",
expectedDocumentStats.totalCost +
expectedDocumentStats.totalCostMimasAdjust,
totalCost);
// Make sure that the fixed cost matches what we have set.
int fixedCost = dissected.getFixedCost();
assertEquals(failures,
"Fixed cost did not match,",
expectedDocumentStats.fixedCost +
expectedDocumentStats.fixedCostMimasAdjust,
fixedCost);