1 17 package org.alfresco.repo.action.executer; 18 19 import org.alfresco.model.ContentModel; 20 import org.alfresco.repo.action.ActionImpl; 21 import org.alfresco.repo.security.authentication.AuthenticationComponent; 22 import org.alfresco.service.cmr.repository.NodeRef; 23 import org.alfresco.service.cmr.repository.NodeService; 24 import org.alfresco.service.cmr.repository.StoreRef; 25 import org.alfresco.service.namespace.QName; 26 import org.alfresco.util.BaseSpringTest; 27 import org.alfresco.util.GUID; 28 29 34 public class SetPropertyValueActionExecuterTest extends BaseSpringTest 35 { 36 private NodeService nodeService; 37 private StoreRef testStoreRef; 38 private NodeRef rootNodeRef; 39 private NodeRef nodeRef; 40 private SetPropertyValueActionExecuter executer; 41 42 private final static String ID = GUID.generate(); 43 44 private final static String TEST_VALUE = "TestValue"; 45 46 @Override 47 protected void onSetUpInTransaction() throws Exception 48 { 49 this.nodeService = (NodeService)this.applicationContext.getBean("nodeService"); 50 51 AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent"); 52 authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); 53 54 this.testStoreRef = this.nodeService.createStore( 56 StoreRef.PROTOCOL_WORKSPACE, "Test_" 57 + System.currentTimeMillis()); 58 this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef); 59 60 this.nodeRef = this.nodeService.createNode( 62 this.rootNodeRef, 63 ContentModel.ASSOC_CHILDREN, 64 QName.createQName("{test}testnode"), 65 ContentModel.TYPE_CONTENT).getChildRef(); 66 67 this.executer = (SetPropertyValueActionExecuter)this.applicationContext.getBean(SetPropertyValueActionExecuter.NAME); 69 } 70 71 74 public void testExecution() 75 { 76 assertNull(this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME)); 78 79 ActionImpl action = new ActionImpl(ID, SetPropertyValueActionExecuter.NAME, null); 81 action.setParameterValue(SetPropertyValueActionExecuter.PARAM_PROPERTY, ContentModel.PROP_NAME); 82 action.setParameterValue(SetPropertyValueActionExecuter.PARAM_VALUE, TEST_VALUE); 83 this.executer.execute(action, this.nodeRef); 84 85 assertEquals(TEST_VALUE, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME)); 87 88 action.setParameterValue(SetPropertyValueActionExecuter.PARAM_PROPERTY, QName.createQName("{test}badProperty")); 90 91 try 92 { 93 this.executer.execute(action, this.nodeRef); 94 fail("We would expect and exception to be thrown since the property name is invalid."); 95 } 96 catch (Throwable exception) 97 { 98 } 100 } 101 } 102 | Popular Tags |