}
@Test
public void testSave() {
Parser p = new Parser("Save Parser");
for (String rule : regexs) {
ParserRule pr = new ParserRule(rule);
for (int i=0; i < 3; i++) {
ParserRuleParam prp = new ParserRuleParam("param"+(i+1));
for (int j=0; j < 5; j++)
prp.addValue("value"+(j+1));
pr.addParam(prp);
}
pr.setGroupName("group1", 0);
pr.setGroupName("group2", 1);
p.addRule(pr);
}
String xmlSource = p.getXML(0);
System.out.println(xmlSource);
InputSource is = new InputSource(new StringReader(xmlSource));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e1) {
fail(e1.getMessage());
}
Document doc = null;
try {
doc = db.parse(is);
} catch (SAXException e) {
fail(e.getMessage());
} catch (IOException e) {
fail(e.getMessage());
}
Parser p2 = new Parser();
p2.loadFromXML(doc.getFirstChild());
assertEquals(p2.getRulesCount(), regexs.length);
for (int i=0; i < p2.getRulesCount(); i++) {
ParserRule pr = p2.getRule(i);
assertEquals(pr.getRule(), regexs[i]);
assertEquals(3, pr.getParamsCount());
for (int j=0; j < pr.getParamsCount(); j++) {