/* Reattore HTTP Server
Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: TestFileCache.java,v 1.3 2003/02/17 04:17:28 michaelh Exp $
*/
package test.juju.reattore.server.intercept.impl;
import java.io.*;
import junit.framework.*;
import juju.reattore.server.intercept.impl.FileCache;
import juju.reattore.io.ByteSource;
public class TestFileCache
extends TestCase {
private FileCache cache = new FileCache();
private static String getBody(ByteSource bs)
throws IOException {
byte[] body = new byte[bs.remaining()];
bs.get(body, 0, body.length);
return new String(body);
}
public void testGet()
throws IOException {
String req = "tests/test/juju/reattore/server/intercept/impl/testfilecache.txt";
File f = new File(req);
ByteSource bs = cache.get(req, f);
String body = getBody(bs);
assertEquals("This is testfilecache.txt", body);
bs.dispose();
}
public void testMultipleGet()
throws IOException {
String req = "tests/test/juju/reattore/server/intercept/impl/testfilecache.txt";
File f = new File(req);
ByteSource bs = cache.get(req, f);
String body = getBody(bs);
assertEquals("This is testfilecache.txt", body);
bs.dispose();
bs = cache.get(req, f);
assertEquals(body, getBody(bs));
bs.dispose();
}
public void testNegativeGet() {
String req = "tests/test/juju/reattore/server/intercept/impl/testfilecache-x.txt";
File f = new File(req);
boolean threw = false;
try {
ByteSource bs = cache.get(req, f);
bs.dispose();
}
catch (IOException ex) {
threw = true;
}
assertTrue(threw);
}
public static Test suite() {
return new TestSuite(TestFileCache.class);
}
}