Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2007 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: daigle $'
7
 *     '$Date: 2008-09-24 11:28:29 -0700 (Wed, 24 Sep 2008) $'
8
 * '$Revision: 4384 $'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24

    
25
package edu.ucsb.nceas.metacattest;
26

    
27
import java.io.BufferedReader;
28
import java.io.File;
29
import java.io.FileNotFoundException;
30
import java.io.FileReader;
31
import java.io.IOException;
32

    
33
import edu.ucsb.nceas.MCTestCase;
34
import edu.ucsb.nceas.metacat.DBConnectionPool;
35
import edu.ucsb.nceas.metacat.Sitemap;
36

    
37
/**
38
 * Test the Sitemap class by generating the sitemaps in a separate directory.
39
 * 
40
 * @author Matt Jones
41
 */
42
public class SitemapTest extends MCTestCase {
43

    
44
    private String directoryName = "/tmp/sitemaps";
45

    
46
    /**
47
     * Initialize the Metacat environment so the test can run.
48
     */
49
    protected void setUp() throws Exception {
50
        super.setUp();
51

    
52
        DBConnectionPool pool = DBConnectionPool.getInstance();
53
    }
54

    
55
    /**
56
     * Test the static generateSitemaps() method.
57
     */
58
    public void testGenerateSitemaps() {
59
        File directory = new File(directoryName);
60
        directory.mkdirs();
61
        String urlRoot = "http://foo.example.com/ctx/metacat";
62
        String skin = "testskin";
63
        Sitemap smap = new Sitemap(directory, urlRoot, skin);
64
        smap.generateSitemaps();
65
        File sitemap1 = new File(directory, "metacat1.xml");
66
        assertTrue(sitemap1.exists() && sitemap1.isFile());
67
        try {
68
            FileReader r = new FileReader(sitemap1);
69
            BufferedReader br = new BufferedReader(r);
70
            char[] buf = new char[1024];
71
            br.read(buf, 0, 1024);
72
            br.close();
73
            String doc = new String(buf);
74
            assertTrue(doc.indexOf("<?xml") >= 0);
75
            assertTrue(doc.indexOf("<urlset") >= 0);
76
            assertTrue(doc.indexOf("<url>") >= 0);
77
            assertTrue(doc.indexOf("http:") >= 0);
78
        } catch (FileNotFoundException e) {
79
            fail("Failed to read the sitemap file." + e.getMessage());
80
        } catch (IOException ioe) {
81
            fail("Failed while reading sitemap file." + ioe.getMessage());
82
        }
83
    }
84
}
(17-17/20)