KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > io > warc > WARCRecordTest


1 /* $Id: WARCRecordTest.java,v 1.1 2006/08/26 00:33:36 stack-sf Exp $
2  *
3  * Created on August 25th, 2006
4  *
5  * Copyright (C) 2006 Internet Archive.
6  *
7  * This file is part of the Heritrix web crawler (crawler.archive.org).
8  *
9  * Heritrix is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * any later version.
13  *
14  * Heritrix is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser Public License
20  * along with Heritrix; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23 package org.archive.io.warc;
24
25 import java.io.ByteArrayInputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27
28 import junit.framework.TestCase;
29
30 public class WARCRecordTest extends TestCase {
31     public void testParseHeaderLine() throws IOException JavaDoc {
32         final String JavaDoc body = "GET /robots.txt HTTP/1.0";
33         final String JavaDoc hdr = "WARC/0.9 000000000496 request " +
34             "http://foo.maths.uq.edu.au/robots.txt 20060825210905 " +
35             "uuri:dbf1ef20-db01-4cc6-ba93-6baf7a906356;type=request " +
36             "application/http; msgtype=request\r\n" +
37             "Related-Record-ID: uuri:dbf1ef20-db01-4cc6-ba93-6baf7a906356\r\n" +
38             "\r\n" +
39             body +
40             "\r\n\r\n";
41         WARCRecord r = new WARCRecord(new ByteArrayInputStream JavaDoc(hdr.getBytes()),
42              "READER_IDENTIFIER", 0, false, true);
43         assertEquals(r.getHeader().getLength(), 496);
44         assertEquals(r.getHeader().getMimetype(),
45             "application/http; msgtype=request");
46         assertEquals(r.getHeader().getRecordIdentifier(),
47             "uuri:dbf1ef20-db01-4cc6-ba93-6baf7a906356;type=request");
48         byte [] b = new byte[body.length()];
49         r.read(b);
50         String JavaDoc bodyRead = new String JavaDoc(b);
51         assertEquals(body, bodyRead);
52     }
53 }
54
Popular Tags