Search in sources :

Example 6 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImplUnitTest method alreadyRecordedCreateRecordFromVersion.

/**
 * Given that a nodes last version is recorded
 * When I try and create a record from the latest version
 * Then nothing will happen, because the latest version is already recorded
 */
@Test
public void alreadyRecordedCreateRecordFromVersion() {
    // latest version is already recorded
    Version mockedVersion = mock(VersionImpl.class);
    NodeRef versionNodeRef = generateNodeRef();
    when(mockedVersion.getFrozenStateNodeRef()).thenReturn(versionNodeRef);
    when(mockedNodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)).thenReturn(true);
    when(mockedDbNodeService.hasAspect(versionNodeRef, RecordableVersionModel.ASPECT_RECORDED_VERSION)).thenReturn(true);
    doReturn(mockedVersion).when(recordableVersionService).getCurrentVersion(nodeRef);
    // create record from version
    recordableVersionService.createRecordFromLatestVersion(filePlan, nodeRef);
    // nothing happens
    verify(mockedRecordService, never()).createRecordFromCopy(eq(filePlan), any(NodeRef.class));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 7 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImplUnitTest method noAspectMarkAsDestroyed.

/**
 * given that the version node doesn't have the recorded version aspect applied
 * when I mark the version as destroyed
 * then nothing happens
 */
@Test
public void noAspectMarkAsDestroyed() {
    // set up version
    Version mockedVersion = mock(VersionImpl.class);
    NodeRef versionNodeRef = generateNodeRef();
    when(mockedVersion.getFrozenStateNodeRef()).thenReturn(versionNodeRef);
    // indicate that the version doesn't have the aspect
    when(mockedDbNodeService.hasAspect(versionNodeRef, RecordableVersionModel.ASPECT_RECORDED_VERSION)).thenReturn(false);
    // mark as destroyed
    recordableVersionService.destroyRecordedVersion(mockedVersion);
    // verify nothing happened
    verify(mockedDbNodeService, never()).setProperty(versionNodeRef, RecordableVersionModel.PROP_DESTROYED, Boolean.TRUE);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 8 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImplUnitTest method propSetVersionDestroyed.

/**
 * given the destroyed prop is set
 * when I ask if the version is destroyed
 * then the result matches the value set in the destroy property
 */
@Test
public void propSetVersionDestroyed() {
    // set up version
    Version mockedVersion = mock(VersionImpl.class);
    NodeRef versionNodeRef = generateNodeRef();
    when(mockedVersion.getFrozenStateNodeRef()).thenReturn(versionNodeRef);
    // set prop
    when(mockedDbNodeService.getProperty(versionNodeRef, RecordableVersionModel.PROP_DESTROYED)).thenReturn(Boolean.TRUE);
    // is version destroyed
    assertTrue(recordableVersionService.isRecordedVersionDestroyed(mockedVersion));
    // set prop
    when(mockedDbNodeService.getProperty(versionNodeRef, RecordableVersionModel.PROP_DESTROYED)).thenReturn(Boolean.FALSE);
    // is version destroyed
    assertFalse(recordableVersionService.isRecordedVersionDestroyed(mockedVersion));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 9 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImplUnitTest method propNotSetVersionNotDestroyed.

/**
 * given the destroyed prop isn't set
 * when I ask if the version is destroyed
 * then the result is false
 */
@Test
public void propNotSetVersionNotDestroyed() {
    // set up version
    Version mockedVersion = mock(VersionImpl.class);
    NodeRef versionNodeRef = generateNodeRef();
    when(mockedVersion.getFrozenStateNodeRef()).thenReturn(versionNodeRef);
    // set prop not set
    when(mockedDbNodeService.getProperty(versionNodeRef, RecordableVersionModel.PROP_DESTROYED)).thenReturn(null);
    // is version destroyed
    assertFalse(recordableVersionService.isRecordedVersionDestroyed(mockedVersion));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 10 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionsBaseTest method createDocumentWithRecordVersions.

/**
 * Creates a document with three versions (1.0, 1.1, 1.2) all of which
 * are recorded.
 *
 * @return  NodeRef node reference
 */
protected NodeRef createDocumentWithRecordVersions() {
    // create document and initial version (1.0)
    final NodeRef myDocument = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() throws Exception {
            // create a document
            NodeRef testDoc = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
            ContentWriter writer = fileFolderService.getWriter(testDoc);
            writer.setEncoding("UTF-8");
            writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
            writer.putContent(GUID.generate());
            // make versionable
            Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
            props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
            props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan);
            nodeService.addAspect(testDoc, RecordableVersionModel.ASPECT_VERSIONABLE, props);
            nodeService.addAspect(testDoc, ContentModel.ASPECT_VERSIONABLE, null);
            return testDoc;
        }
    });
    // create 1.1
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            // update content
            ContentWriter writer = fileFolderService.getWriter(myDocument);
            writer.putContent(GUID.generate());
            return null;
        }
    });
    // create 1.2
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            // update content
            ContentWriter writer = fileFolderService.getWriter(myDocument);
            writer.putContent(GUID.generate());
            return null;
        }
    });
    // we do these checks to ensure that the test data is in the correct state before we
    // start to manipulate the versions and execute tests
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            // verify that the version history looks as expected
            VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
            assertNotNull(versionHistory);
            Collection<Version> versions = versionHistory.getAllVersions();
            assertEquals(3, versions.size());
            // verify 1.2 setup as expected
            Version version12 = versionHistory.getHeadVersion();
            assertEquals("1.2", version12.getVersionLabel());
            NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
            assertNotNull(recordVersion12);
            assertTrue(relationshipService.getRelationshipsTo(recordVersion12, "versions").isEmpty());
            Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, "versions");
            assertEquals(1, from12.size());
            // verify 1.1 setup as expected
            Version version11 = versionHistory.getPredecessor(version12);
            assertEquals("1.1", version11.getVersionLabel());
            NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
            assertNotNull(recordVersion11);
            Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, "versions");
            assertEquals(1, to11.size());
            assertEquals(recordVersion12, to11.iterator().next().getSource());
            Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, "versions");
            assertEquals(1, from11.size());
            // verify 1.0 setup as expected
            Version version10 = versionHistory.getPredecessor(version11);
            assertEquals("1.0", version10.getVersionLabel());
            NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
            assertNotNull(recordVersion10);
            Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, "versions");
            assertEquals(1, to10.size());
            assertEquals(recordVersion11, to10.iterator().next().getSource());
            assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, "versions").isEmpty());
            return null;
        }
    });
    return myDocument;
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) QName(org.alfresco.service.namespace.QName) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) Version(org.alfresco.service.cmr.version.Version) Collection(java.util.Collection) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) Map(java.util.Map) PropertyMap(org.alfresco.util.PropertyMap)

Aggregations

Version (org.alfresco.service.cmr.version.Version)39 NodeRef (org.alfresco.service.cmr.repository.NodeRef)31 VersionHistory (org.alfresco.service.cmr.version.VersionHistory)17 Serializable (java.io.Serializable)12 QName (org.alfresco.service.namespace.QName)9 ArrayList (java.util.ArrayList)8 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 Set (java.util.Set)6 MapNode (org.alfresco.web.bean.repository.MapNode)5 Locale (java.util.Locale)4 Map (java.util.Map)4 Node (org.alfresco.rest.api.model.Node)4 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)4 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)3 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)3 PropertyMap (org.alfresco.util.PropertyMap)3 Collection (java.util.Collection)2