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-03-29 11:24:05 -0800 (Mon, 29 Mar 2004) $'
8
 * '$Revision: 2069 $'
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.FileReader;
29
import java.io.IOException;
30
import java.util.Hashtable;
31

    
32
import junit.framework.Test;
33
import junit.framework.TestCase;
34
import junit.framework.TestSuite;
35

    
36
import edu.ucsb.nceas.metacat.MetaCatUtil;
37
import edu.ucsb.nceas.metacat.QuerySpecification;
38
import edu.ucsb.nceas.utilities.Options;
39

    
40
/**
41
 * @author jones
42
 * 
43
 * Test the output of the QuerySpecification class
44
 */
45
public class QuerySpecificationTest extends TestCase
46
{
47
    /** A test query document in xml format */
48
    private FileReader xml;
49
    
50
    /** The utilities object for accessing property values */
51
    private MetaCatUtil util;
52
    
53
    /**
54
     * Constructor to build the test
55
     * 
56
     * @param name the name of the test method
57
     */
58
    public QuerySpecificationTest(String name)
59
    {
60
        super(name);
61
    }
62

    
63
    /*
64
     * @see TestCase#setUp()
65
     */
66
    protected void setUp() throws Exception
67
    {
68
        super.setUp();
69
        try {
70
            File propertyFile = new File("./lib/metacat.properties");
71
            Options options = Options.initialize(propertyFile);
72
            util = new MetaCatUtil();
73
            String xmlfile = "./test/query.xml";
74
            xml = new FileReader(new File(xmlfile));
75
        } catch (FileNotFoundException e) {
76
            fail(e.getMessage());
77
        } catch (IOException e) {
78
            fail(e.getMessage());
79
        }
80
    }
81

    
82
    /**
83
     * Create a suite of tests to be run together
84
     */
85
    public static Test suite()
86
    {
87
        TestSuite suite = new TestSuite();
88
        suite.addTest(new QuerySpecificationTest("testPrintSQL"));
89
        suite.addTest(new QuerySpecificationTest("testPrintExtendedSQL"));
90
        return suite;
91
    }
92

    
93
    /**
94
     * Print the sql generated from this specification
95
     */
96
    public void testPrintSQL()
97
    {
98
        try {
99
            System.out.println("----------------------");
100
            QuerySpecification qspec = new QuerySpecification(xml, 
101
                    MetaCatUtil.getOption("saxparser"), 
102
                    MetaCatUtil.getOption("accNumberSeparator"));
103
            System.out.println(qspec.printSQL(false));
104
        } catch (IOException e) {
105
            fail(e.getMessage());
106
        }
107
    }
108

    
109
    /**
110
     * Print the extended SQL for a result set.
111
     */
112
    public void testPrintExtendedSQL()
113
    {
114
        try {
115
            System.out.println("----------------------");
116
            Hashtable controlPairs = new Hashtable();
117
            QuerySpecification qspec = new QuerySpecification(xml, 
118
                    MetaCatUtil.getOption("saxparser"), 
119
                    MetaCatUtil.getOption("accNumberSeparator"));
120
            System.out.println(
121
                    qspec.printExtendedSQL("'obfs.45337', 'obfs.45338', 'obfs.45346'", 
122
                            controlPairs, false));
123
        } catch (IOException e) {
124
            fail(e.getMessage());
125
        }
126
    }
127

    
128
}
(3-3/5)