Search in sources :

Example 1 with DOMTestCase

use of org.w3c.domts.DOMTestCase in project webservices-axiom by apache.

the class W3CDOMTestSuiteBuilder method addTests.

protected final void addTests() {
    final DOMTestDocumentBuilderFactory factory;
    try {
        factory = new DOMTestDocumentBuilderFactoryImpl(dbff, new DocumentBuilderSetting[] { DocumentBuilderSetting.notCoalescing, DocumentBuilderSetting.notExpandEntityReferences, DocumentBuilderSetting.notIgnoringElementContentWhitespace, DocumentBuilderSetting.namespaceAware, DocumentBuilderSetting.notValidating });
    } catch (DOMTestIncompatibleException ex) {
        // TODO
        throw new Error(ex);
    }
    DOMTestSuite suite;
    try {
        suite = createDOMTestSuite(factory);
    } catch (Exception ex) {
        // TODO
        throw new Error(ex);
    }
    suite.build(new DOMTestSink() {

        public void addTest(Class testClass) {
            try {
                if (!unsupportedFeatures.isEmpty()) {
                    Set<DOMFeature> usedFeatures = new HashSet<DOMFeature>();
                    DOMFeature.matchFeatures(testClass, usedFeatures);
                    ClassReader classReader = new ClassReader(testClass.getResourceAsStream(testClass.getSimpleName() + ".class"));
                    DOMTSClassVisitor cv = new DOMTSClassVisitor(usedFeatures);
                    classReader.accept(cv, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
                    usedFeatures.retainAll(unsupportedFeatures);
                    if (!usedFeatures.isEmpty()) {
                        return;
                    }
                }
                Constructor<? extends DOMTestCase> testConstructor = ((Class<?>) testClass).asSubclass(DOMTestCase.class).getConstructor(DOMTestDocumentBuilderFactory.class);
                DOMTestCase test;
                try {
                    test = testConstructor.newInstance(new Object[] { factory });
                } catch (InvocationTargetException ex) {
                    throw ex.getTargetException();
                }
                test.setFramework(JUnitTestFramework.INSTANCE);
                W3CDOMTestSuiteBuilder.this.addTest(new W3CTestCase(test));
            } catch (Throwable ex) {
                // TODO
                throw new Error(ex);
            }
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Constructor(java.lang.reflect.Constructor) DOMTestSuite(org.w3c.domts.DOMTestSuite) DOMTestIncompatibleException(org.w3c.domts.DOMTestIncompatibleException) DocumentBuilderSetting(org.w3c.domts.DocumentBuilderSetting) DOMTestDocumentBuilderFactory(org.w3c.domts.DOMTestDocumentBuilderFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) DOMTestIncompatibleException(org.w3c.domts.DOMTestIncompatibleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DOMTestCase(org.w3c.domts.DOMTestCase) DOMTestSink(org.w3c.domts.DOMTestSink) ClassReader(org.objectweb.asm.ClassReader)

Aggregations

Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ClassReader (org.objectweb.asm.ClassReader)1 DOMTestCase (org.w3c.domts.DOMTestCase)1 DOMTestDocumentBuilderFactory (org.w3c.domts.DOMTestDocumentBuilderFactory)1 DOMTestIncompatibleException (org.w3c.domts.DOMTestIncompatibleException)1 DOMTestSink (org.w3c.domts.DOMTestSink)1 DOMTestSuite (org.w3c.domts.DOMTestSuite)1 DocumentBuilderSetting (org.w3c.domts.DocumentBuilderSetting)1