KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > configuration > ConfigurableServiceImplTest


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.configuration;
18
19 import java.util.List JavaDoc;
20
21 import org.alfresco.model.ContentModel;
22 import org.alfresco.service.ServiceRegistry;
23 import org.alfresco.service.cmr.repository.ChildAssociationRef;
24 import org.alfresco.service.cmr.repository.NodeRef;
25 import org.alfresco.service.cmr.repository.NodeService;
26 import org.alfresco.service.cmr.repository.StoreRef;
27 import org.alfresco.service.namespace.RegexQNamePattern;
28 import org.alfresco.util.BaseSpringTest;
29
30 /**
31  * Configurable service implementation test
32  *
33  * @author Roy Wetherall
34  */

35 public class ConfigurableServiceImplTest extends BaseSpringTest
36 {
37     public NodeService nodeService;
38     private ServiceRegistry serviceRegistry;
39     private ConfigurableService configurableService;
40     private StoreRef testStoreRef;
41     private NodeRef rootNodeRef;
42     private NodeRef nodeRef;
43     
44     /**
45      * onSetUpInTransaction
46      */

47     @Override JavaDoc
48     protected void onSetUpInTransaction() throws Exception JavaDoc
49     {
50         this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
51         this.serviceRegistry = (ServiceRegistry)this.applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
52         this.configurableService = (ConfigurableService)this.applicationContext.getBean("configurableService");
53         
54         this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
55         this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
56         
57         // Create the node used for tests
58
this.nodeRef = this.nodeService.createNode(
59                 this.rootNodeRef,
60                 ContentModel.ASSOC_CHILDREN,
61                 ContentModel.ASSOC_CHILDREN,
62                 ContentModel.TYPE_CONTAINER).getChildRef();
63     }
64
65     /**
66      * Test isConfigurable
67      */

68     public void testIsConfigurable()
69     {
70         assertFalse(this.configurableService.isConfigurable(this.nodeRef));
71         this.configurableService.makeConfigurable(this.nodeRef);
72         assertTrue(this.configurableService.isConfigurable(this.nodeRef));
73     }
74     
75     /**
76      * Test make configurable
77      */

78     public void testMakeConfigurable()
79     {
80         this.configurableService.makeConfigurable(this.nodeRef);
81         assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_CONFIGURABLE));
82         List JavaDoc<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(
83                 this.nodeRef,
84                 RegexQNamePattern.MATCH_ALL,
85                 ContentModel.ASSOC_CONFIGURATIONS);
86         assertNotNull(assocs);
87         assertEquals(1, assocs.size());
88     }
89     
90     /**
91      * Test getConfigurationFolder
92      */

93     public void testGetConfigurationFolder()
94     {
95         assertNull(this.configurableService.getConfigurationFolder(this.nodeRef));
96         this.configurableService.makeConfigurable(nodeRef);
97         NodeRef configFolder = this.configurableService.getConfigurationFolder(this.nodeRef);
98         assertNotNull(configFolder);
99         NodeRef parentNodeRef = this.nodeService.getPrimaryParent(configFolder).getParentRef();
100         assertNotNull(parentNodeRef);
101         assertEquals(nodeRef, parentNodeRef);
102     }
103     
104 }
105
Popular Tags