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: daigle $'
7
 *     '$Date: 2008-07-15 10:16:18 -0700 (Tue, 15 Jul 2008) $'
8
 * '$Revision: 4127 $'
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.sql.Timestamp;
27
import java.text.ParseException;
28
import java.text.SimpleDateFormat;
29

    
30
import edu.ucsb.nceas.metacat.DBConnectionPool;
31
import edu.ucsb.nceas.metacat.EventLog;
32
import edu.ucsb.nceas.metacat.service.PropertyService;
33
import edu.ucsb.nceas.metacat.service.ServiceException;
34
import edu.ucsb.nceas.metacat.util.SystemUtil;
35

    
36
import junit.framework.TestCase;
37

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

    
46
    protected void setUp() throws Exception
47
    {
48
    	
49
        super.setUp();
50
        try {
51
			PropertyService.getInstance("build/tests");
52
            DBConnectionPool pool = DBConnectionPool.getInstance();
53
        } catch (ServiceException se) {
54
            fail(se.getMessage());
55
        } 
56
    }
57

    
58
    /**
59
     * Test whether a valid instance of the EventLog can be retrieved.
60
     *
61
     */
62
    public void testGetInstance()
63
    {
64
        EventLog logger = EventLog.getInstance();
65
        assertTrue(logger != null);
66
    }
67

    
68
    /**
69
     * Test whether the log method can properly insert a log record.
70
     */
71
    public void testLog()
72
    {
73
        EventLog.getInstance().log("192.168.1.103", "public", "test.2.1", "read");
74
        assertTrue(1 == 1);
75
    }
76

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