Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: jones $'
7
 *     '$Date: 2004-04-08 13:49:09 -0700 (Thu, 08 Apr 2004) $'
8
 * '$Revision: 2113 $'
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
import java.sql.Timestamp;
30
import java.text.ParseException;
31
import java.text.SimpleDateFormat;
32

    
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

    
48
    protected void setUp() throws Exception
49
    {
50
        super.setUp();
51
        try {
52
            File propertyFile = new File("./lib/metacat.properties");
53
            Options options = Options.initialize(propertyFile);
54
            MetaCatUtil util = new MetaCatUtil();
55
            DBConnectionPool pool = DBConnectionPool.getInstance();
56
        } catch (FileNotFoundException e) {
57
            fail(e.getMessage());
58
        } catch (IOException e) {
59
            fail(e.getMessage());
60
        }
61
    }
62

    
63
    /**
64
     * Test whether a valid instance of the EventLog can be retrieved.
65
     *
66
     */
67
    public void testGetInstance()
68
    {
69
        EventLog logger = EventLog.getInstance();
70
        assertTrue(logger != null);
71
    }
72

    
73
    /**
74
     * Test whether the log method can properly insert a log record.
75
     */
76
    public void testLog()
77
    {
78
        EventLog.getInstance().log("192.168.1.103", "public", "test.2.1", "read");
79
        assertTrue(1 == 1);
80
    }
81

    
82
    /**
83
     * Test whether getReport returns correct reports.
84
     */
85
    public void testGetReport()
86
    {
87
        String[] principals = {"jones", "public", "someone"};
88
        String[] ipList = {"192.168.1.103", "192.168.1.104"};
89
        String[] docList = {"test.2.1", "test.2"};
90
        String[] eventList = {"read", "insert", "update"};
91
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
92
        Timestamp startDate = null;
93
        Timestamp endDate = null;
94
        try {
95
            startDate = new Timestamp((format.parse("2004-04-08 02:32:00")).getTime());
96
            endDate = new Timestamp((format.parse("2004-04-08 11:20:00")).getTime());
97
        } catch (ParseException e) {
98
            System.out.println("Failed to created endDate from format.");
99
        }
100
        String report = EventLog.getInstance().getReport(ipList, principals, docList, 
101
                        eventList, null, null);
102
        System.out.println(report);
103
        report = EventLog.getInstance().getReport(null, null, null, 
104
                        null, startDate, endDate);
105
        System.out.println(report);
106
    }
107
}
(2-2/10)