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-30 10:02:41 -0800 (Tue, 30 Mar 2004) $'
|
8
|
* '$Revision: 2074 $'
|
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
|
suite.addTest(new QuerySpecificationTest("testAttributeSQL"));
|
91
|
return suite;
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* Print the sql generated from this specification
|
96
|
*/
|
97
|
public void testPrintSQL()
|
98
|
{
|
99
|
try {
|
100
|
System.out.println("---- SQL ------------------");
|
101
|
QuerySpecification qspec = new QuerySpecification(xml,
|
102
|
MetaCatUtil.getOption("saxparser"),
|
103
|
MetaCatUtil.getOption("accNumberSeparator"));
|
104
|
System.out.println(qspec.printSQL(false));
|
105
|
} catch (IOException e) {
|
106
|
fail(e.getMessage());
|
107
|
}
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Print the extended SQL for a result set.
|
112
|
*/
|
113
|
public void testPrintExtendedSQL()
|
114
|
{
|
115
|
try {
|
116
|
System.out.println("---- EXT SQL ------------------");
|
117
|
Hashtable controlPairs = new Hashtable();
|
118
|
QuerySpecification qspec = new QuerySpecification(xml,
|
119
|
MetaCatUtil.getOption("saxparser"),
|
120
|
MetaCatUtil.getOption("accNumberSeparator"));
|
121
|
System.out.println(
|
122
|
qspec.printExtendedSQL(
|
123
|
"'obfs.45337', 'obfs.45338', 'obfs.45346'",
|
124
|
controlPairs, false));
|
125
|
} catch (IOException e) {
|
126
|
fail(e.getMessage());
|
127
|
}
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* Print the extended SQL for a result set.
|
132
|
*/
|
133
|
public void testAttributeSQL()
|
134
|
{
|
135
|
try {
|
136
|
System.out.println("---- ATT SQL ------------------");
|
137
|
Hashtable controlPairs = new Hashtable();
|
138
|
QuerySpecification qspec = new QuerySpecification(xml,
|
139
|
MetaCatUtil.getOption("saxparser"),
|
140
|
MetaCatUtil.getOption("accNumberSeparator"));
|
141
|
System.out.println(
|
142
|
qspec.printAttributeQuery(
|
143
|
"'obfs.45337', 'obfs.45338', 'obfs.45346'", false));
|
144
|
} catch (IOException e) {
|
145
|
fail(e.getMessage());
|
146
|
}
|
147
|
}
|
148
|
}
|