Search in sources :

Example 36 with Property

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

the class TokenProviderTest method testTokenNode.

public void testTokenNode() throws Exception {
    Map<String, String> privateAttributes = new HashMap<String, String>();
    privateAttributes.put(".token_exp", "value");
    privateAttributes.put(".tokenTest", "value");
    privateAttributes.put(".token_something", "value");
    Map<String, String> publicAttributes = new HashMap<String, String>();
    publicAttributes.put("any", "value");
    publicAttributes.put("another", "value");
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.putAll(publicAttributes);
    attributes.putAll(privateAttributes);
    SimpleCredentials sc = new SimpleCredentials(userId, userId.toCharArray());
    for (String s : attributes.keySet()) {
        sc.setAttribute(s, attributes.get(s));
    }
    TokenInfo info = tokenProvider.createToken(testuser, sc);
    Node tokenNode = getTokenNode(info);
    Property prop = tokenNode.getProperty("rep:token.key");
    assertNotNull(prop);
    assertEquals(PropertyType.STRING, prop.getType());
    assertTrue(prop.getDefinition().isProtected());
    prop = tokenNode.getProperty("rep:token.exp");
    assertNotNull(prop);
    assertEquals(PropertyType.DATE, prop.getType());
    assertTrue(prop.getDefinition().isProtected());
    for (String key : privateAttributes.keySet()) {
        assertEquals(privateAttributes.get(key), tokenNode.getProperty(key).getString());
    }
    for (String key : publicAttributes.keySet()) {
        assertEquals(publicAttributes.get(key), tokenNode.getProperty(key).getString());
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HashMap(java.util.HashMap) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 37 with Property

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

the class CopyFrozenUuidTest method testCopyFrozenUuidProperty.

public void testCopyFrozenUuidProperty() throws Exception {
    Node firstNode = testRootNode.addNode(nodeName1);
    firstNode.setPrimaryType(JcrConstants.NT_UNSTRUCTURED);
    firstNode.addMixin(JcrConstants.MIX_VERSIONABLE);
    firstNode.getSession().save();
    // create version for the node
    Version firstNodeVersion = firstNode.checkin();
    firstNode.checkout();
    Node secondNode = testRootNode.addNode(nodeName2);
    secondNode.setPrimaryType(JcrConstants.NT_UNSTRUCTURED);
    secondNode.addMixin(JcrConstants.MIX_VERSIONABLE);
    Property firstNodeVersionFrozenUuid = firstNodeVersion.getFrozenNode().getProperty(JcrConstants.JCR_FROZENUUID);
    secondNode.setProperty(JcrConstants.JCR_FROZENUUID, firstNodeVersionFrozenUuid.getValue());
    secondNode.getSession().save();
    // create version of the second node
    Version secondNodeVersion = secondNode.checkin();
    secondNode.checkout();
    // frozenUuid from the second node version node should not be the same as the one from the first node version
    Property secondBodeVersionFrozenUuid = secondNodeVersion.getFrozenNode().getProperty(JcrConstants.JCR_FROZENUUID);
    assertFalse(JcrConstants.JCR_FROZENUUID + " should not be the same for two different versions of different nodes! ", secondBodeVersionFrozenUuid.getValue().equals(firstNodeVersionFrozenUuid.getValue()));
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 38 with Property

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

the class RemoveOrphanVersionHistoryTest method testEmptyNonOrphanVersionHistory.

/**
     * Test that an emptied version history that is still being referenced
     * from another workspace does not get removed.
     *
     * @throws RepositoryException if an error occurs.
     */
public void testEmptyNonOrphanVersionHistory() throws RepositoryException {
    Session session = testRootNode.getSession();
    // Create versionable test node
    Node node = testRootNode.addNode(nodeName1);
    node.addMixin(mixVersionable);
    session.save();
    VersionHistory history = node.getVersionHistory();
    String uuid = history.getUUID();
    // Create version 1.0
    Version v10 = node.checkin();
    // Remove the test node
    node.checkout();
    node.remove();
    session.save();
    Session otherSession = getHelper().getReadWriteSession(workspaceName);
    try {
        // create a reference to the version history in another workspace
        Node otherRoot = otherSession.getRootNode();
        Property reference = otherRoot.setProperty("RemoveOrphanVersionTest", uuid, PropertyType.REFERENCE);
        otherSession.save();
        // Now remove the contents of the version history
        history.removeVersion(v10.getName());
        // Check that the version history still exists!
        try {
            session.getNodeByUUID(uuid);
        } catch (ItemNotFoundException e) {
            fail("Referenced empty version history must note be removed");
        }
        // Cleanup
        reference.remove();
        otherSession.save();
    } finally {
        otherSession.logout();
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 39 with Property

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

the class GetWeakReferencesTest method testSingleValueWithName.

public void testSingleValueWithName() throws RepositoryException {
    Value weakRef = vf.createValue(target, true);
    referring.setProperty(propertyName1, weakRef);
    superuser.save();
    PropertyIterator it = target.getWeakReferences(propertyName1);
    assertTrue("no weak references returned", it.hasNext());
    Property p = it.nextProperty();
    assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath());
    assertFalse("no more weak references expected", it.hasNext());
}
Also used : Value(javax.jcr.Value) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 40 with Property

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

the class GetWeakReferencesTest method testMultiValuesWithName.

public void testMultiValuesWithName() throws RepositoryException {
    Value weakRef = vf.createValue(target, true);
    Value[] refs = new Value[] { weakRef, weakRef };
    referring.setProperty(propertyName1, refs);
    superuser.save();
    PropertyIterator it = target.getWeakReferences(propertyName1);
    assertTrue("no weak references returned", it.hasNext());
    Property p = it.nextProperty();
    assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath());
    assertFalse("no more weak references expected", it.hasNext());
}
Also used : Value(javax.jcr.Value) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Aggregations

Property (javax.jcr.Property)445 Node (javax.jcr.Node)252 Value (javax.jcr.Value)99 Test (org.junit.Test)87 Session (javax.jcr.Session)78 PropertyIterator (javax.jcr.PropertyIterator)68 RepositoryException (javax.jcr.RepositoryException)64 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)47 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)37 ValueFormatException (javax.jcr.ValueFormatException)34 QValue (org.apache.jackrabbit.spi.QValue)29 ArrayList (java.util.ArrayList)24 NodeIterator (javax.jcr.NodeIterator)24 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)23 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)20 Item (javax.jcr.Item)19 PathNotFoundException (javax.jcr.PathNotFoundException)17 InvalidItemStateException (javax.jcr.InvalidItemStateException)16 Version (javax.jcr.version.Version)16 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)15