public boolean testCase7()

in java/src/org/apache/qetest/trax/TransformerFactoryAPITest.java [559:681]


    public boolean testCase7()
    {
        reporter.testCaseInit("Coverage tests for set/getFeature, set/getAttribute API's");
        // This test case should be JAXP-generic, and must not rely on Xalan-J 2.x functionality
        reporter.logInfoMsg("Note: only simple validation: most are negative tests");
        TransformerFactory factory = null;
        final String BOGUS_NAME = "fnord:this/feature/does/not/exist";

        try
        {
            factory = TransformerFactory.newInstance();
            try
            {
                reporter.logStatusMsg("Calling: factory.getFeature(BOGUS_NAME)");
                boolean b = factory.getFeature(BOGUS_NAME);
                reporter.checkPass("factory.getFeature(BOGUS_NAME) did not throw exception");
                reporter.logStatusMsg("factory.getFeature(BOGUS_NAME) = " + b);
            }
            catch (IllegalArgumentException iae1)
            {
                // This isn't documented, but is what I might expect
                reporter.checkPass("factory.getFeature(BOGUS_NAME) threw expected IllegalArgumentException");
            }

            try
            {
                reporter.logStatusMsg("Calling: factory.setAttribute(BOGUS_NAME,...)");
                factory.setAttribute(BOGUS_NAME, "on");
                reporter.checkFail("factory.setAttribute(BOGUS_NAME,...) did not throw expected exception");
            }
            catch (IllegalArgumentException iae2)
            {
                reporter.checkPass("factory.setAttribute(BOGUS_NAME,...) threw expected IllegalArgumentException");
            }

            try
            {
                reporter.logStatusMsg("Calling: factory.getAttribute(BOGUS_NAME)");
                Object o = factory.getAttribute(BOGUS_NAME);
                reporter.checkFail("factory.getAttribute(BOGUS_NAME) did not throw expected exception");
                reporter.logStatusMsg("factory.getAttribute(BOGUS_NAME) = " + o);
            }
            catch (IllegalArgumentException iae3)
            {
                reporter.checkPass("factory.getAttribute(BOGUS_NAME) threw expected IllegalArgumentException");
            }
        }
        catch (Throwable t)
        {
            reporter.checkFail("getFeature/Attribute() tests threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "getFeature/Attribute() tests threw");
        }

        try
        {
            reporter.logWarningMsg("Note testing assumption: all factories must support Streams");
            factory = TransformerFactory.newInstance();
            reporter.logStatusMsg("Calling: factory.getFeature(StreamSource.FEATURE)");
            boolean b = factory.getFeature(StreamSource.FEATURE);
            reporter.check(b, true, "factory.getFeature(StreamSource.FEATURE)");

            reporter.logStatusMsg("Calling: factory.getFeature(StreamResult.FEATURE)");
            b = factory.getFeature(StreamResult.FEATURE);
            reporter.check(b, true, "factory.getFeature(StreamResult.FEATURE)");
        }
        catch (Throwable t)
        {
            reporter.checkFail("getFeature/Attribute()2 tests threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "getFeature/Attribute()2 tests threw");
        }

        try
        {
            reporter.logStatusMsg("Calling: factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING)");
            factory = TransformerFactory.newInstance();
            try
            {
                // All implementations are required to support the XMLConstants.FEATURE_SECURE_PROCESSING feature
                factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
                boolean b = factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
                reporter.check(b, true, "factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)");
                factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
                b = factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
                reporter.check(b, false, "factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)");
                
            }
            catch (TransformerConfigurationException tce)
            {
                reporter.checkFail("set/getFeature(XMLConstants.FEATURE_SECURE_PROCESSING) tests threw: " + tce.toString());
                reporter.logThrowable(reporter.ERRORMSG, tce, "set/getFeature(XMLConstants.FEATURE_SECURE_PROCESSING) tests threw");
            }
            
            try
            {
                factory.setFeature(BOGUS_NAME, true);
                reporter.checkFail("factory.setFeature(BOGUS_NAME) did not throw expected exception");
                
            }
            catch (TransformerConfigurationException tce)
            {
                reporter.checkPass("factory.setFeature(BOGUS_NAME) threw expected TransformerConfigurationException");
            }
            
            try
            {
                factory.setFeature(null, true);
                reporter.checkFail("factory.setFeature(null, true) did not throw expected exception");
            }
            catch (NullPointerException npe)
	    {
	        reporter.checkPass("factory.setFeature(null, true) threw expected NullPointerException");
            }
                
        }
        catch (Throwable t)
        {
            reporter.checkFail("set/getFeature() tests threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "set/getFeature() tests threw");
        }

        reporter.testCaseClose();
        return true;
    }