public boolean testCase2()

in java/src/org/apache/qetest/trax/SystemIdImpInclTest.java [355:570]


    public boolean testCase2()
    {
        reporter.testCaseInit("Verify simple SAXSources with systemIds");

        TransformerFactory factory = null;
        SAXTransformerFactory saxFactory = null;
        InputSource xslInpSrc = null;
        Source xslSource = null;
        Source xmlSource = null;
        try
        {
            factory = TransformerFactory.newInstance();
            saxFactory = (SAXTransformerFactory)factory;
        }
        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 basic transforms with with various systemId
            //  and a SAXSource(InputSource(String))
            // level0: one level up
/********************************
// SAXSource(impSrc(str)) level0, level2
// Note: these cases may not be valid to test, since the setSystemId
//  call will effectively overwrite the underlying InputSource's 
//  real systemId, and thus the stylesheet can't be built
//  Answer: write a custom test case that parses the stylesheet
//  and builds it, but doesn't get imports/includes until later 
//  when we have setSystemId
            xslInpSrc = new InputSource(new InputStreamReader(new FileInputStream(testFileInfo.inputName), "UTF-8")); //@DEM
//            xslInpSrc = new InputSource(new FileReader(testFileInfo.inputName));  @DEM
            xslSource = new SAXSource(xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(inputDir + File.separator + knownGoodBaseName + ".xsl"), 
                                    xmlSource, goldFileLevel0,
                                    "SAXSource(inpSrc(str)).systemId(level0: one up)");
********************************/
            // level1: same systemId as actual file
			// @DEM changes are to allow test to run on various 
			//	platforms regardeless of encodings; force it to 
			//	be UTF-8 since that's what's checked in
            xslInpSrc = new InputSource(new InputStreamReader(new FileInputStream(testFileInfo.inputName), "UTF-8")); //@DEM
//            xslInpSrc = new InputSource(new FileReader(testFileInfo.inputName));  @DEM
            xslSource = new SAXSource(xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(testFileInfo.inputName), 
                                    xmlSource, goldFileLevel1,
                                    "SAXSource(inpSrc(str)).systemId(level1: same level)");

            // level2: one level down
/********************************
// SAXSource(impSrc(str)) level0, level2
// Note: these cases may not be valid to test, since the setSystemId
//  call will effectively overwrite the underlying InputSource's 
//  real systemId, and thus the stylesheet can't be built
//  Answer: write a custom test case that parses the stylesheet
//  and builds it, but doesn't get imports/includes until later 
//  when we have setSystemId
            xslInpSrc = new InputSource(new InputStreamReader(new FileInputStream(testFileInfo.inputName), "UTF-8")); //@DEM
//            xslInpSrc = new InputSource(new FileReader(testFileInfo.inputName));  @DEM
            xslSource = new SAXSource(xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(inputDir + "/trax/systemid/" + knownGoodBaseName + ".xsl"), 
                                    xmlSource, goldFileLevel2,
                                    "SAXSource(inpSrc(str)).systemId(level2: one down)");
********************************/
            reporter.logTraceMsg("@todo: add test for SAXSource with reset systemId (see code comments)");
        }
        catch (Throwable t)
        {
            reporter.checkFail("Problem with SAXSources(1)");
            reporter.logThrowable(reporter.ERRORMSG, t, "Problem with SAXSources(1)");
        }
        try
        {
            // Verify basic transforms with with various systemId
            //  and a SAXSource(InputSource(InputStream))
            // level0: one level up
            xslInpSrc = new InputSource(new FileInputStream(testFileInfo.inputName));
            xslSource = new SAXSource(xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(inputDir + File.separator + knownGoodBaseName + ".xsl"), 
                                    xmlSource, goldFileLevel0,
                                    "SAXSource(inpSrc(byteS)).systemId(level0: one up)");

            // level1: same systemId as actual file
            xslInpSrc = new InputSource(new FileInputStream(testFileInfo.inputName));
            xslSource = new SAXSource(xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(testFileInfo.inputName), 
                                    xmlSource, goldFileLevel1,
                                    "SAXSource(inpSrc(byteS)).systemId(level1: same level)");

            // level2: one level down
            xslInpSrc = new InputSource(new FileInputStream(testFileInfo.inputName));
            xslSource = new SAXSource(xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(inputDir + "/trax/systemid/" + knownGoodBaseName + ".xsl"), 
                                    xmlSource, goldFileLevel2,
                                    "SAXSource(inpSrc(byteS)).systemId(level2: one down)");

            // Verify basic transforms with with various systemId
            //  and a SAXSource(InputSource(Reader))
            // level0: one level up
            xslInpSrc = new InputSource(new InputStreamReader(new FileInputStream(testFileInfo.inputName), "UTF-8")); //@DEM
//            xslInpSrc = new InputSource(new FileReader(testFileInfo.inputName));  @DEM
            xslSource = new SAXSource(xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(inputDir + File.separator + knownGoodBaseName + ".xsl"), 
                                    xmlSource, goldFileLevel0,
                                    "SAXSource(inpSrc(charS)).systemId(level0: one up)");

            // level1: same systemId as actual file
            xslInpSrc = new InputSource(new InputStreamReader(new FileInputStream(testFileInfo.inputName), "UTF-8")); //@DEM
//            xslInpSrc = new InputSource(new FileReader(testFileInfo.inputName));  @DEM
            xslSource = new SAXSource(xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(testFileInfo.inputName), 
                                    xmlSource, goldFileLevel1,
                                    "SAXSource(inpSrc(charS)).systemId(level1: same level)");

            // level2: one level down
            xslInpSrc = new InputSource(new InputStreamReader(new FileInputStream(testFileInfo.inputName), "UTF-8")); //@DEM
//            xslInpSrc = new InputSource(new FileReader(testFileInfo.inputName));  @DEM
            xslSource = new SAXSource(xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(inputDir + "/trax/systemid/" + knownGoodBaseName + ".xsl"), 
                                    xmlSource, goldFileLevel2,
                                    "SAXSource(inpSrc(charS)).systemId(level2: one down)");

            // Verify basic transforms with with various systemId
            //  and a SAXSource(XMLReader, InputSource(various))
            // Be sure to use the JAXP methods only!
            SAXParserFactory spfactory = SAXParserFactory.newInstance();
            spfactory.setNamespaceAware(true);
            SAXParser saxParser = spfactory.newSAXParser();
    	    XMLReader reader = saxParser.getXMLReader();
            // level0: one level up, with a character stream
            xslInpSrc = new InputSource(new InputStreamReader(new FileInputStream(testFileInfo.inputName), "UTF-8")); //@DEM
//            xslInpSrc = new InputSource(new FileReader(testFileInfo.inputName));  @DEM
            xslSource = new SAXSource(reader, xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(inputDir + File.separator + knownGoodBaseName + ".xsl"), 
                                    xmlSource, goldFileLevel0,
                                    "SAXSource(reader, inpSrc(charS)).systemId(level0: one up)");

            // level1: same systemId as actual file, with a systemId
            saxParser = spfactory.newSAXParser();
    	    reader = saxParser.getXMLReader();
            xslInpSrc = new InputSource(testFileInfo.inputName);
            xslSource = new SAXSource(reader, xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(testFileInfo.inputName), 
                                    xmlSource, goldFileLevel1,
                                    "SAXSource(reader, inpSrc(str)).systemId(level1: same level)");

            // level2: one level down, with a byte stream
            saxParser = spfactory.newSAXParser();
    	    reader = saxParser.getXMLReader();
            xslInpSrc = new InputSource(new FileInputStream(testFileInfo.inputName));
            xslSource = new SAXSource(reader, xslInpSrc);

            xmlSource = new StreamSource(new FileInputStream(testFileInfo.xmlName));
            xmlSource.setSystemId(QetestUtils.filenameToURL(testFileInfo.xmlName));

            checkSourceWithSystemId(xslSource, QetestUtils.filenameToURL(inputDir + "/trax/systemid/" + knownGoodBaseName + ".xsl"), 
                                    xmlSource, goldFileLevel2,
                                    "SAXSource(reader, inpSrc(byteS)).systemId(level2: one down)");
        }
        catch (Throwable t)
        {
            reporter.checkFail("Problem with SAXSources(2)");
            reporter.logThrowable(reporter.ERRORMSG, t, "Problem with SAXSources(2)");
        }

        reporter.testCaseClose();
        return true;
    }