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: daigle $'
7
 *     '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
8
 * '$Revision: 4080 $'
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.QueryGroup;
37
import edu.ucsb.nceas.metacat.QueryTerm;
38
import edu.ucsb.nceas.metacat.service.PropertyService;
39
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
40
import edu.ucsb.nceas.utilities.Options;
41

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

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

    
100
  
101

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

    
149
   
150
}
(11-11/18)