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-08-05 17:50:14 -0700 (Tue, 05 Aug 2008) $'
8
 * '$Revision: 4213 $'
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.TestCase;
28
import junit.framework.TestSuite;
29

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

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

    
93
  
94

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

    
142
   
143
}
(12-12/19)