Search in sources :

Example 71 with Value

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

the class NodeDiscoveringNodeTypesTest method testGetMixinNodeTypes.

/**
     * Test if getMixinNodeType returns the node types according to the property
     * "jcr:mixinTypes". Therefore a node with mixin types is located recursively
     * in the entire repository. A NotExecutableException is thrown when no such
     * node is found.
     */
public void testGetMixinNodeTypes() throws NotExecutableException, RepositoryException {
    if (childNode == null) {
        throw new NotExecutableException("Workspace does not have sufficient content for this test. " + "Root node must have at least one child node.");
    }
    Node node = locateNodeWithMixinNodeTypes(testRootNode);
    if (node == null) {
        throw new NotExecutableException("Workspace does not contain a node with mixin node types defined");
    }
    Value[] names = node.getProperty(jcrMixinTypes).getValues();
    NodeType[] types = node.getMixinNodeTypes();
    assertEquals("getMixinNodeTypes() does not return the same number of " + "node types as " + "getProperty(\"jcr:mixinTypes\").getValues()", types.length, names.length);
    StringBuffer namesString = new StringBuffer();
    for (int i = 0; i < names.length; i++) {
        namesString.append("|" + names[i].getString() + "|");
    }
    for (int i = 0; i < types.length; i++) {
        String pattern = "|" + types[i].getName() + "|";
        assertTrue("getMixinNodeTypes() does not return the same node" + "types as getProperty(\"jcr:mixinTypes\").getValues()", namesString.indexOf(pattern) != -1);
        assertTrue("All nodes returned by getMixinNodeTypes() must be" + "mixin", types[i].isMixin());
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value)

Example 72 with Value

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

the class BindVariableValueTest method testPath.

public void testPath() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    Value path = vf.createValue(n.getPath(), PropertyType.PATH);
    n.setProperty(propertyName1, path);
    superuser.save();
    bindVariableValue(qomQuery, "v", path);
    checkResult(qomQuery.execute(), new Node[] { n });
    bindVariableValue(sqlQuery, "v", path);
    checkResult(sqlQuery.execute(), new Node[] { n });
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value)

Example 73 with Value

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

the class BindVariableValueTest method testName.

public void testName() throws RepositoryException {
    Value name = vf.createValue(STRING_VALUE, PropertyType.NAME);
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.setProperty(propertyName1, name);
    superuser.save();
    bindVariableValue(qomQuery, "v", name);
    checkResult(qomQuery.execute(), new Node[] { n });
    bindVariableValue(sqlQuery, "v", name);
    checkResult(sqlQuery.execute(), new Node[] { n });
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value)

Example 74 with Value

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

the class NodeNameTest method testWeakReferenceLiteral.

public void testWeakReferenceLiteral() throws RepositoryException, NotExecutableException {
    ensureMixinType(node1, mixReferenceable);
    superuser.save();
    Value literal = vf.createValue(node1, true);
    try {
        createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
        fail("NodeName comparison with WEAKREFERENCE must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS WEAKREFERENCE)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() comparison with absolute WEAKREFERENCE must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : Value(javax.jcr.Value) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 75 with Value

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

the class NodeNameTest method testReferenceLiteral.

public void testReferenceLiteral() throws RepositoryException, NotExecutableException {
    ensureMixinType(node1, mixReferenceable);
    superuser.save();
    Value literal = vf.createValue(node1);
    try {
        createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
        fail("NodeName comparison with REFERENCE must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
    try {
        String stmt = "SELECT * FROM [" + testNodeType + "] AS s " + "WHERE NAME(s) = CAST('" + literal.getString() + "' AS REFERENCE)";
        qm.createQuery(stmt, Query.JCR_SQL2).execute();
        fail("NAME() comparison with REFERENCE must fail with InvalidQueryException");
    } catch (InvalidQueryException e) {
    // expected
    }
}
Also used : Value(javax.jcr.Value) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Aggregations

Value (javax.jcr.Value)602 Node (javax.jcr.Node)158 Test (org.junit.Test)120 Property (javax.jcr.Property)99 RepositoryException (javax.jcr.RepositoryException)82 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)82 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)70 Session (javax.jcr.Session)63 NodeType (javax.jcr.nodetype.NodeType)57 ValueFormatException (javax.jcr.ValueFormatException)53 ValueFactory (javax.jcr.ValueFactory)51 QValue (org.apache.jackrabbit.spi.QValue)51 HashMap (java.util.HashMap)46 ArrayList (java.util.ArrayList)31 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)30 Privilege (javax.jcr.security.Privilege)30 InputStream (java.io.InputStream)29 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)29 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)29 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)27