use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class AutoRecordableVersionsTest method testVersionRecordsRelated.
/**
* Given that all revisions will be automatically recorded,
* When I update a document 3 times,
* Then all 3 created records will be related together using the "VersionedBy" relationship
*/
public void testVersionRecordsRelated() {
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator, false) {
/**
* given *
*/
public void given() throws Exception {
doTestInTransaction(new VoidTest() {
@Override
public void runImpl() throws Exception {
// set the recordable version policy
PropertyMap recordableVersionProperties = new PropertyMap(1);
recordableVersionProperties.put(PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
recordableVersionProperties.put(PROP_FILE_PLAN, filePlan);
nodeService.addAspect(dmDocument, RecordableVersionModel.ASPECT_VERSIONABLE, recordableVersionProperties);
// make the node versionable
PropertyMap versionableProperties = new PropertyMap(1);
versionableProperties.put(ContentModel.PROP_INITIAL_VERSION, false);
nodeService.addAspect(dmDocument, ContentModel.ASPECT_VERSIONABLE, versionableProperties);
}
});
}
/**
* when *
*/
public void when() {
// update the content 3 times
updateContent();
updateContent();
updateContent();
}
/**
* then
*/
public void then() {
doTestInTransaction(new VoidTest() {
@Override
public void runImpl() throws Exception {
// check that the record has been recorded
checkRecordedVersion(dmDocument, null, "0.3");
Version version = versionService.getCurrentVersion(dmDocument);
NodeRef record = recordableVersionService.getVersionRecord(version);
boolean foundPrevious = false;
Set<Relationship> relationships = relationshipService.getRelationshipsFrom(record);
assertNotNull(relationships);
assertEquals(1, relationships.size());
for (Relationship relationship : relationships) {
if (relationship.getUniqueName().equals(CUSTOM_REF_VERSIONS.getLocalName())) {
NodeRef previousVersionRecord = relationship.getTarget();
assertNotNull(previousVersionRecord);
foundPrevious = true;
}
}
assertTrue(foundPrevious);
}
});
}
/**
* Helper method to update content of dmDocument
*/
private void updateContent() {
doTestInTransaction(new VoidTest() {
@Override
public void runImpl() throws Exception {
ContentWriter writer = contentService.getWriter(dmDocument, ContentModel.PROP_CONTENT, true);
writer.putContent(MY_NEW_CONTENT);
}
});
}
});
}
Aggregations