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)));
}
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
}
}
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;
}
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());
}
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));
}
}
}
Aggregations