[exo-jcr-commits] exo-jcr SVN: r229 - in jcr/trunk/component/core: src/test/java/org/exoplatform/services/jcr/impl/core/query and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Oct 5 11:05:58 EDT 2009
Author: skabashnyuk
Date: 2009-10-05 11:05:57 -0400 (Mon, 05 Oct 2009)
New Revision: 229
Modified:
jcr/trunk/component/core/pom.xml
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestIndexingConfig.java
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/usecases/TestExcerpt.java
Log:
EXOJCR-161 : test updated
Modified: jcr/trunk/component/core/pom.xml
===================================================================
--- jcr/trunk/component/core/pom.xml 2009-10-05 14:56:26 UTC (rev 228)
+++ jcr/trunk/component/core/pom.xml 2009-10-05 15:05:57 UTC (rev 229)
@@ -430,9 +430,6 @@
<include>**/impl/**/Test*.java</include>
</includes>
<excludes>
- <exclude>**/TestIndexingConfig.java</exclude>
- <exclude>**/TestExcerpt.java</exclude>
-
<exclude>**/TestImport.java</exclude>
<exclude>**/TestRollbackBigFiles.java</exclude>
<exclude>**/TestErrorMultithreading.java</exclude>
Modified: jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestIndexingConfig.java
===================================================================
--- jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestIndexingConfig.java 2009-10-05 14:56:26 UTC (rev 228)
+++ jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestIndexingConfig.java 2009-10-05 15:05:57 UTC (rev 229)
@@ -28,11 +28,18 @@
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.BooleanClause.Occur;
import org.exoplatform.services.jcr.impl.core.NodeImpl;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
+import org.exoplatform.services.jcr.impl.core.query.lucene.FieldNames;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexingConfigurationImpl;
+import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import java.io.IOException;
+
import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
/**
* Created by The eXo Platform SAS.
@@ -42,6 +49,10 @@
*/
public class TestIndexingConfig extends BaseQueryTest
{
+ private final String workspaceName = "ws2";
+
+ private final String repositoryName = "db1tck";
+
public final String testString1 = "The quick brown fox jumped over the lazy dogs";
public final String testString2 = "XY&Z Corporation - xyz at example.com";
@@ -64,16 +75,33 @@
*/
private final Log log = ExoLogger.getLogger("jcr.TestIndexingConfig");
+ private SearchManager searchManager;
+
+ private SearchIndex searchIndex;
+
+ private Session testSession;
+
@Override
public void setUp() throws Exception
{
super.setUp();
- IndexingConfigurationImpl indexingConfigurationImpl =
- (IndexingConfigurationImpl)defaultSearchIndex.getIndexingConfig();
-// indexingConfigurationImpl.setPropertyAnalyzer("FULL:" + simple, new SimpleAnalyzer());
-// indexingConfigurationImpl.setPropertyAnalyzer("FULL:" + whitespace, new WhitespaceAnalyzer());
-// indexingConfigurationImpl.setPropertyAnalyzer("FULL:" + stop, new StopAnalyzer());
- testRoot = root.addNode("testrootAnalyzers");
+
+ RepositoryImpl db1tckRepo = (RepositoryImpl)repositoryService.getRepository(repositoryName);
+ assertNotNull(db1tckRepo);
+ testSession = db1tckRepo.login(credentials, workspaceName);
+
+ searchManager = (SearchManager)db1tckRepo.getWorkspaceContainer(workspaceName).getComponent(SearchManager.class);
+ assertNotNull(searchManager);
+ searchIndex = (SearchIndex)(searchManager.getHandler());
+ assertNotNull(searchIndex);
+
+ IndexingConfigurationImpl indexingConfigurationImpl = (IndexingConfigurationImpl)searchIndex.getIndexingConfig();
+ assertNotNull(indexingConfigurationImpl);
+
+ indexingConfigurationImpl.addPropertyAnalyzer("FULL:" + simple, new SimpleAnalyzer());
+ indexingConfigurationImpl.addPropertyAnalyzer("FULL:" + whitespace, new WhitespaceAnalyzer());
+ indexingConfigurationImpl.addPropertyAnalyzer("FULL:" + stop, new StopAnalyzer());
+ testRoot = testSession.getRootNode().addNode("testrootAnalyzers");
root.save();
}
@@ -81,7 +109,7 @@
public void tearDown() throws Exception
{
testRoot.remove();
- root.save();
+ testSession.save();
super.tearDown();
}
@@ -95,14 +123,14 @@
Node testNode2 = testRoot.addNode("node2");
testNode2.setProperty(simple, testString2);
- root.save();
+ testSession.save();
// Test is there are all terms
// There must be [the] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dogs]
// in Node1
Document doc = this.getDocument(testNode1.getInternalIdentifier(), false);
- System.out.println(doc);
+ assertNotNull(doc);
TermQuery the = new TermQuery(new Term("FULL:" + simple, "the"));
TermQuery quick = new TermQuery(new Term("FULL:" + simple, "quick"));
@@ -123,7 +151,7 @@
compl.add(lazy, Occur.MUST);
compl.add(dogs, Occur.MUST);
- IndexReader ir = defaultSearchIndex.getIndexReader();
+ IndexReader ir = searchIndex.getIndexReader();
IndexSearcher is = new IndexSearcher(ir);
Hits hits = is.search(compl);
@@ -171,7 +199,7 @@
Node testNode2 = testRoot.addNode("node2");
testNode2.setProperty(whitespace, testString2);
- root.save();
+ testSession.save();
// Test is there are all terms
// There must be [The] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dogs]
@@ -198,7 +226,7 @@
compl.add(lazy, Occur.MUST);
compl.add(dogs, Occur.MUST);
- IndexReader ir = defaultSearchIndex.getIndexReader();
+ IndexReader ir = searchIndex.getIndexReader();
IndexSearcher is = new IndexSearcher(ir);
Hits hits = is.search(compl);
@@ -241,7 +269,7 @@
Node testNode2 = testRoot.addNode("node2");
testNode2.setProperty(stop, testString2);
- root.save();
+ testSession.save();
// Test is there are all terms
// There must be [quick] [brown] [fox] [jumped] [over] [lazy] [dogs]
@@ -264,7 +292,7 @@
compl.add(lazy, Occur.MUST);
compl.add(dogs, Occur.MUST);
- IndexReader ir = defaultSearchIndex.getIndexReader();
+ IndexReader ir = searchIndex.getIndexReader();
IndexSearcher is = new IndexSearcher(ir);
Hits hits = is.search(compl);
@@ -313,7 +341,7 @@
Node testNode2 = testRoot.addNode("node2");
testNode2.setProperty(def, testString2);
- root.save();
+ testSession.save();
// Test is there are all terms
// There must be [quick] [brown] [fox] [jumped] [over] [lazy] [dogs]
@@ -338,7 +366,7 @@
compl.add(lazy, Occur.MUST);
compl.add(dogs, Occur.MUST);
- IndexReader ir = defaultSearchIndex.getIndexReader();
+ IndexReader ir = searchIndex.getIndexReader();
IndexSearcher is = new IndexSearcher(ir);
Hits hits = is.search(compl);
@@ -372,4 +400,20 @@
}
}
+ protected Document getDocument(String nodeIdentifer, boolean includeSystemIndex) throws IOException,
+ RepositoryException
+ {
+ IndexReader reader = ((SearchIndex)searchManager.getHandler()).getIndexReader();
+ IndexSearcher is = new IndexSearcher(reader);
+ TermQuery query = new TermQuery(new Term(FieldNames.UUID, nodeIdentifer));
+
+ Hits result = is.search(query);
+
+ if (result.length() == 1)
+ return result.doc(0);
+ else if (result.length() > 1)
+ throw new RepositoryException("Results more then one");
+
+ return null;
+ }
}
Modified: jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/usecases/TestExcerpt.java
===================================================================
--- jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/usecases/TestExcerpt.java 2009-10-05 14:56:26 UTC (rev 228)
+++ jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/usecases/TestExcerpt.java 2009-10-05 15:05:57 UTC (rev 229)
@@ -18,12 +18,14 @@
*/
package org.exoplatform.services.jcr.usecases;
+import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
import java.io.InputStream;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
@@ -43,13 +45,26 @@
+ "org.exoplatform.services.jcr.impl.core.query.lucene.DefaultHTMLExcerpt. "
+ "the configuration parameter for this setting is:" + "This is the test for Excerpt query";
+ private String string1_excerpt =
+ "<div><span>the configuration parameter for this setting is:This is the "
+ + "<strong>test</strong> for Excerpt query</span></div>";
+
private String s2 =
- "It is a test for Excerpt query."
- + "Searching with synonyms is integrated in the jcr:contains() function and uses the same syntax "
- + "like synonym searches with Google. If a search term is prefixed with ~ also synonyms of the search term are considered. Example:";
+ "It is a test for Excerpt query.Searching with synonyms is integrated in the jcr:contains() "
+ + "function and uses the same syntax " + "like synonym searches with Google. If a search "
+ + "term is prefixed with ~ also synonyms of the search term are considered. Example:";
+ private String string2_excerpt =
+ "<div><span>Node2 It is a <strong>test</strong> for Excerpt query."
+ + "Searching with synonyms is integrated in the jcr:contains() function and "
+ + "uses the same syntax like synonym ...</span></div>";
+
private String s3 = "JCR supports such features as Lucene Fuzzy Searches";
+ private Session testSession;
+
+ private Node testRoot;
+
/**
* Initialization flag.
*/
@@ -72,43 +87,71 @@
}
}
+ /**
+ * @see org.exoplatform.services.jcr.BaseStandaloneTest#setUp()
+ */
+ @Override
+ public void setUp() throws Exception
+ {
+ // TODO Auto-generated method stub
+ super.setUp();
+ ManageableRepository db1tckRepo = repositoryService.getRepository("db1tck");
+ assertNotNull(db1tckRepo);
+ testSession = db1tckRepo.login(credentials, "ws2");
+ testRoot = testSession.getRootNode();
+ }
+
public void testExcerpt() throws Exception
{
- System.out.println("\n\n----------Test Excerpt");
- Node node1 = root.addNode("Node1", "exo:article");
+ Node node1 = testRoot.addNode("Node1", "exo:article");
node1.setProperty("exo:title", "Node1");
node1.setProperty("exo:text", s1);
- Node node2 = root.addNode("Node2", "exo:article");
+ Node node2 = testRoot.addNode("Node2", "exo:article");
node2.setProperty("exo:title", "Node2");
node2.setProperty("exo:text", s2);
- Node node3 = root.addNode("Node3", "exo:article");
+ Node node3 = testRoot.addNode("Node3", "exo:article");
node3.setProperty("exo:title", "Node3");
node3.setProperty("exo:text", s3);
- session.save();
+ testSession.save();
- System.out.println("\n\n-----Test with SQL");
- QueryManager queryManager = session.getWorkspace().getQueryManager();
- Query q1 = queryManager.createQuery("select excerpt(.) from exo:article where contains(., 'test')", Query.SQL);
+ QueryManager queryManager = testSession.getWorkspace().getQueryManager();
+ Query q1 =
+ queryManager.createQuery("select exo:text, excerpt(.) from exo:article where contains(., 'test')", Query.SQL);
QueryResult result1 = q1.execute();
for (RowIterator it = result1.getRows(); it.hasNext();)
{
Row r = it.nextRow();
Value excerpt = r.getValue("rep:excerpt(.)");
- System.out.println("\n\n---" + excerpt.getString());
+ Value text = r.getValue("exo:text");
+ if (text.getString().equals(s1))
+ {
+ assertEquals(string1_excerpt, excerpt.getString());
+ }
+ else if (text.getString().equals(s2))
+ {
+ assertEquals(string2_excerpt, excerpt.getString());
+ }
}
- System.out.println("\n\n-----Test with XPATH");
Query q2 = queryManager.createQuery("//*[jcr:contains(., 'test')]/(@exo:text|rep:excerpt(.))", Query.XPATH);
QueryResult result2 = q2.execute();
for (RowIterator it = result2.getRows(); it.hasNext();)
{
Row r = it.nextRow();
Value excerpt = r.getValue("rep:excerpt(.)");
- System.out.println("\n\n---" + excerpt.getString());
+ Value text = r.getValue("exo:text");
+ if (text.getString().equals(s1))
+ {
+ assertEquals(string1_excerpt, excerpt.getString());
+ }
+ else if (text.getString().equals(s2))
+ {
+ assertEquals(string2_excerpt, excerpt.getString());
+ }
}
}
}
More information about the exo-jcr-commits
mailing list