Author: natalia Date: Mon Jul 23 18:21:17 2007 New Revision: 558906 URL: http://svn.apache.org/viewvc?view=rev&rev=558906 Log: NameIndexer tests. One test is failing.
Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/NameIndexerTest.java (with props) Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/NameIndexerTest.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/NameIndexerTest.java?view=auto&rev=558906 ============================================================================== --- xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/NameIndexerTest.java (added) +++ xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/NameIndexerTest.java Mon Jul 23 18:21:17 2007 @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.xindice.core.indexer; + +import junit.framework.TestCase; +import org.apache.xindice.core.Database; +import org.apache.xindice.core.Collection; +import org.apache.xindice.core.DatabaseTest; +import org.apache.xindice.core.DBException; +import org.apache.xindice.core.indexer.helpers.IndexQueryANY; +import org.apache.xindice.util.Configuration; +import org.apache.xindice.xml.dom.DOMParser; +import org.w3c.dom.Document; + +/** + * Tests indexed queries + * + * @version $Revision$, $Date$ + */ +public class NameIndexerTest extends TestCase { + + private Database db; + private Collection collection; + protected String indexClass; + + + public NameIndexerTest(String name) { + super(name); + indexClass = "org.apache.xindice.core.indexer.NameIndexer"; + } + + public void setUp() throws Exception { + String name = getClass().getName(); + db = new Database(); + db.setConfig(new Configuration(DOMParser.toDocument(DatabaseTest.DATABASE))); + collection = db.createCollection(name, new Configuration( + DOMParser.toDocument( + "<collection compressed='true' name='" + name + "' inline-metadata='true'>" + + "<filer class='org.apache.xindice.core.filer.BTreeFiler'/>" + + "</collection>"), false + )); + } + + public void tearDown() throws Exception { + db.dropCollection(collection); + db.close(); + } + + private Indexer createIndex(String name, String pattern) throws Exception { + String config = "<index name='" + name + "' " + + "class='" + indexClass + "' " + + "pattern='" + pattern + "'/>"; + Indexer ind = collection.createIndexer(new + Configuration(DOMParser.toDocument(config))); + Thread.sleep(100); + return ind; + } + + private IndexMatch[] query(Indexer ind, String pattern) throws DBException { + return ind.queryMatches(new IndexQueryANY(new IndexPattern(collection.getSymbols(), pattern, null))); + } + + public void testElementIndex() throws Exception { + Indexer ind = createIndex("index", "test"); + + Document document = DOMParser.toDocument("<a><test>q</test></a>"); + collection.insertDocument("key1", document); + + document = DOMParser.toDocument("<a><test/></a>"); + collection.insertDocument("key2", document); + + document = DOMParser.toDocument("<a><test value='abc'/></a>"); + collection.insertDocument("key3", document); + + IndexMatch[] match = query(ind, "test"); + + assertEquals(3, match.length); + } + + public void testAttributeIndex() throws Exception { + Indexer ind = createIndex("index", "[EMAIL PROTECTED]"); + + Document document = DOMParser.toDocument("<a><test value='abc'>q</test></a>"); + collection.insertDocument("key1", document); + + document = DOMParser.toDocument("<a><test/></a>"); + collection.insertDocument("key2", document); + + document = DOMParser.toDocument("<a><test value=''/></a>"); + collection.insertDocument("key3", document); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]"); + + assertEquals(2, match.length); + } +} Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/NameIndexerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/NameIndexerTest.java ------------------------------------------------------------------------------ svn:keywords = Id Revision Author Date