Project

General

Profile

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 2111 jones
import java.sql.Timestamp;
27
import java.text.ParseException;
28
import java.text.SimpleDateFormat;
29 2096 jones
30 4149 daigle
import edu.ucsb.nceas.MCTestCase;
31 5016 daigle
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
32 2096 jones
import edu.ucsb.nceas.metacat.EventLog;
33
34
/**
35
 * Test the logging facility against the database connection.
36
 *
37
 * @author jones
38
 */
39 4149 daigle
public class EventLogTest extends MCTestCase
40 2096 jones
{
41
42
    protected void setUp() throws Exception
43 4149 daigle
    {
44 2096 jones
        super.setUp();
45 4149 daigle
        DBConnectionPool pool = DBConnectionPool.getInstance();
46 2096 jones
    }
47
48
    /**
49
     * Test whether a valid instance of the EventLog can be retrieved.
50
     *
51
     */
52
    public void testGetInstance()
53
    {
54
        EventLog logger = EventLog.getInstance();
55
        assertTrue(logger != null);
56
    }
57
58 2111 jones
    /**
59
     * Test whether the log method can properly insert a log record.
60
     */
61 2096 jones
    public void testLog()
62
    {
63 2111 jones
        EventLog.getInstance().log("192.168.1.103", "public", "test.2.1", "read");
64 2100 jones
        assertTrue(1 == 1);
65 2096 jones
    }
66
67 2111 jones
    /**
68
     * Test whether getReport returns correct reports.
69
     */
70
    public void testGetReport()
71
    {
72
        String[] principals = {"jones", "public", "someone"};
73
        String[] ipList = {"192.168.1.103", "192.168.1.104"};
74
        String[] docList = {"test.2.1", "test.2"};
75
        String[] eventList = {"read", "insert", "update"};
76
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
77
        Timestamp startDate = null;
78
        Timestamp endDate = null;
79
        try {
80 2113 jones
            startDate = new Timestamp((format.parse("2004-04-08 02:32:00")).getTime());
81
            endDate = new Timestamp((format.parse("2004-04-08 11:20:00")).getTime());
82 2111 jones
        } catch (ParseException e) {
83
            System.out.println("Failed to created endDate from format.");
84
        }
85
        String report = EventLog.getInstance().getReport(ipList, principals, docList,
86
                        eventList, null, null);
87
        System.out.println(report);
88
        report = EventLog.getInstance().getReport(null, null, null,
89
                        null, startDate, endDate);
90
        System.out.println(report);
91
    }
92 2096 jones
}