Merged DEV/SWIFT to HEAD

26007: ALF-7070:
          - null property values
          - mltext properties include locales and values
          - content properties include locale, encoding, mimetype, size, id
          - node pre-loading support - wip
          - paths include direct paths and category paths
   26058: ALF-7070
          - fixed null content encoding, mimetype
   26301: Merged BRANCHES/DEV/BM to BRANCHES/DEV/SWIFT:
      24572: WebDAV - switch lock check (to get prop before status) and use getPrimaryParent
      24574: WebDAV - getNodeLockInfo (add request caches for indirect lookup)
      24833: BM - WebDAV perf tweak (getNodeLockInfo - including PutMethod / checkNode)
             (note: related to ALF-6267 / ALF-6224)
      26319: Removed System.out messages
   26320: Moved away from BaseSpringTest
   26321: WIP: ALF-7339: RSOLR 009: Index track and build from SOLR
          - track simple properties (no locale, no dual tokenisation, no sort, no content, no ml text, no acls)
   26322: Merged BRANCHES/DEV/BM to BRANCHES/DEV/SWIFT:
      24745: (RECORD ONLY) Adjust Audit Model Registry for Subsystem read write locks
      24789: (RECORD ONLY) Remove unsafe use of SimpleDateFormat
      24862: (RECORD ONLY) Test content read with larger buffer size
   26331: Fixed ibatis -> mybatis merge issues
   26350: Build fix: iBatis -> myBatis merge error
   26354: Removed svn:mergeinfo

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28257 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2011-06-08 10:03:37 +00:00
parent 95049c96a1
commit 75dc2f5c6a
12 changed files with 853 additions and 319 deletions

View File

