KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Add features action execution test
31  *
32  * @author Roy Wetherall
33  */

34 public class AddFeaturesActionExecuterTest extends BaseSpringTest
35 {
36     /**
37      * The node service
38      */

39     private NodeService nodeService;
40     
41     /**
42      * The store reference
43      */

44     private StoreRef testStoreRef;
45     
46     /**
47      * The root node reference
48      */

49     private NodeRef rootNodeRef;
50     
51     /**
52      * The test node reference
53      */

54     private NodeRef nodeRef;
55     
56     /**
57      * The add features action executer
58      */

59     private AddFeaturesActionExecuter executer;
60     
61     /**
62      * Id used to identify the test action created
63      */

64     private final static String JavaDoc ID = GUID.generate();
65     
66     /**
67      * Called at the begining of all tests
68      */

69     @Override JavaDoc
70     protected void onSetUpInTransaction() throws Exception JavaDoc
71     {
72         this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
73         
74         AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
75         authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
76         
77         // Create the store and get the root node
78
this.testStoreRef = this.nodeService.createStore(
79                 StoreRef.PROTOCOL_WORKSPACE, "Test_"
80                         + System.currentTimeMillis());
81         this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
82
83         // Create the node used for tests
84
this.nodeRef = this.nodeService.createNode(
85                 this.rootNodeRef,
86                 ContentModel.ASSOC_CHILDREN,
87                 QName.createQName("{test}testnode"),
88                 ContentModel.TYPE_CONTENT).getChildRef();
89         
90         // Get the executer instance
91
this.executer = (AddFeaturesActionExecuter)this.applicationContext.getBean(AddFeaturesActionExecuter.NAME);
92     }
93     
94     /**
95      * Test execution
96      */

97     public void testExecution()
98     {
99         // Check that the node does not have the classifiable aspect
100
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_CLASSIFIABLE));
101         
102         // Execute the action
103
ActionImpl action = new ActionImpl(ID, AddFeaturesActionExecuter.NAME, null);
104         action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
105         this.executer.execute(action, this.nodeRef);
106         
107         // Check that the node now has the classifiable aspect applied
108
assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_CLASSIFIABLE));
109     }
110 }
111
Popular Tags