use of org.apache.jackrabbit.commons.jackrabbit.SimpleReferenceBinary in project jackrabbit-oak by apache.
the class RepositoryTest method testReferenceBinary.
@Test
public void testReferenceBinary() throws RepositoryException {
ValueFactory valueFactory = getAdminSession().getValueFactory();
Binary binary = valueFactory.createBinary(new RandomInputStream(1, 256 * 1024));
String reference = binary instanceof ReferenceBinary ? ((ReferenceBinary) binary).getReference() : null;
assumeTrue(reference != null);
Session session = createAdminSession();
try {
valueFactory = session.getValueFactory();
assertEquals(binary, valueFactory.createValue(new SimpleReferenceBinary(reference)).getBinary());
} finally {
session.logout();
}
}
use of org.apache.jackrabbit.commons.jackrabbit.SimpleReferenceBinary in project jackrabbit by apache.
the class ReferenceBinaryTest method testReferenceBinaryExchangeWithSharedRepository.
public void testReferenceBinaryExchangeWithSharedRepository() throws Exception {
Session firstSession = superuser;
// create a binary
Binary b = vf.createBinary(new RandomInputStream(1, STREAM_LENGTH));
ReferenceBinary referenceBinary = null;
if (b instanceof ReferenceBinary) {
referenceBinary = (ReferenceBinary) b;
}
assertNotNull(referenceBinary);
assertNotNull(referenceBinary.getReference());
// in the current test the message is exchanged via repository which is shared as well
// put the reference message value in a property on a node
String newNode = "sample_" + System.nanoTime();
firstSession.getRootNode().addNode(newNode).setProperty("reference", referenceBinary.getReference());
// save the first session
firstSession.save();
// get a second session over the same repository / ds
Session secondSession = getHelper().getRepository().login(new SimpleCredentials("admin", "admin".toCharArray()));
// read the binary referenced by the referencing binary
String reference = secondSession.getRootNode().getNode(newNode).getProperty("reference").getString();
ReferenceBinary ref = new SimpleReferenceBinary(reference);
assertEquals(b, secondSession.getValueFactory().createValue(ref).getBinary());
}
use of org.apache.jackrabbit.commons.jackrabbit.SimpleReferenceBinary in project jackrabbit-oak by apache.
the class ReferenceBinaryIT method testReferenceBinaryExchangeWithSharedRepository.
/**
* Taken from org.apache.jackrabbit.core.value.ReferenceBinaryTest
* @throws Exception
*/
@Test
public void testReferenceBinaryExchangeWithSharedRepository() throws Exception {
Session firstSession = createAdminSession();
// create a binary
Binary b = firstSession.getValueFactory().createBinary(new RandomInputStream(1, STREAM_LENGTH));
ReferenceBinary referenceBinary = null;
if (b instanceof ReferenceBinary) {
referenceBinary = (ReferenceBinary) b;
}
assertNotNull(referenceBinary);
assertNotNull(referenceBinary.getReference());
// in the current test the message is exchanged via repository which is shared as well
// put the reference message value in a property on a node
String newNode = "sample_" + System.nanoTime();
firstSession.getRootNode().addNode(newNode).setProperty("reference", referenceBinary.getReference());
// save the first session
firstSession.save();
// get a second session over the same repository / ds
Session secondSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
// read the binary referenced by the referencing binary
String reference = secondSession.getRootNode().getNode(newNode).getProperty("reference").getString();
ReferenceBinary ref = new SimpleReferenceBinary(reference);
assertEquals(b, secondSession.getValueFactory().createValue(ref).getBinary());
safeLogout(firstSession);
safeLogout(secondSession);
}
Aggregations