Author: skabashnyuk
Date: 2009-10-02 11:39:10 -0400 (Fri, 02 Oct 2009)
New Revision: 196
Removed:
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestIndexRules.java
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestNodeIndexer.java
Modified:
jcr/trunk/component/core/src/test/java/conf/standalone/test-jcr-config.xml
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestErrorLog.java
Log:
EXOJCR-161 : test update
Modified: jcr/trunk/component/core/src/test/java/conf/standalone/test-jcr-config.xml
===================================================================
--- jcr/trunk/component/core/src/test/java/conf/standalone/test-jcr-config.xml 2009-10-02
09:10:30 UTC (rev 195)
+++ jcr/trunk/component/core/src/test/java/conf/standalone/test-jcr-config.xml 2009-10-02
15:39:10 UTC (rev 196)
@@ -298,6 +298,7 @@
<property name="support-highlighting"
value="true" />
<property name="indexing-configuration-path"
value="../../indexing-configuration.xml" />
<property name="query-class"
value="org.exoplatform.services.jcr.impl.core.query.QueryImpl" />
+ <property name="excerptprovider-class"
value="org.exoplatform.services.jcr.impl.core.query.lucene.WeightedHTMLExcerpt"
/>
<property name="spellchecker-class"
value="org.exoplatform.services.jcr.impl.core.query.lucene.spell.LuceneSpellChecker$FiveSecondsRefreshInterval"
/>
</properties>
</query-handler>
Modified:
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestErrorLog.java
===================================================================
---
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestErrorLog.java 2009-10-02
09:10:30 UTC (rev 195)
+++
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestErrorLog.java 2009-10-02
15:39:10 UTC (rev 196)
@@ -26,158 +26,137 @@
import java.util.Set;
/**
- * Created by The eXo Platform SAS Author : Sergey Karpenko
<sergey.karpenko(a)exoplatform.com.ua>
+ * Created by The eXo Platform SAS Author : Sergey Karpenko
+ * <sergey.karpenko(a)exoplatform.com.ua>
*
* @version $Id: $
*/
-public class TestErrorLog extends BaseQueryTest
-{
- ErrorLog log;
+public class TestErrorLog extends BaseQueryTest {
+ ErrorLog log;
- File file;
+ File file;
- private static final int SIZE = 100;
+ private static final int SIZE = 100;
- public void setUp() throws Exception
- {
- super.setUp();
- file = File.createTempFile("error", "log");
- if (file.exists())
- {
- file.delete();
- }
- }
+ public void setUp() throws Exception {
+ super.setUp();
+ file = File.createTempFile("error", "log");
+ if (file.exists()) {
+ file.delete();
+ }
+ }
- public void tearDown() throws Exception
- {
- super.tearDown();
- log.clear();
- file.delete();
- }
+ public void tearDown() throws Exception {
+ super.tearDown();
+ log.clear();
+ file.delete();
+ }
- public void testConcurrentWrite() throws Exception
- {
+ public void testConcurrentWrite() throws Exception {
- class Loader extends Thread
- {
- private String name;
+ class Loader extends Thread {
+ private String name;
- public Loader(String n)
- {
- name = n;
- }
+ public Loader(String n) {
+ name = n;
+ }
- public void run()
- {
- /*
- * try { for (int i = 0; i < SIZE; i++) { log.append(ErrorLog.ADD,name +
i);
- * //System.out.println(name + i); } log.flush(); } catch (Exception e) {
- * System.out.println(e); }
- */
+ public void run() {
+ /*
+ * try { for (int i = 0; i < SIZE; i++) {
+ * log.append(ErrorLog.ADD,name + i); //System.out.println(name
+ * + i); } log.flush(); } catch (Exception e) {
+ * System.out.println(e); }
+ */
- try
- {
- HashSet<String> add = new HashSet<String>();
- HashSet<String> rem = new HashSet<String>();
+ try {
+ HashSet<String> add = new HashSet<String>();
+ HashSet<String> rem = new HashSet<String>();
- for (int j = 0; j < 10; j++)
- {
- add.clear();
- for (int i = 0; i < 10; i++)
- {
- int el = j * 10 + i;
- add.add(name + el);
- }
- log.writeChanges(rem, add);
- }
+ for (int j = 0; j < 10; j++) {
+ add.clear();
+ for (int i = 0; i < 10; i++) {
+ int el = j * 10 + i;
+ add.add(name + el);
+ }
+ log.writeChanges(rem, add);
+ }
- }
- catch (Exception e)
- {
- System.out.println(e);
- }
- }
- }
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ }
+ }
- log = new ErrorLog(file);
+ log = new ErrorLog(file, SearchIndex.DEFAULT_ERRORLOG_FILE_SIZE);
- Thread one = new Loader("first");
- Thread two = new Loader("second");
- one.start();
- two.start();
- one.join();
- two.join();
+ Thread one = new Loader("first");
+ Thread two = new Loader("second");
+ one.start();
+ two.start();
+ one.join();
+ two.join();
- List<String> list = log.readList();
+ List<String> list = log.readList();
- int lost_first = 0;
- int lost_second = 0;
- for (int i = 0; i < SIZE; i++)
- {
- String firstname = ErrorLog.ADD + " first" + i;
- String secondname = ErrorLog.ADD + " second" + i;
- int ffinded = 0;
- int sfinded = 0;
- for (int j = 0; j < list.size(); j++)
- {
- if (list.get(j).equals(firstname))
- {
- ffinded++;
- }
- if (list.get(j).equals(secondname))
- {
- sfinded++;
- }
- }
- if (ffinded == 0)
- {
- System.out.println(firstname + " NOT FINDED");
- }
- if (ffinded > 1)
- {
- System.out.println(firstname + " DUPLICATED");
- }
- if (sfinded == 0)
- {
- System.out.println(secondname + " NOT FINDED");
- }
- if (sfinded > 1)
- {
- System.out.println(secondname + " DUPLICATED");
- }
- }
+ int lost_first = 0;
+ int lost_second = 0;
+ for (int i = 0; i < SIZE; i++) {
+ String firstname = ErrorLog.ADD + " first" + i;
+ String secondname = ErrorLog.ADD + " second" + i;
+ int ffinded = 0;
+ int sfinded = 0;
+ for (int j = 0; j < list.size(); j++) {
+ if (list.get(j).equals(firstname)) {
+ ffinded++;
+ }
+ if (list.get(j).equals(secondname)) {
+ sfinded++;
+ }
+ }
+ if (ffinded == 0) {
+ System.out.println(firstname + " NOT FINDED");
+ }
+ if (ffinded > 1) {
+ System.out.println(firstname + " DUPLICATED");
+ }
+ if (sfinded == 0) {
+ System.out.println(secondname + " NOT FINDED");
+ }
+ if (sfinded > 1) {
+ System.out.println(secondname + " DUPLICATED");
+ }
+ }
- assertEquals("There is mismatch of expected writed messages count ", 200,
list.size());
- assertEquals("First thread has lost apdates", 0, lost_first);
- assertEquals("Second thread has lost apdates", 0, lost_second);
- }
+ assertEquals("There is mismatch of expected writed messages count ",
+ 200, list.size());
+ assertEquals("First thread has lost apdates", 0, lost_first);
+ assertEquals("Second thread has lost apdates", 0, lost_second);
+ }
- public void testExctractNotifyList() throws Exception
- {
- log = new ErrorLog(file);
+ public void testExctractNotifyList() throws Exception {
+ log = new ErrorLog(file, SearchIndex.DEFAULT_ERRORLOG_FILE_SIZE);
- Set<String> removed = new HashSet<String>();
- Set<String> added = new HashSet<String>();
+ Set<String> removed = new HashSet<String>();
+ Set<String> added = new HashSet<String>();
- for (int i = 0; i < 10; i++)
- {
- added.add("uuidadd" + i);
- }
+ for (int i = 0; i < 10; i++) {
+ added.add("uuidadd" + i);
+ }
- for (int i = 0; i < 5; i++)
- {
- removed.add("uuidrem" + i);
- }
+ for (int i = 0; i < 5; i++) {
+ removed.add("uuidrem" + i);
+ }
- log.writeChanges(removed, added);
+ log.writeChanges(removed, added);
- Set<String> rem = new HashSet<String>();
- Set<String> add = new HashSet<String>();
+ Set<String> rem = new HashSet<String>();
+ Set<String> add = new HashSet<String>();
- log.readChanges(rem, add);
+ log.readChanges(rem, add);
- assertTrue(rem.containsAll(removed));
- assertTrue(add.containsAll(added));
- }
+ assertTrue(rem.containsAll(removed));
+ assertTrue(add.containsAll(added));
+ }
}
Deleted:
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestIndexRules.java
===================================================================
---
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestIndexRules.java 2009-10-02
09:10:30 UTC (rev 195)
+++
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestIndexRules.java 2009-10-02
15:39:10 UTC (rev 196)
@@ -1,163 +0,0 @@
-/*
- * Copyright (C) 2003-2007 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not,
see<http://www.gnu.org/licenses/>.
- */
-
-package org.exoplatform.services.jcr.impl.core.query.lucene;
-
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.TermQuery;
-import org.exoplatform.services.jcr.impl.core.query.BaseQueryTest;
-
-import javax.jcr.Node;
-
-/**
- * Created by The eXo Platform SAS Author : Sergey Karpenko
<sergey.karpenko(a)exoplatform.com.ua>
- *
- * @version $Id: TestIndexRules.java 11908 2008-03-13 16:00:12Z ksm $
- */
-
-public class TestIndexRules extends BaseQueryTest
-{
-
- public final String fName = "FileName";
-
- private Node rootNode;
-
- public void setUp() throws Exception
- {
- super.setUp();
- rootNode = root.addNode("indrootparent");
- rootNode.setProperty("priority", "low");
- root.save();
- }
-
- /**
- * <index-rule nodeType="nt:unstructured">
<property>DifText</property> </index-rule>
- */
- /*
- * public void testPropAddConfiguration() throws Exception{ //create Node NodeImpl n
=
- * (NodeImpl)root.addNode(fName);
n.setProperty("DifText","blabla");
- * n.setProperty("OtherProp","gig"); root.save(); //check
IndexReader reader =
- * defaultSearchIndex.getIndexReader(false); IndexSearcher is = new
IndexSearcher(reader);
- * TermQuery query = new TermQuery(new Term(FieldNames.FULLTEXT, "blabla"));
//_PREFIX+fName Hits
- * result = is.search(query); assertEquals(1,result.length()); query = new
TermQuery(new
- * Term(FieldNames.FULLTEXT, "gig")); //_PREFIX+fName result =
is.search(query);
- * assertEquals(0,result.length()); }
- */
-
- /**
- * <index-rule nodeType="nt:unstructured" boost="2.0"
condition="@priority = 'high'">
- * <property>Text</property> </index-rule> <index-rule
nodeType="nt:unstructured">
- * <property>DifText</property> </index-rule>
- */
- /*
- * public void testConditionConfiguration() throws Exception{ // create Node NodeImpl
n =
- * (NodeImpl)root.addNode(fName); n.setProperty("Text","blabla");
- * n.setProperty("priority","high");
n.setProperty("DifText","second"); root.save(); // check
- * IndexReader reader = defaultSearchIndex.getIndexReader(false); IndexSearcher is =
new
- * IndexSearcher(reader); TermQuery query = new TermQuery(new
Term(FieldNames.FULLTEXT,
- * "blabla")); Hits result = is.search(query);
assertEquals(1,result.length()); query = new
- * TermQuery(new Term(FieldNames.FULLTEXT, "second")); result =
is.search(query);
- * assertEquals(0,result.length()); }
- */
-
- /**
- * <index-rule nodeType="nt:unstructured" boost="2.0"
condition="@priority = 'high'">
- * <property>Text</property> </index-rule> <index-rule
nodeType="nt:unstructured">
- * <property>DifText</property> </index-rule>
- */
- /*
- * public void testConditionConfigurationWrongConditionValue() throws Exception{ Node
n =
- * (NodeImpl)root.addNode(fName); n.setProperty("Text","blabla");
n.setProperty("priority","low");
- * n.setProperty("DifText","second"); root.save(); // check
IndexReader reader =
- * defaultSearchIndex.getIndexReader(false); IndexSearcher is = new
IndexSearcher(reader);
- * TermQuery query = new TermQuery(new Term(FieldNames.FULLTEXT, "blabla"));
Hits result =
- * is.search(query); assertEquals(0,result.length()); query = new TermQuery(new
- * Term(FieldNames.FULLTEXT, "second")); result = is.search(query);
- * assertEquals(1,result.length()); }
- */
-
- public void testParentCondition() throws Exception
- {
-
- // create Node
- // assertNotNull(rootNode);
- Node n = rootNode.addNode(fName);
- n.setProperty("Text", "blabla");
- n.setProperty("DifText", "second");
- root.save();
-
- // check
- IndexReader reader = defaultSearchIndex.getIndexReader(false);
- IndexSearcher is = new IndexSearcher(reader);
- TermQuery query = new TermQuery(new Term(FieldNames.FULLTEXT,
"blabla"));
- Hits result = is.search(query);
- assertEquals(1, result.length());
-
- query = new TermQuery(new Term(FieldNames.FULLTEXT, "second"));
- result = is.search(query);
- assertEquals(0, result.length());
- }
-
- public void testAncestorCondition() throws Exception
- {
-
- // create Node
- Node rn = rootNode.addNode("hippo");
- Node n = rn.addNode(fName);
- n.setProperty("Text", "blabla");
- n.setProperty("DifText", "second");
- root.save();
-
- // check
- IndexReader reader = defaultSearchIndex.getIndexReader(false);
- IndexSearcher is = new IndexSearcher(reader);
- TermQuery query = new TermQuery(new Term(FieldNames.FULLTEXT,
"blabla"));
- Hits result = is.search(query);
- assertEquals(1, result.length());
-
- query = new TermQuery(new Term(FieldNames.FULLTEXT, "second"));
- result = is.search(query);
- assertEquals(0, result.length());
- }
-
- public void testChildCondition() throws Exception
- {
-
- // create Node
- Node n = root.addNode(fName);
- n.setProperty("Text", "blabla");
- n.setProperty("DifText", "second");
- Node cn = n.addNode("indrootchild");
- cn.setProperty("priority", "gg");
- root.save();
-
- // check
- IndexReader reader = defaultSearchIndex.getIndexReader(false);
- IndexSearcher is = new IndexSearcher(reader);
- TermQuery query = new TermQuery(new Term(FieldNames.FULLTEXT,
"blabla"));
- Hits result = is.search(query);
- assertEquals(1, result.length());
-
- query = new TermQuery(new Term(FieldNames.FULLTEXT, "second"));
- result = is.search(query);
- assertEquals(0, result.length());
- }
-
-}
Deleted:
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestNodeIndexer.java
===================================================================
---
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestNodeIndexer.java 2009-10-02
09:10:30 UTC (rev 195)
+++
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestNodeIndexer.java 2009-10-02
15:39:10 UTC (rev 196)
@@ -1,423 +0,0 @@
-/*
- * Copyright (C) 2003-2007 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not,
see<http://www.gnu.org/licenses/>.
- */
-
-package org.exoplatform.services.jcr.impl.core.query.lucene;
-
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.exoplatform.commons.utils.MimeTypeResolver;
-import org.exoplatform.services.document.DocumentReaderService;
-import org.exoplatform.services.document.impl.DocumentReaderServiceImpl;
-import org.exoplatform.services.jcr.JcrImplBaseTest;
-import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
-import org.exoplatform.services.jcr.impl.core.NodeImpl;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.io.ByteArrayInputStream;
-import java.util.Calendar;
-import java.util.List;
-import java.util.Vector;
-
-import javax.jcr.Node;
-import javax.jcr.PropertyType;
-
-/**
- * Created by The eXo Platform SAS Author : Sergey Karpenko
<sergey.karpenko(a)exoplatform.com.ua>
- *
- * @version $Id: TestNodeIndexer.java 11907 2008-03-13 15:36:21Z ksm $
- */
-
-public class TestNodeIndexer extends JcrImplBaseTest
-{
- public static final Log logger = ExoLogger.getLogger(TestNodeIndexer.class);
-
- /**
- * Test node with string valued property.
- * <p>
- * In this case there are:
- * <p>
- * - node "test"
- * <p>
- * - property "jcr:primaryType" val "nt:ustructured" string
- * <p>
- * - property "jcr:prop" val "prop value" string
- * <p>
- * <p>
- * Expected lucene document structure. Fields:
- * <p>
- * _:UUID uuid of node;
- * <p>
- * _:PARENT uuid of parent node _:LABEL name of the node "test"
- * <p>
- * _:PROPERTIES
"jcr:primaryType"+'\uFFFF'+"nt:unstructured" _:PROPERTIES
- * "jcr:prop"+'\uFFFF'+"prop value"
- * <p>
- * _:FULLTEXT "prop value"
- * <p>
- * jcr:FULL:prop "prop value"
- * <p>
- *
- *
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public void testCreateDocument_String() throws Exception
- {
-
- Node node = this.root.addNode("test");
- node.setProperty("jcr:prop", "prop value");
- root.save();
-
- ItemDataConsumer manager = this.session.getTransientNodesManager();
-
- node = (Node)this.session.getItem("/test");
-
- NodeData data = (NodeData)((NodeImpl)node).getData();
- assertNotNull(data);
-
- DocumentReaderService extractor =
-
(DocumentReaderService)container.getComponentInstanceOfType(DocumentReaderServiceImpl.class);
- NodeIndexer indexer =
- new NodeIndexer(data, manager, new
NSRegistryBasedNamespaceMappings((NamespaceRegistryImpl)this.repository
- .getNamespaceRegistry()), extractor);
-
- Document doc = indexer.createDoc();
-
- List<Field> list = doc.getFields();
-
- // _:UUID
- List<Field> uuid = this.findField(list, FieldNames.UUID);
- assertNotNull(uuid);
- assertEquals(1, uuid.size());
- assertEquals(data.getIdentifier(), uuid.get(0).stringValue());
-
- // _:PARENT
- List<Field> parent = this.findField(list, FieldNames.PARENT);
- assertNotNull(parent);
- assertEquals(1, parent.size());
- assertEquals(data.getParentIdentifier(), parent.get(0).stringValue());
-
- // _:LABEL
- List<Field> label = this.findField(list, FieldNames.LABEL);
- assertNotNull(label);
- assertEquals(1, label.size());
- assertEquals(node.getName(), label.get(0).stringValue());
-
- // _:PROPERTIES jcr:primaryType
- List<Field> props = this.findField(list, FieldNames.PROPERTIES);
- assertNotNull(props);
- assertEquals(2, props.size());
-
- // :PROPERTIES jcr:primaryType "jcr:prop" + '\uFFFF' + "prop
value"
- List<Field> prop1 = this.findField(list, FieldNames.PROPERTIES,
"jcr:prop" + '[' + "prop value");
- assertNotNull(prop1);
- assertEquals(1, prop1.size());
-
- // :PROPERTIES jcr:primaryType "jcr:prop" + '\uFFFF' + "prop
value"
- List<Field> prop2 = this.findField(list, FieldNames.PROPERTIES,
"jcr:primaryType" + '[' + "nt:unstructured");
- assertNotNull(prop2);
- assertEquals(1, prop2.size());
-
- // _:FULLTEXT
- List<Field> full = this.findField(list, FieldNames.FULLTEXT);
- assertNotNull(full);
- assertEquals(1, full.size());
- assertEquals(node.getProperty("jcr:prop").getString(),
full.get(0).stringValue());
-
- // jcr:FULL:prop "prop","value"
- List<Field> prefixed = this.findField(list, "jcr:FULL:prop");
- assertNotNull(prefixed);
- assertEquals(1, prefixed.size());
- assertEquals(node.getProperty("jcr:prop").getString(),
prefixed.get(0).stringValue());
-
- // Check sum - there must be 6 fields
- assertEquals(7, list.size());
- }
-
- /**
- * Test root node indexing;
- * <p>
- * In this case there are:
- * <p>
- * - root node
- * <p>
- * Expected lucene document structure. Fields:
- * <p>
- * _:UUID uuid of root node;
- * <p>
- * _:PARENT "" _:LABEL name ""
- *
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public void testCreateDocumentRootNode() throws Exception
- {
-
- ItemDataConsumer manager = this.session.getTransientNodesManager();
-
- // ((NodeImpl)node).getData();
-
- NodeData data = (NodeData)((NodeImpl)root).getData();
- assertNotNull(data);
-
- DocumentReaderService extractor =
-
(DocumentReaderService)container.getComponentInstanceOfType(DocumentReaderServiceImpl.class);
- NodeIndexer indexer =
- new NodeIndexer(data, manager, new
NSRegistryBasedNamespaceMappings((NamespaceRegistryImpl)this.repository
- .getNamespaceRegistry()), extractor);
-
- Document doc = indexer.createDoc();
-
- List<Field> list = doc.getFields();
-
- // _:UUID
- List<Field> uuid = this.findField(list, FieldNames.UUID);
- assertNotNull(uuid);
- assertEquals(1, uuid.size());
- assertEquals(data.getIdentifier(), uuid.get(0).stringValue());
-
- // _:PARENT
- List<Field> parent = this.findField(list, FieldNames.PARENT);
- assertNotNull(parent);
- assertEquals(1, parent.size());
- assertEquals("", parent.get(0).stringValue());
-
- // _:LABEL
- List<Field> label = this.findField(list, FieldNames.LABEL);
- assertNotNull(label);
- assertEquals(1, label.size());
- assertEquals("", label.get(0).stringValue());
- }
-
- /**
- * Test of indexing Binary value
- * <p>
- * In this case there are:
- * <p>
- * - node "jcr:content"
- * <p>
- * - property "jcr:primaryType" val "nt:resource" name
- * <p>
- * - property "jcr:lastModified" calendar
- * <p>
- * - property "jcr:uuid" string
- * <p>
- * - property "jcr:mimetype" "text/plain" string
- * <p>
- * - property "jcr:data" "binary value" binary
- * <p>
- * Expected lucene document structure. Fields:
- * <p>
- * _:UUID uuid of node;
- * <p>
- * _:PARENT uuid of parent node _:LABEL name of the node "test"
- * <p>
- * _:PROPERTIES "jcr:primaryType"+'\uFFFF'+"nt:resource"
- * <p>
- * _:PROPERTIES "jcr:lastModified"+'\uFFFF'+currentTtimeString
- * <p>
- * _:PROPERTIES "jcr:uuid"+'\uFFFF'+ uuid
- * <p>
- * jcr:FULL:uuid uuid
- * <p>
- * _:PROPERTIES "jcr:mimetype"+'\uFFFF'+"text/plain"
- * <p>
- * _:FULLTEXT "text/plain"
- * <p>
- * _:FULLTEXT "binary value"
- * <p>
- *
- *
- *
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public void testCreateDocument_Binary() throws Exception
- {
- Node node = root.addNode("jcr:content", "nt:resource");
-
- MimeTypeResolver mimetypeResolver = new MimeTypeResolver();
- mimetypeResolver.setDefaultMimeType("text/plain");//
"application/zip");
- String mimeType = mimetypeResolver.getMimeType("text/plain");
-
- node.setProperty("jcr:mimeType", mimeType);
- node.setProperty("jcr:lastModified", Calendar.getInstance());
- node.setProperty("jcr:data", new ByteArrayInputStream("binary
value".getBytes()));
-
- root.save();
-
- ItemDataConsumer manager = this.session.getTransientNodesManager();
-
- NodeData data = (NodeData)((NodeImpl)node).getData();
- assertNotNull(data);
-
- DocumentReaderService extractor =
-
(DocumentReaderService)container.getComponentInstanceOfType(DocumentReaderServiceImpl.class);
- NodeIndexer indexer =
- new NodeIndexer(data, manager, new
NSRegistryBasedNamespaceMappings((NamespaceRegistryImpl)this.repository
- .getNamespaceRegistry()), extractor);
-
- Document doc = indexer.createDoc();
-
- List<Field> list = doc.getFields();
-
- // Check sum - there must be 6 fields
- assertEquals(10, list.size());
-
- // _:UUID
- List<Field> uuid = this.findField(list, FieldNames.UUID);
- assertNotNull(uuid);
- assertEquals(1, uuid.size());
- assertEquals(data.getIdentifier(), uuid.get(0).stringValue());
-
- // _:PARENT
- List<Field> parent = this.findField(list, FieldNames.PARENT);
- assertNotNull(parent);
- assertEquals(1, parent.size());
- assertEquals(data.getParentIdentifier(), parent.get(0).stringValue());
-
- // _:LABEL
- List<Field> label = this.findField(list, FieldNames.LABEL);
- assertNotNull(label);
- assertEquals(1, label.size());
- assertEquals(node.getName(), label.get(0).stringValue());
-
- }
-
- /**
- * Test of indexing Binary value
- * <p>
- * In this case there are:
- * <p>
- * - node "jcr:content"
- * <p>
- * - property "jcr:primaryType" val "nt:unstructured" name
- * <p>
- * - property "pathprop" "/wooo" path
- * <p>
- * Expected lucene document structure. Fields:
- * <p>
- * _:UUID uuid of node;
- * <p>
- * _:PARENT uuid of parent node _:LABEL name of the node "test"
- * <p>
- * _:PROPERTIES
"jcr:primaryType"+'\uFFFF'+"nt:unstructured"
- * <p>
- * _:PROPERTIES "pathprop"+'\uFFFF'+"/wooo"
- * <p>
- *
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public void testCreateDocument_Path() throws Exception
- {
- Node node = root.addNode("test_path");
-
- node.setProperty("pathprop", "/wooo", PropertyType.PATH);
-
- root.save();
-
- ItemDataConsumer manager = this.session.getTransientNodesManager();
-
- NodeData data = (NodeData)((NodeImpl)node).getData();
- assertNotNull(data);
-
- DocumentReaderService extractor =
-
(DocumentReaderService)container.getComponentInstanceOfType(DocumentReaderServiceImpl.class);
- NodeIndexer indexer =
- new NodeIndexer(data, manager, new
NSRegistryBasedNamespaceMappings((NamespaceRegistryImpl)this.repository
- .getNamespaceRegistry()), extractor);
-
- Document doc = indexer.createDoc();
-
- List<Field> list = doc.getFields();
-
- // Check sum - there must be 6 fields
- assertEquals(5, list.size());
-
- // _:UUID
- List<Field> uuid = this.findField(list, FieldNames.UUID);
- assertNotNull(uuid);
- assertEquals(1, uuid.size());
- assertEquals(data.getIdentifier(), uuid.get(0).stringValue());
-
- // _:PARENT
- List<Field> parent = this.findField(list, FieldNames.PARENT);
- assertNotNull(parent);
- assertEquals(1, parent.size());
- assertEquals(data.getParentIdentifier(), parent.get(0).stringValue());
-
- // _:LABEL
- List<Field> label = this.findField(list, FieldNames.LABEL);
- assertNotNull(label);
- assertEquals(1, label.size());
- assertEquals(node.getName(), label.get(0).stringValue());
-
- // _:PROPERTIES
- List<Field> props = this.findField(list, FieldNames.PROPERTIES);
- assertNotNull(props);
- assertEquals(2, props.size());
-
- // :PROPERTIES jcr:primaryType "pathprop" + '\uFFFF' +
"/wooo"
- List<Field> prop1 = this.findField(list, FieldNames.PROPERTIES,
"pathprop" + '[' + "/wooo");
- assertNotNull(prop1);
- assertEquals(1, prop1.size());
-
- // :PROPERTIES jcr:primaryType "jcr:primaryType" + '\uFFFF' +
"jcr:primaryType" + '\uFFFF' +
- // "nt:unstructured"
- List<Field> prop2 = this.findField(list, FieldNames.PROPERTIES,
"jcr:primaryType" + '[' + "nt:unstructured");
- assertNotNull(prop2);
- assertEquals(1, prop2.size());
-
- }
-
- /**
- * @return Field or null if is not finded
- */
- public List<Field> findField(List<Field> list, String fieldName)
- {
- List<Field> out = new Vector<Field>();
- for (int i = 0; i < list.size(); i++)
- {
- if (list.get(i).name().equalsIgnoreCase(fieldName))
- out.add(list.get(i));
- }
- return (out.isEmpty()) ? null : out;
- }
-
- /**
- * Find Field from list, named as fieldName, and valued as fieldStringValue
- *
- * @return Field or null if is not finded
- */
- public List<Field> findField(List<Field> list, String fieldName, String
fieldStringValue)
- {
- List<Field> out = new Vector<Field>();
- for (int i = 0; i < list.size(); i++)
- {
- if ((list.get(i).name().equalsIgnoreCase(fieldName)) &&
(list.get(i).stringValue() != null)
- && (list.get(i).stringValue().equals(fieldStringValue)))
- {
- out.add(list.get(i));
- }
- }
- return (out.isEmpty()) ? null : out;
- }
-}