in java/src/org/apache/qetest/trax/SystemIdImpInclTest.java [680:796]
public boolean testCase4()
{
reporter.testCaseInit("Verify various simple Sources with http: systemIds");
// This is the name of a directory on the apache server
// that has impincl\SystemIdInclude.xsl and
// impincl\SystemIdImport.xsl files on it - obviously,
// your JVM must have access to this server to successfully
// run this portion of the test!
String httpSystemIdBase = "http://xml.apache.org/xalan-j/test";
// Verify http connectivity
// If your JVM environment can't connect to the http:
// server, then we can't complete the test
// This could happen due to various network problems,
// not being connected, firewalls, etc.
try
{
reporter.logInfoMsg("verifing http connectivity before continuing testCase");
// Note hard-coded path to one of the two files we'll be relying on
URL testURL = new URL(httpSystemIdBase + "/impincl/SystemIdInclude.xsl");
URLConnection urlConnection = testURL.openConnection();
// Ensure we don't get a cached copy
urlConnection.setUseCaches(false);
// Ensure we don't get asked interactive questions
urlConnection.setAllowUserInteraction(false);
// Actually connect to the document; will throw
// IOException if anything goes wrong
urlConnection.connect();
// Convenience: log out when the doc was last modified
reporter.logInfoMsg(testURL.toString() + " last modified: "
+ urlConnection.getLastModified());
int contentLen = urlConnection.getContentLength();
reporter.logStatusMsg("URL.getContentLength() was: " + contentLen);
if (contentLen < 1)
{
// if no content, throw 'fake' exception to
// short-circut test case
throw new IOException("URL.getContentLength() was: " + contentLen);
}
// Also verify that the file there contains (some of) the data we expect!
reporter.logTraceMsg("calling urlConnection.getContent()...");
Object content = urlConnection.getContent();
if (null == content)
{
// if no content, throw 'fake' exception to
// short-circut test case
throw new IOException("URL.getContent() was null!");
}
reporter.logTraceMsg("getContent().toString() is now: " + content.toString());
//@todo we should also verify some key strings in the
// expected .xsl file here, if possible
}
catch (IOException ioe)
{
reporter.logThrowable(Logger.ERRORMSG, ioe, "Can't connect threw");
reporter.logErrorMsg("Can't connect to: " + httpSystemIdBase
+ "/impincl/SystemIdInclude.xsl, skipping testcase");
reporter.checkPass("FAKE PASS RECORD; testCase was skipped");
// Skip the rest of the testcase
reporter.testCaseClose();
return true;
}
TransformerFactory factory = null;
Source xslSource = null;
Source xmlSource = null;
try
{
factory = TransformerFactory.newInstance();
}
catch (Throwable t)
{
reporter.checkFail("Problem creating factory; can't continue testcase");
reporter.logThrowable(reporter.ERRORMSG, t,
"Problem creating factory; can't continue testcase");
return true;
}
try
{
// Verify StreamSource from local disk with a
// http: systemId for imports/includes
xslSource = new StreamSource(new FileInputStream(testFileInfo.inputName));
xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));
// Note that the systemId set (the second argument below)
// must be the path to the proper 'directory' level
// on the webserver: setting it to just ".../test"
// will fail, since it be considered a file of that
// name, not the directory
checkSourceWithSystemId(xslSource, httpSystemIdBase + "/",
xmlSource, goldFileHttp,
"StreamSource().systemId(http:)");
xslSource = new StreamSource(new FileInputStream(testFileInfo.inputName));
xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));
checkSourceWithSystemId(xslSource, httpSystemIdBase + "/" + knownGoodBaseName + ".xsl",
xmlSource, goldFileHttp,
"StreamSource().systemId(http:)");
}
catch (Throwable t)
{
reporter.checkFail("Problem with http systemIds(1)");
reporter.logThrowable(reporter.ERRORMSG, t, "Problem with http systemIds(1)");
}
reporter.testCaseClose();
return true;
}