KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > crawler > selftest > BackgroundImageExtractionSelfTestCase


1 /* BackgroundImageExtractionSelfTest
2  *
3  * Created on Jan 29, 2004
4  *
5  * Copyright (C) 2004 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.crawler.selftest;
24
25
26 import java.io.File JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.archive.io.arc.ARCRecordMetaData;
31
32
33 /**
34  * Test the crawler can find background images in pages.
35  *
36  * @author stack
37  * @version $Id: BackgroundImageExtractionSelfTestCase.java,v 1.5 2006/08/16 00:46:46 stack-sf Exp $
38  */

39 public class BackgroundImageExtractionSelfTestCase
40     extends SelfTestCase
41 {
42     /**
43      * The name of the background image the crawler is supposed to find.
44      */

45     private static final String JavaDoc IMAGE_NAME = "example-background-image.jpeg";
46
47     private static final String JavaDoc JPEG = "image/jpeg";
48
49
50     /**
51      * Read ARC file for the background image the file that contained it.
52      *
53      * Look that there is only one instance of the background image in the
54      * ARC and that it is of the same size as the image in the webapp dir.
55      */

56     public void testBackgroundImageExtraction()
57     {
58         String JavaDoc relativePath = getTestName() + '/' + IMAGE_NAME;
59         String JavaDoc url = getSelftestURLWithTrailingSlash() + relativePath;
60         File JavaDoc image = new File JavaDoc(getHtdocs(), relativePath);
61         assertTrue("Image exists", image.exists());
62         List JavaDoc [] metaDatas = getMetaDatas();
63         boolean found = false;
64         ARCRecordMetaData metaData = null;
65         for (int mi = 0; mi < metaDatas.length; mi++) {
66             List JavaDoc list = metaDatas[mi];
67             for (final Iterator JavaDoc i = list.iterator(); i.hasNext();) {
68                 metaData = (ARCRecordMetaData) i.next();
69                 if (metaData.getUrl().equals(url)
70                         && metaData.getMimetype().equalsIgnoreCase(JPEG)) {
71                     if (!found) {
72                         found = true;
73                     } else {
74                         fail("Found a 2nd instance of " + url);
75                     }
76                 }
77             }
78         }
79     }
80 }
Popular Tags