Methods Summary |
---|
public static void | main(java.lang.String[] args)
if (args.length == 0){
junit.textui.TestRunner.run(RNGValidatorTest.class);
} else {
junit.textui.TestRunner.run(makeSuite(args));
}
|
private static junit.framework.TestSuite | makeSuite(java.lang.String[] args)
final TestSuite ts = new TestSuite();
for (int i = 0; i < args.length; i++){
ts.addTest(new RNGValidatorTest(args[i]));
}
return ts;
|
private void | nyi()
fail("Not Yet Implemented");
|
protected void | setUp()
|
protected void | tearDown()
|
public void | testBasic()
RNGValidator r = new RNGValidator();
final String schema =""+
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"+
"<grammar xmlns='http://relaxng.org/ns/structure/1.0'>"+
"<define name='top'>"+
"<element name='top'>"+
"<empty/>"+
"</element>"+
"</define>"+
"<start>"+
"<ref name='top'/>"+
"</start>"+
"</grammar>";
final String source ="<?xml version='1.0'?> <top></top>";
StringWriter out = new StringWriter();
r.validate(new InputSource(new StringReader(schema)),
new InputSource(new StringReader(source)),
out);
assertEquals("", ""+out);
|
public void | testBasicError()
RNGValidator r = new RNGValidator();
final String schema =""+
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"+
"<grammar xmlns='http://relaxng.org/ns/structure/1.0'>"+
"<define name='top'>"+
"<element name='top'>"+
"<empty/>"+
"</element>"+
"</define>"+
"<start>"+
"<ref name='top'/>"+
"</start>"+
"</grammar>";
final String source ="<?xml version='1.0'?> <top><bottom/></top>";
StringWriter out = new StringWriter();
r.validate(new InputSource(new StringReader(schema)),
new InputSource(new StringReader(source)),
out);
assertEquals("Error: URI=null Line=1: element \"bottom\" was found where no element may occur\n", ""+out);
|
public void | testBasicWithSubstitution()
RNGValidator r = new RNGValidator();
final String schema =""+
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"+
"<grammar xmlns='http://relaxng.org/ns/structure/1.0'>"+
"<define name='top'>"+
"<element name='top'>"+
"<ref name='system-property'/>"+
"<attribute name='id'>"+
"<value>VALUE</value>"+
"</attribute>"+
"</element>"+
"</define>"+
"<define name='system-property'>"+
"<element name='system-property'>"+
"<empty/>"+
"<attribute name='name'/>"+
"<attribute name='value'/>"+
"</element>"+
"</define>"+
"<start>"+
"<ref name='top'/>"+
"</start>"+
"</grammar>";
final String source ="<?xml version='1.0'?> <top id='${var}'><system-property name='var' value='VALUE'/></top>";
StringWriter out = new StringWriter();
VariableResolver vr = new VariableResolver();
r.validate(new InputSource(new StringReader(schema)),
new InputSource(new StringReader(source)),
vr,
out);
assertEquals("", ""+out);
|
public void | testBasicWithSubstitutionError()
RNGValidator r = new RNGValidator();
final String schema =""+
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"+
"<grammar xmlns='http://relaxng.org/ns/structure/1.0'>"+
"<define name='top'>"+
"<element name='top'>"+
"<ref name='system-property'/>"+
"<attribute name='id'>"+
"<value>VALUE</value>"+
"</attribute>"+
"</element>"+
"</define>"+
"<define name='system-property'>"+
"<element name='system-property'>"+
"<empty/>"+
"<attribute name='name'/>"+
"<attribute name='value'/>"+
"</element>"+
"</define>"+
"<start>"+
"<ref name='top'/>"+
"</start>"+
"</grammar>";
final String source ="<?xml version='1.0'?> <top id='${var}'><system-property name='var' value='Not Expected Value'/></top>";
StringWriter out = new StringWriter();
VariableResolver vr = new VariableResolver();
r.validate(new InputSource(new StringReader(schema)),
new InputSource(new StringReader(source)),
vr,
out);
assertEquals("Error: URI=null Line=1: attribute \"id\" has a bad value\n", ""+out);
|
public void | testEntityResolver()
RNGValidator r = new RNGValidator();
final String schema =""+
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"+
"<grammar xmlns='http://relaxng.org/ns/structure/1.0'>"+
"<define name='top'>"+
"<element name='top'>"+
"<empty/>"+
"</element>"+
"</define>"+
"<start>"+
"<ref name='top'/>"+
"</start>"+
"</grammar>";
final String dtd = ""+
"<?xml version='1.0' encoding='UTF-8'?>"+
"<!ELEMENT top (bottom)>"+
"<!ELEMENT bottom EMPTY>";
final String source ="<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE top PUBLIC '-//Sun Microsystems Inc.//DTD Application Server 8.0 Domain//EN' 'http://www.sun.com/software/appserver/dtds/sun-domain_1_1.dtd'><top/>";
VariableResolver vr = new VariableResolver();
StringWriter out = new StringWriter();
vr.setEntityResolver(new MyEntityResolver(dtd));
r.validate(new InputSource(new StringReader(schema)),
new InputSource(new StringReader(source)),
vr,
out);
assertEquals("", out+"");
|
public void | testEntityResolverWithError()
RNGValidator r = new RNGValidator();
final String schema =""+
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"+
"<grammar xmlns='http://relaxng.org/ns/structure/1.0'>"+
"<define name='top'>"+
"<element name='top'>"+
"<empty/>"+
"</element>"+
"</define>"+
"<start>"+
"<ref name='top'/>"+
"</start>"+
"</grammar>";
final String source ="<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE top PUBLIC '-//Sun Microsystems Inc.//DTD Application Server 8.0 Domain//EN' 'http://www.sun.com/software/appserver/dtds/sun-domain_1_1.dtd'><top/>";
VariableResolver vr = new VariableResolver();
StringWriter out = new StringWriter();
vr.setEntityResolver(new MyEntityResolver());
try {
r.validate(new InputSource(new StringReader(schema)),
new InputSource(new StringReader(source)),
vr,
out);
fail("Expected a SAX Exception indicating problems with the external entity");
}
catch (SAXParseException spe){
assertEquals("External parameter entity \"%[dtd];\" has characters after markup.", spe.getMessage());
}
|
public void | testacceptanceTest()
final RNGValidator r = new RNGValidator();
final VariableResolver vr = new VariableResolver();
vr.setEntityResolver(new MyEntityResolver(new File ("sun-domain_1_1.dtd")));
final InputStream schema = this.getClass().getResourceAsStream("/domain.rng");
if (null ==schema ){
throw new IOException("couldn't get resource: /domain.rng");
}
StringWriter out = new StringWriter();
r.validate(new InputSource(schema),
new InputSource("domain.xml"),
vr,
out);
assertEquals("Error: URI=file:/opt/S1AS8/NewBuild/admin/validator/tests/com/sun/enterprise/config/serverbeans/validation/domain.xml Line=11: attribute \"load-order\" has a bad value: \"ABC\" does not satisfy the \"positiveInteger\" type\n", ""+out);
|
public void | testacceptanceTestNoEntityFile()
final RNGValidator r = new RNGValidator();
final VariableResolver vr = new VariableResolver();
vr.setEntityResolver(new MyEntityResolver());
final InputStream schema = this.getClass().getResourceAsStream("/domain.rng");
if (null ==schema ){
throw new IOException("couldn't get resource: /domain.rng");
}
StringWriter out = new StringWriter();
try {
r.validate(new InputSource(schema),
new InputSource("domain.xml"),
vr,
out);
fail("Expected Error indicating no file");
}
catch (SAXParseException spe){
assertEquals("External entity not found: \"http://www.sun.com/software/appserver/dtds/sun-domain_1_1.dtd\".", spe.getMessage());
}
|
public void | testacceptanceTestNoInputFile()
final RNGValidator r = new RNGValidator();
final VariableResolver vr = new VariableResolver();
vr.setEntityResolver(new MyEntityResolver(new File ("sun-domain_1_1.dtd")));
final InputStream schema = this.getClass().getResourceAsStream("/domain.rng");
if (null ==schema ){
throw new IOException("couldn't get resource: /domain.rng");
}
StringWriter out = new StringWriter();
try {
r.validate(new InputSource(schema),
new InputSource("domain.xml.notHere"),
vr,
out);
fail("Expected Error indicating no file");
}
catch (IOException ioe){
assertEquals("/opt/S1AS8/NewBuild/admin/validator/tests/com/sun/enterprise/config/serverbeans/validation/domain.xml.notHere (No such file or directory)", ioe.getMessage());
}
|