FileDocCategorySizeDatePackage
SchematronTest.javaAPI DocGlassfish v2 API11160Fri May 04 22:24:40 BST 2007com.sun.enterprise.config.serverbeans.validation

SchematronTest

public class SchematronTest extends TestCase
author
Toby H Ferguson
version
$Revision: 1.4 $

Fields Summary
Constructors Summary
public SchematronTest(String name)

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        if (args.length == 0){
            TestRunner.run(SchematronTest.class);
        } else {
            TestRunner.run(makeSuite(args));
        }
    
private static junit.framework.TestSuitemakeSuite(java.lang.String[] args)

        final TestSuite ts = new TestSuite();
        for (int i = 0; i < args.length; i++){
            ts.addTest(new SchematronTest(args[i]));
        }
        return ts;
    
private voidnyi()

        fail("Not Yet Implemented");
    
protected voidsetUp()

    
protected voidtearDown()

    
public voidtestComment()

        Schematron s = new Schematron("/schema2.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        String input = "<?xml version='1.0'?><!-- comment --><root id=\"${var}\"><system-property name=\"var\" value=\"value\"/></root>";
        SAXSource src = new SAXSource(new VariableResolver(),
                                      new InputSource(new StringReader(input)));
        s.analyze(src, r);
        assertEquals("This is the id: value", ""+actual);
    
public voidtestExternal()

        Schematron s = new Schematron("/schema2.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        SAXSource src = new SAXSource(new VariableResolver(),
                                      new InputSource("schema2.xml"));
        
        s.analyze(src, r);
        assertEquals("This is the id: value", ""+actual);
    
public voidtestExternalWithEntityResolver()

        Schematron s = new Schematron("/schema2.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        VariableResolver vr = new VariableResolver();
        vr.setEntityResolver(new MyEntityResolver("/schema2.dtd"));
        SAXSource src = new SAXSource(vr,
                                      new InputSource("schema2.xml"));
        
        s.analyze(src, r);
        assertEquals("This is the id: value", ""+actual);
    
public voidtestPipeline()

        Schematron s = new Schematron("/schema2.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        String input = "<?xml version='1.0'?><root id=\"${var}\"><system-property name=\"var\" value=\"value\"/></root>";
        SAXSource src = new SAXSource(new VariableResolver(),
                                      new InputSource(new StringReader(input)));
        s.analyze(src, r);
        assertEquals("This is the id: value", ""+actual);
    
public voidtestSchematron()

        Schematron s = new Schematron("/schema.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        s.analyze(new SAXSource(new InputSource(new StringReader("<top><root id ='foo'/></top>"))), r);
        assertEquals("This is the result", ""+actual);
    
public voidtestSimpleTransform()

        Schematron s = new Schematron("/simple.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        VariableResolver vr = new VariableResolver();
        vr.setEntityResolver(new MyEntityResolver("/sun-domain_1_1.dtd"));
        SAXSource src = new SAXSource(vr,
                                      new InputSource("domain.xml"));
        s.analyze(src, r);
    
public voidtestWithEntityResolver()

        Schematron s = new Schematron("/schema2.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        String input = "<?xml version='1.0'?><!DOCTYPE domain PUBLIC '-//Sun Microsystems Inc.//DTD Application Server 8.0 Domain//EN' 'http://www.sun.com/software/appserver/dtds/sun-domain_1_1.dtd'><root id=\"${var}\"><system-property name=\"var\" value=\"value\"/></root>";
        VariableResolver vr = new VariableResolver();
        vr.setEntityResolver(new MyEntityResolver("/schema2.dtd"));
        SAXSource src = new SAXSource(vr,
                                      new InputSource(new StringReader(input)));
        
        s.analyze(src, r);
        assertEquals("This is the id: value", ""+actual);
    
public voidtestWithEntityResolverError()

        Schematron s = new Schematron("/schema2.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        String input = "<?xml version='1.0'?><!DOCTYPE root PUBLIC 'DO NOT MATCH' 'http://www.google.com'><root id=\"${var}\"><system-property name=\"var\" value=\"value\"/></root>";
        VariableResolver vr = new VariableResolver();
        vr.setEntityResolver(new MyEntityResolver("/schema2.dtd"));
        SAXSource src = new SAXSource(vr,
                                      new InputSource(new StringReader(input)));
        try {
            s.analyze(src, r);
            fail("Expected a Transformer Exception");
        }
        catch (TransformerException te){
            assertEquals("javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: External parameter entity \"%[dtd];\" has characters after markup.", te.getMessage());
        }

    
public voidtestWithSAXSourceNoVR()

        Schematron s = new Schematron("/domain.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        SAXSource src = new SAXSource(new InputSource("domain.xml.no.dtd"));
        s.analyze(src, r);
        assertEquals(1540, actual.toString().length());
    
public voidtestWithSAXSourceWithVRAndER()

        Schematron s = new Schematron("/domain.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        VariableResolver vr = new VariableResolver();
        vr.setEntityResolver(new MyEntityResolver("/sun-domain_1_1.dtd"));
        SAXSource src = new SAXSource(vr,
                                      new InputSource("domain.xml.no.dtd"));
        s.analyze(src, r);
        assertEquals(1540, actual.toString().length());

    
public voidtestWithSAXSourceWithVRNoER()

        Schematron s = new Schematron("/domain.xsl");
        StringWriter actual = new StringWriter();
        Result r = new StreamResult(actual);
        VariableResolver vr = new VariableResolver();
        SAXSource src = new SAXSource(vr,
                                      new InputSource(new FileReader("domain.xml.no.dtd")));
        s.analyze(src, r);
        assertEquals(1540, actual.toString().length());