Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)

51903 to 54309 


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Samuel Langlois
2013-08-20 17:17:31 +00:00
parent 0a36e2af67
commit ab4ca7177f
1576 changed files with 36419 additions and 8603 deletions

View File

@@ -1,505 +0,0 @@
/*
* Copyright (C) 2005-2010 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.repo.version;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.dictionary.DictionaryBootstrap;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.node.archive.NodeArchiveService;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.version.common.versionlabel.SerialVersionLabelPolicy;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MLText;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.BaseSpringTest;
public abstract class BaseVersionStoreTest extends BaseSpringTest
{
/*
* Services used by the tests
*/
protected NodeService dbNodeService;
protected VersionService versionService;
protected ContentService contentService;
protected DictionaryDAO dictionaryDAO;
protected MutableAuthenticationService authenticationService;
protected TransactionService transactionService;
protected RetryingTransactionHelper txnHelper;
protected MutableAuthenticationDao authenticationDAO;
protected NodeArchiveService nodeArchiveService;
protected NodeService nodeService;
protected PermissionService permissionService;
protected CheckOutCheckInService checkOutCheckInService;
protected VersionMigrator versionMigrator;
protected SearchService versionSearchService;
protected DictionaryService dictionaryService;
protected PolicyComponent policyComponent;
protected BehaviourFilter policyBehaviourFilter;
/*
* Data used by tests
*/
protected StoreRef testStoreRef;
protected NodeRef rootNodeRef;
protected Map<String, Serializable> versionProperties;
protected HashMap<QName, Serializable> nodeProperties;
/**
* The most recent set of versionable nodes created by createVersionableNode
*/
protected HashMap<String, NodeRef> versionableNodes;
/*
* Property names and values
*/
protected static final String TEST_NAMESPACE = "http://www.alfresco.org/test/versionstorebasetest/1.0";
protected static final QName TEST_TYPE_QNAME = QName.createQName(TEST_NAMESPACE, "testtype");
protected static final QName TEST_ASPECT_QNAME = QName.createQName(TEST_NAMESPACE, "testaspect");
protected static final QName PROP_1 = QName.createQName(TEST_NAMESPACE, "prop1");
protected static final QName PROP_2 = QName.createQName(TEST_NAMESPACE, "prop2");
protected static final QName PROP_3 = QName.createQName(TEST_NAMESPACE, "prop3");
protected static final QName MULTI_PROP = QName.createQName(TEST_NAMESPACE, "multiProp");
protected static final String VERSION_PROP_1 = "versionProp1";
protected static final String VERSION_PROP_2 = "versionProp2";
protected static final String VERSION_PROP_3 = "versionProp3";
protected static final String VALUE_1 = "value1";
protected static final String VALUE_2 = "value2";
protected static final String VALUE_3 = "value3";
protected static final QName TEST_CHILD_ASSOC_1 = QName.createQName(TEST_NAMESPACE, "childassoc1");
protected static final QName TEST_CHILD_ASSOC_2 = QName.createQName(TEST_NAMESPACE, "childassoc2");
protected static final QName TEST_ASSOC = QName.createQName(TEST_NAMESPACE, "assoc1");
protected Collection<String> multiValue = null;
protected static final String MULTI_VALUE_1 = "multi1";
protected static final String MULTI_VALUE_2 = "multi2";
protected MLText mlText;
protected static final QName MLTEXT_PROP = QName.createQName(TEST_NAMESPACE, "propMl");
/**
* Test content
*/
protected static final String TEST_CONTENT = "This is the versioned test content.";
/**
* Test user details
*/
private static final String PWD = "admin";
/**
* Sets the meta model dao
*
* @param dictionaryDAO the meta model dao
*/
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
{
this.dictionaryDAO = dictionaryDAO;
}
public void setVersionService(VersionService versionService)
{
this.versionService = versionService;
}
/**
* Called during the transaction setup
*/
protected void onSetUpInTransaction() throws Exception
{
// Set the multi value if required
if (this.multiValue == null)
{
this.multiValue = new ArrayList<String>();
this.multiValue.add(MULTI_VALUE_1);
this.multiValue.add(MULTI_VALUE_2);
}
// Get the services by name from the application context
this.dbNodeService = (NodeService)applicationContext.getBean("dbNodeService");
this.contentService = (ContentService)applicationContext.getBean("contentService");
this.authenticationService = (MutableAuthenticationService)applicationContext.getBean("authenticationService");
this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
this.txnHelper = (RetryingTransactionHelper) applicationContext.getBean("retryingTransactionHelper");
this.authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
this.nodeArchiveService = (NodeArchiveService) applicationContext.getBean("nodeArchiveService");
this.nodeService = (NodeService)applicationContext.getBean("nodeService");
this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
this.checkOutCheckInService = (CheckOutCheckInService) applicationContext.getBean("checkOutCheckInService");
this.versionSearchService = (SearchService)this.applicationContext.getBean("versionSearchService");
this.versionMigrator = (VersionMigrator)this.applicationContext.getBean("versionMigrator");
this.dictionaryService = (DictionaryService)this.applicationContext.getBean("dictionaryService");
this.policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent");
this.policyBehaviourFilter = (BehaviourFilter)this.applicationContext.getBean("policyBehaviourFilter");
setVersionService((VersionService)applicationContext.getBean("versionService"));
authenticationService.clearCurrentSecurityContext();
// Create the test model
createTestModel();
// Create a bag of properties for later use
this.versionProperties = new HashMap<String, Serializable>();
versionProperties.put(VERSION_PROP_1, VALUE_1);
versionProperties.put(VERSION_PROP_2, VALUE_2);
versionProperties.put(VERSION_PROP_3, VALUE_3);
// Create the node properties
this.nodeProperties = new HashMap<QName, Serializable>();
this.nodeProperties.put(PROP_1, VALUE_1);
this.nodeProperties.put(PROP_2, VALUE_2);
this.nodeProperties.put(PROP_3, VALUE_3);
this.nodeProperties.put(MULTI_PROP, (Serializable)multiValue);
this.nodeProperties.put(ContentModel.PROP_CONTENT, new ContentData(null, "text/plain", 0L, "UTF-8"));
// Add mlText property
this.mlText = new MLText(Locale.UK, "UK value");
this.mlText.addValue(Locale.US, "Y'all US value");
this.nodeProperties.put(MLTEXT_PROP, this.mlText);
// Create a workspace that contains the 'live' nodes
this.testStoreRef = this.dbNodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
// Get a reference to the root node
this.rootNodeRef = this.dbNodeService.getRootNode(this.testStoreRef);
// Create and authenticate the user
if(!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
{
authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), PWD.toCharArray());
}
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
}
/**
* Creates the test model used by the tests
*/
private void createTestModel()
{
// register the test model
List<String> bootstrapModels = new ArrayList<String>();
bootstrapModels.add("org/alfresco/repo/version/VersionStoreBaseTest_model.xml");
DictionaryBootstrap bootstrap = new DictionaryBootstrap();
bootstrap.setModels(bootstrapModels);
bootstrap.setDictionaryDAO(dictionaryDAO);
bootstrap.bootstrap();
}
/**
* Creates a new versionable node
*
* @return the node reference
*/
protected NodeRef createNewVersionableNode()
{
return createNode(true, TEST_TYPE_QNAME);
}
protected NodeRef createNewNode()
{
return createNode(false, TEST_TYPE_QNAME);
}
protected NodeRef createNode(boolean versionable, QName nodeType)
{
// Use this map to retrive the versionable nodes in later tests
this.versionableNodes = new HashMap<String, NodeRef>();
// Create node (this node has some content)
NodeRef nodeRef = this.dbNodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}MyVersionableNode"),
nodeType,
this.nodeProperties).getChildRef();
if (versionable)
{
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
}
assertNotNull(nodeRef);
this.versionableNodes.put(nodeRef.getId(), nodeRef);
// Add the content to the node
ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.putContent(TEST_CONTENT);
// Set author
Map<QName, Serializable> authorProps = new HashMap<QName, Serializable>(1, 1.0f);
authorProps.put(ContentModel.PROP_AUTHOR, "Charles Dickens");
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, authorProps);
// Add some children to the node
NodeRef child1 = this.dbNodeService.createNode(
nodeRef,
TEST_CHILD_ASSOC_1,
TEST_CHILD_ASSOC_1,
nodeType,
this.nodeProperties).getChildRef();
if (versionable)
{
this.dbNodeService.addAspect(child1, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
}
assertNotNull(child1);
this.versionableNodes.put(child1.getId(), child1);
NodeRef child2 = this.dbNodeService.createNode(
nodeRef,
TEST_CHILD_ASSOC_2,
TEST_CHILD_ASSOC_2,
nodeType,
this.nodeProperties).getChildRef();
if (versionable)
{
this.dbNodeService.addAspect(child2, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
}
assertNotNull(child2);
this.versionableNodes.put(child2.getId(), child2);
// Create a node that can be associated with the root node
NodeRef assocNode = this.dbNodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}MyAssocNode"),
nodeType,
this.nodeProperties).getChildRef();
assertNotNull(assocNode);
this.dbNodeService.createAssociation(nodeRef, assocNode, TEST_ASSOC);
return nodeRef;
}
/**
* Creates a new version, checking the properties of the version.
* <p>
* The default test propreties are assigned to the version.
*
* @param versionableNode the versionable node
* @return the created (and checked) new version
*/
protected Version createVersion(NodeRef versionableNode)
{
return createVersion(versionableNode, this.versionProperties);
}
/**
* Creates a new version, checking the properties of the version.
*
* @param versionableNode the versionable node
* @param versionProperties the version properties
* @return the created (and checked) new version
*/
protected Version createVersion(NodeRef versionableNode, Map<String, Serializable> versionProperties)
{
// Get the next version label
String nextVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
// Now lets create a new version for this node
Version newVersion = versionService.createVersion(versionableNode, this.versionProperties);
checkNewVersion(beforeVersionTime, nextVersionLabel, newVersion, versionableNode);
// Return the new version
return newVersion;
}
protected Collection<Version> createVersion(NodeRef versionableNode, Map<String, Serializable> versionProperties, boolean versionChildren)
{
// Get the next version label
String nextVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
// Now lets create new version for this node (optionally with children)
Collection<Version> versions = versionService.createVersion(versionableNode, this.versionProperties, versionChildren);
// Check the returned versions are correct
checkVersionCollection(nextVersionLabel, beforeVersionTime, versions);
// Return the new versions
return versions;
}
/**
* Gets the next version label
*/
protected String peekNextVersionLabel(NodeRef nodeRef, Map<String, Serializable> versionProperties)
{
Version version = this.versionService.getCurrentVersion(nodeRef);
SerialVersionLabelPolicy policy = new SerialVersionLabelPolicy();
return policy.calculateVersionLabel(ContentModel.TYPE_CMOBJECT, version, versionProperties);
}
/**
* Checkd the validity of a new version
*
* @param beforeVersionTime the time snap shot before the version was created
* @param newVersion the new version
* @param versionableNode the versioned node
*/
protected void checkVersion(long beforeVersionTime, String expectedVersionLabel, Version newVersion, NodeRef versionableNode)
{
assertNotNull(newVersion);
// Check the version label
assertEquals(
"The expected version label was not used.",
expectedVersionLabel,
newVersion.getVersionLabel());
// Check the created date
long afterVersionTime = System.currentTimeMillis();
long createdDate = newVersion.getFrozenModifiedDate().getTime();
if (createdDate < beforeVersionTime || createdDate > afterVersionTime)
{
fail("The created date of the version is incorrect.");
}
// Check the creator
assertEquals(AuthenticationUtil.getAdminUserName(), newVersion.getFrozenModifier());
// Check the metadata properties of the version
Map<String, Serializable> props = newVersion.getVersionProperties();
assertNotNull("The version properties collection should not be null.", props);
if (versionProperties != null)
{
// TODO sort this out - need to check for the reserved properties too
//assertEquals(versionProperties.size(), props.size());
for (String key : versionProperties.keySet())
{
assertEquals(
versionProperties.get(key),
newVersion.getVersionProperty(key));
}
}
// Check that the node reference is correct
NodeRef nodeRef = newVersion.getFrozenStateNodeRef();
assertNotNull(nodeRef);
// Switch VersionStore depending on configured impl
if (versionService.getVersionStoreReference().getIdentifier().equals(Version2Model.STORE_ID))
{
// V2 version store (eg. workspace://version2Store)
assertEquals(
Version2Model.STORE_ID,
nodeRef.getStoreRef().getIdentifier());
assertEquals(
Version2Model.STORE_PROTOCOL,
nodeRef.getStoreRef().getProtocol());
assertNotNull(nodeRef.getId());
}
else if (versionService.getVersionStoreReference().getIdentifier().equals(VersionModel.STORE_ID))
{
// Deprecated V1 version store (eg. workspace://lightWeightVersionStore)
assertEquals(
VersionModel.STORE_ID,
nodeRef.getStoreRef().getIdentifier());
assertEquals(
VersionModel.STORE_PROTOCOL,
nodeRef.getStoreRef().getProtocol());
assertNotNull(nodeRef.getId());
}
}
protected void checkNewVersion(long beforeVersionTime, String expectedVersionLabel, Version newVersion, NodeRef versionableNode)
{
checkVersion(beforeVersionTime, expectedVersionLabel, newVersion, versionableNode);
// TODO: How do we check the frozen attributes ??
// Check the node ref for the current version
String currentVersionLabel = (String)this.dbNodeService.getProperty(
versionableNode,
ContentModel.PROP_VERSION_LABEL);
assertEquals(newVersion.getVersionLabel(), currentVersionLabel);
}
/**
* Helper method to check the validity of the list of newly created versions.
*
* @param beforeVersionTime the time before the versions where created
* @param versions the collection of version objects
*/
private void checkVersionCollection(String expectedVersionLabel, long beforeVersionTime, Collection<Version> versions)
{
for (Version version : versions)
{
// Get the frozen id from the version
String frozenNodeId = null;
// Switch VersionStore depending on configured impl
if (versionService.getVersionStoreReference().getIdentifier().equals(Version2Model.STORE_ID))
{
// V2 version store (eg. workspace://version2Store)
frozenNodeId = ((NodeRef)version.getVersionProperty(Version2Model.PROP_FROZEN_NODE_REF)).getId();
}
else if (versionService.getVersionStoreReference().getIdentifier().equals(VersionModel.STORE_ID))
{
// Deprecated V1 version store (eg. workspace://lightWeightVersionStore)
frozenNodeId = (String)version.getVersionProperty(VersionModel.PROP_FROZEN_NODE_ID);
}
assertNotNull("Unable to retrieve the frozen node id from the created version.", frozenNodeId);
// Get the original node ref (based on the forzen node)
NodeRef origionaNodeRef = this.versionableNodes.get(frozenNodeId);
assertNotNull("The versionable node ref that relates to the frozen node id can not be found.", origionaNodeRef);
// Check the new version
checkNewVersion(beforeVersionTime, expectedVersionLabel, version, origionaNodeRef);
}
}
}

