1 17 package org.alfresco.repo.audit; 18 19 import java.io.Serializable ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 import java.util.Set ; 23 24 import org.alfresco.model.ContentModel; 25 import org.alfresco.service.cmr.repository.ChildAssociationRef; 26 import org.alfresco.service.cmr.repository.NodeRef; 27 import org.alfresco.service.cmr.repository.NodeService; 28 import org.alfresco.service.cmr.repository.StoreRef; 29 import org.alfresco.service.namespace.QName; 30 import org.alfresco.util.BaseSpringTest; 31 import org.alfresco.util.debug.NodeStoreInspector; 32 33 39 public class AuditableAspectTest extends BaseSpringTest 40 { 41 44 private NodeService nodeService; 45 46 49 private StoreRef storeRef; 50 private NodeRef rootNodeRef; 51 52 55 @Override 56 protected void onSetUpInTransaction() 57 throws Exception 58 { 59 this.nodeService = (NodeService)this.applicationContext.getBean("dbNodeService"); 61 62 this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); 64 this.rootNodeRef = this.nodeService.getRootNode(storeRef); 65 } 66 67 68 public void testAudit() 69 { 70 ChildAssociationRef childAssocRef = nodeService.createNode( 72 rootNodeRef, 73 ContentModel.ASSOC_CHILDREN, 74 QName.createQName("{test}testfolder"), 75 ContentModel.TYPE_FOLDER); 76 77 assertAuditableProperties(childAssocRef.getChildRef()); 79 80 System.out.println(NodeStoreInspector.dumpNodeStore(nodeService, storeRef)); 81 } 82 83 84 public void testNoAudit() 85 { 86 Map <QName, Serializable > personProps = new HashMap <QName, Serializable >(); 88 personProps.put(ContentModel.PROP_USERNAME, "test person"); 89 personProps.put(ContentModel.PROP_HOMEFOLDER, rootNodeRef); 90 personProps.put(ContentModel.PROP_FIRSTNAME, "test first name"); 91 personProps.put(ContentModel.PROP_LASTNAME, "test last name"); 92 93 ChildAssociationRef childAssocRef = nodeService.createNode( 94 rootNodeRef, 95 ContentModel.ASSOC_CHILDREN, 96 QName.createQName("{test}testperson"), 97 ContentModel.TYPE_PERSON, 98 personProps); 99 100 Set <QName> aspects = nodeService.getAspects(childAssocRef.getChildRef()); 102 assertFalse(aspects.contains(ContentModel.ASPECT_AUDITABLE)); 103 104 System.out.println(NodeStoreInspector.dumpNodeStore(nodeService, storeRef)); 105 } 106 107 108 public void testAddAudit() 109 { 110 Map <QName, Serializable > personProps = new HashMap <QName, Serializable >(); 112 personProps.put(ContentModel.PROP_USERNAME, "test person"); 113 personProps.put(ContentModel.PROP_HOMEFOLDER, rootNodeRef); 114 personProps.put(ContentModel.PROP_FIRSTNAME, "test first name"); 115 personProps.put(ContentModel.PROP_LASTNAME, "test last name"); 116 117 ChildAssociationRef childAssocRef = nodeService.createNode( 118 rootNodeRef, 119 ContentModel.ASSOC_CHILDREN, 120 QName.createQName("{test}testperson"), 121 ContentModel.TYPE_PERSON, 122 personProps); 123 124 Set <QName> aspects = nodeService.getAspects(childAssocRef.getChildRef()); 126 assertFalse(aspects.contains(ContentModel.ASPECT_AUDITABLE)); 127 128 nodeService.addAspect(childAssocRef.getChildRef(), ContentModel.ASPECT_AUDITABLE, null); 130 131 nodeService.addAspect(childAssocRef.getChildRef(), ContentModel.ASPECT_TITLED, null); 132 133 aspects = nodeService.getAspects(childAssocRef.getChildRef()); 135 assertTrue(aspects.contains(ContentModel.ASPECT_AUDITABLE)); 136 137 assertAuditableProperties(childAssocRef.getChildRef()); 139 140 System.out.println(NodeStoreInspector.dumpNodeStore(nodeService, storeRef)); 141 } 142 143 144 public void testAddAspect() 145 { 146 Map <QName, Serializable > personProps = new HashMap <QName, Serializable >(); 148 personProps.put(ContentModel.PROP_USERNAME, "test person"); 149 personProps.put(ContentModel.PROP_HOMEFOLDER, rootNodeRef); 150 personProps.put(ContentModel.PROP_FIRSTNAME, "test first name "); 151 personProps.put(ContentModel.PROP_LASTNAME, "test last name"); 152 153 ChildAssociationRef childAssocRef = nodeService.createNode( 154 rootNodeRef, 155 ContentModel.ASSOC_CHILDREN, 156 QName.createQName("{test}testperson"), 157 ContentModel.TYPE_PERSON, 158 personProps); 159 160 nodeService.addAspect(childAssocRef.getChildRef(), ContentModel.ASPECT_TITLED, null); 162 163 System.out.println(NodeStoreInspector.dumpNodeStore(nodeService, storeRef)); 164 } 165 166 167 private void assertAuditableProperties(NodeRef nodeRef) 168 { 169 Map <QName, Serializable > props = nodeService.getProperties(nodeRef); 170 assertNotNull(props.get(ContentModel.PROP_CREATED)); 171 assertNotNull(props.get(ContentModel.PROP_MODIFIED)); 172 assertNotNull(props.get(ContentModel.PROP_CREATOR)); 173 assertNotNull(props.get(ContentModel.PROP_MODIFIER)); 174 } 175 176 } 177 | Popular Tags |