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-07 02:31:28 -0700 (Wed, 07 Apr 2004) $'
8
 * '$Revision: 2111 $'
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
import java.util.Date;
33

    
34
import edu.ucsb.nceas.metacat.DBConnectionPool;
35
import edu.ucsb.nceas.metacat.EventLog;
36
import edu.ucsb.nceas.metacat.MetaCatUtil;
37
import edu.ucsb.nceas.utilities.Options;
38

    
39
import junit.framework.TestCase;
40

    
41
/**
42
 * Test the logging facility against the database connection.
43
 * 
44
 * @author jones
45
 */
46
public class EventLogTest extends TestCase
47
{
48

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

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

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

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