MockArticle mock = new MockArticle();
Reference[] hard = new Reference[HARD];
for (int i=0; i < HARD; i++) {
hard[i] = new Reference("hard-"+URI+i, NAME+i, true);
}
mock.setReferences(hard);
Reference[] soft = new Reference[HARD];
for (int i=0; i < SOFT; i++) {
soft[i] = new Reference("hard-"+URI+i, NAME+i, false);
}
StringBuffer body = new StringBuffer();
body.append("<sect1><title>Reference test</title>");
for (int i=0; i < SOFT; i++) {
body.append("<para>This is a ");
body.append("<qv uri=\""+soft[i].getUri()+"\">");
body.append(soft[i].getName()+"</qv>");
body.append("</para>");
}
body.append("</sect1>");
mock.setBody(body.toString());
try {
Article article = new Article("test", mock.toXML());
Iterator iter = article.getReferences();
if (!iter.hasNext()) {
fail("Did not find any references");
}
for (int i = 0; i < HARD; i++) {
if (!iter.hasNext()) {
fail("Failed to find all hard references");
}
Reference reference = (Reference) iter.next();
assertEquals("Hard reference uri "+i+" was wrong",
hard[i].getUri(), reference.getUri());
assertEquals("Hard reference name "+i+" was wrong",
hard[i].getName(), reference.getName());
assertEquals("Hard reference uri "+i+" was soft",
true, reference.isHard());
}
if (!iter.hasNext()) {
fail("Did not find any soft references");
}
for (int i = 0; i < SOFT; i++) {
if (!iter.hasNext()) {
fail("Failed to find all soft references");
}
Reference reference = (Reference) iter.next();
assertEquals("Soft reference uri "+i+" was wrong",
soft[i].getUri(), reference.getUri());
assertEquals("Soft reference name "+i+" was wrong",
soft[i].getName(), reference.getName());
assertEquals("Soft reference uri "+i+" was hard",
false, reference.isHard());
}
if (iter.hasNext()) {
fail("Too many references returned");
}
} catch (IOException e) {