View File

@@ -1,150 +0,0 @@
/*
* Copyright (C) 2005-2012 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.repo.version;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.transform.ContentTransformer;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.alfresco.service.cmr.version.Version;
/**
* Tests for retrieving frozen content from a verioned node
*
* @author Roy Wetherall
*/
public class ContentServiceImplTest extends BaseVersionStoreTest
{
/**
* Test content data
*/
private final static String UPDATED_CONTENT = "This content has been updated with a new value.";
/**
* The version content store
*/
private ContentService contentService;
/**
* Called during the transaction setup
*/
protected void onSetUpInTransaction() throws Exception
{
super.onSetUpInTransaction();
// Get the instance of the required content service
this.contentService = (ContentService)this.applicationContext.getBean("contentService");
}
/**
* Test getReader
*/
public void testGetReader()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
NodeRef versionNodeRef = version.getFrozenStateNodeRef();
// Get the content reader for the frozen node
ContentReader contentReader = this.contentService.getReader(versionNodeRef, ContentModel.PROP_CONTENT);
assertNotNull(contentReader);
assertEquals(TEST_CONTENT, contentReader.getContentString());
// Now update the content and verison again
ContentWriter contentWriter = this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, true);
assertNotNull(contentWriter);
contentWriter.putContent(UPDATED_CONTENT);
Version version2 = createVersion(versionableNode, this.versionProperties);
NodeRef version2NodeRef = version2.getFrozenStateNodeRef();
// Get the content reader for the new verisoned content
ContentReader contentReader2 = this.contentService.getReader(version2NodeRef, ContentModel.PROP_CONTENT);
assertNotNull(contentReader2);
assertEquals(UPDATED_CONTENT, contentReader2.getContentString());
}
/**
* Test getWriter
*/
public void testGetWriter()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
// Get writer is not supported by the version content service
try
{
ContentWriter contentWriter = this.contentService.getWriter(
version.getFrozenStateNodeRef(),
ContentModel.PROP_CONTENT,
true);
contentWriter.putContent("bobbins");
fail("This operation is not supported.");
}
catch (Exception exception)
{
// An exception should be raised
}
}
// Commented out as OpenOffice is not on the build machines.
// public void testGetTransformer0()
// {
// ContentTransformer transformer = contentService.getTransformer("test", "application/vnd.ms-excel", 0,
// "application/x-shockwave-flash", new TransformationOptions());
// assertTrue("Should have found a transformer for 0 bytes", transformer != null);
// }
//
// public void testGetTransformer10K()
// {
// ContentTransformer transformer = contentService.getTransformer("test", "application/vnd.ms-excel", 1024*10,
// "application/x-shockwave-flash", new TransformationOptions());
// assertTrue("Should have found a transformer for 10 K", transformer != null);
// }
//
// public void testGetTransformer1M()
// {
// ContentTransformer transformer = contentService.getTransformer("test", "application/vnd.ms-excel", 1024*1024,
// "application/x-shockwave-flash", new TransformationOptions());
// assertTrue("Should have found a transformer for 1M", transformer != null);
// }
//
// public void testGetTransformer10M()
// {
// ContentTransformer transformer = contentService.getTransformer("test", "application/vnd.ms-excel", 1024*1024*10,
// "application/x-shockwave-flash", new TransformationOptions());
// assertTrue("Should NOT have found a transformer for 10M as the is a 1M limit on xsl mimetype", transformer == null);
// }
//
// public void testGetMaxSourceSizeByes()
// {
// long maxSourceSizeBytes = contentService.getMaxSourceSizeBytes("application/vnd.ms-excel",
// "application/x-shockwave-flash", new TransformationOptions());
// assertEquals("Should have found a transformer that can handle 1M", 1024*1024, maxSourceSizeBytes);
// }
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -142,7 +142,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void deleteStore(StoreRef storeRef)
public boolean deleteStore(StoreRef storeRef)
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -229,7 +229,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void deleteNode(NodeRef nodeRef) throws InvalidNodeRefException
public boolean deleteNode(NodeRef nodeRef) throws InvalidNodeRefException
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -262,7 +262,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void removeChild(NodeRef parentRef, NodeRef childRef) throws InvalidNodeRefException
public boolean removeChild(NodeRef parentRef, NodeRef childRef) throws InvalidNodeRefException
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -305,7 +305,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void setChildAssociationIndex(ChildAssociationRef childAssocRef, int index) throws InvalidChildAssociationRefException
public boolean setChildAssociationIndex(ChildAssociationRef childAssocRef, int index) throws InvalidChildAssociationRefException
{
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
}
@@ -322,7 +322,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @see org.alfresco.service.cmr.repository.NodeService#setType(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void setType(NodeRef nodeRef, QName typeQName) throws InvalidNodeRefException
public boolean setType(NodeRef nodeRef, QName typeQName) throws InvalidNodeRefException
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -331,7 +331,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void addAspect(NodeRef nodeRef, QName aspectRef, Map<QName, Serializable> aspectProperties) throws InvalidNodeRefException, InvalidAspectException
public boolean addAspect(NodeRef nodeRef, QName aspectRef, Map<QName, Serializable> aspectProperties) throws InvalidNodeRefException, InvalidAspectException
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -348,7 +348,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void removeAspect(NodeRef nodeRef, QName aspectRef) throws InvalidNodeRefException, InvalidAspectException
public boolean removeAspect(NodeRef nodeRef, QName aspectRef) throws InvalidNodeRefException, InvalidAspectException
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -442,7 +442,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void setProperties(NodeRef nodeRef, Map<QName, Serializable> properties) throws InvalidNodeRefException
public boolean setProperties(NodeRef nodeRef, Map<QName, Serializable> properties) throws InvalidNodeRefException
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -451,7 +451,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void addProperties(NodeRef nodeRef, Map<QName, Serializable> properties) throws InvalidNodeRefException
public boolean addProperties(NodeRef nodeRef, Map<QName, Serializable> properties) throws InvalidNodeRefException
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -460,7 +460,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void setProperty(NodeRef nodeRef, QName qame, Serializable value) throws InvalidNodeRefException
public boolean setProperty(NodeRef nodeRef, QName qame, Serializable value) throws InvalidNodeRefException
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -469,7 +469,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
public boolean removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -568,7 +568,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
}
@Override
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef, QName typeQName, QName qname, int maxResults,
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef, QNamePattern typeQName, QNamePattern qname, int maxResults,
boolean preload) throws InvalidNodeRefException
{
List<ChildAssociationRef> result = getChildAssocs(nodeRef, typeQName, qname);
@@ -632,7 +632,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
* @throws UnsupportedOperationException always
*/
@Override
public void setAssociations(NodeRef sourceRef, QName assocTypeQName, List<NodeRef> targetRefs)
public boolean setAssociations(NodeRef sourceRef, QName assocTypeQName, List<NodeRef> targetRefs)
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
@@ -641,7 +641,7 @@ public class NodeServiceImpl implements NodeService, VersionModel
/**
* @throws UnsupportedOperationException always
*/
public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
public boolean removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
{
// This operation is not supported for a version store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);

View File

@@ -1,718 +0,0 @@
/*
* Copyright (C) 2005-2010 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.repo.version;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.cache.TransactionalCache;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.debug.NodeStoreInspector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Roy Wetherall
*/
public class NodeServiceImplTest extends BaseVersionStoreTest
{
private static Log logger = LogFactory.getLog(NodeServiceImplTest.class);
/**
* version store node service
*/
protected NodeService versionStoreNodeService = null;
/**
* Error message
*/
private final static String MSG_ERR =
"This operation is not supported by a version store implementation of the node service.";
/**
* Dummy data used in failure tests
*/
private NodeRef dummyNodeRef = null;
private QName dummyQName = null;
/**
* Called during the transaction setup
*/
protected void onSetUpInTransaction() throws Exception
{
super.onSetUpInTransaction();
// Get the node service by name
this.versionStoreNodeService = (NodeService)this.applicationContext.getBean("versionNodeService");
// Create some dummy data used during the tests
this.dummyNodeRef = new NodeRef(
this.versionService.getVersionStoreReference(),
"dummy");
this.dummyQName = QName.createQName("{dummy}dummy");
}
/**
* Test getType
*/
public void testGetType()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
// Get the type from the versioned state
QName versionedType = this.versionStoreNodeService.getType(version.getFrozenStateNodeRef());
assertNotNull(versionedType);
assertEquals(this.dbNodeService.getType(versionableNode), versionedType);
}
/**
* Test getProperties
*/
public void testGetProperties()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Get a list of the nodes properties
Map<QName, Serializable> origProps = this.dbNodeService.getProperties(versionableNode);
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
// Get the properties of the versioned state
Map<QName, Serializable> versionedProperties = this.versionStoreNodeService.getProperties(version.getFrozenStateNodeRef());
if (logger.isDebugEnabled())
{
logger.debug("original ("+origProps.size()+"): " + origProps.keySet());
logger.debug("versioned ("+versionedProperties.size()+"): " + versionedProperties.keySet());
}
for (QName key : origProps.keySet())
{
assertTrue(versionedProperties.containsKey(key));
assertEquals(""+key, origProps.get(key), versionedProperties.get(key));
}
// NOTE: cm:versionLabel is an expected additional property
//assertEquals(origProps.size(), versionedProperties.size());
// check version label
assertEquals("first version label", "0.1", versionedProperties.get(ContentModel.PROP_VERSION_LABEL));
// TODO do futher versioning and check by changing values
}
/**
* Test getProperty
*/
public void testGetProperty()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
// Check the property values can be retrieved
Serializable value1 = this.versionStoreNodeService.getProperty(
version.getFrozenStateNodeRef(),
PROP_1);
assertEquals(VALUE_1, value1);
// Check the mlText property
// TODO
// Check the multi values property specifically
Collection<String> multiValue = (Collection<String>)this.versionStoreNodeService.getProperty(version.getFrozenStateNodeRef(), MULTI_PROP);
assertNotNull(multiValue);
assertEquals(2, multiValue.size());
String[] array = multiValue.toArray(new String[multiValue.size()]);
assertEquals(MULTI_VALUE_1, array[0]);
assertEquals(MULTI_VALUE_2, array[1]);
}
/**
* Test getChildAssocs
*/
public void testGetChildAssocs()
{
if (logger.isTraceEnabled())
{
// Let's have a look at the version store ..
logger.trace(NodeStoreInspector.dumpNodeStore(
this.dbNodeService,
this.versionService.getVersionStoreReference()) + "\n\n");
logger.trace("");
}
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
Collection<ChildAssociationRef> originalChildren = this.dbNodeService.getChildAssocs(versionableNode);
assertNotNull(originalChildren);
// Store the original children in a map for easy navigation later
HashMap<String, ChildAssociationRef> originalChildAssocRefs = new HashMap<String, ChildAssociationRef>();
for (ChildAssociationRef ref : originalChildren)
{
originalChildAssocRefs.put(ref.getChildRef().getId(), ref);
}
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
if (logger.isTraceEnabled())
{
// Let's have a look at the version store ..
logger.trace(NodeStoreInspector.dumpNodeStore(
this.dbNodeService,
this.versionService.getVersionStoreReference()));
logger.trace("");
}
// Get the children of the versioned node
Collection<ChildAssociationRef> versionedChildren = this.versionStoreNodeService.getChildAssocs(version.getFrozenStateNodeRef());
assertNotNull(versionedChildren);
assertEquals(originalChildren.size(), versionedChildren.size());
for (ChildAssociationRef versionedChildRef : versionedChildren)
{
ChildAssociationRef origChildAssocRef = originalChildAssocRefs.get(versionedChildRef.getChildRef().getId());
assertNotNull(origChildAssocRef);
assertEquals(
origChildAssocRef.getChildRef(),
versionedChildRef.getChildRef());
assertEquals(
origChildAssocRef.isPrimary(),
versionedChildRef.isPrimary());
assertEquals(
origChildAssocRef.getNthSibling(),
versionedChildRef.getNthSibling());
}
}
/**
* Test getAssociationTargets
*/
public void testGetAssociationTargets()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Store the current details of the target associations
List<AssociationRef> origAssocs = this.dbNodeService.getTargetAssocs(
versionableNode,
RegexQNamePattern.MATCH_ALL);
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
List<AssociationRef> assocs = this.versionStoreNodeService.getTargetAssocs(
version.getFrozenStateNodeRef(),
RegexQNamePattern.MATCH_ALL);
assertNotNull(assocs);
assertEquals(origAssocs.size(), assocs.size());
}
/**
* Test hasAspect
*/
public void testHasAspect()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
boolean test1 = this.versionStoreNodeService.hasAspect(
version.getFrozenStateNodeRef(),
ApplicationModel.ASPECT_UIFACETS);
assertFalse(test1);
boolean test2 = this.versionStoreNodeService.hasAspect(
version.getFrozenStateNodeRef(),
ContentModel.ASPECT_VERSIONABLE);
assertTrue(test2);
}
/**
* Test getAspects
*/
public void testGetAspects()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
Set<QName> origAspects = this.dbNodeService.getAspects(versionableNode);
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
Set<QName> aspects = this.versionStoreNodeService.getAspects(version.getFrozenStateNodeRef());
assertEquals(origAspects.size(), aspects.size());
for (QName origAspect : origAspects)
{
assertTrue(origAspect+"",aspects.contains(origAspect));
}
}
/**
* Test getParentAssocs
*/
public void testGetParentAssocs()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
NodeRef nodeRef = version.getFrozenStateNodeRef();
List<ChildAssociationRef> results = this.versionStoreNodeService.getParentAssocs(nodeRef);
assertNotNull(results);
assertEquals(1, results.size());
ChildAssociationRef childAssoc = results.get(0);
assertEquals(nodeRef, childAssoc.getChildRef());
NodeRef versionStoreRoot = this.dbNodeService.getRootNode(this.versionService.getVersionStoreReference());
assertEquals(versionStoreRoot, childAssoc.getParentRef());
}
/**
* Test getPrimaryParent
*/
public void testGetPrimaryParent()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
NodeRef nodeRef = version.getFrozenStateNodeRef();
ChildAssociationRef childAssoc = this.versionStoreNodeService.getPrimaryParent(nodeRef);
assertNotNull(childAssoc);
assertEquals(nodeRef, childAssoc.getChildRef());
NodeRef versionStoreRoot = this.dbNodeService.getRootNode(this.versionService.getVersionStoreReference());
assertEquals(versionStoreRoot, childAssoc.getParentRef());
}
/** ================================================
* These test ensure that the following operations
* are not supported as expected.
*/
/**
* Test createNode
*/
public void testCreateNode()
{
try
{
this.versionStoreNodeService.createNode(
dummyNodeRef,
null,
dummyQName,
ContentModel.TYPE_CONTENT);
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test addAspect
*/
public void testAddAspect()
{
try
{
this.versionStoreNodeService.addAspect(
dummyNodeRef,
TEST_ASPECT_QNAME,
null);
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test removeAspect
*/
public void testRemoveAspect()
{
try
{
this.versionStoreNodeService.removeAspect(
dummyNodeRef,
TEST_ASPECT_QNAME);
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test delete node
*/
public void testDeleteNode()
{
try
{
this.versionStoreNodeService.deleteNode(this.dummyNodeRef);
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test addChild
*/
public void testAddChild()
{
try
{
this.versionStoreNodeService.addChild(
this.dummyNodeRef,
this.dummyNodeRef,
this.dummyQName,
this.dummyQName);
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test removeChild
*/
public void testRemoveChild()
{
try
{
this.versionStoreNodeService.removeChild(
this.dummyNodeRef,
this.dummyNodeRef);
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test setProperties
*/
public void testSetProperties()
{
try
{
this.versionStoreNodeService.setProperties(
this.dummyNodeRef,
new HashMap<QName, Serializable>());
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test setProperty
*/
public void testSetProperty()
{
try
{
this.versionStoreNodeService.setProperty(
this.dummyNodeRef,
this.dummyQName,
"dummy");
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test createAssociation
*/
public void testCreateAssociation()
{
try
{
this.versionStoreNodeService.createAssociation(
this.dummyNodeRef,
this.dummyNodeRef,
this.dummyQName);
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test removeAssociation
*/
public void testRemoveAssociation()
{
try
{
this.versionStoreNodeService.removeAssociation(
this.dummyNodeRef,
this.dummyNodeRef,
this.dummyQName);
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test getAssociationSources
*/
public void testGetAssociationSources()
{
try
{
this.versionStoreNodeService.getSourceAssocs(
this.dummyNodeRef,
this.dummyQName);
fail("This operation is not supported.");
}
catch (UnsupportedOperationException exception)
{
if (exception.getMessage() != MSG_ERR)
{
fail("Unexpected exception raised during method excution: " + exception.getMessage());
}
}
}
/**
* Test getPath
*/
public void testGetPath()
{
Path path = this.versionStoreNodeService.getPath(this.dummyNodeRef);
}
/**
* Test getPaths
*/
public void testGetPaths()
{
List<Path> paths = this.versionStoreNodeService.getPaths(this.dummyNodeRef, false);
}
/**
* Tests that we can store and retrieve unicode properties
* and association names.
* If there's something wrong with how we're setting up the
* database or database connection WRT unicode, this is a
* test that'll hopefully break in testing and alert us!
*/
public void testUnicodeNamesAndProperties()
{
// Get our cache objects
List<TransactionalCache> cachesToClear = new ArrayList<TransactionalCache>();
cachesToClear.add( (TransactionalCache)this.applicationContext.getBean("propertyValueCache") );
cachesToClear.add( (TransactionalCache)this.applicationContext.getBean("node.nodesCache") );
cachesToClear.add( (TransactionalCache)this.applicationContext.getBean("node.propertiesCache") );
// First up, try with a simple English name+properties
String engProp = "This is a property in English";
QName engQName = QName.createQName("NameSpace", "In English");
NodeRef engNode = nodeService.createNode(
this.rootNodeRef, ContentModel.ASSOC_CONTAINS,
engQName, ContentModel.TYPE_CONTENT
).getChildRef();
nodeService.setProperty(engNode, ContentModel.PROP_NAME, engProp);
// Check they exist and are correct
assertEquals(engProp, nodeService.getProperty(engNode, ContentModel.PROP_NAME));
assertEquals(1, nodeService.getChildAssocs(this.rootNodeRef, ContentModel.ASSOC_CONTAINS, engQName).size());
assertEquals(engNode, nodeService.getChildByName(rootNodeRef, ContentModel.ASSOC_CONTAINS, engProp));
// Now French
String frProp = "C'est une propri\u00e9t\u00e9 en fran\u00e7ais"; // C'est une propriété en français
QName frQName = QName.createQName("NameSpace", "En Fran\u00e7ais"); // En Français
NodeRef frNode = nodeService.createNode(
this.rootNodeRef, ContentModel.ASSOC_CONTAINS,
frQName, ContentModel.TYPE_CONTENT
).getChildRef();
nodeService.setProperty(frNode, ContentModel.PROP_NAME, frProp);
assertEquals(frProp, nodeService.getProperty(frNode, ContentModel.PROP_NAME));
assertEquals(1, nodeService.getChildAssocs(this.rootNodeRef, ContentModel.ASSOC_CONTAINS, frQName).size());
assertEquals(frNode, nodeService.getChildByName(rootNodeRef, ContentModel.ASSOC_CONTAINS, frProp));
// Zap the cache and re-check
// (If the DB is broken but the cache works, then the above
// tests could pass even in the face of a problem)
for(TransactionalCache tc : cachesToClear) tc.clear();
assertEquals(frProp, nodeService.getProperty(frNode, ContentModel.PROP_NAME));
assertEquals(1, nodeService.getChildAssocs(this.rootNodeRef, ContentModel.ASSOC_CONTAINS, frQName).size());
assertEquals(frNode, nodeService.getChildByName(rootNodeRef, ContentModel.ASSOC_CONTAINS, frProp));
// Next Spanish
String esProp = "Esta es una propiedad en Espa\u00f1ol"; // Esta es una propiedad en Español
QName esQName = QName.createQName("NameSpace", "En Espa\u00f1ol"); // En Español
NodeRef esNode = nodeService.createNode(
this.rootNodeRef, ContentModel.ASSOC_CONTAINS,
esQName, ContentModel.TYPE_CONTENT
).getChildRef();
nodeService.setProperty(esNode, ContentModel.PROP_NAME, esProp);
assertEquals(esProp, nodeService.getProperty(esNode, ContentModel.PROP_NAME));
assertEquals(1, nodeService.getChildAssocs(this.rootNodeRef, ContentModel.ASSOC_CONTAINS, esQName).size());
assertEquals(esNode, nodeService.getChildByName(rootNodeRef, ContentModel.ASSOC_CONTAINS, esProp));
// Zap cache and re-test the Spanish
for(TransactionalCache tc : cachesToClear) tc.clear();
assertEquals(esProp, nodeService.getProperty(esNode, ContentModel.PROP_NAME));
assertEquals(1, nodeService.getChildAssocs(this.rootNodeRef, ContentModel.ASSOC_CONTAINS, esQName).size());
assertEquals(esNode, nodeService.getChildByName(rootNodeRef, ContentModel.ASSOC_CONTAINS, esProp));
// Finally Japanese
String jpProp = "\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u304f\u3060\u3055\u3044\u3002"; // ãã¯ãƒªãƒƒã¯ã<C2AF>—ã<E28094>¦ã<C2A6><C3A3>ã<EFBFBD> ã<C2A0>•ã<E280A2>„ã€
QName jpQName = QName.createQName("NameSpace", "\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u304f"); // ãã¯ãƒªãƒƒã¯ã<C2AF>—ã<E28094>¦ã<C2A6><C3A3>
NodeRef jpNode = nodeService.createNode(
this.rootNodeRef, ContentModel.ASSOC_CONTAINS,
jpQName, ContentModel.TYPE_CONTENT
).getChildRef();
nodeService.setProperty(jpNode, ContentModel.PROP_NAME, jpProp);
assertEquals(jpProp, nodeService.getProperty(jpNode, ContentModel.PROP_NAME));
assertEquals(1, nodeService.getChildAssocs(this.rootNodeRef, ContentModel.ASSOC_CONTAINS, jpQName).size());
assertEquals(jpNode, nodeService.getChildByName(rootNodeRef, ContentModel.ASSOC_CONTAINS, jpProp));
// Zap the cache and check the Japanese
for(TransactionalCache tc : cachesToClear) tc.clear();
assertEquals(jpProp, nodeService.getProperty(jpNode, ContentModel.PROP_NAME));
assertEquals(1, nodeService.getChildAssocs(this.rootNodeRef, ContentModel.ASSOC_CONTAINS, jpQName).size());
assertEquals(jpNode, nodeService.getChildByName(rootNodeRef, ContentModel.ASSOC_CONTAINS, jpProp));
}
/*
* Test that during applying versionable aspect to the node
* that does not already have versionable aspect
* version history of this node should be deleted
*/
public void testALF1793AddVersionableAspect()
{
// Create a new versionable node and create new version
NodeRef versionableNode = createNewVersionableNode();
createVersion(versionableNode, this.versionProperties);
//Copy UUID from node properties
Map<QName, Serializable> oldProperties = this.dbNodeService.getProperties(versionableNode);
Map<QName, Serializable> newProperties = new HashMap<QName, Serializable>();
newProperties.put(ContentModel.PROP_NODE_UUID, oldProperties.get(ContentModel.PROP_NODE_UUID));
// Delete node and create new one with the same UUID
this.dbNodeService.deleteNode(versionableNode);
NodeRef newNode = this.dbNodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}MyNode"),
TEST_TYPE_QNAME,
newProperties).getChildRef();
// add the versionable aspect to the node and create new version
this.dbNodeService.addAspect(newNode, ContentModel.ASPECT_VERSIONABLE, null);
Version version = createVersion(newNode, this.versionProperties);
assertNotNull(version);
}
}

View File

@@ -1214,6 +1214,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
{
if (children.contains(versionedChild) == false)
{
NodeRef childRef = null;
if (this.nodeService.exists(versionedChild.getChildRef()) == true)
{
// The node was a primary child of the parent, but that is no longer the case. Despite this
@@ -1221,11 +1222,24 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
// The best thing to do in this situation will be to re-add the node as a child, but it will not
// be a primary child
String childRefName = (String) this.nodeService.getProperty(versionedChild.getChildRef(), ContentModel.PROP_NAME);
NodeRef childAssocOnVersionNode = this.nodeService.getChildByName(nodeRef, versionedChild.getTypeQName(), childRefName);
if (childAssocOnVersionNode == null )
{
this.nodeService.addChild(nodeRef, versionedChild.getChildRef(), versionedChild.getTypeQName(), versionedChild.getQName());
}
childRef = this.nodeService.getChildByName(nodeRef, versionedChild.getTypeQName(), childRefName);
// we can faced with association that allow duplicate names
if (childRef == null)
{
List<ChildAssociationRef> allAssocs = nodeService.getParentAssocs(versionedChild.getChildRef(), versionedChild.getTypeQName(), RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef assocToCheck : allAssocs)
{
if (children.contains(assocToCheck))
{
childRef = assocToCheck.getChildRef();
break;
}
}
}
if (childRef == null )
{
childRef = this.nodeService.addChild(nodeRef, versionedChild.getChildRef(), versionedChild.getTypeQName(), versionedChild.getQName()).getChildRef();
}
}
else
{
@@ -1236,7 +1250,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
if (deep == true && getVersionHistoryNodeRef(versionedChild.getChildRef()) != null)
{
// We're going to try and restore the missing child node and recreate the assoc
restore(
childRef = restore(
versionedChild.getChildRef(),
nodeRef,
versionedChild.getTypeQName(),
@@ -1250,6 +1264,10 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
// Since this was never a primary assoc and the child has been deleted we won't recreate
// the missing node as it was never owned by the node and we wouldn't know where to put it.
}
if (childRef != null)
{
children.remove(nodeService.getPrimaryParent(childRef));
}
}
else
{

View File

@@ -1,625 +0,0 @@
/*
* Copyright (C) 2005-2010 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.repo.version;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.integrity.IntegrityChecker;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.EqualsHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Test simple version store migration
*/
public class VersionMigratorTest extends BaseVersionStoreTest
{
private static Log logger = LogFactory.getLog(VersionMigratorTest.class);
protected VersionServiceImpl version1Service = new VersionServiceImpl();
protected Version2ServiceImpl version2Service;
protected NodeService versionNodeService;
protected VersionMigrator versionMigrator;
protected PolicyComponent policyComponent;
protected DictionaryService dictionaryService;
protected CheckOutCheckInService cociService;
protected IntegrityChecker integrityChecker;
public VersionMigratorTest()
{
//super.setDefaultRollback(false); // default is true
}
protected void onSetUpInTransaction() throws Exception
{
super.onSetUpInTransaction();
this.versionMigrator = (VersionMigrator)applicationContext.getBean("versionMigrator");
this.policyComponent = (PolicyComponent)applicationContext.getBean("policyComponent");
this.dictionaryService = (DictionaryService)applicationContext.getBean("dictionaryService");
this.version2Service = (Version2ServiceImpl)applicationContext.getBean("versionService");
this.versionNodeService = (NodeService)applicationContext.getBean("versionNodeService"); // note: auto-switches between V1 and V2
this.cociService = (CheckOutCheckInService)applicationContext.getBean("CheckoutCheckinService");
this.integrityChecker = (IntegrityChecker)applicationContext.getBean("integrityChecker");
// Version1Service is used to create the version nodes in Version1Store (workspace://lightWeightVersionStore)
version1Service.setDbNodeService(dbNodeService);
version1Service.setNodeService(dbNodeService);
version1Service.setPolicyComponent(policyComponent);
version1Service.setDictionaryService(dictionaryService);
version1Service.initialiseWithoutBind(); // TODO - temp - if use intialise, get: "More than one CalculateVersionLabelPolicy behaviour has been registered for the type {http://www.alfresco.org/model/content/1.0}content"
super.setVersionService(version1Service);
}
/**
* Test migration of a simple versioned node (one version, no children)
*/
public void testMigrateOneVersion() throws Exception
{
if (version2Service.useDeprecatedV1 == true)
{
logger.info("testMigrateOneVersion: skip");
return;
}
NodeRef versionableNode = createNewVersionableNode();
logger.info("testMigrateOneVersion: versionedNodeRef = " + versionableNode);
// Get the next version label
String nextVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
Date beforeVersionDate = (Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED);
long beforeVersionTime = beforeVersionDate.getTime();
logger.info("beforeVersion Date/Time: " + beforeVersionDate + " [" + beforeVersionTime + "]");
Version oldVersion = createVersion(versionableNode);
// get and store old version details for later comparison - versionNodeService will retrieve these from the old version store
QName oldVersionType = versionNodeService.getType(oldVersion.getFrozenStateNodeRef());
Set<QName> oldVersionAspects = versionNodeService.getAspects(oldVersion.getFrozenStateNodeRef());
Map<QName, Serializable> oldVersionProps = versionNodeService.getProperties(oldVersion.getFrozenStateNodeRef());
logger.info("oldVersion props: " + oldVersion);
logger.info("oldVersion created: " + oldVersion.getFrozenModifiedDate() + " [" + oldVersion.getFrozenModifiedDate().getTime()+"]");
logger.info("oldVersion props via versionNodeService: " + oldVersionProps);
VersionHistory vh = version1Service.getVersionHistory(versionableNode);
assertEquals(1, vh.getAllVersions().size());
NodeRef oldVHNodeRef = version1Service.getVersionHistoryNodeRef(versionableNode);
Thread.sleep(70000);
// Migrate and delete old version history !
NodeRef versionedNodeRef = versionMigrator.v1GetVersionedNodeRef(oldVHNodeRef);
NodeRef newVHNodeRef = versionMigrator.migrateVersionHistory(oldVHNodeRef, versionedNodeRef);
versionMigrator.v1DeleteVersionHistory(oldVHNodeRef);
VersionHistory vh2 = version2Service.getVersionHistory(versionableNode);
assertEquals(1, vh2.getAllVersions().size());
Version newVersion = vh2.getRootVersion();
logger.info("newVersion props: " + newVersion);
logger.info("newVersion created: " + newVersion.getFrozenModifiedDate() + " [" + newVersion.getFrozenModifiedDate().getTime()+"]");
// check new version - switch to new version service to do the check
super.setVersionService(version2Service);
checkNewVersion(beforeVersionTime, nextVersionLabel, newVersion, versionableNode);
// get and compare new version details - - versionNodeService will retrieve these from the new version store
QName newVersionType = versionNodeService.getType(newVersion.getFrozenStateNodeRef());
Set<QName> newVersionAspects = versionNodeService.getAspects(newVersion.getFrozenStateNodeRef());
Map<QName, Serializable> newVersionProps = versionNodeService.getProperties(newVersion.getFrozenStateNodeRef());
logger.info("newVersion props via versionNodeService: " + newVersionProps);
assertEquals(oldVersionType, newVersionType);
assertEquals(oldVersionAspects.size(), newVersionAspects.size());
for (QName key : oldVersionAspects)
{
assertTrue(""+key, newVersionAspects.contains(key));
}
// note: since 3.4, "cm:accessed" is not returned/migrated if null
int expectedPropCount = oldVersionProps.size();
if (oldVersionProps.get(ContentModel.PROP_ACCESSED) == null)
{
expectedPropCount--;
}
assertEquals(expectedPropCount, newVersionProps.size());
for (QName key : oldVersionProps.keySet())
{
if (! (key.equals(ContentModel.PROP_ACCESSED) && (oldVersionProps.get(key) == null)))
{
assertEquals(""+key, oldVersionProps.get(key), newVersionProps.get(key));
}
}
// ALFCOM-2658
assertEquals(oldVersion.getFrozenStateNodeRef().getId(), newVersion.getFrozenStateNodeRef().getId());
logger.info("testMigrateOneVersion: Migrated from oldVHNodeRef = " + oldVHNodeRef + " to newVHNodeRef = " + newVHNodeRef);
}
/**
* Test migration of a multiple versioned nodes
*/
public void testMigrateMultipleVersions() throws Exception
{
if (version2Service.useDeprecatedV1 == true)
{
logger.info("testMigrateOneVersion: skip");
return;
}
NodeRef versionableNode = createNewVersionableNode();
// Get the next version label and snapshot the date-time
String nextVersionLabel1 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime1 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
Version version1 = createVersion(versionableNode);
logger.info(version1);
// Get the next version label and snapshot the date-time
String nextVersionLabel2 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime2 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
Version version2 = createVersion(versionableNode);
logger.info(version2);
// Get the next version label and snapshot the date-time
String nextVersionLabel3 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime3 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
Version version3 = createVersion(versionableNode);
logger.info(version3);
VersionHistory vh1 = version1Service.getVersionHistory(versionableNode);
assertEquals(3, vh1.getAllVersions().size());
logger.info("testMigrateMultipleVersions: versionedNodeRef = " + versionableNode);
NodeRef oldVHNodeRef = version1Service.getVersionHistoryNodeRef(versionableNode);
// Migrate and delete old version history !
NodeRef versionedNodeRef = versionMigrator.v1GetVersionedNodeRef(oldVHNodeRef);
NodeRef newVHNodeRef = versionMigrator.migrateVersionHistory(oldVHNodeRef, versionedNodeRef);
versionMigrator.v1DeleteVersionHistory(oldVHNodeRef);
VersionHistory vh2 = version2Service.getVersionHistory(versionableNode);
assertEquals(3, vh2.getAllVersions().size());
// TODO move check version history into BaseVersionStoreTest
// check new versions - switch to new version service to do the check
super.setVersionService(version2Service);
Version[] newVersions = vh2.getAllVersions().toArray(new Version[]{});
checkVersion(beforeVersionTime1, nextVersionLabel1, newVersions[2], versionableNode);
checkVersion(beforeVersionTime2, nextVersionLabel2, newVersions[1], versionableNode);
checkNewVersion(beforeVersionTime3, nextVersionLabel3, newVersions[0], versionableNode);
// ALFCOM-2658
assertEquals(version1.getFrozenStateNodeRef().getId(), newVersions[2].getFrozenStateNodeRef().getId());
assertEquals(version2.getFrozenStateNodeRef().getId(), newVersions[1].getFrozenStateNodeRef().getId());
assertEquals(version3.getFrozenStateNodeRef().getId(), newVersions[0].getFrozenStateNodeRef().getId());
logger.info("testMigrateMultipleVersions: Migrated from oldVHNodeRef = " + oldVHNodeRef + " to newVHNodeRef = " + newVHNodeRef);
}
public void testMigrateMultipleNodesSuccessful() throws Exception
{
testMigrateMultipleNodes(false);
}
public void test_ETHREEOH_2091() throws Exception
{
// test partial migration (with skipped nodes)
testMigrateMultipleNodes(true);
}
/**
* Test migration of a multiple nodes (each with one version)
*/
private void testMigrateMultipleNodes(final boolean withSkip)
{
if (version2Service.useDeprecatedV1 == true)
{
logger.info("testMigrateOneVersion: skip");
return;
}
final int nodeCount = 5;
assert(nodeCount > 3);
final NodeRef[] versionableNodes = new NodeRef[nodeCount];
setComplete();
endTransaction();
RetryingTransactionHelper txHelper = transactionService.getRetryingTransactionHelper();
for (int i = 0; i < nodeCount; i++)
{
final int idx = i;
txHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
NodeRef versionableNode = null;
if ((idx % 2) == 0)
{
versionableNode = createNewVersionableNode();
}
else
{
versionableNode = createNewVersionableContentNode(true);
}
createVersion(versionableNode);
versionableNodes[idx] = versionableNode;
return null;
}
});
}
setComplete();
endTransaction();
txHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
// check old version histories
for (int i = 0; i< nodeCount; i++)
{
VersionHistory vh1 = version1Service.getVersionHistory(versionableNodes[i]);
assertNotNull(vh1);
assertEquals(1, vh1.getAllVersions().size());
}
return null;
}
});
setComplete();
endTransaction();
if (withSkip)
{
// remove test model - those nodes should fail - currently all - add separate create ...
// TODO ...
dictionaryDAO.removeModel(QName.createQName("http://www.alfresco.org/test/versionstorebasetest/1.0", "versionstorebasetestmodel"));
}
txHelper = transactionService.getRetryingTransactionHelper();
txHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
// Migrate (and don't delete old version history) !
versionMigrator.migrateVersions(1, 1, -1, false, null, false);
return null;
}
});
setComplete();
endTransaction();
txHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
// check new version histories
for (int i = 0; i < nodeCount; i++)
{
VersionHistory vh2 = version2Service.getVersionHistory(versionableNodes[i]);
if (withSkip && ((i % 2) == 0))
{
assertNull(vh2);
}
else
{
assertNotNull(vh2);
assertEquals(1, vh2.getAllVersions().size());
}
}
return null;
}
});
}
private NodeRef createNewVersionableContentNode(boolean versionable)
{
// Use this map to retrieve the versionable nodes in later tests
this.versionableNodes = new HashMap<String, NodeRef>();
// Create node (this node has some content)
NodeRef nodeRef = this.dbNodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myNode"),
ContentModel.TYPE_CONTENT,
this.nodeProperties).getChildRef();
if (versionable)
{
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
}
assertNotNull(nodeRef);
this.versionableNodes.put(nodeRef.getId(), nodeRef);
// Add the content to the node
ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.putContent(TEST_CONTENT);
// Set author
Map<QName, Serializable> authorProps = new HashMap<QName, Serializable>(1, 1.0f);
authorProps.put(ContentModel.PROP_AUTHOR, "Charles Dickens");
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, authorProps);
return nodeRef;
}
public void test_ETHREEOH_1540() throws Exception
{
// Create the node used for tests
NodeRef nodeRef = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(TEST_NAMESPACE, "MyVersionableNode"),
TEST_TYPE_QNAME,
this.nodeProperties).getChildRef();
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "name");
// Add the initial content to the node
ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype("text/plain");
contentWriter.setEncoding("UTF-8");
contentWriter.putContent("my content");
VersionHistory vh1 = version1Service.getVersionHistory(nodeRef);
assertNull(vh1);
version2Service.useDeprecatedV1 = true;
// Add the version aspect to the created node
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
vh1 = version1Service.getVersionHistory(nodeRef);
assertNull(vh1);
NodeRef workingCopyNodeRef = cociService.checkout(nodeRef);
vh1 = version1Service.getVersionHistory(nodeRef);
assertNull(vh1);
int v1count = 3;
for (int i = 1; i <= v1count; i++)
{
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
versionProperties.put(Version.PROP_DESCRIPTION, "This is a test checkin - " + i);
cociService.checkin(workingCopyNodeRef, versionProperties);
vh1 = version1Service.getVersionHistory(nodeRef);
assertEquals(i, vh1.getAllVersions().size());
workingCopyNodeRef = cociService.checkout(nodeRef);
vh1 = version1Service.getVersionHistory(nodeRef);
assertEquals(i, vh1.getAllVersions().size());
}
NodeRef oldVHNodeRef = version1Service.getVersionHistoryNodeRef(nodeRef);
version2Service.useDeprecatedV1 = false;
// Migrate and delete old version history !
NodeRef versionedNodeRef = versionMigrator.v1GetVersionedNodeRef(oldVHNodeRef);
//int nextVersionNumber = versionCounterService.nextVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, VersionModel.STORE_ID));
//versionCounterService.setVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID), nextVersionNumber);
// to force the error: https://issues.alfresco.com/jira/browse/ETHREEOH-1540
//versionCounterService.setVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID), 0);
NodeRef newVHNodeRef = versionMigrator.migrateVersionHistory(oldVHNodeRef, versionedNodeRef);
versionMigrator.v1DeleteVersionHistory(oldVHNodeRef);
VersionHistory vh2 = version2Service.getVersionHistory(nodeRef);
assertEquals(v1count, vh2.getAllVersions().size());
int v2count = 3;
for (int i = 1; i <= v2count; i++)
{
versionProperties = new HashMap<String, Serializable>();
versionProperties.put(Version.PROP_DESCRIPTION, "This is a test checkin - " + (v1count + i));
cociService.checkin(workingCopyNodeRef, versionProperties);
vh2 = version2Service.getVersionHistory(nodeRef);
assertEquals((v1count + i), vh2.getAllVersions().size());
workingCopyNodeRef = cociService.checkout(nodeRef);
vh2 = version2Service.getVersionHistory(nodeRef);
assertEquals((v1count + i), vh2.getAllVersions().size());
}
logger.info("testMigrateOneCheckoutVersion: Migrated from oldVHNodeRef = " + oldVHNodeRef + " to newVHNodeRef = " + newVHNodeRef);
}
/**
* Test migration of a single versioned node with versioned child assocs & peer assocs
*
* @since 3.3 Ent - applies only to direct upgrade from 2.x to 3.3 Ent or higher
*/
public void testMigrateVersionWithAssocs() throws Exception
{
if (version2Service.useDeprecatedV1 == true)
{
logger.info("testMigrateVersionWithAssocs: skip");
return;
}
NodeRef versionableNode = createNewVersionableNode();
NodeRef targetNode = createNewNode();
nodeService.createAssociation(versionableNode, targetNode, TEST_ASSOC);
// Get the next version label and snapshot the date-time
String nextVersionLabel1 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime1 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
Version version1 = createVersion(versionableNode);
logger.info(version1);
VersionHistory vh1 = version1Service.getVersionHistory(versionableNode);
assertEquals(1, vh1.getAllVersions().size());
List<ChildAssociationRef> oldChildAssocs = nodeService.getChildAssocs(version1.getFrozenStateNodeRef());
List<AssociationRef> oldAssocs = nodeService.getTargetAssocs(version1.getFrozenStateNodeRef(), RegexQNamePattern.MATCH_ALL);
logger.info("testMigrateVersionWithAssocs: versionedNodeRef = " + versionableNode);
NodeRef oldVHNodeRef = version1Service.getVersionHistoryNodeRef(versionableNode);
// Migrate and delete old version history !
NodeRef versionedNodeRef = versionMigrator.v1GetVersionedNodeRef(oldVHNodeRef);
NodeRef newVHNodeRef = versionMigrator.migrateVersionHistory(oldVHNodeRef, versionedNodeRef);
versionMigrator.v1DeleteVersionHistory(oldVHNodeRef);
VersionHistory vh2 = version2Service.getVersionHistory(versionableNode);
assertEquals(1, vh2.getAllVersions().size());
// check new version - switch to new version service to do the check
super.setVersionService(version2Service);
Version[] newVersions = vh2.getAllVersions().toArray(new Version[]{});
Version newVersion1 = newVersions[0];
checkVersion(beforeVersionTime1, nextVersionLabel1, newVersion1, versionableNode);
List<ChildAssociationRef> newChildAssocs = nodeService.getChildAssocs(newVersion1.getFrozenStateNodeRef());
assertEquals(oldChildAssocs.size(), newChildAssocs.size());
for (ChildAssociationRef oldChildAssoc : oldChildAssocs)
{
boolean found = false;
for (ChildAssociationRef newChildAssoc : newChildAssocs)
{
if (newChildAssoc.getParentRef().getId().equals(oldChildAssoc.getParentRef().getId()) &&
newChildAssoc.getChildRef().equals(oldChildAssoc.getChildRef()) &&
newChildAssoc.getTypeQName().equals(oldChildAssoc.getTypeQName()) &&
newChildAssoc.getQName().equals(oldChildAssoc.getQName()) &&
(newChildAssoc.isPrimary() == oldChildAssoc.isPrimary()) &&
(newChildAssoc.getNthSibling() == oldChildAssoc.getNthSibling()))
{
found = true;
break;
}
}
if (! found)
{
fail(oldChildAssoc.toString()+ " not found");
}
}
List<AssociationRef> newAssocs = nodeService.getTargetAssocs(newVersion1.getFrozenStateNodeRef(), RegexQNamePattern.MATCH_ALL);
assertEquals(oldAssocs.size(), newAssocs.size());
for (AssociationRef oldAssoc : oldAssocs)
{
boolean found = false;
for (AssociationRef newAssoc : newAssocs)
{
if (newAssoc.getSourceRef().getId().equals(oldAssoc.getSourceRef().getId()) &&
newAssoc.getTargetRef().equals(oldAssoc.getTargetRef()) &&
newAssoc.getTypeQName().equals(oldAssoc.getTypeQName()) &&
EqualsHelper.nullSafeEquals(newAssoc.getId(), oldAssoc.getId()))
{
found = true;
break;
}
}
if (! found)
{
fail(oldAssoc.toString()+ " not found");
}
}
logger.info("testMigrateVersionWithAssocs: Migrated from oldVHNodeRef = " + oldVHNodeRef + " to newVHNodeRef = " + newVHNodeRef);
}
}

View File

@@ -1,120 +0,0 @@
<model name="test:versionstorebasetestmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>VersionStoreBaseTest model</description>
<author>Alfresco</author>
<published>2005-05-30</published>
<version>1.0</version>
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
</imports>
<namespaces>
<namespace uri="http://www.alfresco.org/test/versionstorebasetest/1.0" prefix="test"/>
</namespaces>
<types>
<type name="test:testtype">
<title>Test type</title>
<description>The test type</description>
<parent>cm:content</parent>
<properties>
<property name="test:prop1">
<type>d:text</type>
<protected>false</protected>
<default></default>
</property>
<property name="test:prop2">
<type>d:text</type>
<protected>false</protected>
<default></default>
</property>
<property name="test:prop3">
<type>d:text</type>
<protected>false</protected>
<default></default>
</property>
<property name="test:propMl">
<type>d:mltext</type>
<protected>false</protected>
<default></default>
</property>
<property name="test:multiProp">
<type>d:text</type>
<multiple>true</multiple>
</property>
<property name="test:intProp">
<type>d:int</type>
</property>
</properties>
<associations>
<association name="test:assoc1">
<source>
<mandatory>false</mandatory>
<many>false</many>
</source>
<target>
<class>test:testtype</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</association>
<child-association name="test:childassoc1">
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>test:testtype</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
<child-name>childassoc1</child-name>
<duplicate>true</duplicate>
</child-association>
<child-association name="test:childassoc2">
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>test:testtype</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
<child-name>childassoc2</child-name>
<duplicate>true</duplicate>
</child-association>
</associations>
</type>
</types>
<aspects>
<aspect name="test:testaspect">
<title>Test Aspect</title>
<description>The test aspect</description>
<parent></parent>
<properties>
<property name="test:aspectprop1">
<type>d:text</type>
<protected>false</protected>
<default></default>
</property>
<property name="test:aspectprop2">
<type>d:text</type>
<protected>false</protected>
<default></default>
</property>
</properties>
</aspect>
</aspects>
</model>

View File

@@ -1,66 +0,0 @@
/*
* Copyright (C) 2005-2010 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.repo.version;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.alfresco.repo.version.common.VersionHistoryImplTest;
import org.alfresco.repo.version.common.VersionImplTest;
import org.alfresco.repo.version.common.versionlabel.SerialVersionLabelPolicyTest;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
/**
* Version test suite
*
* @author Roy Wetherall, janv
*/
public class VersionTestSuite extends TestSuite
{
public static ApplicationContext getContext()
{
ApplicationContextHelper.setUseLazyLoading(false);
ApplicationContextHelper.setNoAutoStart(true);
return ApplicationContextHelper.getApplicationContext(
new String[] { "classpath:alfresco/minimal-context.xml" }
);
}
/**
* Creates the test suite
*
* @return the test suite
*/
public static Test suite()
{
// Setup the context
getContext();
TestSuite suite = new TestSuite();
suite.addTestSuite(VersionImplTest.class);
suite.addTestSuite(VersionHistoryImplTest.class);
suite.addTestSuite(SerialVersionLabelPolicyTest.class);
suite.addTestSuite(VersionServiceImplTest.class);
suite.addTestSuite(NodeServiceImplTest.class);
suite.addTestSuite(ContentServiceImplTest.class);
suite.addTestSuite(VersionMigratorTest.class);
return suite;
}
}

View File

@@ -1,285 +0,0 @@
/*
* Copyright (C) 2005-2012 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.repo.version;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
/**
* @author Dmitry Velichkevich
*/
public class VersionableAspectTest extends TestCase
{
private static final String NAME_AND_EXT_DELIMETER = ".";
private static final String NAME_AND_EXT_DELIMETER_REGEXP = "\\" + NAME_AND_EXT_DELIMETER;
private static final String ADMIN_CREDENTIAL = "admin";
private static final String ROOT_NODE_TERM = "PATH:\"/app\\:company_home\"";
private static final String DOCUMENT_NAME = "ChildDocumentWithVersionLabel-.txt";
private static final String PARENT_FOLDER_NAME = "ParentFolder-" + System.currentTimeMillis();
private static final String TEST_CONTENT_01 = "Test Content version 0.1\n";
private static final String TEST_CONTENT_10 = "Test Content version 1.0\n";
private ApplicationContext applicationContext = ApplicationContextHelper.getApplicationContext();
private NodeService nodeService = (NodeService) applicationContext.getBean("nodeService");
private LockService lockService = (LockService) applicationContext.getBean("lockService");
private SearchService searchService = (SearchService) applicationContext.getBean("searchService");
private ContentService contentService = (ContentService) applicationContext.getBean("contentService");
private TransactionService transactionService = (TransactionService) applicationContext.getBean("transactionService");
private CheckOutCheckInService checkOutCheckInService = (CheckOutCheckInService) applicationContext.getBean("checkOutCheckInService");
private AuthenticationService authenticationService = (AuthenticationService) applicationContext.getBean("authenticationService");
private NodeRef document;
private NodeRef parentFolder;
@Override
protected void setUp() throws Exception
{
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
authenticationService.authenticate(ADMIN_CREDENTIAL, ADMIN_CREDENTIAL.toCharArray());
ResultSet query = null;
NodeRef rootNode = null;
try
{
query = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_LUCENE, ROOT_NODE_TERM);
rootNode = query.getNodeRef(0);
}
finally
{
if (null != query)
{
query.close();
}
}
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(ContentModel.PROP_NAME, PARENT_FOLDER_NAME);
parentFolder = nodeService.createNode(rootNode, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, PARENT_FOLDER_NAME),
ContentModel.TYPE_FOLDER, properties).getChildRef();
properties.clear();
properties.put(ContentModel.PROP_NAME, DOCUMENT_NAME);
document = nodeService.createNode(parentFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, DOCUMENT_NAME),
ContentModel.TYPE_CONTENT, properties).getChildRef();
contentService.getWriter(document, ContentModel.PROP_CONTENT, true).putContent(TEST_CONTENT_01);
if (!nodeService.hasAspect(document, ContentModel.ASPECT_VERSIONABLE))
{
Map<QName, Serializable> versionProperties = new HashMap<QName, Serializable>();
versionProperties.put(ContentModel.PROP_VERSION_LABEL, "0.1");
versionProperties.put(ContentModel.PROP_INITIAL_VERSION, true);
versionProperties.put(ContentModel.PROP_VERSION_TYPE, VersionType.MINOR);
nodeService.addAspect(document, ContentModel.ASPECT_VERSIONABLE, versionProperties);
}
return null;
}
});
}
@Override
protected void tearDown() throws Exception
{
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (null != parentFolder)
{
nodeService.deleteNode(parentFolder);
}
authenticationService.clearCurrentSecurityContext();
return null;
}
});
}
public void testAutoVersionIncrementOnPropertiesUpdateAfterCheckInAlf14584() throws Exception
{
final String name02 = generateDocumentName(DOCUMENT_NAME, "0.2");
final String name11 = generateDocumentName(DOCUMENT_NAME, "1.1");
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
Map<QName, Serializable> properties = getAndAssertProperties(document, "0.1");
Serializable autoVersionProps = properties.get(ContentModel.PROP_AUTO_VERSION_PROPS);
assertNotNull(("Autoversion property is NULL! NodeRef = '" + document.toString() + "'"), autoVersionProps);
assertTrue(("Autoversion must be TRUE! NodeRef = '" + document.toString() + "'"), (Boolean) autoVersionProps);
nodeService.setProperty(document, ContentModel.PROP_NAME, name02);
return null;
}
});
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
Map<QName, Serializable> properties = getAndAssertProperties(document, "0.2");
assertEquals(name02, properties.get(ContentModel.PROP_NAME));
NodeRef workingCopy = checkOutCheckInService.checkout(document);
contentService.getWriter(workingCopy, ContentModel.PROP_CONTENT, true).putContent(TEST_CONTENT_10);
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
document = checkOutCheckInService.checkin(workingCopy, versionProperties);
return null;
}
});
assertDocumentVersionAndName("1.0", name02);
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
nodeService.setProperty(document, ContentModel.PROP_NAME, name11);
return null;
}
});
assertDocumentVersionAndName("1.1", name11);
}
public void testAutoVersionIncrementOnPropertiesUpdateByLockOwnerAlf14584() throws Exception
{
final String name = generateDocumentName(DOCUMENT_NAME, "0.2");
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
Map<QName, Serializable> properties = getAndAssertProperties(document, "0.1");
Serializable autoVersionProps = properties.get(ContentModel.PROP_AUTO_VERSION_PROPS);
assertNotNull(("Autoversion property is NULL! NodeRef = '" + document.toString() + "'"), autoVersionProps);
assertTrue(("Autoversion must be TRUE! NodeRef = '" + document.toString() + "'"), (Boolean) autoVersionProps);
lockService.lock(document, LockType.WRITE_LOCK);
LockStatus lockStatus = lockService.getLockStatus(document);
assertFalse(
("Node with NodeRef = '" + document.toString() + "' must not be locked for " + AuthenticationUtil.getFullyAuthenticatedUser() + " user! The user is lock owner"),
isLocked(document));
assertEquals(LockStatus.LOCK_OWNER, lockService.getLockStatus(document));
nodeService.setProperty(document, ContentModel.PROP_NAME, name);
return null;
}
});
assertDocumentVersionAndName("0.2", name);
}
// Copy of code from VersionableAspect which really should be in LockService
private boolean isLocked(NodeRef nodeRef)
{
LockStatus lockStatus = lockService.getLockStatus(nodeRef);
return (LockStatus.NO_LOCK != lockStatus) && (LockStatus.LOCK_OWNER != lockStatus);
}
private void assertDocumentVersionAndName(final String versionLabel, final String name)
{
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
Map<QName, Serializable> properties = getAndAssertProperties(document, versionLabel);
assertEquals(name, properties.get(ContentModel.PROP_NAME));
return null;
}
}, true);
}
private Map<QName, Serializable> getAndAssertProperties(NodeRef nodeRef, String versionLabel)
{
assertNotNull("NodeRef of document is NULL!", nodeRef);
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
assertNotNull(("Properties must not be NULL! NodeRef = '" + nodeRef.toString() + "'"), properties);
assertFalse(("Version specific properties can't be found! NodeRef = '" + nodeRef.toString() + "'"), properties.isEmpty());
assertEquals(versionLabel, properties.get(ContentModel.PROP_VERSION_LABEL));
return properties;
}
private String generateDocumentName(String namePattern, String versionLabel)
{
int i = 0;
String[] nameAndExt = namePattern.split(NAME_AND_EXT_DELIMETER_REGEXP);
StringBuilder result = new StringBuilder(nameAndExt[i++]).append(versionLabel).append(NAME_AND_EXT_DELIMETER).append(nameAndExt[i++]);
return result.toString();
}
}

