KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > executer > SetPropertyValueActionExecuterTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

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 /**
30  * Is sub class evaluator test
31  *
32  * @author Roy Wetherall
33  */

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 JavaDoc ID = GUID.generate();
43     
44     private final static String JavaDoc TEST_VALUE = "TestValue";
45
46     @Override JavaDoc
47     protected void onSetUpInTransaction() throws Exception JavaDoc
48     {
49         this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
50         
51         AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
52         authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
53         
54         // Create the store and get the root node
55
this.testStoreRef = this.nodeService.createStore(
56                 StoreRef.PROTOCOL_WORKSPACE, "Test_"
57                         + System.currentTimeMillis());
58         this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
59
60         // Create the node used for tests
61
this.nodeRef = this.nodeService.createNode(
62                 this.rootNodeRef,
63                 ContentModel.ASSOC_CHILDREN,
64                 QName.createQName("{test}testnode"),
65                 ContentModel.TYPE_CONTENT).getChildRef();
66         
67         // Get the executer instance
68
this.executer = (SetPropertyValueActionExecuter)this.applicationContext.getBean(SetPropertyValueActionExecuter.NAME);
69     }
70     
71     /**
72      * Test execution
73      */

74     public void testExecution()
75     {
76         // Check that the property is empty
77
assertNull(this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME));
78         
79         // Execute the action
80
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         // Check that the property value has been set
86
assertEquals(TEST_VALUE, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME));
87         
88         // Check what happens when a bad property name is set
89
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 JavaDoc exception)
97         {
98             // Good .. we where expecting this
99
}
100     }
101 }
102
Popular Tags