KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 import junit.framework.TestCase;
21
22 import org.alfresco.repo.security.authentication.AuthenticationComponent;
23 import org.alfresco.repo.security.authentication.AuthenticationException;
24 import org.alfresco.service.ServiceRegistry;
25 import org.alfresco.service.cmr.action.ActionService;
26 import org.alfresco.service.cmr.repository.ContentService;
27 import org.alfresco.service.cmr.repository.NodeRef;
28 import org.alfresco.service.cmr.repository.NodeService;
29 import org.alfresco.service.cmr.repository.StoreRef;
30 import org.alfresco.service.cmr.security.AuthenticationService;
31 import org.alfresco.service.transaction.TransactionService;
32 import org.springframework.context.ApplicationContext;
33
34 /**
35  * Base Alfresco test.
36  *
37  * Creates a store and root node that can be used in the tests.
38  *
39  * @author Roy Wetherall
40  */

41 public abstract class BaseAlfrescoTestCase extends TestCase
42 {
43     /** the context to keep between tests */
44     public static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
45
46     /** the service registry */
47     protected ServiceRegistry serviceRegistry;
48     
49     /** The node service */
50     protected NodeService nodeService;
51     
52     /** The content service */
53     protected ContentService contentService;
54     
55     /** The authentication service */
56     protected AuthenticationService authenticationService;
57     
58     /** The store reference */
59     protected StoreRef storeRef;
60     
61     /** The root node reference */
62     protected NodeRef rootNodeRef;
63     
64     
65     protected ActionService actionService;
66     protected TransactionService transactionService;
67     
68     
69     @Override JavaDoc
70     protected void setUp() throws Exception JavaDoc
71     {
72         super.setUp();
73         // get the service register
74
this.serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
75         //Get a reference to the node service
76
this.nodeService = (NodeService)ctx.getBean("NodeService");
77         this.contentService = (ContentService)ctx.getBean("ContentService");
78         this.authenticationService = (AuthenticationService)ctx.getBean("authenticationService");
79         this.actionService = (ActionService)ctx.getBean("actionService");
80         this.transactionService = (TransactionService)ctx.getBean("transactionComponent");
81         
82         // Authenticate as the system user - this must be done before we create the store
83
AuthenticationComponent authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
84         authenticationComponent.setSystemUserAsCurrentUser();
85         
86         // Create the store and get the root node
87
this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
88         this.rootNodeRef = this.nodeService.getRootNode(this.storeRef);
89         
90        
91     }
92     
93     
94     @Override JavaDoc
95     protected void tearDown() throws Exception JavaDoc
96     {
97         authenticationService.clearCurrentSecurityContext();
98         super.tearDown();
99     }
100     
101 }
Popular Tags