01: /*
02: * Piscator: a small SQL/XML search engine
03: * Copyright (C) 2007 Luk Morbee
04: *
05: * This program is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU General Public License as published by
07: * the Free Software Foundation; either version 2 of the License, or
08: * (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: */
19: package piscator.junit;
20:
21: import java.io.File;
22:
23: import junit.framework.TestCase;
24:
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27:
28: import piscator.SearchEngine;
29:
30: public class SearchEngineTest extends TestCase {
31:
32: private static Log LOG = LogFactory.getLog(SearchEngineTest.class);
33:
34: private static SearchEngine searchEngine = null;
35:
36: /* (non-Javadoc)
37: * @see junit.framework.TestCase#setUp()
38: */
39: protected void setUp() throws Exception {
40: if (searchEngine == null) {
41: searchEngine = new SearchEngine();
42: File documentsFile = new File(".\\xml\\test-documents.xml");
43: File configFile = new File(".\\xml\\test-config.xml");
44: searchEngine.load(documentsFile, configFile);
45: }
46: }
47:
48: public static void main(String[] args) {
49: junit.textui.TestRunner.run(SearchEngineTest.class);
50: }
51:
52: public void test1() {
53: String xml = searchEngine
54: .getXML("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES WHERE table_schem='PUBLIC'");
55: LOG.info(xml);
56: boolean actual = (xml.indexOf("table_name=\"DOCUMENT\"") != -1)
57: && (xml.indexOf("table_name=\"PROPERTY\"") != -1)
58: && (xml.indexOf("table_name=\"UNIT\"") != -1);
59: assertEquals(true, actual);
60: }
61:
62: public void test2() {
63: String xml = searchEngine
64: .getDocuments("select xml, reference from document d, property p where d.doc_id = p.doc_id and sector = 'Industrial' order by reference desc");
65: LOG.info(xml);
66: assertEquals(
67: true,
68: xml
69: .startsWith("<Property Dimensions=\"M\" Reference=\"ZONING INDUSTRIEL TOURNAI OUEST\">"));
70: }
71:
72: public void test3() {
73: String xml = searchEngine
74: .getDocuments("select xml, min_area from document d, property p, unit u where d.doc_id = p.doc_id and p.doc_id = u.doc_id and 200 > min_area and 200 < max_area and postcode in (2000, 1000) order by min_area");
75: LOG.info(xml);
76: assertEquals(
77: true,
78: xml
79: .startsWith("<Property Dimensions=\"M\" Reference=\"THE LOFTHOUSE\">"));
80: }
81:
82: public void test4() {
83: String xml = searchEngine
84: .getXML("select * from (select count(doc_id) as properties, postcode from property group by postcode) order by properties desc");
85: LOG.info(xml);
86: int actual = xml
87: .indexOf("<row properties=\"29\" postcode=\"1000\"/>");
88: assertEquals(178, actual);
89: }
90:
91: }
|