public boolean testCase2()

in java/src/org/apache/qetest/trax/sax/SAXSourceAPITest.java [269:413]


    public boolean testCase2()
    {
        reporter.testCaseInit("Basic functionality of SAXSources");
        // Provide local copies of URLized filenames, so that we can
        //  later run tests with either Strings or URLs
        String xslURI = QetestUtils.filenameToURL(testFileInfo.inputName);
        String xmlURI = QetestUtils.filenameToURL(testFileInfo.xmlName);
        String xslImpInclURI = QetestUtils.filenameToURL(impInclFileInfo.inputName);
        String xmlImpInclURI = QetestUtils.filenameToURL(impInclFileInfo.xmlName);

        TransformerFactory factory = null;
        SAXTransformerFactory saxFactory = null;
        try
        {
            factory = TransformerFactory.newInstance();
            factory.setErrorListener(new DefaultErrorHandler());
            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
        {
            // Validate process of a stylesheet using a simple SAXSource with a URL
            reporter.logTraceMsg("Create templates/transformer from SAXSource(new InputSource(URL))");
            SAXSource xslSAXSrc = new SAXSource(new InputSource(xslURI));
            Templates templates = factory.newTemplates(xslSAXSrc);
            reporter.check((templates != null), true, "Create templates from SAXSource(new InputSource(URL))");
            
            xslSAXSrc = new SAXSource(new InputSource(xslURI));
            Transformer transformer1 = factory.newTransformer(xslSAXSrc);
            transformer1.setErrorListener(new DefaultErrorHandler());
            reporter.check((transformer1 != null), true, "Create transformer from SAXSource(new InputSource(URL))");

            Transformer transformer2 = templates.newTransformer();
            transformer2.setErrorListener(new DefaultErrorHandler());
            reporter.check((transformer2 != null), true, "Create transformer from earlier templates");

            reporter.logTraceMsg("Validate transform of SAXSource(XML) using above transformers");
            SAXSource xmlSAXSrc = new SAXSource(new InputSource(xmlURI));

            reporter.logTraceMsg("Create FileOutputStream to " + outNames.nextName());
            transformer1.transform(xmlSAXSrc, new StreamResult(outNames.currentName()));
            fileChecker.check(reporter, 
                              new File(outNames.currentName()), 
                              new File(testFileInfo.goldName), 
                              "transform of SAXSource(URL) using newTransformer transformer into: " + outNames.currentName());

            reporter.logTraceMsg("Create FileOutputStream to " + outNames.nextName());
            transformer2.transform(xmlSAXSrc, new StreamResult(outNames.currentName()));
            fileChecker.check(reporter, 
                              new File(outNames.currentName()), 
                              new File(testFileInfo.goldName), 
                              "transform of SAXSource(URL) using templates.getTransformer into: " + outNames.currentName());


            // Validate process of a stylesheet using a simple SAXSource with an InputStream
            //  Note setting systemId is not necessary with this stylesheet
            reporter.logTraceMsg("Create templates/transformer from SAXSource(...new InputStream(" + testFileInfo.inputName + ")))");
            SAXSource xslSAXSrcStream = new SAXSource(new InputSource(new FileInputStream(testFileInfo.inputName)));
            Templates templatesStream = factory.newTemplates(xslSAXSrc);
            reporter.check((templatesStream != null), true, "Create templates from SAXSource(FileInputStream())");
            Transformer transformerStream = templatesStream.newTransformer();
            transformerStream.setErrorListener(new DefaultErrorHandler());
            reporter.check((transformerStream != null), true, "Create transformer from templates");
            
            reporter.logTraceMsg("Validate transform of SAXSource(...new InputStream(" + testFileInfo.xmlName + " )) using above transformers");
            SAXSource xmlSAXSrcStream = new SAXSource(new InputSource(new FileInputStream(testFileInfo.xmlName)));

            reporter.logTraceMsg("Create FileOutputStream to " + outNames.nextName());
            transformerStream.transform(xmlSAXSrcStream, new StreamResult(outNames.currentName()));
            fileChecker.check(reporter, 
                              new File(outNames.currentName()), 
                              new File(testFileInfo.goldName), 
                              "transform of SAXSource(FileInputStreams) into: " + outNames.currentName());
            
        reporter.logTraceMsg("@todo: add more systemId tests of various types here");

        }
        catch (Throwable t)
        {
            reporter.checkFail("simple SAXSources threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "simple SAXSources threw");
        }

        try
        {
            // Validate process of a stylesheet using a simple SAXSource with imports/includes
            // Since we're providing the InputSource with a URL, we
            //  don't also need to setSystemId
            reporter.logTraceMsg("Create templates/transformer from SAXSource(new InputSource(" + xslImpInclURI + "))");
            SAXSource xslSAXSrc = new SAXSource(new InputSource(xslImpInclURI));
            Templates templates = factory.newTemplates(xslSAXSrc);
            reporter.check((templates != null), true, "Create templates from SAXSource(new InputSource(" + xslImpInclURI + "))");
            
            xslSAXSrc = new SAXSource(new InputSource(xslImpInclURI));
            Transformer transformer1 = factory.newTransformer(xslSAXSrc);
            transformer1.setErrorListener(new DefaultErrorHandler());
            reporter.check((transformer1 != null), true, "Create transformer from SAXSource(new InputSource(" + xslImpInclURI + "))");

            Transformer transformer2 = factory.newTransformer(xslSAXSrc);
            transformer2.setErrorListener(new DefaultErrorHandler());
            reporter.check((transformer2 != null), true, "Create transformer from earlier templates");

            reporter.logTraceMsg("Validate transform of SAXSource(" + xmlImpInclURI + ") using above transformers");
            SAXSource xmlSAXSrc = new SAXSource(new InputSource(xmlImpInclURI));

            reporter.logTraceMsg("Create FileOutputStream to " + outNames.nextName());
            transformer1.transform(xmlSAXSrc, new StreamResult(outNames.currentName()));
            fileChecker.check(reporter, 
                              new File(outNames.currentName()), 
                              new File(impInclFileInfo.goldName), 
                              "transform of SAXSource(impinclURLXML) using newTransformer transformer into: " + outNames.currentName());

            reporter.logTraceMsg("Create FileOutputStream to " + outNames.nextName());
            xmlSAXSrc = new SAXSource(new InputSource(xmlImpInclURI));
            xmlSAXSrc.setSystemId(xmlImpInclURI); // see if setting it affects anything
            transformer2.transform(xmlSAXSrc, new StreamResult(outNames.currentName()));
            fileChecker.check(reporter, 
                              new File(outNames.currentName()), 
                              new File(impInclFileInfo.goldName), 
                              "transform of SAXSource(impinclURLXML) using templates.getTransformer into: " + outNames.currentName());

            reporter.logTraceMsg("@todo: add systemId tests, etc. for various kinds of InputSources");

        }
        catch (Throwable t)
        {
            reporter.checkFail("impinclURL SAXSources threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "impinclURL SAXSources threw");
        }

        reporter.logTraceMsg("@todo: add SAXSource(Reader, InputSource) tests");

        reporter.logTraceMsg("@todo: add wacky tests: reuse SAXSource, use then set/get then reuse, etc.");

        reporter.logTraceMsg("@todo: test static sourceToInputSource() method");

        reporter.testCaseClose();
        return true;
    }