Author: erwan
Date: Sun Dec 19 15:57:13 2010 New Revision: 1050883 URL: http://svn.apache.org/viewvc?rev=1050883&view=rev Log: Adding test and test data for lucene search Added: ofbiz/trunk/applications/content/src/org/ofbiz/content/test/ ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java ofbiz/trunk/applications/content/testdef/ ofbiz/trunk/applications/content/testdef/data/ ofbiz/trunk/applications/content/testdef/data/LuceneTestsData.xml ofbiz/trunk/applications/content/testdef/lucenetests.xml Modified: ofbiz/trunk/applications/content/build.xml ofbiz/trunk/applications/content/ofbiz-component.xml Modified: ofbiz/trunk/applications/content/build.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/build.xml?rev=1050883&r1=1050882&r2=1050883&view=diff ============================================================================== --- ofbiz/trunk/applications/content/build.xml (original) +++ ofbiz/trunk/applications/content/build.xml Sun Dec 19 15:57:13 2010 @@ -54,4 +54,9 @@ under the License. <exclude name="org/ofbiz/content/report/JRMapCollectionDataSource.java"/> <exclude name="org/ofbiz/content/openoffice/*.java"/> </patternset> + + <target name="jar" depends="classes"> + <main-jar/> + <test-jar/> + </target> </project> Modified: ofbiz/trunk/applications/content/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/ofbiz-component.xml?rev=1050883&r1=1050882&r2=1050883&view=diff ============================================================================== --- ofbiz/trunk/applications/content/ofbiz-component.xml (original) +++ ofbiz/trunk/applications/content/ofbiz-component.xml Sun Dec 19 15:57:13 2010 @@ -64,6 +64,9 @@ under the License. <service-resource type="model" loader="main" location="servicedef/services_website.xml"/> <service-resource type="eca" loader="main" location="servicedef/secas.xml"/> <service-resource type="mca" loader="main" location="servicedef/mca.xml"/> + + <test-suite loader="main" location="testdef/lucenetests.xml"/> + <webapp name="content" title="Content" server="default-server" Added: ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java?rev=1050883&view=auto ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java (added) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java Sun Dec 19 15:57:13 2010 @@ -0,0 +1,88 @@ +/* + 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. + */ + +package org.ofbiz.content.test; + +import javolution.util.FastMap; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.Term; +import org.apache.lucene.queryParser.QueryParser; +import org.apache.lucene.search.*; +import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.util.Version; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.content.search.SearchWorker; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.service.testtools.OFBizTestCase; + +import java.io.File; +import java.util.List; +import java.util.Map; + +public class LuceneTests extends OFBizTestCase { + + protected GenericValue userLogin = null; + + public LuceneTests(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); + } + + @Override + protected void tearDown() throws Exception { + //destruction index + } + + public void testCreateIndex() throws Exception { + Map ctx = FastMap.newInstance(); + ctx.put("contentId", "WebStoreCONTENT"); + ctx.put("userLogin", userLogin); + Map resp = dispatcher.runSync("indexTree", ctx); + + assertEquals(7, resp.get("goodIndexCount")); + + List<String> badIndexList = (List<String>) resp.get("badIndexList"); + assertEquals(8, badIndexList.size()); + } + + public void testSearchTermHand() throws Exception { + BooleanQuery combQuery = new BooleanQuery(); + String queryLine = "hand"; + IndexReader reader = IndexReader.open(FSDirectory.open(new File(SearchWorker.getIndexPath(null))), true); + + Searcher searcher = new IndexSearcher(reader); + Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30); + + QueryParser parser = new QueryParser(Version.LUCENE_30, "content", analyzer); + Query query = parser.parse(queryLine); + combQuery.add(query, BooleanClause.Occur.MUST); + + TopScoreDocCollector collector = TopScoreDocCollector.create(10, false); + searcher.search(combQuery, collector); + + assertEquals("Only 1 result expected from the testdata", 1, collector.getTotalHits()); + } +} Added: ofbiz/trunk/applications/content/testdef/data/LuceneTestsData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/testdef/data/LuceneTestsData.xml?rev=1050883&view=auto ============================================================================== --- ofbiz/trunk/applications/content/testdef/data/LuceneTestsData.xml (added) +++ ofbiz/trunk/applications/content/testdef/data/LuceneTestsData.xml Sun Dec 19 15:57:13 2010 @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> + +<entity-engine-xml> + <DataResource dataResourceId="CNTGIZMOSLRG" dataResourceTypeId="ELECTRONIC_TEXT" mimeTypeId="text/html" localeString="en_US" isPublic="Y" dataResourceName="Large Gizmos"/> + <ElectronicText dataResourceId="CNTGIZMOSLRG"> + <textData><![CDATA[ + <div class="tabletext"> + <ol> + <li>Large Gizmos are for those who loves them large!</li> + <li>A lot of them and more to come</li> + </ol> + </div> + ]]></textData> + </ElectronicText> + <DataResource dataResourceId="CNTGIZMOSSML" dataResourceTypeId="ELECTRONIC_TEXT" mimeTypeId="text/html" localeString="en_US" isPublic="Y" dataResourceName="Small Gizmos"/> + <ElectronicText dataResourceId="CNTGIZMOSSML"> + <textData><![CDATA[ + <div class="tabletext"> + <ol> + <li>Not only for children</li> + <li>Just need to be able to hold it in your hand</li> + </ol> + </div> + ]]></textData> + </ElectronicText> + <DataResource dataResourceId="GIZMOSLRG" dataResourceTypeId="ELECTRONIC_TEXT" mimeTypeId="text/html" localeString="en_US" isPublic="Y" dataResourceName="Advocacy"/> + <ElectronicText dataResourceId="GIZMOSLRG"> + <textData><![CDATA[ + <div class="tabletext"> + <ol> + <li>Gizmos are the best ones</li> + <li>Don't use widgets, use gizmos !</li> + </ol> + </div> + ]]></textData> + </ElectronicText> + + <Content contentId="CNTGIZMOSLRG" contentTypeId="WEB_SITE_PUB_PT" ownerContentId="CNTGIZMOS" contentName="Large Gizmos" description="Large Widgets" createdDate="2001-05-13 12:00:00.000" createdByUserLogin="admin" + dataResourceId="CNTGIZMOSLRG" mimeTypeId="text/html" localeString="en_US"/> + <Content contentId="CNTGIZMOSSML" contentTypeId="WEB_SITE_PUB_PT" ownerContentId="CNTGIZMOS" contentName="Small Gizmos" description="Large Widgets" createdDate="2001-05-13 12:00:00.000" createdByUserLogin="admin" + dataResourceId="CNTGIZMOSSML" mimeTypeId="text/html" localeString="en_US"/> + <Content contentId="GIZMOSLRG" contentTypeId="WEB_SITE_PUB_PT" ownerContentId="CNTGIZMOS" contentName="Advocacy" description="Advocacy" createdDate="2001-05-13 12:00:00.000" createdByUserLogin="admin" + dataResourceId="GIZMOSLRG" mimeTypeId="text/html" localeString="en_US"/> +</entity-engine-xml> \ No newline at end of file Added: ofbiz/trunk/applications/content/testdef/lucenetests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/testdef/lucenetests.xml?rev=1050883&view=auto ============================================================================== --- ofbiz/trunk/applications/content/testdef/lucenetests.xml (added) +++ ofbiz/trunk/applications/content/testdef/lucenetests.xml Sun Dec 19 15:57:13 2010 @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + 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. + --> + +<test-suite suite-name="lucenetests" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd"> + + <test-case case-name="lucene-tests-data-load"> + <entity-xml action="load" entity-xml-url="component://content/testdef/data/LuceneTestsData.xml"/> + </test-case> + + <test-case case-name="lucene-tests"><junit-test-suite class-name="org.ofbiz.content.test.LuceneTests"/></test-case> + +</test-suite> |
Free forum by Nabble | Edit this page |