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-12-26 13:10:24 -0800 (Fri, 26 Dec 2008) $'
8
 * '$Revision: 4700 $'
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 junit.framework.Test;
27
import junit.framework.TestSuite;
28

    
29
import edu.ucsb.nceas.MCTestCase;
30
import edu.ucsb.nceas.metacat.QueryGroup;
31
import edu.ucsb.nceas.metacat.QueryTerm;
32
import edu.ucsb.nceas.metacat.service.PropertyService;
33
import edu.ucsb.nceas.metacat.util.MetacatUtil;
34

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

    
82
    
83
    /**
84
     * Releases any objects after tests are complete.
85
     */
86
    protected void tearDown() throws Exception
87
    {
88
 
89
      super.tearDown();
90
    }
91

    
92
  
93

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

    
141
   
142
}
(12-12/20)