1 |
2096
|
jones
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2004 Regents of the University of California and the
|
4 |
|
|
* National Center for Ecological Analysis and Synthesis
|
5 |
|
|
*
|
6 |
|
|
* '$Author$'
|
7 |
|
|
* '$Date$'
|
8 |
|
|
* '$Revision$'
|
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 |
|
|
package edu.ucsb.nceas.metacattest;
|
25 |
|
|
|
26 |
|
|
import java.io.File;
|
27 |
|
|
import java.io.FileNotFoundException;
|
28 |
|
|
import java.io.IOException;
|
29 |
2111
|
jones
|
import java.sql.Timestamp;
|
30 |
|
|
import java.text.ParseException;
|
31 |
|
|
import java.text.SimpleDateFormat;
|
32 |
2096
|
jones
|
|
33 |
|
|
import edu.ucsb.nceas.metacat.DBConnectionPool;
|
34 |
|
|
import edu.ucsb.nceas.metacat.EventLog;
|
35 |
|
|
import edu.ucsb.nceas.metacat.MetaCatUtil;
|
36 |
|
|
import edu.ucsb.nceas.utilities.Options;
|
37 |
|
|
|
38 |
|
|
import junit.framework.TestCase;
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* Test the logging facility against the database connection.
|
42 |
|
|
*
|
43 |
|
|
* @author jones
|
44 |
|
|
*/
|
45 |
|
|
public class EventLogTest extends TestCase
|
46 |
|
|
{
|
47 |
2329
|
jones
|
private String propertyFileName =
|
48 |
|
|
"@install-dir@/WEB-INF/metacat.properties";
|
49 |
2096
|
jones
|
|
50 |
|
|
protected void setUp() throws Exception
|
51 |
|
|
{
|
52 |
|
|
super.setUp();
|
53 |
|
|
try {
|
54 |
2329
|
jones
|
File propertyFile = new File(propertyFileName);
|
55 |
2096
|
jones
|
Options options = Options.initialize(propertyFile);
|
56 |
|
|
MetaCatUtil util = new MetaCatUtil();
|
57 |
|
|
DBConnectionPool pool = DBConnectionPool.getInstance();
|
58 |
|
|
} catch (FileNotFoundException e) {
|
59 |
|
|
fail(e.getMessage());
|
60 |
|
|
} catch (IOException e) {
|
61 |
|
|
fail(e.getMessage());
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Test whether a valid instance of the EventLog can be retrieved.
|
67 |
|
|
*
|
68 |
|
|
*/
|
69 |
|
|
public void testGetInstance()
|
70 |
|
|
{
|
71 |
|
|
EventLog logger = EventLog.getInstance();
|
72 |
|
|
assertTrue(logger != null);
|
73 |
|
|
}
|
74 |
|
|
|
75 |
2111
|
jones
|
/**
|
76 |
|
|
* Test whether the log method can properly insert a log record.
|
77 |
|
|
*/
|
78 |
2096
|
jones
|
public void testLog()
|
79 |
|
|
{
|
80 |
2111
|
jones
|
EventLog.getInstance().log("192.168.1.103", "public", "test.2.1", "read");
|
81 |
2100
|
jones
|
assertTrue(1 == 1);
|
82 |
2096
|
jones
|
}
|
83 |
|
|
|
84 |
2111
|
jones
|
/**
|
85 |
|
|
* Test whether getReport returns correct reports.
|
86 |
|
|
*/
|
87 |
|
|
public void testGetReport()
|
88 |
|
|
{
|
89 |
|
|
String[] principals = {"jones", "public", "someone"};
|
90 |
|
|
String[] ipList = {"192.168.1.103", "192.168.1.104"};
|
91 |
|
|
String[] docList = {"test.2.1", "test.2"};
|
92 |
|
|
String[] eventList = {"read", "insert", "update"};
|
93 |
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
94 |
|
|
Timestamp startDate = null;
|
95 |
|
|
Timestamp endDate = null;
|
96 |
|
|
try {
|
97 |
2113
|
jones
|
startDate = new Timestamp((format.parse("2004-04-08 02:32:00")).getTime());
|
98 |
|
|
endDate = new Timestamp((format.parse("2004-04-08 11:20:00")).getTime());
|
99 |
2111
|
jones
|
} catch (ParseException e) {
|
100 |
|
|
System.out.println("Failed to created endDate from format.");
|
101 |
|
|
}
|
102 |
|
|
String report = EventLog.getInstance().getReport(ipList, principals, docList,
|
103 |
|
|
eventList, null, null);
|
104 |
|
|
System.out.println(report);
|
105 |
|
|
report = EventLog.getInstance().getReport(null, null, null,
|
106 |
|
|
null, startDate, endDate);
|
107 |
|
|
System.out.println(report);
|
108 |
|
|
}
|
109 |
2096
|
jones
|
}
|