Search in sources :

Example 21 with Value

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

the class VersionGraphTest method testInitialNodePredecessors.

/**
     * Test if after creation of a versionable node N the multi-value
     * REFERENCE property jcr:predecessors of N is initialized to contain a
     * single UUID, that of the root version (the same as jcr:baseVersion).
     *
     * @throws RepositoryException
     */
public void testInitialNodePredecessors() throws RepositoryException {
    Property predecessors = versionableNode.getProperty(jcrPredecessors);
    Value[] values = predecessors.getValues();
    Version rV = versionableNode.getVersionHistory().getRootVersion();
    if (values.length != 1) {
        fail("The jcr:predecessors property of a versionable node must be initialized to contain a single value");
    }
    Value initialVal = values[0];
    assertTrue("The jcr:predecessors property of a versionable node is initialized to contain a single UUID, that of the root version", initialVal.equals(superuser.getValueFactory().createValue(rV)));
}
Also used : Version(javax.jcr.version.Version) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 22 with Value

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

the class RemoveVersionTest method testReferentialIntegrityException.

/**
     * Checks if {@link javax.jcr.version.VersionHistory#removeVersion(String)}
     * throws a {@link javax.jcr.ReferentialIntegrityException} if the named
     * version is still referenced by another node.
     * <ul>
     * <li>{@code nodetype} name of a node type that supports a reference
     *  property.
     * <li>{@code nodename4} name of the node created with <code>nodetype</code>.
     * <li>{@code propertyname1} a single value reference property available
     *  in <code>nodetype</code>.
     *  </ul>
     */
public void testReferentialIntegrityException() throws RepositoryException, NotExecutableException {
    // create reference: n1.p1 -> version
    Node n1 = testRootNode.addNode(nodeName4, testNodeType);
    Value refValue = superuser.getValueFactory().createValue(version);
    ensureCanSetProperty(n1, propertyName1, refValue);
    n1.setProperty(propertyName1, refValue);
    testRootNode.getSession().save();
    try {
        vHistory.removeVersion(version.getName());
        fail("Method removeVersion() must throw a ReferentialIntegrityException " + "if the version is the target of a REFERENCE property and the current " + "Session has read access to that REFERENCE property");
    } catch (ReferentialIntegrityException e) {
    // success
    }
}
Also used : ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) Node(javax.jcr.Node) Value(javax.jcr.Value)

Example 23 with Value

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

the class AbstractLsProperties method getMultiplePreview.

/**
     * @param property
     * @return a <code>Collection</code> in which element contains the first
     *         50 characters of the <code>Value</code>'s string
     *         representation
     * @throws RepositoryException
     * @throws ValueFormatException
     */
private Collection getMultiplePreview(Property p) throws ValueFormatException, RepositoryException {
    Collection c = new ArrayList();
    Value[] values = p.getValues();
    for (int i = 0; i < values.length; i++) {
        try {
            String value = values[i].getString();
            c.add(value.substring(0, Math.min(value.length(), 50)));
        } catch (ValueFormatException e) {
            c.add(bundle.getString("phrase.notavailable"));
        }
    }
    return c;
}
Also used : ArrayList(java.util.ArrayList) Value(javax.jcr.Value) Collection(java.util.Collection) ValueFormatException(javax.jcr.ValueFormatException)

Example 24 with Value

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

the class DefaultSyncContextTest method testCreateValueFromBinary.

/**
     * @see <a href="https://issues.apache.org/jira/browse/OAK-4231">OAK-4231</a>
     */
@Test
public void testCreateValueFromBinary() throws Exception {
    byte[] bytes = new byte[] { 'a', 'b' };
    ByteArrayInputStream is = new ByteArrayInputStream(bytes);
    Binary binary = valueFactory.createBinary(is);
    Value v = syncCtx.createValue(binary);
    assertNotNull(v);
    assertEquals(PropertyType.BINARY, v.getType());
    assertEquals(binary, v.getBinary());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Value(javax.jcr.Value) Binary(javax.jcr.Binary) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 25 with Value

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

the class DefaultSyncContextTest method testSyncProperties.

@Test
public void testSyncProperties() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER);
    Authorizable a = syncCtx.createUser(externalUser);
    // create exact mapping
    Map<String, String> mapping = new HashMap();
    Map<String, ?> extProps = externalUser.getProperties();
    for (String propName : extProps.keySet()) {
        mapping.put(propName, propName);
    }
    syncCtx.syncProperties(externalUser, a, mapping);
    for (String propName : extProps.keySet()) {
        assertTrue(a.hasProperty(propName));
        Object obj = extProps.get(propName);
        Value[] vs = a.getProperty(propName);
        if (vs.length == 1) {
            assertEquals(syncCtx.createValue(obj), a.getProperty(propName)[0]);
        } else {
            Value[] expected = (obj instanceof Collection) ? syncCtx.createValues((Collection) obj) : syncCtx.createValues(Arrays.asList((Object[]) obj));
            assertArrayEquals(expected, a.getProperty(propName));
        }
    }
}
Also used : HashMap(java.util.HashMap) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Collection(java.util.Collection) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Aggregations

Value (javax.jcr.Value)600 Node (javax.jcr.Node)158 Test (org.junit.Test)118 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