KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > util > BaseAlfrescoSpringTest


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.util;
18
19 import org.alfresco.repo.security.authentication.AuthenticationComponent;
20 import org.alfresco.service.cmr.action.ActionService;
21 import org.alfresco.service.cmr.repository.ContentService;
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.cmr.security.AuthenticationService;
26 import org.alfresco.service.transaction.TransactionService;
27
28 /**
29  * Base Alfresco test.
30  *
31  * Creates a store and root node that can be used in the tests.
32  *
33  * Runs all tests as the system user.
34  *
35  * @author Roy Wetherall
36  */

37 public abstract class BaseAlfrescoSpringTest extends BaseSpringTest
38 {
39     /** The node service */
40     protected NodeService nodeService;
41
42     /** The content service */
43     protected ContentService contentService;
44
45     /** The authentication service */
46     protected AuthenticationService authenticationService;
47
48     /** The store reference */
49     protected StoreRef storeRef;
50
51     /** The root node reference */
52     protected NodeRef rootNodeRef;
53     
54     
55     protected ActionService actionService;
56     protected TransactionService transactionService;
57
58     /**
59      * On setup in transaction override
60      */

61     @Override JavaDoc
62     protected void onSetUpInTransaction() throws Exception JavaDoc
63     {
64         super.onSetUpInTransaction();
65
66         // Get a reference to the node service
67
this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
68         this.contentService = (ContentService) this.applicationContext.getBean("contentService");
69         this.authenticationService = (AuthenticationService) this.applicationContext.getBean("authenticationService");
70         this.actionService = (ActionService)this.applicationContext.getBean("actionService");
71         this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
72
73         // Authenticate as the system user
74
AuthenticationComponent authenticationComponent = (AuthenticationComponent) this.applicationContext
75                 .getBean("authenticationComponent");
76         authenticationComponent.setSystemUserAsCurrentUser();
77         
78         // Create the store and get the root node
79
this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
80         this.rootNodeRef = this.nodeService.getRootNode(this.storeRef);
81
82       
83
84     }
85
86     @Override JavaDoc
87     protected void onTearDownInTransaction() throws Exception JavaDoc
88     {
89         authenticationService.clearCurrentSecurityContext();
90         super.onTearDownInTransaction();
91     }
92
93 }
94
Popular Tags