Methods Summary |
---|
private org.xml.sax.ContentHandler | getContentHandler(java.io.StringWriter w)
ToXMLStream xml = new ToXMLStream();
xml.setWriter(w);
xml.setOmitXMLDeclaration(true);
return xml.asContentHandler();
|
private org.xml.sax.InputSource | getInputSource(java.lang.String s)
return new InputSource(new StringReader(s));
|
private org.xml.sax.XMLReader | getXMLReader()
final XMLReader xr = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
xr.setFeature("http://xml.org/sax/features/namespaces", true);
xr.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
return xr;
|
public static void | main(java.lang.String[] args)
if (args.length == 0){
junit.textui.TestRunner.run(VariableResolverTest.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 VariableResolverTest(args[i]));
}
return ts;
|
private void | nyi()
fail("Not Yet Implemented");
|
protected void | setUp()
vr = new VariableResolver();
vr.setParent(getXMLReader());
out = new StringWriter();
vr.setContentHandler(getContentHandler(out));
|
protected void | tearDown()
|
public void | testAComplexExample()
String input = "<r>"+
"<foo><bar><gargle/>la di da</bar><bar>hick</bar>"+
"<system-property name=\"k1\" value=\"this is the value of k1\"/>"+
"A reference to k1 yields: \"${k1}\""+
"</foo>"+
"<config name=\"config1\">" +
"k1: \"${k1}\""+
"<system-property name=\"k1\" value=\"K1 VALUE\"/>"+
"</config>"+
"<config name=\"config2\">"+
"k1: \"${k1}\""+
"</config>"+
"</r>";
String expected = "<r>"+
"<foo><bar><gargle/>la di da</bar><bar>hick</bar>"+
"<system-property name=\"k1\" value=\"this is the value of k1\"/>"+
"A reference to k1 yields: \"this is the value of k1\""+
"</foo>"+
"<config name=\"config1\">" +
"k1: \"K1 VALUE\""+
"<system-property name=\"k1\" value=\"K1 VALUE\"/>"+
"</config>"+
"<config name=\"config2\">"+
"k1: \"this is the value of k1\""+
"</config>"+
"</r>";
vr.parse(getInputSource(input));
assertEquals(expected, ""+out);
|
public void | testBasicOperation()
String doc = "<foo/>";
vr.parse(getInputSource(doc));
out.flush();
assertEquals("<foo/>", ""+out);
|
public void | testBasicSystemVariable()
String input = "<foo att=\"${var}\"><system-property name=\"var\" value=\"value\"/></foo>";
String expected = "<foo att=\"value\"><system-property name=\"var\" value=\"value\"/></foo>";
vr.parse(getInputSource(input));
assertEquals(expected, ""+out);
|
public void | testConfigStuff()
String input = "<r>"+
"<config name=\"c1\" att=\"${k1}\">"+
"<child>${k2}</child>"+
"<system-property name=\"k2\" value=\"v2\"/>"+
"</config>"+
"<system-property name=\"k1\" value=\"v1\"/>"+
"</r>";
String expected = "<r>"+
"<config name=\"c1\" att=\"v1\">"+
"<child>v2</child>"+
"<system-property name=\"k2\" value=\"v2\"/>"+
"</config>"+
"<system-property name=\"k1\" value=\"v1\"/>"+
"</r>";
vr.parse(getInputSource(input));
assertEquals(expected, ""+out);
|
public void | testFile()
vr.parse(new InputSource("test.xml"));
String expected = "<r>\n"+
" <foo>\n"+
" <bar>\n"+
" <gargle>la di da</gargle>\n"+
" </bar>\n"+
" <bar>\n"+
" hick\n"+
" </bar>\n"+
" <system-property name=\"k1\" value=\"this is the value of k1\"/>\n"+
" A reference to k1 yields: \"this is the value of k1\"\n"+
" </foo>\n"+
" <config name=\"config1\">\n"+
" k1: \"K1 VALUE\"\n"+
" <system-property name=\"k1\" value=\"K1 VALUE\"/>\n"+
" </config>\n"+
" <config name=\"config2\">\n"+
" K1: \"this is the value of k1\"\n"+
" </config>\n"+
"</r>";
assertEquals(expected, ""+out);
|
public void | testSimpleExpansion()
String input = "<foo>${path.separator}</foo>";
vr.parse(getInputSource(input));
assertEquals("<foo>"+System.getProperty("path.separator")+"</foo>", ""+out);
|
public void | testURI()
final String uri = new File ("test.xml").toURI().toURL().toString();
vr.parse(new InputSource(uri));
String expected = "<r>\n"+
" <foo>\n"+
" <bar>\n"+
" <gargle>la di da</gargle>\n"+
" </bar>\n"+
" <bar>\n"+
" hick\n"+
" </bar>\n"+
" <system-property name=\"k1\" value=\"this is the value of k1\"/>\n"+
" A reference to k1 yields: \"this is the value of k1\"\n"+
" </foo>\n"+
" <config name=\"config1\">\n"+
" k1: \"K1 VALUE\"\n"+
" <system-property name=\"k1\" value=\"K1 VALUE\"/>\n"+
" </config>\n"+
" <config name=\"config2\">\n"+
" K1: \"this is the value of k1\"\n"+
" </config>\n"+
"</r>";
assertEquals(expected, ""+out);
|
public void | testUseOfDefaultReader()
VariableResolver myVr = new VariableResolver();
myVr.setContentHandler(getContentHandler(out));
String input = "<foo att=\"${var}\"><system-property name=\"var\" value=\"value\"/></foo>";
String expected = "<foo att=\"value\"><system-property name=\"var\" value=\"value\"/></foo>";
myVr.parse(getInputSource(input));
assertEquals(expected, ""+out);
|
public void | testXMLSerialization()
StringWriter w = new StringWriter();
ToXMLStream xml = new ToXMLStream();
xml.setWriter(w);
xml.setOmitXMLDeclaration(true);
xml.startElement("uri", "localName", "name", null);
xml.endElement("uri", "localName", "name");
assertEquals("<name xmlns=\"uri\"/>", w.toString());
|