View File

@@ -1,406 +0,0 @@
/*
* Copyright (C) 2005-2010 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.repo.version.common;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionDoesNotExistException;
import org.alfresco.service.cmr.version.VersionServiceException;
import org.alfresco.util.TempFileProvider;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
/**
* VersionHistoryImpl Unit Test Class
*
* @author Roy Wetherall
*/
public class VersionHistoryImplTest extends TestCase
{
/**
* Data used in the tests
*/
private NodeRef nodeRef;
private Version rootVersion = null;
private Version childVersion1 = null;
private Version childVersion2 = null;
/**
* Set up
*/
protected void setUp() throws Exception
{
super.setUp();
// Create dummy node ref
nodeRef = new NodeRef(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "test"), "test");
this.rootVersion = newVersion(nodeRef, "1");
this.childVersion1 = newVersion(nodeRef, "2");
this.childVersion2 = newVersion(nodeRef, "3");
}
private VersionImpl newVersion(NodeRef nodeRef, String label)
{
HashMap<String, Serializable> versionProperties1 = new HashMap<String, Serializable>();
versionProperties1.put(VersionModel.PROP_VERSION_LABEL, label);
versionProperties1.put(VersionModel.PROP_CREATED_DATE, new Date());
versionProperties1.put("testProperty", "testValue");
return new VersionImpl(versionProperties1, nodeRef);
}
/**
* Test constructor
*/
public void testConstructor()
{
testContructorImpl();
}
/**
* Test construtor helper
*
* @return new version history
*/
private VersionHistoryImpl testContructorImpl()
{
VersionHistoryImpl vh = new VersionHistoryImpl(this.rootVersion, null);
assertNotNull(vh);
return vh;
}
/**
* Exception case - a root version must be specified when creating a
* version history object
*/
public void testRootVersionSpecified()
{
try
{
new VersionHistoryImpl(null, null);
fail();
}
catch(VersionServiceException exception)
{
}
}
/**
* Test getRootVersion
*
*@return root version
*/
public void testGetRootVersion()
{
VersionHistoryImpl vh = testContructorImpl();
Version rootVersion = vh.getRootVersion();
assertNotNull(rootVersion);
assertEquals(rootVersion, this.rootVersion);
}
/**
* Test getAllVersions
*/
public void testGetAllVersions()
{
VersionHistoryImpl vh = testAddVersionImpl();
Collection<Version> allVersions = vh.getAllVersions();
assertNotNull(allVersions);
assertEquals(3, allVersions.size());
}
/**
* Test getAllVersions using a comparator to resort versions which are in the
* wrong order.
*/
public void testGetAllVersionsComparator()
{
String[] labels = new String[] { "1.0", "1.1", "1.2", "2.0", "2.1" };
List<Version> versions = new ArrayList<Version>(labels.length);
for (String label: labels)
{
versions.add(newVersion(nodeRef, label));
}
Collections.shuffle(versions);
Iterator<Version> itr = versions.iterator();
Version version = itr.next();
Version predecessor;
VersionHistoryImpl vh = new VersionHistoryImpl(version,
Collections.reverseOrder(new VersionLabelComparator()));
while (itr.hasNext())
{
predecessor = version;
version = itr.next();
vh.addVersion(version, predecessor);
}
Collection<Version> allVersions = vh.getAllVersions();
assertNotNull(allVersions);
assertEquals(labels.length, allVersions.size());
itr = allVersions.iterator();
for (String label: labels)
{
assertEquals(label, itr.next().getVersionLabel());
}
}
/**
* Test addVersion
*
* @return version history
*/
public void testAddVersion()
{
testAddVersionImpl();
}
/**
* Test addVersion helper
*
* @return version history with version tree built
*/
private VersionHistoryImpl testAddVersionImpl()
{
VersionHistoryImpl vh = testContructorImpl();
Version rootVersion = vh.getRootVersion();
vh.addVersion(this.childVersion1, rootVersion);
vh.addVersion(this.childVersion2, rootVersion);
return vh;
}
/**
* TODO Exception case - add version that has already been added
*/
/**
* TODO Exception case - add a version with a duplicate version label
*/
/**
* Test getPredecessor
*/
public void testGetPredecessor()
{
VersionHistoryImpl vh = testAddVersionImpl();
Version version1 = vh.getPredecessor(this.childVersion1);
assertEquals(version1.getVersionLabel(), this.rootVersion.getVersionLabel());
Version version2 = vh.getPredecessor(this.childVersion2);
assertEquals(version2.getVersionLabel(), this.rootVersion.getVersionLabel());
Version version3 = vh.getPredecessor(this.rootVersion);
assertNull(version3);
try
{
Version version4 = vh.getPredecessor(null);
assertNull(version4);
}
catch (Exception exception)
{
fail("Should continue by returning null.");
}
}
/**
* Test getSuccessors
*/
public void testGetSuccessors()
{
VersionHistoryImpl vh = testAddVersionImpl();
Collection<Version> versions1 = vh.getSuccessors(this.rootVersion);
assertNotNull(versions1);
assertEquals(versions1.size(), 2);
for (Version version : versions1)
{
String versionLabel = version.getVersionLabel();
if (!(versionLabel == "2" || versionLabel == "3"))
{
fail("There is a version in this collection that should not be here.");
}
}
Collection<Version> versions2 = vh.getSuccessors(this.childVersion1);
assertNotNull(versions2);
assertTrue(versions2.isEmpty());
Collection<Version> versions3 = vh.getSuccessors(this.childVersion2);
assertNotNull(versions3);
assertTrue(versions3.isEmpty());
}
/**
* Test getSuccessors using a comparator to resort versions which are in the
* wrong order.
*/
public void testGetSuccessorsComparator()
{
rootVersion = newVersion(nodeRef, "1.0");
String[] labels = new String[] { "1.1", "1.2", "2.0", "2.1" };
List<Version> versions = new ArrayList<Version>(labels.length);
for (String label: labels)
{
versions.add(newVersion(nodeRef, label));
}
Collections.shuffle(versions);
Iterator<Version> itr = versions.iterator();
Version version = rootVersion;
VersionHistoryImpl vh = new VersionHistoryImpl(version,
Collections.reverseOrder(new VersionLabelComparator()));
while (itr.hasNext())
{
vh.addVersion(itr.next(), rootVersion);
}
Collection<Version> allVersions = vh.getSuccessors(rootVersion);
assertNotNull(allVersions);
assertEquals(labels.length, allVersions.size());
itr = allVersions.iterator();
for (String label: labels)
{
assertEquals(label, itr.next().getVersionLabel());
}
}
/**
* Test getVersion
*/
public void testGetVersion()
{
VersionHistoryImpl vh = testAddVersionImpl();
Version version1 = vh.getVersion("1");
assertEquals(version1.getVersionLabel(), this.rootVersion.getVersionLabel());
Version version2 = vh.getVersion("2");
assertEquals(version2.getVersionLabel(), this.childVersion1.getVersionLabel());
Version version3 = vh.getVersion("3");
assertEquals(version3.getVersionLabel(), this.childVersion2.getVersionLabel());
try
{
vh.getVersion("invalidLabel");
fail("An exception should have been thrown if the version can not be retrieved.");
}
catch (VersionDoesNotExistException exception)
{
System.out.println("Error message: " + exception.getMessage());
}
}
/**
* Checks that the current version can be serialized and deserialized.
*/
public void testSerialize() throws Exception
{
File file = TempFileProvider.createTempFile(getName(), ".bin");
System.out.println("Test " + getName() + " writing to " + file.getPath());
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(file));
VersionHistoryImpl vh = testAddVersionImpl();
try
{
os.writeObject(vh);
}
finally
{
try { os.close(); } catch (Throwable e) {}
}
ObjectInputStream is = new ObjectInputStream(new FileInputStream(file));
VersionHistoryImpl vhObj;
try
{
vhObj = (VersionHistoryImpl) is.readObject();
}
finally
{
try { is.close(); } catch (Throwable e) {}
}
assertNotNull(vhObj);
assertNotNull("No root version", vhObj.getRootVersion());
assertEquals(
"Deserialized object does not match original",
vh.getRootVersion().getFrozenStateNodeRef(),
vhObj.getRootVersion().getFrozenStateNodeRef());
}
public static final String DESERIALIZE_V22SP4 = "classpath:version-history/VersionHistoryImplTest-testSerialize-V2.2.4.bin";
public static final String DESERIALIZE_V310_DEV = "classpath:version-history/VersionHistoryImplTest-testSerialize-V3.1.0-dev.bin";
public static final String DESERIALIZE_V310 = "classpath:version-history/VersionHistoryImplTest-testSerialize-V3.1.0.bin";
/**
* @see {@link #DESERIALIZE_V22SP4}
* @see {@link #DESERIALIZE_V310_DEV}
* @see {@link #DESERIALIZE_V310}
*/
public void testDeserializeV22SP4() throws Exception
{
String[] resourceLocations = new String[] {
DESERIALIZE_V22SP4,
DESERIALIZE_V310_DEV,
DESERIALIZE_V310
};
for (String resourceLocation : resourceLocations)
{
Resource resource = new DefaultResourceLoader().getResource(resourceLocation);
assertNotNull("Unable to find " + resourceLocation, resource);
assertTrue("Unable to find " + resourceLocation, resource.exists());
@SuppressWarnings("unused")
VersionHistoryImpl vhObj;
ObjectInputStream is = new ObjectInputStream(resource.getInputStream());
try
{
vhObj = (VersionHistoryImpl) is.readObject();
}
finally
{
try { is.close(); } catch (Throwable e) {}
}
}
}
}

