Author: natalia Date: Tue Jul 24 18:42:23 2007 New Revision: 559274 URL: http://svn.apache.org/viewvc?view=rev&rev=559274 Log: Tests for Name/Value indexers on empty elements. Result checking fixed.
Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java?view=diff&rev=559274&r1=559273&r2=559274 ============================================================================== --- xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java (original) +++ xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java Tue Jul 24 18:42:23 2007 @@ -74,13 +74,13 @@ if (!aCollectionCreated) { try { - this.client.dropCollection(PARENT_COLLECTION_PATH, COLLECTION_NAME); + client.dropCollection(PARENT_COLLECTION_PATH, COLLECTION_NAME); } catch (Exception anException) { /* * ignore problems during drop collection above... */ } finally { - this.client.createCollection(PARENT_COLLECTION_PATH, COLLECTION_NAME); + client.createCollection(PARENT_COLLECTION_PATH, COLLECTION_NAME); aCollectionCreated = true; } } @@ -104,7 +104,7 @@ " <last>Jones" + aNumber + "</last>" + " <phone type='home'>555-345-6789</phone>" + "</person>"; - this.client.insertDocument(COLLECTION_PATH, "doc" + String.valueOf(anIndex), aDocument); + client.insertDocument(COLLECTION_PATH, "doc" + String.valueOf(anIndex), aDocument); } } @@ -192,10 +192,9 @@ */ public void runTest() throws Exception { try { - Result aResult; addTestDocuments(); - aResult = runNonIndexed(); + Result aResult = runNonIndexed(); checkResult(aResult); long aNonIndexedTime = aResult.getElapsedTime(); aResult = runIndexed(); @@ -270,12 +269,12 @@ } if (itsExpectedResources != null && itsExpectedResources.length > 1) { - for (int anIndex = 0; anIndex < itsExpectedResources.length / 2; anIndex += 2) { + for (int anIndex = 0; anIndex < itsExpectedResources.length / 2; anIndex++) { XMLResource aResource = (XMLResource) aResourceSet.getResource(anIndex); Node aNode = aResource.getContentAsDOM(); - int anExpectedSourceDocumentIndex = ((Integer) itsExpectedResources[anIndex]).intValue(); - String anExpected = "<?xml version=\"1.0\"?>\n" + addSource((String) itsExpectedResources[anIndex + 1], - TEST_DOCUMENT_PREFIX + anIndex, + int anExpectedSourceDocumentIndex = ((Integer) itsExpectedResources[anIndex * 2]).intValue(); + String anExpected = "<?xml version=\"1.0\"?>\n" + addSource((String) itsExpectedResources[anIndex * 2 + 1], + TEST_DOCUMENT_PREFIX + anExpectedSourceDocumentIndex, IndexedSearchTest.COLLECTION_PATH); String anActual = TextWriter.toString(aNode); //itsLog.info(itsDescription); @@ -284,7 +283,7 @@ //itsLog.info(anExpected); //itsLog.info("Actual:"); //itsLog.info(anActual); - XMLAssert.assertXMLEqual("While checking target Resource " + anIndex / 2, + XMLAssert.assertXMLEqual("While checking target Resource " + anIndex, anExpected, anActual); } } @@ -317,10 +316,10 @@ */ public void createIndex() throws Exception { if (!itsIndexCreated) { - IndexedSearchTest.this.client.createIndexer(COLLECTION_PATH, - "<?xml version='1.0'?><index name='" + itsTestIndexName + "' " + - "class='org.apache.xindice.core.indexer." + itsTestIndexType + "Indexer' " + - "pattern='" + itsTestIndexPattern + "' />"); + client.createIndexer(COLLECTION_PATH, + "<?xml version='1.0'?><index name='" + itsTestIndexName + "' " + + "class='org.apache.xindice.core.indexer." + itsTestIndexType + "Indexer' " + + "pattern='" + itsTestIndexPattern + "' />"); itsIndexCreated = true; // Wait for the indexer to do the background indexing @@ -333,7 +332,7 @@ */ public void dropIndex() throws Exception { if (itsIndexCreated) { - IndexedSearchTest.this.client.dropIndexer(COLLECTION_PATH, itsTestIndexName); + client.dropIndexer(COLLECTION_PATH, itsTestIndexName); itsIndexCreated = false; } } @@ -386,22 +385,40 @@ "<?xml version='1.0'?>" + "<person number3='yes'>" + "<first surname='no' given='yes'>Sally</first>" + - "<last surname='yes'>aSm</last>" + + "<last surname='yes'>Sam</last>" + "<phone call='no' type='work'>555-345-6789</phone>" + - "<address> " + + "<address>" + "<street>" + "<number given='no' />" + "</street>" + "</address>" + + "</person>", + + "<?xml version='1.0'?>" + + "<person number3='yes'>" + + "<first surname='no' given='yes'>Sally</first>" + + "<last surname='yes'>Sam</last>" + + "<phone call='no' type='work'>555-345-6789</phone>" + + "<address>" + + "<street>" + + "<number given='no' />Main St" + + "</street>" + + "</address>" + "</person>" }, - 1, // expected result count + 2, // expected result count new Object[] { // expected resources to check for (can be empty or partial set) - new Integer(1), - "<address> " + + new Integer(0), + "<address>" + "<street>" + "<number given='no' />" + "</street>" + + "</address>", + new Integer(1), + "<address>" + + "<street>" + + "<number given='no' />Main St" + + "</street>" + "</address>" }); @@ -428,7 +445,7 @@ "<second surname='no' given='yes'>Wally</second>" + "<last surname='yes'>aSm</last>" + "<phone call='no' type='work'>555-345-6789</phone>" + - "<address> " + + "<address>" + "<street>" + "<number given='no' />" + "</street>" + @@ -437,7 +454,7 @@ }, 1, // expected result count new Object[] { // expected resources to check for (can be empty or partial set) - new Integer(1), + new Integer(0), "<second surname='no' given='yes'>Wally</second>" }); @@ -464,7 +481,7 @@ "<first surname='no' given='yes'>Sally</first>" + "<last surname='yes'>aSm</last>" + "<phone call='no' type='work'>555-345-6789</phone>" + - "<address> " + + "<address>" + "<street>" + "<number given='no' />" + "</street>" + @@ -473,7 +490,7 @@ }, 1, // expected result count new Object[] { // expected resources to check for (can be empty or partial set) - new Integer(1), + new Integer(0), "<phone call='no' type='work'>555-345-6789</phone>" }); @@ -501,7 +518,7 @@ "<second surname='no' given='yes'>Wally</second>" + "<last surname='yes'>aSm</last>" + "<phone call='no' type='work'>555-345-6789</phone>" + - "<address> " + + "<address>" + "<street>" + "<number given='no' />" + "</street>" + @@ -510,7 +527,7 @@ }, 1, // expected result count new Object[] { // expected resources to check for (can be empty or partial set) - new Integer(1), + new Integer(0), "<second surname='no' given='yes'>Wally</second>", }); @@ -537,7 +554,7 @@ "<first surname='no' given='yes'>Sally</first>" + "<last surname='yes'>aSm</last>" + "<phone call='no' type='work'>555-345-6789</phone>" + - "<address> " + + "<address>" + "<street>" + "<number given='no' />" + "</street>" + @@ -546,15 +563,8 @@ }, 2, // expected result count new Object[] { // expected resources to check for (can be empty or partial set) - new Integer(1), - "<first surname='no' given='yes'>Sally</first>", - - new Integer(1), - "<address> " + - "<street>" + - "<number given='no' />" + - "</street>" + - "</address>" + new Integer(0), "<first surname='no' given='yes'>Sally</first>", + new Integer(0), "<number given='no' />" }); aTest.runTest(); @@ -581,7 +591,7 @@ "<first surname='no' given='yes'>Sally</first>" + "<last surname='yes'>aSm</last>" + "<phone call='no' type='work'>555-345-6789</phone>" + - "<address> " + + "<address>" + "<street>" + "<number given='no' />" + "</street>" + @@ -590,8 +600,8 @@ }, 2, // expected result count new Object[] { // expected resources to check for (can be empty or partial set) - new Integer(1), "<first surname='no' given='yes'>Sally</first>", - new Integer(1), "<number given='no' />" + new Integer(0), "<first surname='no' given='yes'>Sally</first>", + new Integer(0), "<number given='no' />" }); aTest.runTest(); @@ -638,7 +648,7 @@ }, 2, // expected result count new Object[] { // expected resources to check for (can be empty or partial set) - new Integer(1), "<person number3='yes'>" + + new Integer(0), "<person number3='yes'>" + "<first surname='no' given='yes'>Sally</first>" + "<last surname='yes'>Smith</last>" + "<phone call='no' type='work'>555-345-6789</phone>" + @@ -649,7 +659,7 @@ "</address>" + "</person>", - new Integer(2), "<person number3='yes'>" + + new Integer(1), "<person number3='yes'>" + "<first surname='no' given='yes'>Sally</first>" + "<last surname='yes'>Smithers</last>" + "<phone call='no' type='work'>555-345-6789</phone>" + @@ -693,7 +703,7 @@ }, 1, // expected result count new Object[] { // expected resources to check for (can be empty or partial set) - new Integer(1), "<phone call='no' type='work'>555-345-6789</phone>" + new Integer(0), "<phone call='no' type='work'>555-345-6789</phone>" }); aTest.runTest(); @@ -740,8 +750,59 @@ }, 2, // expected result count new Object[] { // expected resources to check for (can be empty or partial set) - new Integer(1), "<phone call='no' type='work'>555-345-6789</phone>", + new Integer(0), "<phone call='no' type='work'>555-345-6789</phone>", new Integer(1), "<phone call='no' type='work'>525-345-6789</phone>" + }); + + aTest.runTest(); + } + + /** + * Tests an equals search query for an empty Element value that should be resolvable using + * indexed searching on a value index. + */ + public void testSpecificElementNoAttributeValueIndexedEmptyStringSearch() + throws Exception { + // search all records whose address is empty + IndexerTestDefinition aTest = new IndexerTestDefinition( + "testSpecificElementNoAttributeValueIndexedEqualsSearch", // description + "//address[. = '']", // query + "SENA", // index name + "Value", // index type + "address", // index pattern + 8, // indexed query speedup expected (conservative) + new String[] { // test docs specifically for this test + "<?xml version='1.0'?>" + + "<person number3='yes'>" + + "<first surname='no' given='yes'>Sally</first>" + + "<last surname='yes'>Smith</last>" + + "<phone call='no' type='work'>555-345-6789</phone>" + + "<address>" + + "<street>" + + "<number given='no' />" + + "</street>" + + "</address>" + + "</person>", + + "<?xml version='1.0'?>" + + "<person number3='yes'>" + + "<first surname='no' given='yes'>Sally</first>" + + "<last surname='yes'>Smithers</last>" + + "<phone call='no' type='work'>555-345-6789</phone>" + + "<address>" + + "<street>" + + "<number given='no' />Main St" + + "</street>" + + "</address>" + + "</person>" + }, + 1, // expected result count + new Object[] { // expected resources to check for (can be empty or partial set) + new Integer(0), "<address>" + + "<street>" + + "<number given='no' />" + + "</street>" + + "</address>" }); aTest.runTest();