Search in sources :

Example 76 with ContentWriter

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);
                }
            });
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) PropertyMap(org.alfresco.util.PropertyMap) Version(org.alfresco.service.cmr.version.Version) Relationship(org.alfresco.module.org_alfresco_module_rm.relationship.Relationship)

Aggregations

ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)76 NodeRef (org.alfresco.service.cmr.repository.NodeRef)50 HashMap (java.util.HashMap)31 Serializable (java.io.Serializable)22 QName (org.alfresco.service.namespace.QName)21 ContentReader (org.alfresco.service.cmr.repository.ContentReader)20 Test (org.junit.Test)18 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)14 InputStream (java.io.InputStream)13 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)13 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)13 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)13 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)13 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)13 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)13 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)13 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)12 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)12 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)11 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)11