View File

@@ -1,190 +0,0 @@
/*
* Copyright (C) 2005-2010 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.repo.version.common;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionServiceException;
import org.alfresco.service.cmr.version.VersionType;
import junit.framework.TestCase;
/**
* VersionImpl Unit Test
*
* @author Roy Wetherall
*/
public class VersionImplTest extends TestCase
{
/**
* Property names and values
*/
private final static String PROP_1 = "prop1";
private final static String PROP_2 = "prop2";
private final static String PROP_3 = "prop3";
private final static String VALUE_1 = "value1";
private final static String VALUE_2 = "value2";
private final static String VALUE_3 = "value3";
private final static String VALUE_DESCRIPTION = "This string describes the version details.";
private final static VersionType VERSION_TYPE = VersionType.MINOR;
private final static String USER_NAME = "userName";
/**
* Version labels
*/
private final static String VERSION_1 = "1";
/**
* Data used during tests
*/
private VersionImpl version = null;
private NodeRef nodeRef = null;
private Map<String, Serializable> versionProperties = null;
private Date createdDate = new Date();
/**
* Test case set up
*/
protected void setUp() throws Exception
{
super.setUp();
// Create the node reference
this.nodeRef = new NodeRef(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "testWS"), "testID");
assertNotNull(this.nodeRef);
// Create the version property map
this.versionProperties = new HashMap<String, Serializable>();
this.versionProperties.put(VersionModel.PROP_VERSION_LABEL, VERSION_1);
this.versionProperties.put(VersionModel.PROP_CREATED_DATE, this.createdDate);
this.versionProperties.put(VersionModel.PROP_CREATOR, USER_NAME);
this.versionProperties.put(Version.PROP_DESCRIPTION, VALUE_DESCRIPTION);
this.versionProperties.put(VersionModel.PROP_VERSION_TYPE, VERSION_TYPE);
this.versionProperties.put(PROP_1, VALUE_1);
this.versionProperties.put(PROP_2, VALUE_2);
this.versionProperties.put(PROP_3, VALUE_3);
// Create the root version
this.version = new VersionImpl(this.versionProperties, this.nodeRef);
assertNotNull(this.version);
}
/**
* Test getCreatedDate()
*/
public void testGetCreatedDate()
{
Date createdDate1 = this.version.getCreatedDate();
assertEquals(this.createdDate, createdDate1);
}
/**
* Test getCreator
*/
public void testGetCreator()
{
assertEquals(USER_NAME, this.version.getCreator());
}
/**
* Test getVersionLabel()
*/
public void testGetVersionLabel()
{
String versionLabel1 = this.version.getVersionLabel();
assertEquals(VersionImplTest.VERSION_1, versionLabel1);
}
/**
* Test getDescription
*/
public void testGetDescription()
{
String description = this.version.getDescription();
assertEquals(VALUE_DESCRIPTION, description);
}
/**
* Test getVersionType
*/
public void testGetVersionType()
{
VersionType versionType = this.version.getVersionType();
assertEquals(VERSION_TYPE, versionType);
}
/**
* Test getVersionProperties
*
*/
public void testGetVersionProperties()
{
Map<String, Serializable> versionProperties = version.getVersionProperties();
assertNotNull(versionProperties);
assertEquals(this.versionProperties.size(), versionProperties.size());
}
/**
* Test getVersionProperty
*/
public void testGetVersionProperty()
{
String value1 = (String)version.getVersionProperty(VersionImplTest.PROP_1);
assertEquals(value1, VersionImplTest.VALUE_1);
String value2 = (String)version.getVersionProperty(VersionImplTest.PROP_2);
assertEquals(value2, VersionImplTest.VALUE_2);
String value3 = (String)version.getVersionProperty(VersionImplTest.PROP_3);
assertEquals(value3, VersionImplTest.VALUE_3);
}
/**
* Test getNodeRef()
*/
public void testGetNodeRef()
{
NodeRef nodeRef = this.version.getFrozenStateNodeRef();
assertNotNull(nodeRef);
assertEquals(nodeRef.toString(), this.nodeRef.toString());
}
/**
* Exception case - no node ref supplied when creating a verison
*/
public void testNoNodeRefOnVersionCreate()
{
try
{
new VersionImpl(this.versionProperties, null);
fail("It is invalid to create a version object without a node ref specified.");
}
catch (VersionServiceException exception)
{
}
}
}

