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: 2009-08-24 14:42:25 -0700 (Mon, 24 Aug 2009) $'
8
 * '$Revision: 5035 $'
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.properties.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
			PropertyService.getInstance();
49
 	  }
50
  	  catch(Exception e)
51
  	  {
52
  		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
53
  	  }
54
    }
55
    private String query = "(SELECT DISTINCT docid FROM xml_path_index WHERE  (UPPER(nodedata) "+
56
                                            "LIKE '%LAND%' AND path IN ('dataset/title','geographicCoverage/boundingCoordinates/southBoundingCoordinate')) " +
57
                                            "OR ((UPPER(nodedata) LIKE '%JONES%' AND path LIKE 'organizationName') ) OR ((UPPER(nodedata) LIKE '%LAND %' AND path LIKE 'keyword') ) " +
58
                                            "OR ((UPPER(nodedata) LIKE '%DATOS%' AND path LIKE 'entityName') ) UNION ((SELECT DISTINCT docid FROM xml_nodes WHERE UPPER(nodedata) " +
59
                                            "LIKE '%VALUE1%' AND parentnodeid IN (SELECT nodeid FROM xml_index WHERE path LIKE 'path1') )  UNION " +
60
                                            "(SELECT DISTINCT docid FROM xml_nodes WHERE UPPER(nodedata) LIKE '%VALUE2%' AND parentnodeid IN " +
61
                                            "(SELECT nodeid FROM xml_index WHERE path LIKE 'path2') ) ))";
62
    
63
    /**
64
     * Constructor to build the test
65
     * 
66
     * @param name the name of the test method
67
     */
68
    public QueryGroupTest(String name)
69
    {
70
        super(name);
71
    }
72
    /**
73
     * Establishes a testing framework by initializing appropriate objects.
74
     */
75
    protected void setUp() throws Exception
76
    {
77
      super.setUp();
78
   
79
    }
80

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

    
91
  
92

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

    
140
   
141
}
(15-15/24)