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 RefEntryTransformer class using the
* JUnit test framework.
* @author <a href="mailto:mark@mcraig.org">Mark Craig</a>
*/
public class TestRefEntryTransformer extends TestCase {
protected RefEntryTransformer transformer;
protected File infile;
protected File outfile;
protected Properties xslt;
protected RefEntry refentry;
protected void setUp() throws Exception {
try {
transformer = new RefEntryTransformer("TestCase");
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 testTransformSet() {
HashSet set = new HashSet();
set.add(refentry);
String output = transformer.transform(set, "test");
output = output.concat("\n");
String str = new String();
try {
BufferedReader br =
new BufferedReader(new FileReader("src/test/test.xhtml"));
String tmp = new String();
while ((tmp = br.readLine()) != null)
str = str.concat(tmp + "\n");
br.close();
PrintWriter pr =
new PrintWriter(
new FileWriter(
File.createTempFile("out", "xhtml")));
pr.write(output);
pr.close();
} catch (Exception e) {
fail(e.toString());
}
assertTrue(output.equals(str));
}
public void testTransformOne() {
String output = transformer.transform(refentry, "test");
// TODO: check that it matches certain output
}
public void testTransformEmpty() {
// TODO: check that it matches certain output
}
public void runTest() {
// The problem with testing these is that they contain the
// date each time a page is generated, so diffs do not work.
//testTransformSet();
testTransformOne();
testTransformEmpty();
}
} |