View File

@@ -1,86 +0,0 @@
/*
* Copyright (C) 2005-2010 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.repo.version.common.versionlabel;
import java.io.Serializable;
import java.util.HashMap;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.repo.version.common.VersionImpl;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionType;
/**
* Unit test class for SerialVersionLabelPolicy class
*
* @author Roy Wetherall
*/
public class SerialVersionLabelPolicyTest extends TestCase
{
/**
* Test getVersionLabelValue
*/
public void testGetVersionLabelValue()
{
SerialVersionLabelPolicy policy = new SerialVersionLabelPolicy();
NodeRef dummyNodeRef = new NodeRef(new StoreRef("", ""), "");
HashMap<String, Serializable> versionProp1 = new HashMap<String, Serializable>();
versionProp1.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
String initialVersion = policy.calculateVersionLabel(
ContentModel.TYPE_CMOBJECT,
null,
0,
versionProp1);
assertEquals("Minor initial version not 0.1", "0.1", initialVersion);
HashMap<String, Serializable> versionProp2 = new HashMap<String, Serializable>();
versionProp2.put(VersionModel.PROP_VERSION_LABEL, "1.0");
Version version1 = new VersionImpl(versionProp2, dummyNodeRef);
String verisonLabel1 = policy.calculateVersionLabel(
ContentModel.TYPE_CMOBJECT,
version1,
1,
versionProp1);
assertEquals("Minor update from 1.0 not correct", "1.1", verisonLabel1);
HashMap<String, Serializable> versionProp3 = new HashMap<String, Serializable>();
versionProp3.put(VersionModel.PROP_VERSION_LABEL, "1.1");
Version version2 = new VersionImpl(versionProp3, dummyNodeRef);
HashMap<String, Serializable> versionProp4 = new HashMap<String, Serializable>();
versionProp4.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
String verisonLabel2 = policy.calculateVersionLabel(
ContentModel.TYPE_CMOBJECT,
version2,
1,
versionProp4);
assertEquals("major version update not correct", "2.0", verisonLabel2);
}
}

