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: jones $'
|
7
|
* '$Date: 2007-04-18 02:26:24 -0700 (Wed, 18 Apr 2007) $'
|
8
|
* '$Revision: 3244 $'
|
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.metacat.DBConnectionPool;
|
34
|
import edu.ucsb.nceas.metacat.MetaCatUtil;
|
35
|
import edu.ucsb.nceas.metacat.Sitemap;
|
36
|
import edu.ucsb.nceas.utilities.Options;
|
37
|
|
38
|
import junit.framework.TestCase;
|
39
|
|
40
|
/**
|
41
|
* Test the Sitemap class by generating the sitemaps in a separate directory.
|
42
|
*
|
43
|
* @author Matt Jones
|
44
|
*/
|
45
|
public class SitemapTest extends TestCase {
|
46
|
|
47
|
private String propertyFileName =
|
48
|
"@install-dir@/WEB-INF/metacat.properties";
|
49
|
// "/usr/share/tomcat5.5/webapps/knb/WEB-INF/metacat.properties";
|
50
|
|
51
|
private String directoryName = "/tmp/sitemaps";
|
52
|
|
53
|
/**
|
54
|
* Initialize the Metacat environment so the test can run.
|
55
|
*/
|
56
|
protected void setUp() throws Exception {
|
57
|
super.setUp();
|
58
|
try {
|
59
|
File propertyFile = new File(propertyFileName);
|
60
|
Options options = Options.initialize(propertyFile);
|
61
|
MetaCatUtil util = new MetaCatUtil();
|
62
|
DBConnectionPool pool = DBConnectionPool.getInstance();
|
63
|
} catch (FileNotFoundException e) {
|
64
|
fail(e.getMessage());
|
65
|
} catch (IOException e) {
|
66
|
fail(e.getMessage());
|
67
|
}
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Test the static generateSitemaps() method.
|
72
|
*/
|
73
|
public void testGenerateSitemaps() {
|
74
|
File directory = new File(directoryName);
|
75
|
directory.mkdirs();
|
76
|
String urlRoot = "http://foo.example.com/ctx/metacat";
|
77
|
String skin = "testskin";
|
78
|
Sitemap smap = new Sitemap(directory, urlRoot, skin);
|
79
|
smap.generateSitemaps();
|
80
|
File sitemap1 = new File(directory, "metacat1.xml");
|
81
|
assertTrue(sitemap1.exists() && sitemap1.isFile());
|
82
|
try {
|
83
|
FileReader r = new FileReader(sitemap1);
|
84
|
BufferedReader br = new BufferedReader(r);
|
85
|
char[] buf = new char[1024];
|
86
|
br.read(buf, 0, 1024);
|
87
|
br.close();
|
88
|
String doc = new String(buf);
|
89
|
assertTrue(doc.indexOf("<?xml") >= 0);
|
90
|
assertTrue(doc.indexOf("<urlset") >= 0);
|
91
|
assertTrue(doc.indexOf("<url>") >= 0);
|
92
|
assertTrue(doc.indexOf("http:") >= 0);
|
93
|
} catch (FileNotFoundException e) {
|
94
|
fail("Failed to read the sitemap file." + e.getMessage());
|
95
|
} catch (IOException ioe) {
|
96
|
fail("Failed while reading sitemap file." + ioe.getMessage());
|
97
|
}
|
98
|
}
|
99
|
}
|