Project

General

Profile

« Previous | Next » 

Revision 4142

Added by daigle over 16 years ago

Create TestCase base class that makes sure PropertyService is instantiated and implements a debug() method that allows us to print to stderr

View differences:

test/edu/ucsb/nceas/MCTestCase.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2008 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *  Purpose: To test the Access Controls in metacat by JUnit
6
 *
7
 *   '$Author$'
8
 *     '$Date$'
9
 * '$Revision$'
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
 */
25

  
26
package edu.ucsb.nceas;
27

  
28
import junit.framework.TestCase;
29

  
30
import edu.ucsb.nceas.metacat.service.PropertyService;
31
import edu.ucsb.nceas.metacat.service.ServiceException;
32
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
33

  
34
/**
35
 * A base JUnit class for Metacat tests
36
 */
37
public class MCTestCase
38
    extends TestCase {
39
	
40
    private static boolean printDebug = false;
41
	
42
	static {
43
		try {
44
			PropertyService.getInstance("build/tests");
45
		    String printDebugString = PropertyService.getProperty("test.printdebug");
46
		    printDebug = Boolean.parseBoolean(printDebugString);
47
		} catch (PropertyNotFoundException pnfe) {
48
			System.err.println("Could not get property in static block: " 
49
					+ pnfe.getMessage());
50
		} catch (ServiceException se) {
51
			System.err.println("Could not get PropertyService instance in static block: " 
52
					+ se.getMessage());
53
		}
54
	}
55
	
56
    /**
57
     * Constructor to build the test
58
     *
59
     * @param name the name of the test method
60
     */
61
    public MCTestCase(String name) {
62
        super(name);
63
    }
64
    
65
    public void debug(String debugMessage) {
66
    	if (printDebug) {
67
    		System.err.println(debugMessage);
68
    	}
69
    }
70
}
0 71

  

Also available in: Unified diff