Search in sources :

Example 21 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class DerefTest method testDerefToVersionNode.

/**
     * Checks if jcr:deref works when dereferencing into the version storage.
     */
public void testDerefToVersionNode() throws RepositoryException {
    Node referenced = testRootNode.addNode(nodeName1);
    referenced.addMixin(mixVersionable);
    testRootNode.save();
    Version version = referenced.checkin();
    Node referencedVersionNode = version.getNode(jcrFrozenNode);
    Node referencer = testRootNode.addNode(nodeName2);
    referencer.setProperty(propertyName1, referencedVersionNode);
    testRootNode.save();
    String query = "/" + testRoot + "/*[@" + propertyName1 + "]/jcr:deref(@" + propertyName1 + ",'*')";
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    Query q = qm.createQuery(query, Query.XPATH);
    QueryResult qr = q.execute();
    NodeIterator ni = qr.getNodes();
    assertEquals("Must find one result in query", 1, ni.getSize());
    while (ni.hasNext()) {
        Node node = (Node) ni.next();
        assertTrue(node.getProperty("jcr:frozenUuid").getString().equals(referenced.getUUID()));
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Version(javax.jcr.version.Version) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 22 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class ExcerptTest method testQuotedPhraseNoMatch.

/**
     * Verifies excerpt generation on a node property that does not contain any
     * excerpt info for a quoted phrase
     */
public void testQuotedPhraseNoMatch() throws RepositoryException {
    String text = "one two three four";
    String excerpt = createExcerpt("one two three four");
    String terms = "\"five six\"";
    Node n = testRootNode.addNode(nodeName1);
    n.setProperty("text", text);
    n.setProperty("other", terms);
    superuser.save();
    String stmt = getStatement(terms);
    QueryResult result = executeQuery(stmt);
    RowIterator rows = result.getRows();
    assertEquals(1, rows.getSize());
    String ex = rows.nextRow().getValue("rep:excerpt(text)").getString();
    assertEquals("Expected " + excerpt + ", but got ", excerpt, ex);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 23 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class ExcerptTest method testQuotedPhraseNoMatchScrambled.

/**
     * 
     * Verifies excerpt generation on a node property that contains the exact
     * quoted phrase but with scrambled words.
     * 
     * More clearly it actually checks that the order of tokens is respected for
     * a quoted phrase.
     */
public void testQuotedPhraseNoMatchScrambled() throws RepositoryException {
    String text = "one two three four";
    String excerpt = createExcerpt("one two three four");
    String terms = "\"three two\"";
    Node n = testRootNode.addNode(nodeName1);
    n.setProperty("text", text);
    n.setProperty("other", terms);
    superuser.save();
    String stmt = getStatement(terms);
    QueryResult result = executeQuery(stmt);
    RowIterator rows = result.getRows();
    assertEquals(1, rows.getSize());
    String ex = rows.nextRow().getValue("rep:excerpt(text)").getString();
    assertEquals("Expected " + excerpt + ", but got ", excerpt, ex);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 24 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class ExcerptTest method testMatchMultipleNonMatchingTokens.

/**
     * <p>
     * Test when there are multiple tokens that match the fulltext search (which
     * will generate multiple lucene terms for the highlighter to use) in the
     * repository but not all of them are present in the current property.
     * </p>
     * 
     */
public void testMatchMultipleNonMatchingTokens() throws RepositoryException {
    String text = "lorem ipsum";
    String fragmentText = "lorem <strong>ipsum</strong>";
    String terms = "ipsu*";
    String excerpt = createExcerpt(fragmentText);
    // here we'll add more matching garbage data so we have more tokens
    // passed to the highlighter
    Node parent = testRootNode.addNode(nodeName1);
    Node n = parent.addNode("test");
    n.setProperty("text", text);
    testRootNode.addNode(nodeName2).setProperty("foo", "ipsuFoo");
    testRootNode.addNode(nodeName3).setProperty("bar", "ipsuBar");
    superuser.save();
    // --
    String stmt = testPath + "/" + nodeName1 + "//*[jcr:contains(., '" + terms + "')]/rep:excerpt(.)";
    QueryResult result = executeQuery(stmt);
    RowIterator rows = result.getRows();
    assertEquals(1, rows.getSize());
    assertEquals(excerpt, getExcerpt(rows.nextRow()));
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 25 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class AbstractQueryTest method checkResult.

/**
     * Checks if the result contains exactly the <code>nodes</code>.
     * @param result the query result.
     * @param nodes the expected nodes in the result set.
     * @throws RepositoryException if an error occurs while reading from the result.
     */
protected void checkResult(NodeIterator result, Node[] nodes) throws RepositoryException {
    // collect paths
    Set<String> expectedPaths = new HashSet<String>();
    for (Node n : nodes) {
        expectedPaths.add(n.getPath());
    }
    Set<String> resultPaths = new HashSet<String>();
    while (result.hasNext()) {
        resultPaths.add(result.nextNode().getPath());
    }
    // check if all expected are in result
    for (Iterator<String> it = expectedPaths.iterator(); it.hasNext(); ) {
        String path = it.next();
        assertTrue(path + " is not part of the result set " + resultPaths, resultPaths.contains(path));
    }
    // check result does not contain more than expected
    for (Iterator<String> it = resultPaths.iterator(); it.hasNext(); ) {
        String path = it.next();
        assertTrue(path + " is not expected to be part of the result set " + expectedPaths, expectedPaths.contains(path));
    }
}
Also used : Node(javax.jcr.Node) HashSet(java.util.HashSet)

Aggregations

Node (javax.jcr.Node)2620 Session (javax.jcr.Session)645 Test (org.junit.Test)643 RepositoryException (javax.jcr.RepositoryException)317 Property (javax.jcr.Property)251 NodeIterator (javax.jcr.NodeIterator)214 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)182 Value (javax.jcr.Value)158 Version (javax.jcr.version.Version)155 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)151 Query (javax.jcr.query.Query)122 QueryResult (javax.jcr.query.QueryResult)108 Event (javax.jcr.observation.Event)103 VersionManager (javax.jcr.version.VersionManager)97 Resource (org.apache.sling.api.resource.Resource)96 ArrayList (java.util.ArrayList)93 AccessDeniedException (javax.jcr.AccessDeniedException)89 InvalidItemStateException (javax.jcr.InvalidItemStateException)82 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)82 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)81