1 17 package org.alfresco.repo.action.executer; 18 19 import java.io.Serializable ; 20 import java.util.Map ; 21 22 import org.alfresco.model.ContentModel; 23 import org.alfresco.repo.action.ActionImpl; 24 import org.alfresco.repo.content.MimetypeMap; 25 import org.alfresco.repo.content.transform.AbstractContentTransformerTest; 26 import org.alfresco.repo.security.authentication.AuthenticationComponent; 27 import org.alfresco.service.cmr.repository.ContentService; 28 import org.alfresco.service.cmr.repository.ContentWriter; 29 import org.alfresco.service.cmr.repository.NodeRef; 30 import org.alfresco.service.cmr.repository.NodeService; 31 import org.alfresco.service.cmr.repository.StoreRef; 32 import org.alfresco.service.namespace.QName; 33 import org.alfresco.util.BaseSpringTest; 34 import org.alfresco.util.GUID; 35 36 42 public class ContentMetadataExtracterTest extends BaseSpringTest 43 { 44 protected static final String QUICK_TITLE = "The quick brown fox jumps over the lazy dog"; 45 protected static final String QUICK_DESCRIPTION = "Gym class featuring a brown fox and lazy dog"; 46 protected static final String QUICK_CREATOR = "Nevin Nollop"; 47 48 private NodeService nodeService; 49 private ContentService contentService; 50 private StoreRef testStoreRef; 51 private NodeRef rootNodeRef; 52 private NodeRef nodeRef; 53 54 private ContentMetadataExtracter executer; 55 56 private final static String ID = GUID.generate(); 57 58 @Override 59 protected void onSetUpInTransaction() throws Exception 60 { 61 this.nodeService = (NodeService) this.applicationContext.getBean("nodeService"); 62 this.contentService = (ContentService) this.applicationContext.getBean("contentService"); 63 64 AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent"); 65 authenticationComponent.setSystemUserAsCurrentUser(); 66 67 this.testStoreRef = this.nodeService.createStore( 69 StoreRef.PROTOCOL_WORKSPACE, 70 "Test_" + System.currentTimeMillis()); 71 this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef); 72 73 this.nodeRef = this.nodeService.createNode( 75 this.rootNodeRef, ContentModel.ASSOC_CHILDREN, 76 QName.createQName("{test}testnode"), 77 ContentModel.TYPE_CONTENT).getChildRef(); 78 79 ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); 81 cw.setMimetype(MimetypeMap.MIMETYPE_PDF); 82 cw.putContent(AbstractContentTransformerTest.loadQuickTestFile("pdf")); 83 84 this.executer = (ContentMetadataExtracter) this.applicationContext.getBean(ContentMetadataExtracter.NAME); 86 } 87 88 91 public void testFromBlanks() 92 { 93 96 Map <QName, Serializable > props = this.nodeService.getProperties(this.nodeRef); 98 props.remove(ContentModel.PROP_AUTHOR); 99 props.put(ContentModel.PROP_TITLE, ""); 100 props.put(ContentModel.PROP_DESCRIPTION, null); this.nodeService.setProperties(this.nodeRef, props); 103 104 ActionImpl action = new ActionImpl(ID, SetPropertyValueActionExecuter.NAME, null); 106 107 this.executer.execute(action, this.nodeRef); 108 109 assertEquals(QUICK_TITLE, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_TITLE)); 111 assertEquals(QUICK_DESCRIPTION, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_DESCRIPTION)); 112 assertEquals(QUICK_CREATOR, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_AUTHOR)); 113 } 114 115 118 public void testFromPartial() 119 { 120 String myCreator = "Null-op"; 123 String myTitle = "The hot dog is eaten by the city fox"; 124 125 Map <QName, Serializable > props = this.nodeService.getProperties(this.nodeRef); 127 props.put(ContentModel.PROP_AUTHOR, myCreator); 128 props.put(ContentModel.PROP_TITLE, myTitle); 129 props.remove(ContentModel.PROP_DESCRIPTION); this.nodeService.setProperties(this.nodeRef, props); 131 132 ActionImpl action = new ActionImpl(ID, SetPropertyValueActionExecuter.NAME, null); 134 135 this.executer.execute(action, this.nodeRef); 136 137 assertEquals(myTitle, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_TITLE)); 139 assertEquals(myCreator, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_AUTHOR)); 140 141 assertEquals(QUICK_DESCRIPTION, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_DESCRIPTION)); 143 144 } 145 146 } 149 | Popular Tags |