package org.mcraig.cs445.refentry;
import java.io.*;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import junit.framework.TestCase;
/**
* Test friendly methods of the RefEntryBackEnd class using the
* JUnit test framework.
* @author <a href="mailto:mark@mcraig.org">Mark Craig</a>
*/
public class TestRefEntryBackEnd extends TestCase {
protected RefEntryBackEnd backend;
protected File infile;
protected File outfile;
protected Properties xslt;
protected RefEntry refentry;
protected void setUp() throws Exception {
try {
backend = new RefEntryBackEnd(new HashSet());
infile = new File("src/test/test.xml");
outfile = File.createTempFile("test", ".html");
xslt = new Properties();
xslt.load(
new BufferedInputStream(
new FileInputStream("src/conf/xslt.props")));
refentry = new RefEntry(infile, outfile, xslt);
} catch (Exception e) {
throw e;
}
}
protected void tearDown() throws Exception {
try {
outfile.delete();
} catch (Exception e) {
throw e;
}
}
public void testAdd() {
boolean result = backend.add(refentry);
assertTrue(result);
}
public void testGetEntry() {
HashSet test = backend.getEntry(refentry.getID());
Iterator iter = test.iterator();
RefEntry re = (RefEntry)iter.next();
assertEquals(re, refentry);
}
public void testGetValues() {
HashSet keys = new HashSet();
keys.add("test");
HashSet vals = backend.getValues(keys);
assertTrue(vals.size() == 1);
Iterator iter = vals.iterator();
RefEntry re = (RefEntry)iter.next();
assertEquals(re, refentry);
}
public void runTest() {
testAdd();
testGetEntry();
testGetValues();
}
} |