View File

@@ -1,179 +0,0 @@
<model name="ver2:versionmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>Alfresco Version2 Store Model</description>
<author>Alfresco</author>
<published>2010-04-29</published>
<version>2.1</version>
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<import uri="http://www.alfresco.org/model/system/1.0" prefix="sys"/>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
</imports>
<namespaces>
<namespace uri="http://www.alfresco.org/model/versionstore/2.0" prefix="ver2"/>
</namespaces>
<types>
<type name="ver2:versionHistory">
<parent>cm:cmobject</parent>
<properties>
<property name="ver2:versionedNodeId">
<type>d:text</type>
</property>
</properties>
<associations>
<child-association name="ver2:version">
<target>
<class>sys:base</class>
</target>
</child-association>
<association name="ver2:rootVersion">
<target>
<class>sys:base</class>
</target>
</association>
</associations>
</type>
<!-- since 3.3 (Ent) -->
<type name="ver2:versionedAssoc">
<parent>sys:reference</parent>
<properties>
<property name="ver2:assocDbId">
<type>d:long</type>
</property>
<property name="ver2:targetVersionRef">
<type>d:noderef</type>
</property>
</properties>
</type>
</types>
<aspects>
<aspect name="ver2:versionStoreRoot">
<title>Version Store Root</title>
<associations>
<child-association name="ver2:versionHistory">
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>ver2:versionHistory</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
<duplicate>false</duplicate>
</child-association>
</associations>
</aspect>
<aspect name="ver2:version">
<title>Version</title>
<properties>
<property name="ver2:versionNumber">
<type>d:int</type>
</property>
<property name="ver2:versionLabel">
<type>d:text</type>
</property>
<property name="ver2:description">
<type>d:text</type>
</property>
<property name="ver2:frozenNodeType">
<type>d:qname</type>
</property>
<property name="ver2:frozenAspects">
<type>d:qname</type>
<multiple>true</multiple>
</property>
<!-- frozen sys:referenceable properties (x4) -->
<property name="ver2:frozenNodeStoreProtocol">
<type>d:text</type>
<mandatory enforced="true">true</mandatory>
</property>
<property name="ver2:frozenNodeStoreId">
<type>d:text</type>
<mandatory enforced="true">true</mandatory>
</property>
<property name="ver2:frozenNodeId">
<type>d:text</type>
<mandatory enforced="true">true</mandatory>
</property>
<property name="ver2:frozenNodeDbId">
<type>d:long</type>
<mandatory enforced="true">true</mandatory>
</property>
<!-- frozen cm:auditable properties (x5) -->
<property name="ver2:frozenCreated">
<title>Created</title>
<type>d:datetime</type>
<protected>true</protected>
<index enabled="true">
<atomic>true</atomic>
<stored>false</stored>
<tokenised>both</tokenised>
</index>
</property>
<property name="ver2:frozenCreator">
<title>Creator</title>
<type>d:text</type>
<protected>true</protected>
</property>
<property name="ver2:frozenModified">
<title>Modified</title>
<type>d:datetime</type>
<protected>true</protected>
<index enabled="true">
<atomic>true</atomic>
<stored>false</stored>
<tokenised>both</tokenised>
</index>
</property>
<property name="ver2:frozenModifier">
<title>Modifier</title>
<type>d:text</type>
<protected>true</protected>
</property>
<property name="ver2:frozenAccessed">
<title>Accessed</title>
<type>d:datetime</type>
<protected>true</protected>
<index enabled="true">
<atomic>true</atomic>
<stored>false</stored>
<tokenised>both</tokenised>
</index>
</property>
</properties>
<associations>
<!-- since 3.3 (Ent) -->
<child-association name="ver2:versionedAssocs">
<target>
<class>ver2:versionedAssoc</class>
</target>
</child-association>
</associations>
</aspect>
</aspects>
</model>

