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: tao $'
7
 *     '$Date: 2008-05-15 18:25:04 -0700 (Thu, 15 May 2008) $'
8
 * '$Revision: 3875 $'
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
	 /* Initialize Options*/
48
    static
49
    {
50
  	  try
51
  	  {
52
  		  Options.initialize(new File("build/tests/metacat.properties"));
53
  		  MetaCatUtil.pathsForIndexing 
54
  		         = MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexPaths"));
55
  	  }
56
  	  catch(Exception e)
57
  	  {
58
  		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
59
  	  }
60
    }
61
	
62
    private String propertyFileName = 
63
    	MetaCatUtil.getOption("installDir") + "/WEB-INF/metacat.properties";
64

    
65
    protected void setUp() throws Exception
66
    {
67
        super.setUp();
68
        try {
69
            File propertyFile = new File(propertyFileName);
70
            Options options = Options.initialize(propertyFile);
71
            MetaCatUtil util = new MetaCatUtil();
72
            DBConnectionPool pool = DBConnectionPool.getInstance();
73
        } catch (FileNotFoundException e) {
74
            fail(e.getMessage());
75
        } catch (IOException e) {
76
            fail(e.getMessage());
77
        }
78
    }
79

    
80
    /**
81
     * Test whether a valid instance of the EventLog can be retrieved.
82
     *
83
     */
84
    public void testGetInstance()
85
    {
86
        EventLog logger = EventLog.getInstance();
87
        assertTrue(logger != null);
88
    }
89

    
90
    /**
91
     * Test whether the log method can properly insert a log record.
92
     */
93
    public void testLog()
94
    {
95
        EventLog.getInstance().log("192.168.1.103", "public", "test.2.1", "read");
96
        assertTrue(1 == 1);
97
    }
98

    
99
    /**
100
     * Test whether getReport returns correct reports.
101
     */
102
    public void testGetReport()
103
    {
104
        String[] principals = {"jones", "public", "someone"};
105
        String[] ipList = {"192.168.1.103", "192.168.1.104"};
106
        String[] docList = {"test.2.1", "test.2"};
107
        String[] eventList = {"read", "insert", "update"};
108
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
109
        Timestamp startDate = null;
110
        Timestamp endDate = null;
111
        try {
112
            startDate = new Timestamp((format.parse("2004-04-08 02:32:00")).getTime());
113
            endDate = new Timestamp((format.parse("2004-04-08 11:20:00")).getTime());
114
        } catch (ParseException e) {
115
            System.out.println("Failed to created endDate from format.");
116
        }
117
        String report = EventLog.getInstance().getReport(ipList, principals, docList, 
118
                        eventList, null, null);
119
        System.out.println(report);
120
        report = EventLog.getInstance().getReport(null, null, null, 
121
                        null, startDate, endDate);
122
        System.out.println(report);
123
    }
124
}
(4-4/18)