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: 2007-11-03 22:16:17 -0700 (Sat, 03 Nov 2007) $'
8
 * '$Revision: 3567 $'
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.QueryGroup;
38
import edu.ucsb.nceas.metacat.QueryTerm;
39
import edu.ucsb.nceas.utilities.Options;
40

    
41
/**
42
 * @author jones
43
 * 
44
 * Test the output of the QuerySpecification class
45
 */
46
public class QueryGroupTest extends TestCase
47
{
48
	private QueryGroup group = null;
49
	 /* Initialize Options*/
50
    static
51
    {
52
  	  try
53
  	  {
54
  		  Options.initialize(new File("build/tests/metacat.properties"));
55
  		  MetaCatUtil.pathsForIndexing 
56
  		         = MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexPaths"));
57
  	  }
58
  	  catch(Exception e)
59
  	  {
60
  		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
61
  	  }
62
    }
63
    private String query = "(SELECT DISTINCT docid FROM xml_path_index WHERE  (UPPER(nodedata) "+
64
                                            "LIKE '%LAND%' AND path IN ('dataset/title','geographicCoverage/boundingCoordinates/southBoundingCoordinate')) " +
65
                                            "OR ((UPPER(nodedata) LIKE '%JONES%' AND path LIKE 'organizationName') ) OR ((UPPER(nodedata) LIKE '%LAND %' AND path LIKE 'keyword') ) " +
66
                                            "OR ((UPPER(nodedata) LIKE '%DATOS%' AND path LIKE 'entityName') ) UNION ((SELECT DISTINCT docid FROM xml_nodes WHERE UPPER(nodedata) " +
67
                                            "LIKE '%VALUE1%' AND parentnodeid IN (SELECT nodeid FROM xml_index WHERE path LIKE 'path1') )  UNION " +
68
                                            "(SELECT DISTINCT docid FROM xml_nodes WHERE UPPER(nodedata) LIKE '%VALUE2%' AND parentnodeid IN " +
69
                                            "(SELECT nodeid FROM xml_index WHERE path LIKE 'path2') ) ))";
70
    
71
    /**
72
     * Constructor to build the test
73
     * 
74
     * @param name the name of the test method
75
     */
76
    public QueryGroupTest(String name)
77
    {
78
        super(name);
79
    }
80
    /**
81
     * Establishes a testing framework by initializing appropriate objects.
82
     */
83
    protected void setUp() throws Exception
84
    {
85
      super.setUp();
86
   
87
    }
88

    
89
    
90
    /**
91
     * Releases any objects after tests are complete.
92
     */
93
    protected void tearDown() throws Exception
94
    {
95
 
96
      super.tearDown();
97
    }
98

    
99
  
100

    
101
    /**
102
     * Tests initial
103
     */
104
    public void initial()
105
    {
106
    	assertTrue(1 == 1);   
107
    }
108
    
109
    /**
110
     * Tests print out sql command of QueryGroup with UNION 
111
     */
112
    public void printUnion()
113
    {
114
    	group = new QueryGroup("UNION");
115
    	QueryTerm term1 = new QueryTerm ( false, "contains", "land", "dataset/title");
116
    	QueryTerm term2 = new QueryTerm ( false, "contains", "jones", "organizationName");
117
    	QueryTerm term3 = new QueryTerm ( false, "contains", "land ", "keyword");
118
    	QueryTerm term4 = new QueryTerm ( false, "contains", "land", "geographicCoverage/boundingCoordinates/southBoundingCoordinate");
119
    	QueryTerm term5 = new QueryTerm ( false, "contains", "datos",  "entityName");
120
    	QueryGroup child = new QueryGroup("UNION");
121
    	QueryTerm term6 = new QueryTerm ( false, "contains", "value1", "path1");
122
    	QueryTerm term7 = new QueryTerm ( false, "contains", "value2", "path2");
123
    	child.addChild(term6);
124
    	child.addChild(term7);
125
    	group.addChild(term1);
126
    	group.addChild(term2);
127
    	group.addChild(term3);
128
    	group.addChild(term4);
129
    	group.addChild(term5);
130
    	group.addChild(child);
131
    	String queryString = group.printSQL(true);
132
    	assertTrue(queryString.equals(query)); 
133
    	
134
    }
135
    
136
    
137
    /**
138
     * Create a suite of tests to be run together
139
     */
140
    public static Test suite()
141
    {
142
        TestSuite suite = new TestSuite();
143
        suite.addTest(new QueryGroupTest("initial"));
144
        suite.addTest(new QueryGroupTest("printUnion"));
145
        return suite;
146
    }
147

    
148
   
149
}
(11-11/18)