View File

@@ -1,178 +0,0 @@
<model name="ver:versionmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<!-- deprecated -->
<description>Alfresco Version Store Model</description>
<author>Alfresco</author>
<published>2005-05-30</published>
<version>0.1</version>
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<import uri="http://www.alfresco.org/model/system/1.0" prefix="sys"/>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
</imports>
<namespaces>
<namespace uri="http://www.alfresco.org/model/versionstore/1.0" prefix="ver"/>
</namespaces>
<types>
<type name="ver:versionMetaDataValue">
<parent>sys:base</parent>
<properties>
<property name="ver:metaDataName">
<type>d:text</type>
</property>
<property name="ver:metaDataValue">
<type>d:any</type>
</property>
</properties>
</type>
<type name="ver:versionedProperty">
<parent>sys:base</parent>
<properties>
<property name="ver:qname">
<type>d:qname</type>
</property>
<property name="ver:value">
<type>d:any</type>
</property>
<property name="ver:multiValue">
<type>d:any</type>
<multiple>true</multiple>
</property>
<property name="ver:isMultiValue">
<type>d:boolean</type>
</property>
</properties>
</type>
<type name="ver:versionedAssoc">
<parent>sys:reference</parent>
<properties>
<property name="ver:assocQName">
<type>d:qname</type>
</property>
</properties>
</type>
<type name="ver:versionedChildAssoc">
<parent>ver:versionedAssoc</parent>
<properties>
<property name="ver:isPrimary">
<type>d:boolean</type>
</property>
<property name="ver:nthSibling">
<type>d:int</type>
</property>
</properties>
</type>
<type name="ver:version">
<parent>sys:container</parent>
<properties>
<property name="ver:versionNumber">
<type>d:int</type>
</property>
<property name="ver:versionLabel">
<type>d:text</type>
</property>
<property name="ver:frozenNodeId">
<type>d:text</type>
</property>
<property name="ver:frozenNodeStoreId">
<type>d:text</type>
</property>
<property name="ver:frozenNodeStoreProtocol">
<type>d:text</type>
</property>
<property name="ver:frozenNodeType">
<type>d:qname</type>
</property>
<property name="ver:frozenAspects">
<type>d:qname</type>
<multiple>true</multiple>
</property>
</properties>
<associations>
<child-association name="ver:versionMetaData">
<target>
<class>ver:versionMetaDataValue</class>
</target>
</child-association>
<child-association name="ver:versionedAttributes">
<target>
<class>ver:versionedProperty</class>
</target>
</child-association>
<child-association name="ver:versionedChildAssocs">
<target>
<class>ver:versionedChildAssoc</class>
</target>
</child-association>
<child-association name="ver:versionedAssocs">
<target>
<class>ver:versionedAssoc</class>
</target>
</child-association>
<association name="ver:successor">
<target>
<class>ver:version</class>
</target>
</association>
</associations>
<mandatory-aspects>
<aspect>cm:auditable</aspect>
</mandatory-aspects>
</type>
<type name="ver:versionHistory">
<parent>cm:cmobject</parent>
<properties>
<property name="ver:versionedNodeId">
<type>d:text</type>
</property>
</properties>
<associations>
<child-association name="ver:version">
<target>
<class>ver:version</class>
</target>
</child-association>
<association name="ver:rootVersion">
<target>
<class>ver:version</class>
</target>
</association>
</associations>
</type>
</types>
<aspects>
<aspect name="ver:versionStoreRoot">
<title>Version Store Root</title>
<associations>
<child-association name="ver:versionHistory">
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>ver:versionHistory</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
<duplicate>false</duplicate>
</child-association>
</associations>
</aspect>
</aspects>
</model>