in java/src/org/apache/qetest/trax/dom/DOMSourceAPITest.java [198:368]
public boolean testCase2()
{
reporter.testCaseInit("Basic functionality of DOMSources");
TransformerFactory factory = null;
Templates templates = null;
Transformer transformerXSL = null;
DocumentBuilder docBuilder = null;
Node xmlNode = null;
Node xslNode = null;
Node xslImpInclNode = null;
Node xmlImpInclNode = null;
try
{
// Startup a factory, create some nodes/DOMs
factory = TransformerFactory.newInstance();
factory.setErrorListener(new DefaultErrorHandler());
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(true);
docBuilder = dfactory.newDocumentBuilder();
reporter.logTraceMsg("parsing xml, xsl files");
xslNode = docBuilder.parse(new InputSource(testFileInfo.inputName));
xmlNode = docBuilder.parse(new InputSource(testFileInfo.xmlName));
xslImpInclNode = docBuilder.parse(new InputSource(impInclFileInfo.inputName));
xmlImpInclNode = docBuilder.parse(new InputSource(impInclFileInfo.xmlName));
}
catch (Throwable t)
{
reporter.checkErr("Problem with factory; testcase may not work");
reporter.logThrowable(reporter.ERRORMSG, t, "Problem with factory; testcase may not work");
}
try
{
// A blank DOM as an input stylesheet - what should happen?
DOMSource blankXSLDOM = new DOMSource();
reporter.logTraceMsg("About to newTemplates(blankXSLDOM)");
Templates blankTemplates = factory.newTemplates(blankXSLDOM); // SPR SCUU4R5JYZ throws npe; 0b29CVS now returns null
// Note: functionality (and hopefully Javadoc too) have
// been updated to make it illegal to use a DOMSource
// with a null node as the XSL document -sc 18-Dec-00
reporter.checkFail("blankXSLDOM should throw exception per Resolved bug", "SCUU4R5JYZ");
}
catch (Throwable t)
{
reporter.checkPass("blankXSLDOM should throw exception per Resolved bug", "SCUU4R5JYZ");
reporter.logThrowable(reporter.ERRORMSG, t, "blankXSLDOM(1) should throw exception");
}
try
{
// A blank DOM as an input stylesheet - what should happen?
DOMSource blankXSLDOM = new DOMSource();
reporter.logTraceMsg("About to newTransformer(blankXSLDOM)");
Transformer blankTransformer = factory.newTransformer(blankXSLDOM); // SPR SCUU4R5JYZ throws npe
reporter.checkFail("blankXSLDOM should throw exception per Resolved bug", "SCUU4R5JYZ");
}
catch (Throwable t)
{
reporter.checkPass("blankXSLDOM should throw exception per Resolved bug", "SCUU4R5JYZ");
reporter.logThrowable(reporter.ERRORMSG, t, "blankXSLDOM(2) should throw exception");
}
try
{
// Try to get templates, transformerXSL from node
DOMSource xslDOM = new DOMSource(xslNode);
templates = factory.newTemplates(xslDOM);
reporter.check((templates != null), true, "factory.newTemplates(DOMSource) is non-null");
transformerXSL = factory.newTransformer(xslDOM);
transformerXSL.setErrorListener(new DefaultErrorHandler());
reporter.check((transformerXSL != null), true, "factory.newTransformer(DOMSource) is non-null");
// A simple DOM-DOM-DOM transform
DOMSource xmlDOM = new DOMSource(xmlNode);
Node outNode = docBuilder.newDocument();
DOMResult outDOM = new DOMResult(outNode);
transformerXSL.transform(xmlDOM, outDOM);
Node gotNode = outDOM.getNode();
reporter.check((gotNode != null), true, "transform(xmlDOM, outDOM) has non-null outNode");
serializeDOMAndCheck(gotNode, testFileInfo.goldName, "transform(xmlDOM, outDOM)");
reporter.logTraceMsg("@todo validate the dom in memory as well");
// A blank DOM as source doc of the transform - should
// create an empty source Document using
// DocumentBuilder.newDocument().
DOMSource blankSource = new DOMSource();
Node emptyNode = docBuilder.newDocument();
DOMResult emptyNodeDOM = new DOMResult(emptyNode);
reporter.logTraceMsg("About to transform(blankSource, emptyNodeDOM)");
transformerXSL.transform(blankSource, emptyNodeDOM);
reporter.check(emptyNodeDOM.getNode().toString(),"[#document: null]","transform(blankDOM, result) should create an empty document");
}
catch (Throwable t)
{
reporter.checkPass("transform(blankDOM, result) should throw exception", "SCUU4R5KLL");
reporter.logThrowable(reporter.ERRORMSG, t, "transform(blankDOM, result) should throw exception");
}
try
{
// A blank DOM as an output of the transform - should
// auto-create a source Document
DOMSource xmlDOM = new DOMSource(xmlNode);
Node outNode = docBuilder.newDocument();
DOMResult outResult = new DOMResult(outNode);
reporter.logTraceMsg("About to transform(xmlDOM, emptyResult)");
transformerXSL.transform(xmlDOM, outResult);
outNode = outResult.getNode();
reporter.check((outNode != null), true, "transform(xmlDOM, outResult) has non-null node");
serializeDOMAndCheck(outNode, testFileInfo.goldName, "transform(xmlDOM, outResult)");
}
catch (Throwable t)
{
reporter.checkFail("Problem with transform(doms 2)");
reporter.logThrowable(reporter.ERRORMSG, t, "Problem with transform(doms 2)");
}
try
{
// Setting SystemId with imports/inclues
DOMSource xslDOM = new DOMSource(xslImpInclNode);
// Note that inputName, xmlName are already URL'd
xslDOM.setSystemId(impInclFileInfo.inputName);
transformerXSL = factory.newTransformer(xslDOM);
transformerXSL.setErrorListener(new DefaultErrorHandler());
DOMSource xmlDOM = new DOMSource(xmlImpInclNode);
// Do we really need to set SystemId on both XML and XSL?
xmlDOM.setSystemId(impInclFileInfo.xmlName);
DOMResult emptyResult = new DOMResult();
reporter.logTraceMsg("About to transformXSLImpIncl(xmlDOM, emptyResult)");
transformerXSL.transform(xmlDOM, emptyResult);
Node outNode = emptyResult.getNode();
reporter.check((outNode != null), true, "transformXSLImpIncl(xmlDOM, emptyResult) has non-null node");
serializeDOMAndCheck(outNode, impInclFileInfo.goldName, "transformXSLImpIncl(xmlDOM, emptyResult)");
}
catch (Throwable t)
{
reporter.checkFail("Problem with SystemId");
reporter.logThrowable(reporter.ERRORMSG, t, "Problem with SystemId");
}
try
{
// Do a transform without systemId set
// Note: is affected by user.dir property; if we're
// already in the correct place, this won't be different
// But: most people will run from xml-xalan\test, so this should fail
try
{
reporter.logStatusMsg("System.getProperty(user.dir) = " + System.getProperty("user.dir"));
}
catch (SecurityException e) // in case of Applet context
{
reporter.logTraceMsg("System.getProperty(user.dir) threw SecurityException");
}
DOMSource xslDOM = new DOMSource(xslImpInclNode);
transformerXSL = factory.newTransformer(xslDOM);
transformerXSL.setErrorListener(new DefaultErrorHandler());
DOMSource xmlDOM = new DOMSource(xmlImpInclNode);
DOMResult emptyResult = new DOMResult();
reporter.logStatusMsg("About to transform without systemID; probably throws exception");
transformerXSL.transform(xmlDOM, emptyResult);
reporter.checkFail("The above transform should probably have thrown an exception");
}
catch (Throwable t)
{
reporter.checkPass("Transforming with include/import and wrong SystemId throws exception");
reporter.logThrowable(reporter.ERRORMSG, t, "Transforming with include/import and wrong SystemId");
}
reporter.testCaseClose();
return true;
}