mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
RM-2194: unit tests used to demonstrate current behaviour
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.3@118277 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
|
||||
/**
|
||||
* Test recorded version histories when interacting with cm:versionable aspect
|
||||
* and the auto-version behvaiour.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.3.1
|
||||
*/
|
||||
public class AutoVersionTest extends RecordableVersionsBaseTest
|
||||
{
|
||||
/**
|
||||
* Given a versionable document
|
||||
* When I specialise the type of the document
|
||||
* Then the version history has only one initial version
|
||||
* And it does not represent the current type of the document
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionCreated()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
|
||||
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState));
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a versionable document with initial version turned off
|
||||
* When I specialise the type of the document
|
||||
* Then the version history remains empty
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionNotCreated()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNull(versionHistory);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -28,6 +28,7 @@ import org.alfresco.repo.version.VersionModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionType;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
* Declare as record version integration tests
|
||||
@@ -99,7 +100,7 @@ public class DeclareAsRecordVersionTest extends RecordableVersionsBaseTest
|
||||
|
||||
/**
|
||||
* Given versionable content with a recorded latest version
|
||||
* When I delcare a version record
|
||||
* When I declare a version record
|
||||
* Then nothing happens since the latest version is already recorded
|
||||
* And a warning is logged
|
||||
*/
|
||||
@@ -146,5 +147,62 @@ public class DeclareAsRecordVersionTest extends RecordableVersionsBaseTest
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a document is a specialized type
|
||||
* When version is declared as a record
|
||||
* Then the record is the same type as the source document
|
||||
*
|
||||
* @see https://issues.alfresco.com/jira/browse/RM-2194
|
||||
*/
|
||||
public void testSpecializedContentType()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private NodeRef customDocument;
|
||||
private NodeRef versionRecord;
|
||||
private Map<String, Serializable> versionProperties;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create content
|
||||
customDocument = fileFolderService.create(dmFolder, GUID.generate(), TYPE_CUSTOM_TYPE).getNodeRef();
|
||||
prepareContent(customDocument);
|
||||
|
||||
// setup version properties
|
||||
versionProperties = new HashMap<String, Serializable>(2);
|
||||
versionProperties.put(Version.PROP_DESCRIPTION, DESCRIPTION);
|
||||
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
|
||||
|
||||
// create version
|
||||
versionService.createVersion(customDocument, versionProperties);
|
||||
|
||||
// assert that the latest version is not recorded
|
||||
assertFalse(recordableVersionService.isCurrentVersionRecorded(customDocument));
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// create version record from latest version
|
||||
versionRecord = recordableVersionService.createRecordFromLatestVersion(filePlan, customDocument);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// check the created record
|
||||
assertNotNull(versionRecord);
|
||||
assertTrue(recordService.isRecord(versionRecord));
|
||||
|
||||
// check the record type is correct
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(versionRecord));
|
||||
|
||||
// assert the current version is recorded
|
||||
assertTrue(recordableVersionService.isCurrentVersionRecorded(customDocument));
|
||||
|
||||
// check the recorded version
|
||||
checkRecordedVersion(customDocument, DESCRIPTION, "0.1");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -76,25 +76,31 @@ public abstract class RecordableVersionsBaseTest extends BaseRMTestCase implemen
|
||||
// create authentication for owner
|
||||
createPerson(OWNER);
|
||||
|
||||
// prepare content
|
||||
prepareContent(dmDocument);
|
||||
}
|
||||
|
||||
protected void prepareContent(NodeRef content)
|
||||
{
|
||||
// add titled aspect
|
||||
PropertyMap titledProperties = new PropertyMap(2);
|
||||
titledProperties.put(ContentModel.PROP_TITLE, "document title");
|
||||
titledProperties.put(ContentModel.PROP_DESCRIPTION, "document description");
|
||||
nodeService.addAspect(dmDocument, ContentModel.ASPECT_TITLED, titledProperties);
|
||||
nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProperties);
|
||||
|
||||
// add ownable aspect
|
||||
PropertyMap ownableProperties = new PropertyMap(1);
|
||||
ownableProperties.put(ContentModel.PROP_OWNER, OWNER);
|
||||
nodeService.addAspect(dmDocument, ContentModel.ASPECT_OWNABLE, ownableProperties);
|
||||
nodeService.addAspect(content, ContentModel.ASPECT_OWNABLE, ownableProperties);
|
||||
|
||||
// add Dublin core aspect
|
||||
PropertyMap dublinCoreProperties = new PropertyMap(2);
|
||||
dublinCoreProperties.put(QNAME_PUBLISHER, PUBLISHER);
|
||||
dublinCoreProperties.put(QNAME_SUBJECT, SUBJECT);
|
||||
nodeService.addAspect(dmDocument, ContentModel.ASPECT_DUBLINCORE, dublinCoreProperties);
|
||||
nodeService.addAspect(content, ContentModel.ASPECT_DUBLINCORE, dublinCoreProperties);
|
||||
|
||||
// add content
|
||||
ContentWriter writer = contentService.getWriter(dmDocument, ContentModel.PROP_CONTENT, true);
|
||||
ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.putContent(CONTENT);
|
||||
@@ -122,7 +128,7 @@ public abstract class RecordableVersionsBaseTest extends BaseRMTestCase implemen
|
||||
|
||||
// store document state
|
||||
Map<QName, Serializable> beforeProperties = nodeService.getProperties(document);
|
||||
Set<QName> beforeAspects = nodeService.getAspects(dmDocument);
|
||||
Set<QName> beforeAspects = nodeService.getAspects(document);
|
||||
|
||||
// get the current version
|
||||
Version version = versionService.getCurrentVersion(document);
|
||||
@@ -230,6 +236,9 @@ public abstract class RecordableVersionsBaseTest extends BaseRMTestCase implemen
|
||||
}
|
||||
}
|
||||
|
||||
// remove "owner" from cloneFrozenProperties
|
||||
cloneFrozenProperties.remove(ContentModel.PROP_OWNER);
|
||||
|
||||
|
||||
// frozen properties should be empty
|
||||
assertTrue("Properties in frozen state, but not in origional. " + cloneFrozenProperties.keySet(), cloneFrozenProperties.isEmpty());
|
||||
|
@@ -33,7 +33,8 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
{
|
||||
AdHocRecordableVersionsTest.class,
|
||||
AutoRecordableVersionsTest.class,
|
||||
DeclareAsRecordVersionTest.class
|
||||
DeclareAsRecordVersionTest.class,
|
||||
AutoVersionTest.class
|
||||
})
|
||||
public class VersionTestSuite
|
||||
{
|
||||
|
Reference in New Issue
Block a user