}
public void manyDelegatesCommon() throws Exception {
// Test that an aggregate can be copied preserving all comments and ordering of delegates
XMLParser.ParsingOptions parsingOptions = new XMLParser.ParsingOptions(false);
parsingOptions.preserveComments = true;
XMLParser parser = UIMAFramework.getXMLParser();
File inFile = JUnitExtension.getFile("TextAnalysisEngineImplTest/AggregateWithManyDelegates.xml");
AnalysisEngineDescription desc = parser.parseAnalysisEngineDescription(new XMLInputSource(inFile), parsingOptions);
// Write out descriptor
File cloneFile = new File(inFile.getParentFile(), "CopyOfAggregateWithManyDelegates.xml");
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(cloneFile));
XMLSerializer xmlSerializer = new XMLSerializer(true);
xmlSerializer.setOutputStream(os);
// set the amount to a value which will show up if used
// indent should not be used because we're using a parser mode which preserves
// comments and ignorable white space.
xmlSerializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
ContentHandler contentHandler = xmlSerializer.getContentHandler();
contentHandler.startDocument();
desc.toXML(contentHandler, true);
contentHandler.endDocument();
os.close();
long diff = cloneFile.length() - inFile.length();
// One platform inserts a blank line and a final newline, so don't insist on perfection
assertTrue("File size changed by "+diff+" should be no more than 2", diff >= -2 && diff <= 2);
// Initialize all delegates and check the initialization order (should be declaration order)
TestAnnotator2.allContexts = "";
UIMAFramework.produceAnalysisEngine(desc);
assertEquals("D/C/B/A/F/E/", TestAnnotator2.allContexts);
// Check that copying aggregate preserved the order of the delegates
desc = parser.parseAnalysisEngineDescription(new XMLInputSource(cloneFile), parsingOptions);
TestAnnotator2.allContexts = "";
UIMAFramework.produceAnalysisEngine(desc);
assertEquals("D/C/B/A/F/E/", TestAnnotator2.allContexts);
// cloneFile.delete();
}