@@ -25,6 +25,10 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.evaluator.NoConditionEvaluator;
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
@@ -40,8 +44,9 @@ import org.alfresco.repo.dictionary.M2Type;
import org.alfresco.repo.rule.RuleModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionService;
@@ -67,20 +72,26 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.PropertyMap;
import org.springframework.context.ApplicationContext;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Unit tests for copy service
*
* @author Roy Wetherall
* @author Derek Hulley
*/
public class CopyServiceImplTest extends BaseSpringTest
public class CopyServiceImplTest extends TestCase
{
/**
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
/*
* Services used by the tests
*/
private TransactionService transactionService;
private NodeService nodeService;
private NodeService publicNodeService;
private CopyService copyService;
@@ -93,9 +104,10 @@ public class CopyServiceImplTest extends BaseSpringTest
private AuthenticationComponent authenticationComponent;
private MutableAuthenticationService authenticationService;
/**
/*
* Data used by the tests
*/
private UserTransaction txn;
private StoreRef storeRef;
private NodeRef sourceNodeRef;
private NodeRef rootNodeRef;
@@ -104,7 +116,7 @@ public class CopyServiceImplTest extends BaseSpringTest
private NodeRef childNodeRef;
private NodeRef destinationNodeRef;
/**
/*
* Types and properties used by the tests
*/
private static final String TEST_TYPE_NAMESPACE = "testTypeNamespaceURI";
@@ -145,52 +157,50 @@ public class CopyServiceImplTest extends BaseSpringTest
*/
private static final String SOME_CONTENT = "This is some content ...";
/**
* Sets the meta model DAO
*
* @param dictionaryDAO the meta model DAO
*/
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
{
this.dictionaryDAO = dictionaryDAO;
}
/**
* On setup in transaction implementation
*/
@Override
protected void onSetUpInTransaction()
throws Exception
protected void setUp() throws Exception
{
// Set the services
this.nodeService = (NodeService)this.applicationContext.getBean("dbNodeService");
this.publicNodeService = (NodeService)this.applicationContext.getBean("NodeService");
this.copyService = (CopyService)this.applicationContext.getBean("copyService");
this.contentService = (ContentService)this.applicationContext.getBean("contentService");
this.ruleService = (RuleService)this.applicationContext.getBean("ruleService");
this.actionService = (ActionService)this.applicationContext.getBean("actionService");
this.permissionService = (PermissionService)this.applicationContext.getBean("PermissionService");
this.personService = (PersonService)this.applicationContext.getBean("PersonService");
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
this.authenticationService = (MutableAuthenticationService) this.applicationContext.getBean("authenticationService");
if (AlfrescoTransactionSupport.isActualTransactionActive())
{
fail("Test started with transaction in progress");
}
this.authenticationComponent.setSystemUserAsCurrentUser();
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
// Set the services
transactionService = serviceRegistry.getTransactionService();
nodeService = (NodeService) ctx.getBean("dbNodeService");
publicNodeService = serviceRegistry.getNodeService();
copyService = (CopyService) ctx.getBean("copyService");
contentService = (ContentService) ctx.getBean("contentService");
ruleService = (RuleService) ctx.getBean("ruleService");
actionService = (ActionService)ctx.getBean("actionService");
permissionService = (PermissionService)ctx.getBean("PermissionService");
personService = serviceRegistry.getPersonService();
authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
authenticationComponent.setSystemUserAsCurrentUser();
// Ensure that a transaction is present
txn = transactionService.getUserTransaction();
txn.begin();
// Create the test model
createTestModel();
// Create the store and get the root node reference
this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(storeRef);
storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
rootNodeRef = nodeService.getRootNode(storeRef);
// Create the node used for copying
ChildAssociationRef childAssocRef = this.nodeService.createNode(
ChildAssociationRef childAssocRef = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}test"),
TEST_TYPE_QNAME,
createTypePropertyBag());
this.sourceNodeRef = childAssocRef.getChildRef();
sourceNodeRef = childAssocRef.getChildRef();
// Create another bag of properties
Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>();
@@ -198,59 +208,59 @@ public class CopyServiceImplTest extends BaseSpringTest
aspectProperties.put(PROP4_QNAME_OPTIONAL, TEST_VALUE_2);
// Apply the test aspect
this.nodeService.addAspect(
this.sourceNodeRef,
nodeService.addAspect(
sourceNodeRef,
TEST_ASPECT_QNAME,
aspectProperties);
this.nodeService.addAspect(sourceNodeRef, ContentModel.ASPECT_TITLED, null);
nodeService.addAspect(sourceNodeRef, ContentModel.ASPECT_TITLED, null);
// Add a child
ChildAssociationRef temp3 =this.nodeService.createNode(
this.sourceNodeRef,
ChildAssociationRef temp3 =nodeService.createNode(
sourceNodeRef,
TEST_CHILD_ASSOC_TYPE_QNAME,
TEST_CHILD_ASSOC_QNAME,
TEST_TYPE_QNAME,
createTypePropertyBag());
this.childNodeRef = temp3.getChildRef();
childNodeRef = temp3.getChildRef();
// Add a child that is primary
ChildAssociationRef temp2 = this.nodeService.createNode(
ChildAssociationRef temp2 = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testNonPrimaryChild"),
TEST_TYPE_QNAME,
createTypePropertyBag());
this.nonPrimaryChildNodeRef = temp2.getChildRef();
this.nodeService.addChild(
this.sourceNodeRef,
this.nonPrimaryChildNodeRef,
nonPrimaryChildNodeRef = temp2.getChildRef();
nodeService.addChild(
sourceNodeRef,
nonPrimaryChildNodeRef,
TEST_CHILD_ASSOC_TYPE_QNAME,
TEST_CHILD_ASSOC_QNAME2);
// Add a target assoc
ChildAssociationRef temp = this.nodeService.createNode(
ChildAssociationRef temp = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testAssoc"),
TEST_TYPE_QNAME,
createTypePropertyBag());
this.targetNodeRef = temp.getChildRef();
this.nodeService.createAssociation(this.sourceNodeRef, this.targetNodeRef, TEST_ASSOC_TYPE_QNAME);
targetNodeRef = temp.getChildRef();
nodeService.createAssociation(sourceNodeRef, targetNodeRef, TEST_ASSOC_TYPE_QNAME);
// Create a node we can use as the destination in a copy
Map<QName, Serializable> destinationProps = new HashMap<QName, Serializable>();
destinationProps.put(PROP1_QNAME_MANDATORY, TEST_VALUE_1);
destinationProps.put(PROP5_QNAME_MANDATORY, TEST_VALUE_3);
destinationProps.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
ChildAssociationRef temp5 = this.nodeService.createNode(
this.rootNodeRef,
ChildAssociationRef temp5 = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testDestinationNode"),
TEST_TYPE_QNAME,
destinationProps);
this.destinationNodeRef = temp5.getChildRef();
destinationNodeRef = temp5.getChildRef();
// Create two users, for use as part of
// the permission related tests
@@ -277,10 +287,13 @@ public class CopyServiceImplTest extends BaseSpringTest
}
@Override
protected void onTearDownInTransaction() throws Exception
protected void tearDown() throws Exception
{
if (txn != null)
{
try { txn.rollback(); } catch (Throwable e) {}
}
authenticationComponent.clearCurrentSecurityContext();
super.onTearDownInTransaction();
}
/**
@@ -370,9 +383,9 @@ public class CopyServiceImplTest extends BaseSpringTest
permissionService.setPermission(rootNodeRef, AuthenticationUtil.getGuestUserName(), PermissionService.CREATE_CHILDREN, true);
assertEquals(3, permissionService.getAllSetPermissions(sourceNodeRef).size());
NodeRef copy = this.copyService.copy(
this.sourceNodeRef,
this.rootNodeRef,
NodeRef copy = copyService.copy(
sourceNodeRef,
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}aclCopyOne"));
@@ -380,7 +393,7 @@ public class CopyServiceImplTest extends BaseSpringTest
// Admin
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
copy = copyService.copy(
sourceNodeRef,
@@ -392,7 +405,7 @@ public class CopyServiceImplTest extends BaseSpringTest
// guest
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
copy = copyService.copy(
sourceNodeRef,
@@ -403,9 +416,9 @@ public class CopyServiceImplTest extends BaseSpringTest
// guest with read permissions - write from ownership
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
permissionService.setPermission(sourceNodeRef, AuthenticationUtil.getGuestUserName(), PermissionService.READ_PERMISSIONS, true);
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
copy = copyService.copy(
sourceNodeRef,
@@ -417,9 +430,9 @@ public class CopyServiceImplTest extends BaseSpringTest
// guest with read and write
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
permissionService.setPermission(rootNodeRef, AuthenticationUtil.getGuestUserName(), PermissionService.CHANGE_PERMISSIONS, true);
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
copy = copyService.copy(
sourceNodeRef,
@@ -431,9 +444,9 @@ public class CopyServiceImplTest extends BaseSpringTest
// guest with write but not read
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
permissionService.setPermission(sourceNodeRef, AuthenticationUtil.getGuestUserName(), PermissionService.READ_PERMISSIONS, false);
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
copy = copyService.copy(
sourceNodeRef,
@@ -443,9 +456,9 @@ public class CopyServiceImplTest extends BaseSpringTest
assertEquals(3, permissionService.getAllSetPermissions(copy).size());
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
permissionService.deletePermission(sourceNodeRef, AuthenticationUtil.getGuestUserName(), PermissionService.READ_PERMISSIONS);
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
authenticationComponent.setCurrentUser(AuthenticationUtil.getGuestUserName());
copy = copyService.copy(
sourceNodeRef,
@@ -466,37 +479,37 @@ public class CopyServiceImplTest extends BaseSpringTest
public void testCopyToNewNode()
{
// Check that the node has no copies
List<NodeRef> copies = this.copyService.getCopies(this.sourceNodeRef);
List<NodeRef> copies = copyService.getCopies(sourceNodeRef);
assertNotNull(copies);
assertTrue(copies.isEmpty());
// Copy to new node without copying children
NodeRef copy = this.copyService.copy(
this.sourceNodeRef,
this.rootNodeRef,
NodeRef copy = copyService.copy(
sourceNodeRef,
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}copyAssoc"));
checkCopiedNode(this.sourceNodeRef, copy, true, true, false);
List<NodeRef> copies2 = this.copyService.getCopies(this.sourceNodeRef);
checkCopiedNode(sourceNodeRef, copy, true, true, false);
List<NodeRef> copies2 = copyService.getCopies(sourceNodeRef);
assertNotNull(copies2);
assertEquals(1, copies2.size());
// Copy to new node, copying children
NodeRef copy2 = this.copyService.copy(
this.sourceNodeRef,
this.rootNodeRef,
NodeRef copy2 = copyService.copy(
sourceNodeRef,
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}copyAssoc2"),
true);
checkCopiedNode(this.sourceNodeRef, copy2, true, true, true);
List<NodeRef> copies3 = this.copyService.getCopies(this.sourceNodeRef);
checkCopiedNode(sourceNodeRef, copy2, true, true, true);
List<NodeRef> copies3 = copyService.getCopies(sourceNodeRef);
assertNotNull(copies3);
assertEquals(2, copies3.size());
// Check that a copy of a copy works correctly
NodeRef copyOfCopy = this.copyService.copy(
NodeRef copyOfCopy = copyService.copy(
copy,
this.rootNodeRef,
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}copyOfCopy"));
checkCopiedNode(copy, copyOfCopy, true, true, false);
@@ -505,22 +518,22 @@ public class CopyServiceImplTest extends BaseSpringTest
// TODO check copying from a lockable copy
// Check copying from a node with content
ContentWriter contentWriter = this.contentService.getWriter(this.sourceNodeRef, ContentModel.PROP_CONTENT, true);
ContentWriter contentWriter = contentService.getWriter(sourceNodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.putContent(SOME_CONTENT);
NodeRef copyWithContent = this.copyService.copy(
this.sourceNodeRef,
this.rootNodeRef,
NodeRef copyWithContent = copyService.copy(
sourceNodeRef,
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}copyWithContent"));
checkCopiedNode(this.sourceNodeRef, copyWithContent, true, true, false);
ContentReader contentReader = this.contentService.getReader(copyWithContent, ContentModel.PROP_CONTENT);
checkCopiedNode(sourceNodeRef, copyWithContent, true, true, false);
ContentReader contentReader = contentService.getReader(copyWithContent, ContentModel.PROP_CONTENT);
assertNotNull(contentReader);
assertEquals(SOME_CONTENT, contentReader.getContentString());
// TODO check copying to a different store
//System.out.println(
// NodeStoreInspector.dumpNodeStore(this.nodeService, this.storeRef));
// NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
}
public void testCopyNodeWithRules()
@@ -531,38 +544,38 @@ public class CopyServiceImplTest extends BaseSpringTest
Map<String, Serializable> props = new HashMap<String, Serializable>(1);
props.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME, props);
Action action = actionService.createAction(AddFeaturesActionExecuter.NAME, props);
rule.setAction(action);
ActionCondition actionCondition = this.actionService.createActionCondition(NoConditionEvaluator.NAME);
ActionCondition actionCondition = actionService.createActionCondition(NoConditionEvaluator.NAME);
action.addActionCondition(actionCondition);
this.ruleService.saveRule(this.sourceNodeRef, rule);
ruleService.saveRule(sourceNodeRef, rule);
assertNotNull(rule.getNodeRef());
assertEquals(this.sourceNodeRef, this.ruleService.getOwningNodeRef(rule));
assertEquals(sourceNodeRef, ruleService.getOwningNodeRef(rule));
//System.out.println(
// NodeStoreInspector.dumpNodeStore(this.nodeService, this.storeRef));
// NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
//System.out.println(" ------------------------------ ");
// Now copy the node that has rules associated with it
NodeRef copy = this.copyService.copy(
this.sourceNodeRef,
this.rootNodeRef,
NodeRef copy = copyService.copy(
sourceNodeRef,
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}withRulesCopy"),
true);
//System.out.println(
// NodeStoreInspector.dumpNodeStore(this.nodeService, this.storeRef));
// NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
checkCopiedNode(this.sourceNodeRef, copy, true, true, true);
checkCopiedNode(sourceNodeRef, copy, true, true, true);
assertTrue(this.nodeService.hasAspect(copy, RuleModel.ASPECT_RULES));
assertTrue(this.ruleService.hasRules(copy));
assertTrue(this.ruleService.rulesEnabled(copy));
assertTrue(nodeService.hasAspect(copy, RuleModel.ASPECT_RULES));
assertTrue(ruleService.hasRules(copy));
assertTrue(ruleService.rulesEnabled(copy));
List<Rule> copiedRules = this.ruleService.getRules(copy);
List<Rule> copiedRules = ruleService.getRules(copy);
assertEquals(1, copiedRules.size());
Rule copiedRule = copiedRules.get(0);
@@ -570,44 +583,44 @@ public class CopyServiceImplTest extends BaseSpringTest
assertFalse(copiedRule.getNodeRef().equals(rule.getNodeRef()));
assertEquals(rule.getTitle(), copiedRule.getTitle());
assertEquals(rule.getDescription(), copiedRule.getDescription());
assertEquals(copy, this.ruleService.getOwningNodeRef(copiedRule));
assertEquals(copy, ruleService.getOwningNodeRef(copiedRule));
assertEquals(rule.getAction().getActionDefinitionName(), copiedRule.getAction().getActionDefinitionName());
// Now copy the node without copying the children and check that the rules have been copied
NodeRef copy2 = this.copyService.copy(
this.sourceNodeRef,
this.rootNodeRef,
NodeRef copy2 = copyService.copy(
sourceNodeRef,
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}withRuleCopyNoChildren"),
false);
// System.out.println(
// NodeStoreInspector.dumpNodeStore(this.nodeService, this.storeRef));
// NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
checkCopiedNode(this.sourceNodeRef, copy2, true, true, false);
checkCopiedNode(sourceNodeRef, copy2, true, true, false);
//assertTrue(this.configurableService.isConfigurable(copy2));
//assertNotNull(this.configurableService.getConfigurationFolder(copy2));
//assertFalse(this.configurableService.getConfigurationFolder(this.sourceNodeRef) == this.configurableService.getConfigurationFolder(copy2));
//assertTrue(configurableService.isConfigurable(copy2));
//assertNotNull(configurableService.getConfigurationFolder(copy2));
//assertFalse(configurableService.getConfigurationFolder(sourceNodeRef) == configurableService.getConfigurationFolder(copy2));
assertTrue(this.nodeService.hasAspect(copy2, RuleModel.ASPECT_RULES));
assertTrue(this.ruleService.hasRules(copy2));
assertTrue(this.ruleService.rulesEnabled(copy2));
List<Rule> copiedRules2 = this.ruleService.getRules(copy2);
assertTrue(nodeService.hasAspect(copy2, RuleModel.ASPECT_RULES));
assertTrue(ruleService.hasRules(copy2));
assertTrue(ruleService.rulesEnabled(copy2));
List<Rule> copiedRules2 = ruleService.getRules(copy2);
assertEquals(1, copiedRules.size());
Rule copiedRule2 = copiedRules2.get(0);
assertFalse(rule.getNodeRef().equals(copiedRule2.getNodeRef()));
assertEquals(rule.getTitle(), copiedRule2.getTitle());
assertEquals(rule.getDescription(), copiedRule2.getDescription());
assertEquals(this.ruleService.getOwningNodeRef(copiedRule2), copy2);
assertEquals(ruleService.getOwningNodeRef(copiedRule2), copy2);
assertEquals(rule.getAction().getActionDefinitionName(), copiedRule2.getAction().getActionDefinitionName());
}
public void testCopyToExistingNode()
{
// Copy nodes within the same store
this.copyService.copy(this.sourceNodeRef, this.destinationNodeRef);
checkCopiedNode(this.sourceNodeRef, this.destinationNodeRef, false, true, true);
copyService.copy(sourceNodeRef, destinationNodeRef);
checkCopiedNode(sourceNodeRef, destinationNodeRef, false, true, true);
// TODO check copying from a copy
// TODO check copying from a versioned copy
@@ -617,7 +630,7 @@ public class CopyServiceImplTest extends BaseSpringTest
// TODO check copying nodes between stores
//System.out.println(
// NodeStoreInspector.dumpNodeStore(this.nodeService, this.storeRef));
// NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
}
/**
@@ -628,21 +641,21 @@ public class CopyServiceImplTest extends BaseSpringTest
PropertyMap props = new PropertyMap();
// Need to create a potentially recursive node structure
props.put(ContentModel.PROP_NODE_UUID, "nodeOne");
NodeRef nodeOne = this.nodeService.createNode(
this.rootNodeRef,
NodeRef nodeOne = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN,
ContentModel.TYPE_CONTAINER,
props).getChildRef();
props.put(ContentModel.PROP_NODE_UUID, "nodeTwo");
NodeRef nodeTwo = this.nodeService.createNode(
NodeRef nodeTwo = nodeService.createNode(
nodeOne,
ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN,
ContentModel.TYPE_CONTAINER,
props).getChildRef();
props.put(ContentModel.PROP_NODE_UUID, "nodeThree");
NodeRef nodeThree = this.nodeService.createNode(
NodeRef nodeThree = nodeService.createNode(
nodeTwo,
ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN,
@@ -650,23 +663,23 @@ public class CopyServiceImplTest extends BaseSpringTest
props).getChildRef();
// Issue a potentialy recursive copy
this.copyService.copy(nodeOne, nodeThree, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, true);
copyService.copy(nodeOne, nodeThree, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, true);
//System.out.println(
// NodeStoreInspector.dumpNodeStore(this.nodeService, this.storeRef));
// NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
}
public void testCopyResidualProperties() throws Exception
{
QName nodeOneAssocName = QName.createQName("{test}nodeOne");
NodeRef nodeOne = this.nodeService.createNode(
this.rootNodeRef,
NodeRef nodeOne = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
nodeOneAssocName,
TEST_TYPE_QNAME).getChildRef();
this.nodeService.setProperty(nodeOne, PROP_QNAME_RESIDUAL_NODE_REF, nodeOne);
this.nodeService.setProperty(nodeOne, PROP_QNAME_RESIDUAL_ANY, nodeOne);
nodeService.setProperty(nodeOne, PROP_QNAME_RESIDUAL_NODE_REF, nodeOne);
nodeService.setProperty(nodeOne, PROP_QNAME_RESIDUAL_ANY, nodeOne);
NodeRef nodeOneCopy = copyService.copy(
nodeOne,
rootNodeRef,
@@ -692,56 +705,56 @@ public class CopyServiceImplTest extends BaseSpringTest
QName nodeThreeAssocName = QName.createQName("{test}nodeThree");
QName nodeFourAssocName = QName.createQName("{test}nodeFour");
NodeRef nodeNotCopied = this.nodeService.createNode(
this.rootNodeRef,
NodeRef nodeNotCopied = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
nodeOneAssocName,
TEST_TYPE_QNAME).getChildRef();
NodeRef nodeOne = this.nodeService.createNode(
this.rootNodeRef,
NodeRef nodeOne = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
nodeOneAssocName,
TEST_TYPE_QNAME).getChildRef();
NodeRef nodeTwo = this.nodeService.createNode(
NodeRef nodeTwo = nodeService.createNode(
nodeOne,
TEST_CHILD_ASSOC_TYPE_QNAME,
nodeTwoAssocName,
TEST_TYPE_QNAME).getChildRef();
NodeRef nodeThree = this.nodeService.createNode(
NodeRef nodeThree = nodeService.createNode(
nodeTwo,
TEST_CHILD_ASSOC_TYPE_QNAME,
nodeThreeAssocName,
TEST_TYPE_QNAME).getChildRef();
NodeRef nodeFour = this.nodeService.createNode(
NodeRef nodeFour = nodeService.createNode(
nodeOne,
TEST_CHILD_ASSOC_TYPE_QNAME,
nodeFourAssocName,
TEST_TYPE_QNAME).getChildRef();
this.nodeService.addChild(nodeFour, nodeThree, TEST_CHILD_ASSOC_TYPE_QNAME, TEST_CHILD_ASSOC_QNAME);
this.nodeService.createAssociation(nodeTwo, nodeThree, TEST_ASSOC_TYPE_QNAME);
this.nodeService.createAssociation(nodeTwo, nodeNotCopied, TEST_ASSOC_TYPE_QNAME);
nodeService.addChild(nodeFour, nodeThree, TEST_CHILD_ASSOC_TYPE_QNAME, TEST_CHILD_ASSOC_QNAME);
nodeService.createAssociation(nodeTwo, nodeThree, TEST_ASSOC_TYPE_QNAME);
nodeService.createAssociation(nodeTwo, nodeNotCopied, TEST_ASSOC_TYPE_QNAME);
// Make node one actionable with a rule to copy nodes into node two
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, nodeTwo);
Rule rule = new Rule();
rule.setRuleType(RuleType.INBOUND);
Action action = this.actionService.createAction(CopyActionExecuter.NAME, params);
ActionCondition condition = this.actionService.createActionCondition(NoConditionEvaluator.NAME);
Action action = actionService.createAction(CopyActionExecuter.NAME, params);
ActionCondition condition = actionService.createActionCondition(NoConditionEvaluator.NAME);
action.addActionCondition(condition);
rule.setAction(action);
this.ruleService.saveRule(nodeOne, rule);
ruleService.saveRule(nodeOne, rule);
// Do a deep copy
NodeRef nodeOneCopy = this.copyService.copy(nodeOne, this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}copiedNodeOne"), true);
NodeRef nodeOneCopy = copyService.copy(nodeOne, rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}copiedNodeOne"), true);
NodeRef nodeTwoCopy = null;
NodeRef nodeThreeCopy = null;
NodeRef nodeFourCopy = null;
//System.out.println(
// NodeStoreInspector.dumpNodeStore(this.nodeService, this.storeRef));
// NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
List<ChildAssociationRef> nodeOneCopyChildren = this.nodeService.getChildAssocs(nodeOneCopy);
List<ChildAssociationRef> nodeOneCopyChildren = nodeService.getChildAssocs(nodeOneCopy);
assertNotNull(nodeOneCopyChildren);
assertEquals(3, nodeOneCopyChildren.size());
for (ChildAssociationRef nodeOneCopyChild : nodeOneCopyChildren)
@@ -750,7 +763,7 @@ public class CopyServiceImplTest extends BaseSpringTest
{
nodeTwoCopy = nodeOneCopyChild.getChildRef();
List<ChildAssociationRef> nodeTwoCopyChildren = this.nodeService.getChildAssocs(nodeTwoCopy);
List<ChildAssociationRef> nodeTwoCopyChildren = nodeService.getChildAssocs(nodeTwoCopy);
assertNotNull(nodeTwoCopyChildren);
assertEquals(1, nodeTwoCopyChildren.size());
for (ChildAssociationRef nodeTwoCopyChild : nodeTwoCopyChildren)
@@ -771,7 +784,7 @@ public class CopyServiceImplTest extends BaseSpringTest
assertNotNull(nodeFourCopy);
// Check the non primary child assoc
List<ChildAssociationRef> children = this.nodeService.getChildAssocs(
List<ChildAssociationRef> children = nodeService.getChildAssocs(
nodeFourCopy,
RegexQNamePattern.MATCH_ALL,
TEST_CHILD_ASSOC_QNAME);
@@ -781,7 +794,7 @@ public class CopyServiceImplTest extends BaseSpringTest
assertEquals(child.getChildRef(), nodeThree);
// Check the target assoc
List<AssociationRef> assocs = this.nodeService.getTargetAssocs(nodeTwoCopy, TEST_ASSOC_TYPE_QNAME);
List<AssociationRef> assocs = nodeService.getTargetAssocs(nodeTwoCopy, TEST_ASSOC_TYPE_QNAME);
assertNotNull(assocs);
assertEquals(2, assocs.size());
AssociationRef assoc0 = assocs.get(0);
@@ -790,7 +803,7 @@ public class CopyServiceImplTest extends BaseSpringTest
assertTrue(assoc1.getTargetRef().equals(nodeThreeCopy) || assoc1.getTargetRef().equals(nodeNotCopied));
// Check that the rule parameter values have been made relative
List<Rule> rules = this.ruleService.getRules(nodeOneCopy);
List<Rule> rules = ruleService.getRules(nodeOneCopy);
assertNotNull(rules);
assertEquals(1, rules.size());
Rule copiedRule = rules.get(0);
@@ -805,26 +818,26 @@ public class CopyServiceImplTest extends BaseSpringTest
public void testCopyAndRename()
{
// Check a normal copy with no dup restrictions
NodeRef copy = this.copyService.copyAndRename(
this.sourceNodeRef,
this.rootNodeRef,
NodeRef copy = copyService.copyAndRename(
sourceNodeRef,
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}copyAssoc"),
false);
checkCopiedNode(this.sourceNodeRef, copy, true, true, false);
assertTrue(TEST_NAME.equals(this.nodeService.getProperty(copy, ContentModel.PROP_NAME)));
checkCopiedNode(sourceNodeRef, copy, true, true, false);
assertTrue(TEST_NAME.equals(nodeService.getProperty(copy, ContentModel.PROP_NAME)));
// Create a folder and content node
Map<QName, Serializable> propsFolder = new HashMap<QName, Serializable>(1);
propsFolder.put(ContentModel.PROP_NAME, "tempFolder");
NodeRef folderNode = this.nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}tempFolder"), ContentModel.TYPE_FOLDER, propsFolder).getChildRef();
NodeRef folderNode = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}tempFolder"), ContentModel.TYPE_FOLDER, propsFolder).getChildRef();
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, TEST_NAME);
NodeRef contentNode = this.nodeService.createNode(folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}renametest"), ContentModel.TYPE_CONTENT, props).getChildRef();
NodeRef contentNode = nodeService.createNode(folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}renametest"), ContentModel.TYPE_CONTENT, props).getChildRef();
// Now copy the content node with the duplicate name restriction
NodeRef contentCopy = this.copyService.copy(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}bobbins"), false);
assertFalse(TEST_NAME.equals(this.nodeService.getProperty(contentCopy, ContentModel.PROP_NAME)));
NodeRef contentCopy = copyService.copy(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}bobbins"), false);
assertFalse(TEST_NAME.equals(nodeService.getProperty(contentCopy, ContentModel.PROP_NAME)));
}
/**
@@ -835,25 +848,25 @@ public class CopyServiceImplTest extends BaseSpringTest
// Create a folder and content node
Map<QName, Serializable> propsFolder = new HashMap<QName, Serializable>(1);
propsFolder.put(ContentModel.PROP_NAME, "tempFolder");
NodeRef folderNode = this.nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "tempFolder"), ContentModel.TYPE_FOLDER, propsFolder).getChildRef();
NodeRef folderNode = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "tempFolder"), ContentModel.TYPE_FOLDER, propsFolder).getChildRef();
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, "myDoc.txt");
NodeRef contentNode = this.nodeService.createNode(folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDoc.txt"), ContentModel.TYPE_CONTENT, props).getChildRef();
NodeRef contentNode = nodeService.createNode(folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDoc.txt"), ContentModel.TYPE_CONTENT, props).getChildRef();
NodeRef copy = this.copyService.copyAndRename(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, null, false);
assertEquals("Copy of myDoc.txt", this.nodeService.getProperty(copy, ContentModel.PROP_NAME));
NodeRef copy = copyService.copyAndRename(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, null, false);
assertEquals("Copy of myDoc.txt", nodeService.getProperty(copy, ContentModel.PROP_NAME));
QName copyQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Copy of myDoc.txt");
assertEquals(copyQName, this.nodeService.getPrimaryParent(copy).getQName());
assertEquals(copyQName, nodeService.getPrimaryParent(copy).getQName());
copy = this.copyService.copyAndRename(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, null, false);
assertEquals("Copy of Copy of myDoc.txt", this.nodeService.getProperty(copy, ContentModel.PROP_NAME));
copy = copyService.copyAndRename(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, null, false);
assertEquals("Copy of Copy of myDoc.txt", nodeService.getProperty(copy, ContentModel.PROP_NAME));
copyQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Copy of Copy of myDoc.txt");
assertEquals(copyQName, this.nodeService.getPrimaryParent(copy).getQName());
assertEquals(copyQName, nodeService.getPrimaryParent(copy).getQName());
copy = this.copyService.copyAndRename(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, null, false);
assertEquals("Copy of Copy of Copy of myDoc.txt", this.nodeService.getProperty(copy, ContentModel.PROP_NAME));
copy = copyService.copyAndRename(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, null, false);
assertEquals("Copy of Copy of Copy of myDoc.txt", nodeService.getProperty(copy, ContentModel.PROP_NAME));
copyQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Copy of Copy of Copy of myDoc.txt");
assertEquals(copyQName, this.nodeService.getPrimaryParent(copy).getQName());
assertEquals(copyQName, nodeService.getPrimaryParent(copy).getQName());
}
@@ -867,7 +880,7 @@ public class CopyServiceImplTest extends BaseSpringTest
// Create a folder and content node
Map<QName, Serializable> propsFolder = new HashMap<QName, Serializable>(1);
propsFolder.put(ContentModel.PROP_NAME, "tempFolder");
NodeRef folderNode = this.nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "tempFolder"), ContentModel.TYPE_FOLDER, propsFolder).getChildRef();
NodeRef folderNode = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "tempFolder"), ContentModel.TYPE_FOLDER, propsFolder).getChildRef();
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, "myDoc.txt");
@@ -883,12 +896,12 @@ public class CopyServiceImplTest extends BaseSpringTest
description.addValue(Locale.ITALY, ITALY_DESCRIPTION);
props.put(ContentModel.PROP_DESCRIPTION, description);
NodeRef contentNode = this.nodeService.createNode(folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDoc.txt"), ContentModel.TYPE_CONTENT, props).getChildRef();
NodeRef contentNode = nodeService.createNode(folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDoc.txt"), ContentModel.TYPE_CONTENT, props).getChildRef();
NodeRef copy = this.copyService.copyAndRename(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, null, false);
assertEquals("Copy of myDoc.txt", this.nodeService.getProperty(copy, ContentModel.PROP_NAME));
NodeRef copy = copyService.copyAndRename(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, null, false);
assertEquals("Copy of myDoc.txt", nodeService.getProperty(copy, ContentModel.PROP_NAME));
QName copyQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Copy of myDoc.txt");
assertEquals(copyQName, this.nodeService.getPrimaryParent(copy).getQName());
assertEquals(copyQName, nodeService.getPrimaryParent(copy).getQName());
// Test uses DB Node Service.
Serializable desc = nodeService.getProperty(copy, ContentModel.PROP_DESCRIPTION);
@@ -937,7 +950,7 @@ public class CopyServiceImplTest extends BaseSpringTest
} catch(AccessDeniedException e) {}
// Allow the read, but the destination won't accept it
this.authenticationComponent.setSystemUserAsCurrentUser();
authenticationComponent.setSystemUserAsCurrentUser();
permissionService.setPermission(sourceNodeRef, USER_2, PermissionService.CONTRIBUTOR, true);
permissionService.setPermission(targetNodeRef, USER_2, PermissionService.CONTRIBUTOR, false);
AuthenticationUtil.setFullyAuthenticatedUser(USER_2);
@@ -948,7 +961,7 @@ public class CopyServiceImplTest extends BaseSpringTest
// Now allow on the destination, should go through
this.authenticationComponent.setSystemUserAsCurrentUser();
authenticationComponent.setSystemUserAsCurrentUser();
permissionService.setPermission(targetNodeRef, USER_2, PermissionService.CONTRIBUTOR, true);
AuthenticationUtil.setFullyAuthenticatedUser(USER_2);
@@ -1053,9 +1066,9 @@ public class CopyServiceImplTest extends BaseSpringTest
if (sameStore == true)
{
// Check that the copy aspect has been applied to the copy
boolean hasCopyAspect = this.nodeService.hasAspect(destinationNodeRef, ContentModel.ASPECT_COPIEDFROM);
boolean hasCopyAspect = nodeService.hasAspect(destinationNodeRef, ContentModel.ASPECT_COPIEDFROM);
assertTrue("Missing aspect: " + ContentModel.ASPECT_COPIEDFROM, hasCopyAspect);
NodeRef copyNodeRef = (NodeRef)this.nodeService.getProperty(destinationNodeRef, ContentModel.PROP_COPY_REFERENCE);
NodeRef copyNodeRef = (NodeRef)nodeService.getProperty(destinationNodeRef, ContentModel.PROP_COPY_REFERENCE);
assertNotNull(copyNodeRef);
assertEquals(sourceNodeRef, copyNodeRef);
}
@@ -1066,11 +1079,11 @@ public class CopyServiceImplTest extends BaseSpringTest
}
}
boolean hasTestAspect = this.nodeService.hasAspect(destinationNodeRef, TEST_ASPECT_QNAME);
boolean hasTestAspect = nodeService.hasAspect(destinationNodeRef, TEST_ASPECT_QNAME);
assertTrue(hasTestAspect);
// Check that all the correct properties have been copied
Map<QName, Serializable> destinationProperties = this.nodeService.getProperties(destinationNodeRef);
Map<QName, Serializable> destinationProperties = nodeService.getProperties(destinationNodeRef);
assertNotNull(destinationProperties);
String value1 = (String)destinationProperties.get(PROP1_QNAME_MANDATORY);
assertNotNull(value1);
@@ -1086,18 +1099,18 @@ public class CopyServiceImplTest extends BaseSpringTest
assertEquals(TEST_VALUE_2, value4);
// Check all the target associations have been copied
List<AssociationRef> destinationTargets = this.nodeService.getTargetAssocs(destinationNodeRef, TEST_ASSOC_TYPE_QNAME);
List<AssociationRef> destinationTargets = nodeService.getTargetAssocs(destinationNodeRef, TEST_ASSOC_TYPE_QNAME);
assertNotNull(destinationTargets);
assertEquals(1, destinationTargets.size());
AssociationRef nodeAssocRef = destinationTargets.get(0);
assertNotNull(nodeAssocRef);
assertEquals(this.targetNodeRef, nodeAssocRef.getTargetRef());
assertEquals(targetNodeRef, nodeAssocRef.getTargetRef());
// Check all the child associations have been copied
List<ChildAssociationRef> childAssocRefs = this.nodeService.getChildAssocs(destinationNodeRef);
List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(destinationNodeRef);
assertNotNull(childAssocRefs);
int expectedSize = copyChildren ? 2 : 0;
if (this.nodeService.hasAspect(destinationNodeRef, RuleModel.ASPECT_RULES) == true)
if (nodeService.hasAspect(destinationNodeRef, RuleModel.ASPECT_RULES) == true)
{
expectedSize = expectedSize + 1;
}
@@ -1109,7 +1122,7 @@ public class CopyServiceImplTest extends BaseSpringTest
{
// Since this child is non-primary in the source it will always be non-primary in the destination
assertFalse(ref.isPrimary());
assertEquals(this.nonPrimaryChildNodeRef, ref.getChildRef());
assertEquals(nonPrimaryChildNodeRef, ref.getChildRef());
}
else
{
@@ -1118,18 +1131,18 @@ public class CopyServiceImplTest extends BaseSpringTest
if (ref.getTypeQName().equals(RuleModel.ASSOC_RULE_FOLDER) == true)
{
assertTrue(ref.isPrimary());
assertTrue(this.childNodeRef.equals(ref.getChildRef()) == false);
assertTrue(childNodeRef.equals(ref.getChildRef()) == false);
}
else
{
assertFalse(ref.isPrimary());
assertEquals(this.childNodeRef, ref.getChildRef());
assertEquals(childNodeRef, ref.getChildRef());
}
}
else
{
assertTrue(ref.isPrimary());
assertTrue(this.childNodeRef.equals(ref.getChildRef()) == false);
assertTrue(childNodeRef.equals(ref.getChildRef()) == false);
// TODO need to check that the copied child has all the correct details ..
}