01: /* $Id: WARCRecordTest.java 4545 2006-08-26 00:33:38Z stack-sf $
02: *
03: * Created on August 25th, 2006
04: *
05: * Copyright (C) 2006 Internet Archive.
06: *
07: * This file is part of the Heritrix web crawler (crawler.archive.org).
08: *
09: * 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.v10;
24:
25: import java.io.ByteArrayInputStream;
26: import java.io.IOException;
27:
28: import junit.framework.TestCase;
29:
30: public class WARCRecordTest extends TestCase {
31: public void testParseHeaderLine() throws IOException {
32: final String body = "GET /robots.txt HTTP/1.0";
33: final String 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" + body + "\r\n\r\n";
39: WARCRecord r = new WARCRecord(new ByteArrayInputStream(hdr
40: .getBytes()), "READER_IDENTIFIER", 0, false, true);
41: assertEquals(r.getHeader().getLength(), 496);
42: assertEquals(r.getHeader().getMimetype(),
43: "application/http; msgtype=request");
44: assertEquals(r.getHeader().getRecordIdentifier(),
45: "uuri:dbf1ef20-db01-4cc6-ba93-6baf7a906356;type=request");
46: byte[] b = new byte[body.length()];
47: r.read(b);
48: String bodyRead = new String(b);
49: assertEquals(body, bodyRead);
50: }
51: }
|