mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
REPO-5163: Added CMIS integration test for node downloaded event (#1012)
Co-authored-by: Chris Shields <christopher.shields@alfresco.com> Co-authored-by: Sara Aspery <sara.aspery@alfresco.com>
This commit is contained in:
@@ -1,28 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
*
|
*
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* 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
|
* 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
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.repo.node;
|
package org.alfresco.repo.node;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -197,13 +197,13 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return uuid.hashCode();
|
return uuid.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the node policies as well as node indexing behaviour
|
* Registers the node policies as well as node indexing behaviour
|
||||||
*/
|
*/
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
// Register the various policies
|
// Register the various policies
|
||||||
beforeCreateStoreDelegate = policyComponent.registerClassPolicy(NodeServicePolicies.BeforeCreateStorePolicy.class);
|
beforeCreateStoreDelegate = policyComponent.registerClassPolicy(NodeServicePolicies.BeforeCreateStorePolicy.class);
|
||||||
onCreateStoreDelegate = policyComponent.registerClassPolicy(NodeServicePolicies.OnCreateStorePolicy.class);
|
onCreateStoreDelegate = policyComponent.registerClassPolicy(NodeServicePolicies.OnCreateStorePolicy.class);
|
||||||
@@ -310,13 +310,13 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
// execute policy for node type and aspects
|
// execute policy for node type and aspects
|
||||||
NodeServicePolicies.OnCreateNodePolicy policy = onCreateNodeDelegate.get(childNodeRef, qnames);
|
NodeServicePolicies.OnCreateNodePolicy policy = onCreateNodeDelegate.get(childNodeRef, qnames);
|
||||||
policy.onCreateNode(childAssocRef);
|
policy.onCreateNode(childAssocRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NodeServicePolicies.BeforeMoveNodePolicy#beforeMoveNode(ChildAssociationRef, NodeRef)
|
* @see NodeServicePolicies.BeforeMoveNodePolicy#beforeMoveNode(ChildAssociationRef, NodeRef)
|
||||||
*/
|
*/
|
||||||
protected void invokeBeforeMoveNode(ChildAssociationRef oldChildAssocRef, NodeRef newParentRef)
|
protected void invokeBeforeMoveNode(ChildAssociationRef oldChildAssocRef, NodeRef newParentRef)
|
||||||
{
|
{
|
||||||
NodeRef childNodeRef = oldChildAssocRef.getChildRef();
|
NodeRef childNodeRef = oldChildAssocRef.getChildRef();
|
||||||
|
|
||||||
if (ignorePolicy(childNodeRef))
|
if (ignorePolicy(childNodeRef))
|
||||||
@@ -416,13 +416,13 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
// execute policy for node type and aspects
|
// execute policy for node type and aspects
|
||||||
NodeServicePolicies.BeforeSetNodeTypePolicy policy = beforeSetNodeTypeDelegate.get(nodeRef, qnames);
|
NodeServicePolicies.BeforeSetNodeTypePolicy policy = beforeSetNodeTypeDelegate.get(nodeRef, qnames);
|
||||||
policy.beforeSetNodeType(nodeRef, oldType, newType);
|
policy.beforeSetNodeType(nodeRef, oldType, newType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(NodeRef, Map, Map)
|
* @see NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(NodeRef, Map, Map)
|
||||||
*/
|
*/
|
||||||
protected void invokeOnUpdateProperties(
|
protected void invokeOnUpdateProperties(
|
||||||
NodeRef nodeRef,
|
NodeRef nodeRef,
|
||||||
Map<QName, Serializable> before,
|
Map<QName, Serializable> before,
|
||||||
Map<QName, Serializable> after)
|
Map<QName, Serializable> after)
|
||||||
{
|
{
|
||||||
@@ -489,13 +489,13 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
// execute policy for node type and aspects
|
// execute policy for node type and aspects
|
||||||
NodeServicePolicies.BeforeDeleteNodePolicy policy = beforeDeleteNodeDelegate.get(nodeRef, qnames);
|
NodeServicePolicies.BeforeDeleteNodePolicy policy = beforeDeleteNodeDelegate.get(nodeRef, qnames);
|
||||||
policy.beforeDeleteNode(nodeRef);
|
policy.beforeDeleteNode(nodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NodeServicePolicies.BeforeArchiveNodePolicy
|
* @see NodeServicePolicies.BeforeArchiveNodePolicy
|
||||||
*/
|
*/
|
||||||
protected void invokeBeforeArchiveNode(NodeRef nodeRef)
|
protected void invokeBeforeArchiveNode(NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
if (ignorePolicy(nodeRef))
|
if (ignorePolicy(nodeRef))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -506,13 +506,13 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
// execute policy for node type and aspects
|
// execute policy for node type and aspects
|
||||||
NodeServicePolicies.BeforeArchiveNodePolicy policy = beforeArchiveNodeDelegate.get(nodeRef, qnames);
|
NodeServicePolicies.BeforeArchiveNodePolicy policy = beforeArchiveNodeDelegate.get(nodeRef, qnames);
|
||||||
policy.beforeArchiveNode(nodeRef);
|
policy.beforeArchiveNode(nodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NodeServicePolicies.OnDeleteNodePolicy#onDeleteNode(ChildAssociationRef, boolean)
|
* @see NodeServicePolicies.OnDeleteNodePolicy#onDeleteNode(ChildAssociationRef, boolean)
|
||||||
*/
|
*/
|
||||||
protected void invokeOnDeleteNode(ChildAssociationRef childAssocRef, QName childNodeTypeQName, Set<QName> childAspectQnames, boolean isArchivedNode)
|
protected void invokeOnDeleteNode(ChildAssociationRef childAssocRef, QName childNodeTypeQName, Set<QName> childAspectQnames, boolean isArchivedNode)
|
||||||
{
|
{
|
||||||
NodeRef childNodeRef = childAssocRef.getChildRef();
|
NodeRef childNodeRef = childAssocRef.getChildRef();
|
||||||
|
|
||||||
Set<QName> qnames = null;
|
Set<QName> qnames = null;
|
||||||
@@ -540,13 +540,13 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
NodeServicePolicies.OnDeleteNodePolicy policy = onDeleteNodeDelegate.get(childAssocRef.getChildRef(), qnames);
|
NodeServicePolicies.OnDeleteNodePolicy policy = onDeleteNodeDelegate.get(childAssocRef.getChildRef(), qnames);
|
||||||
policy.onDeleteNode(childAssocRef, isArchivedNode);
|
policy.onDeleteNode(childAssocRef, isArchivedNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NodeServicePolicies.OnRestoreNodePolicy#onRestoreNode(ChildAssociationRef)
|
* @see NodeServicePolicies.OnRestoreNodePolicy#onRestoreNode(ChildAssociationRef)
|
||||||
*/
|
*/
|
||||||
protected void invokeOnRestoreNode(ChildAssociationRef childAssocRef)
|
protected void invokeOnRestoreNode(ChildAssociationRef childAssocRef)
|
||||||
{
|
{
|
||||||
NodeRef childNodeRef = childAssocRef.getChildRef();
|
NodeRef childNodeRef = childAssocRef.getChildRef();
|
||||||
// get qnames to invoke against
|
// get qnames to invoke against
|
||||||
Set<QName> qnames = getTypeAndAspectQNames(childNodeRef);
|
Set<QName> qnames = getTypeAndAspectQNames(childNodeRef);
|
||||||
@@ -582,13 +582,13 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
|
|
||||||
NodeServicePolicies.OnAddAspectPolicy policy = onAddAspectDelegate.get(nodeRef, aspectTypeQName);
|
NodeServicePolicies.OnAddAspectPolicy policy = onAddAspectDelegate.get(nodeRef, aspectTypeQName);
|
||||||
policy.onAddAspect(nodeRef, aspectTypeQName);
|
policy.onAddAspect(nodeRef, aspectTypeQName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NodeServicePolicies.BeforeRemoveAspectPolicy#beforeRemoveAspect(NodeRef,
|
* @see NodeServicePolicies.BeforeRemoveAspectPolicy#beforeRemoveAspect(NodeRef,
|
||||||
* QName)
|
* QName)
|
||||||
*/
|
*/
|
||||||
protected void invokeBeforeRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
|
protected void invokeBeforeRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
|
||||||
{
|
{
|
||||||
if (ignorePolicy(nodeRef))
|
if (ignorePolicy(nodeRef))
|
||||||
{
|
{
|
||||||
@@ -612,13 +612,13 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
|
|
||||||
NodeServicePolicies.OnRemoveAspectPolicy policy = onRemoveAspectDelegate.get(nodeRef, aspectTypeQName);
|
NodeServicePolicies.OnRemoveAspectPolicy policy = onRemoveAspectDelegate.get(nodeRef, aspectTypeQName);
|
||||||
policy.onRemoveAspect(nodeRef, aspectTypeQName);
|
policy.onRemoveAspect(nodeRef, aspectTypeQName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(ChildAssociationRef, boolean)
|
* @see NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(ChildAssociationRef, boolean)
|
||||||
*/
|
*/
|
||||||
protected void invokeOnCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
|
protected void invokeOnCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
|
||||||
{
|
{
|
||||||
// Get the parent reference and the assoc type qName
|
// Get the parent reference and the assoc type qName
|
||||||
NodeRef parentNodeRef = childAssocRef.getParentRef();
|
NodeRef parentNodeRef = childAssocRef.getParentRef();
|
||||||
|
|
||||||
@@ -673,13 +673,13 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
// execute policy for node type and aspects
|
// execute policy for node type and aspects
|
||||||
NodeServicePolicies.OnDeleteChildAssociationPolicy policy = onDeleteChildAssociationDelegate.get(parentNodeRef, qnames, assocTypeQName);
|
NodeServicePolicies.OnDeleteChildAssociationPolicy policy = onDeleteChildAssociationDelegate.get(parentNodeRef, qnames, assocTypeQName);
|
||||||
policy.onDeleteChildAssociation(childAssocRef);
|
policy.onDeleteChildAssociation(childAssocRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NodeServicePolicies.OnCreateAssociationPolicy#onCreateAssociation(AssociationRef)
|
* @see NodeServicePolicies.OnCreateAssociationPolicy#onCreateAssociation(AssociationRef)
|
||||||
*/
|
*/
|
||||||
protected void invokeOnCreateAssociation(AssociationRef nodeAssocRef)
|
protected void invokeOnCreateAssociation(AssociationRef nodeAssocRef)
|
||||||
{
|
{
|
||||||
NodeRef sourceNodeRef = nodeAssocRef.getSourceRef();
|
NodeRef sourceNodeRef = nodeAssocRef.getSourceRef();
|
||||||
|
|
||||||
if (ignorePolicy(sourceNodeRef))
|
if (ignorePolicy(sourceNodeRef))
|
||||||
@@ -814,12 +814,12 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default property values
|
* Sets the default property values
|
||||||
*
|
*
|
||||||
* @param classDefinition the model type definition for which to get defaults
|
* @param classDefinition the model type definition for which to get defaults
|
||||||
*/
|
*/
|
||||||
protected Map<QName, Serializable> getDefaultProperties(ClassDefinition classDefinition)
|
protected Map<QName, Serializable> getDefaultProperties(ClassDefinition classDefinition)
|
||||||
{
|
{
|
||||||
PropertyMap properties = new PropertyMap();
|
PropertyMap properties = new PropertyMap();
|
||||||
for (Map.Entry<QName, Serializable> entry : classDefinition.getDefaultValues().entrySet())
|
for (Map.Entry<QName, Serializable> entry : classDefinition.getDefaultValues().entrySet())
|
||||||
{
|
{
|
||||||
|
@@ -35,6 +35,7 @@ import java.util.List;
|
|||||||
import javax.jms.ConnectionFactory;
|
import javax.jms.ConnectionFactory;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.opencmis.CMISConnector;
|
||||||
import org.alfresco.repo.event.databind.ObjectMapperFactory;
|
import org.alfresco.repo.event.databind.ObjectMapperFactory;
|
||||||
import org.alfresco.repo.event.v1.model.EventData;
|
import org.alfresco.repo.event.v1.model.EventData;
|
||||||
import org.alfresco.repo.event.v1.model.NodeResource;
|
import org.alfresco.repo.event.v1.model.NodeResource;
|
||||||
@@ -84,6 +85,9 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
|
|||||||
|
|
||||||
private static boolean isCamelConfigured;
|
private static boolean isCamelConfigured;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected CMISConnector cmisConnector;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected RetryingTransactionHelper retryingTransactionHelper;
|
protected RetryingTransactionHelper retryingTransactionHelper;
|
||||||
|
|
||||||
|
196
src/test/java/org/alfresco/repo/event2/DownloadRepoEventIT.java
Normal file
196
src/test/java/org/alfresco/repo/event2/DownloadRepoEventIT.java
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.event2;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.opencmis.dictionary.CMISNodeInfo;
|
||||||
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
|
import org.alfresco.repo.event.v1.model.EventData;
|
||||||
|
import org.alfresco.repo.event.v1.model.NodeResource;
|
||||||
|
import org.alfresco.repo.event.v1.model.RepoEvent;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adina Ababei
|
||||||
|
*/
|
||||||
|
public class DownloadRepoEventIT extends AbstractContextAwareRepoEvent
|
||||||
|
{
|
||||||
|
private ContentService contentService;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup()
|
||||||
|
{
|
||||||
|
contentService = (ContentService) applicationContext.getBean("contentService");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDownload()
|
||||||
|
{
|
||||||
|
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
|
||||||
|
|
||||||
|
// node.Created event should be generated
|
||||||
|
RepoEvent<NodeResource> resultRepoEvent = getRepoEvent(1);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
|
||||||
|
|
||||||
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
|
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.TYPE_CONTENT,
|
||||||
|
true);
|
||||||
|
writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
|
||||||
|
writer.setEncoding("UTF-8");
|
||||||
|
writer.putContent("test content");
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// node.Updated event should be generated
|
||||||
|
resultRepoEvent = getRepoEvent(2);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
|
||||||
|
|
||||||
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
|
CMISNodeInfo cmisNodeInfo = cmisConnector.createNodeInfo(nodeRef);
|
||||||
|
cmisConnector.getContentStream(cmisNodeInfo, null, null, null);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// we should have 3 events: node.Created, node.Updated, node.Downloaded
|
||||||
|
checkNumOfEvents(3);
|
||||||
|
|
||||||
|
// node.Downloaded event should be generated
|
||||||
|
RepoEvent<NodeResource> downloadedRepoEvent = getRepoEvent(3);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_DOWNLOADED.getType(), downloadedRepoEvent.getType());
|
||||||
|
assertEquals(EventData.JSON_SCHEMA, downloadedRepoEvent.getDataschema());
|
||||||
|
assertNotNull("The event should not have null id", downloadedRepoEvent.getId());
|
||||||
|
assertNotNull("The event should not have null time", downloadedRepoEvent.getTime());
|
||||||
|
|
||||||
|
NodeResource nodeResource = downloadedRepoEvent.getData().getResource();
|
||||||
|
assertNotNull("Resource ID is null", nodeResource.getId());
|
||||||
|
assertNotNull("Default aspects were not added. ", nodeResource.getAspectNames());
|
||||||
|
assertNotNull("Missing createdByUser property.", nodeResource.getCreatedByUser());
|
||||||
|
assertNotNull("Missing createdAt property.", nodeResource.getCreatedAt());
|
||||||
|
assertNotNull("Missing modifiedByUser property.", nodeResource.getModifiedByUser());
|
||||||
|
assertNotNull("Missing modifiedAt property.", nodeResource.getModifiedAt());
|
||||||
|
assertNotNull("Missing node resource properties", nodeResource.getProperties());
|
||||||
|
assertTrue("Incorrect value for isFile field", nodeResource.isFile());
|
||||||
|
assertFalse("Incorrect value for isFolder files", nodeResource.isFolder());
|
||||||
|
assertNull("ResourceBefore is not null", downloadedRepoEvent.getData().getResourceBefore());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDownloadTwiceInTheSameTransaction()
|
||||||
|
{
|
||||||
|
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
|
||||||
|
|
||||||
|
// node.Created event should be generated
|
||||||
|
RepoEvent<NodeResource> resultRepoEvent = getRepoEvent(1);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
|
||||||
|
|
||||||
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
|
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.TYPE_CONTENT,
|
||||||
|
true);
|
||||||
|
writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
|
||||||
|
writer.setEncoding("UTF-8");
|
||||||
|
writer.putContent("test content");
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// node.Updated event should be generated
|
||||||
|
resultRepoEvent = getRepoEvent(2);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
|
||||||
|
|
||||||
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
|
CMISNodeInfo cmisNodeInfo = cmisConnector.createNodeInfo(nodeRef);
|
||||||
|
cmisConnector.getContentStream(cmisNodeInfo, null, null, null);
|
||||||
|
cmisConnector.getContentStream(cmisNodeInfo, null, null, null);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// we should have 3 events: node.Created, node.Updated, node.Downloaded
|
||||||
|
checkNumOfEvents(3);
|
||||||
|
|
||||||
|
RepoEvent<NodeResource> downloadedRepoEvent = getRepoEvent(3);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_DOWNLOADED.getType(), downloadedRepoEvent.getType());
|
||||||
|
assertEquals("Downloaded event does not have the correct id",
|
||||||
|
getNodeResource(resultRepoEvent).getId(),
|
||||||
|
getNodeResource(downloadedRepoEvent).getId());
|
||||||
|
assertNull("ResourceBefore field is not null", downloadedRepoEvent.getData().getResourceBefore());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDownloadEventTwiceInDifferentTransactions()
|
||||||
|
{
|
||||||
|
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
|
||||||
|
|
||||||
|
// node.Created event should be generated
|
||||||
|
RepoEvent<NodeResource> resultRepoEvent = getRepoEvent(1);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
|
||||||
|
|
||||||
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
|
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.TYPE_CONTENT,
|
||||||
|
true);
|
||||||
|
writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
|
||||||
|
writer.setEncoding("UTF-8");
|
||||||
|
writer.putContent("test content");
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// node.Updated event should be generated
|
||||||
|
resultRepoEvent = getRepoEvent(2);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
|
||||||
|
|
||||||
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
|
CMISNodeInfo cmisNodeInfo = cmisConnector.createNodeInfo(nodeRef);
|
||||||
|
cmisConnector.getContentStream(cmisNodeInfo, null, null, null);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
RepoEvent<NodeResource> downloadedRepoEvent = getRepoEvent(3);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_DOWNLOADED.getType(), downloadedRepoEvent.getType());
|
||||||
|
assertEquals("Downloaded event does not have the correct id",
|
||||||
|
getNodeResource(resultRepoEvent).getId(),
|
||||||
|
getNodeResource(downloadedRepoEvent).getId());
|
||||||
|
assertNull("ResourceBefore field is not null", downloadedRepoEvent.getData().getResourceBefore());
|
||||||
|
|
||||||
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
|
CMISNodeInfo cmisNodeInfo = cmisConnector.createNodeInfo(nodeRef);
|
||||||
|
cmisConnector.getContentStream(cmisNodeInfo, null, null, null);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// we should have 4 events: node.Created, node.Updated, node.Downloaded, node.Downloaded
|
||||||
|
checkNumOfEvents(4);
|
||||||
|
|
||||||
|
downloadedRepoEvent = getRepoEvent(4);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_DOWNLOADED.getType(), downloadedRepoEvent.getType());
|
||||||
|
assertEquals("Downloaded event does not have the correct id",
|
||||||
|
getNodeResource(resultRepoEvent).getId(),
|
||||||
|
getNodeResource(downloadedRepoEvent).getId());
|
||||||
|
assertNull("ResourceBefore field is not null", downloadedRepoEvent.getData().getResourceBefore());
|
||||||
|
}
|
||||||
|
}
|
@@ -32,7 +32,8 @@ import org.junit.runners.Suite.SuiteClasses;
|
|||||||
@RunWith(Suite.class)
|
@RunWith(Suite.class)
|
||||||
@SuiteClasses({ org.alfresco.repo.event2.CreateRepoEventIT.class,
|
@SuiteClasses({ org.alfresco.repo.event2.CreateRepoEventIT.class,
|
||||||
org.alfresco.repo.event2.UpdateRepoEventIT.class,
|
org.alfresco.repo.event2.UpdateRepoEventIT.class,
|
||||||
org.alfresco.repo.event2.DeleteRepoEventIT.class })
|
org.alfresco.repo.event2.DeleteRepoEventIT.class,
|
||||||
|
org.alfresco.repo.event2.DownloadRepoEventIT.class })
|
||||||
public class RepoEvent2ITSuite
|
public class RepoEvent2ITSuite
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user