1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: TestFileCache.java,v 1.3 2003/02/17 04:17:28 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.server.intercept.impl; 23 24 import java.io.*; 25 import junit.framework.*; 26 27 import juju.reattore.server.intercept.impl.FileCache; 28 import juju.reattore.io.ByteSource; 29 30 public class TestFileCache 31 extends TestCase { 32 33 private FileCache cache = new FileCache(); 34 35 private static String getBody(ByteSource bs) 36 throws IOException { 37 38 byte[] body = new byte[bs.remaining()]; 39 bs.get(body, 0, body.length); 40 41 return new String(body); 42 } 43 44 public void testGet() 45 throws IOException { 46 47 String req = "tests/test/juju/reattore/server/intercept/impl/testfilecache.txt"; 48 File f = new File(req); 49 50 ByteSource bs = cache.get(req, f); 51 String body = getBody(bs); 52 53 assertEquals("This is testfilecache.txt", body); 54 bs.dispose(); 55 } 56 57 public void testMultipleGet() 58 throws IOException { 59 60 String req = "tests/test/juju/reattore/server/intercept/impl/testfilecache.txt"; 61 File f = new File(req); 62 63 ByteSource bs = cache.get(req, f); 64 String body = getBody(bs); 65 66 assertEquals("This is testfilecache.txt", body); 67 bs.dispose(); 68 69 bs = cache.get(req, f); 70 assertEquals(body, getBody(bs)); 71 72 bs.dispose(); 73 } 74 75 public void testNegativeGet() { 76 77 String req = "tests/test/juju/reattore/server/intercept/impl/testfilecache-x.txt"; 78 File f = new File(req); 79 80 boolean threw = false; 81 82 try { 83 ByteSource bs = cache.get(req, f); 84 bs.dispose(); 85 } 86 catch (IOException ex) { 87 threw = true; 88 } 89 90 assertTrue(threw); 91 } 92 93 public static Test suite() { 94 return new TestSuite(TestFileCache.class); 95 } 96 }

This page was automatically generated by Maven