KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > descriptor > DescriptorServiceTest


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.descriptor;
18
19 import org.alfresco.repo.importer.ImporterBootstrap;
20 import org.alfresco.repo.security.authentication.AuthenticationComponent;
21 import org.alfresco.service.ServiceRegistry;
22 import org.alfresco.service.cmr.repository.NodeService;
23 import org.alfresco.service.cmr.repository.StoreRef;
24 import org.alfresco.service.descriptor.Descriptor;
25 import org.alfresco.service.descriptor.DescriptorService;
26 import org.alfresco.util.BaseSpringTest;
27 import org.alfresco.util.debug.NodeStoreInspector;
28
29 public class DescriptorServiceTest extends BaseSpringTest
30 {
31     private NodeService nodeService;
32     private ImporterBootstrap systemBootstrap;
33     private StoreRef storeRef;
34     private AuthenticationComponent authenticationComponent;
35     
36     
37     @Override JavaDoc
38     protected void onSetUpInTransaction() throws Exception JavaDoc
39     {
40         nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
41         systemBootstrap = (ImporterBootstrap)applicationContext.getBean("systemBootstrap");
42         
43         storeRef = new StoreRef("system", "Test_" + System.currentTimeMillis());
44         systemBootstrap.setStoreUrl(storeRef.toString());
45         systemBootstrap.bootstrap();
46         
47         this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
48         
49         this.authenticationComponent.setSystemUserAsCurrentUser();
50         
51         
52       
53       
54         System.out.println(NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
55     }
56     
57     @Override JavaDoc
58     protected void onTearDownInTransaction() throws Exception JavaDoc
59     {
60         authenticationComponent.clearCurrentSecurityContext();
61         super.onTearDownInTransaction();
62     }
63     
64     
65     public void testServerDescriptor()
66     {
67         ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
68         DescriptorService descriptorService = registry.getDescriptorService();
69         Descriptor serverDescriptor = descriptorService.getServerDescriptor();
70         
71         String JavaDoc major = serverDescriptor.getVersionMajor();
72         String JavaDoc minor = serverDescriptor.getVersionMinor();
73         String JavaDoc revision = serverDescriptor.getVersionRevision();
74         String JavaDoc label = serverDescriptor.getVersionLabel();
75         String JavaDoc version = major + "." + minor + "." + revision;
76         if (label != null && label.length() > 0)
77         {
78             version += " (" + label + ")";
79         }
80         
81         assertEquals(version, serverDescriptor.getVersion());
82         
83         int schemaVersion = serverDescriptor.getSchema();
84         assertTrue("Server schema version must be greater than 0", schemaVersion > 0);
85     }
86
87     public void testRepositoryDescriptor()
88     {
89         ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
90         DescriptorService descriptorService = registry.getDescriptorService();
91         Descriptor repoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
92         
93         String JavaDoc major = repoDescriptor.getVersionMajor();
94         String JavaDoc minor = repoDescriptor.getVersionMinor();
95         String JavaDoc revision = repoDescriptor.getVersionRevision();
96         String JavaDoc label = repoDescriptor.getVersionLabel();
97         String JavaDoc version = major + "." + minor + "." + revision;
98         if (label != null && label.length() > 0)
99         {
100             version += " (" + label + ")";
101         }
102         
103         assertEquals(version, repoDescriptor.getVersion());
104         
105         int schemaVersion = repoDescriptor.getSchema();
106         assertTrue("Repository schema version must be greater than -1", schemaVersion > -1);
107     }
108         
109 }
110
Popular Tags