KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > dictionary > DictionaryDAOTest


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.dictionary;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import junit.framework.TestCase;
23
24 import org.alfresco.service.cmr.dictionary.AssociationDefinition;
25 import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
26 import org.alfresco.service.cmr.dictionary.DictionaryService;
27 import org.alfresco.service.cmr.dictionary.InvalidTypeException;
28 import org.alfresco.service.cmr.dictionary.ModelDefinition;
29 import org.alfresco.service.cmr.dictionary.PropertyDefinition;
30 import org.alfresco.service.cmr.dictionary.TypeDefinition;
31 import org.alfresco.service.namespace.QName;
32
33
34 public class DictionaryDAOTest extends TestCase
35 {
36     
37     private static final String JavaDoc TEST_MODEL = "org/alfresco/repo/dictionary/dictionarydaotest_model.xml";
38     private static final String JavaDoc TEST_BUNDLE = "org/alfresco/repo/dictionary/dictionarydaotest_model";
39     private DictionaryService service;
40     
41     
42     @Override JavaDoc
43     public void setUp()
44     {
45         // Instantiate Dictionary Service
46
NamespaceDAO namespaceDAO = new NamespaceDAOImpl();
47         DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
48
49         // Populate with appropriate models
50
DictionaryBootstrap bootstrap = new DictionaryBootstrap();
51         List JavaDoc<String JavaDoc> bootstrapModels = new ArrayList JavaDoc<String JavaDoc>();
52         bootstrapModels.add("alfresco/model/dictionaryModel.xml");
53         bootstrapModels.add(TEST_MODEL);
54         List JavaDoc<String JavaDoc> labels = new ArrayList JavaDoc<String JavaDoc>();
55         labels.add(TEST_BUNDLE);
56         bootstrap.setModels(bootstrapModels);
57         bootstrap.setLabels(labels);
58         bootstrap.setDictionaryDAO(dictionaryDAO);
59         bootstrap.bootstrap();
60         
61         DictionaryComponent component = new DictionaryComponent();
62         component.setDictionaryDAO(dictionaryDAO);
63         service = component;
64     }
65     
66
67     public void testBootstrap()
68     {
69         NamespaceDAO namespaceDAO = new NamespaceDAOImpl();
70         DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
71         
72         DictionaryBootstrap bootstrap = new DictionaryBootstrap();
73         List JavaDoc<String JavaDoc> bootstrapModels = new ArrayList JavaDoc<String JavaDoc>();
74         
75         bootstrapModels.add("alfresco/model/dictionaryModel.xml");
76         bootstrapModels.add("alfresco/model/systemModel.xml");
77         bootstrapModels.add("alfresco/model/contentModel.xml");
78         bootstrapModels.add("alfresco/model/applicationModel.xml");
79         
80         bootstrapModels.add("org/alfresco/repo/security/authentication/userModel.xml");
81         bootstrapModels.add("org/alfresco/repo/action/actionModel.xml");
82         bootstrapModels.add("org/alfresco/repo/rule/ruleModel.xml");
83         bootstrapModels.add("org/alfresco/repo/version/version_model.xml");
84         
85         bootstrap.setModels(bootstrapModels);
86         bootstrap.setDictionaryDAO(dictionaryDAO);
87         bootstrap.bootstrap();
88     }
89
90
91     public void testLabels()
92     {
93         QName model = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "dictionarydaotest");
94         ModelDefinition modelDef = service.getModel(model);
95         assertEquals("Model Description", modelDef.getDescription());
96         QName type = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "base");
97         TypeDefinition typeDef = service.getType(type);
98         assertEquals("Base Title", typeDef.getTitle());
99         assertEquals("Base Description", typeDef.getDescription());
100         QName prop = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "prop1");
101         PropertyDefinition propDef = service.getProperty(prop);
102         assertEquals("Prop1 Title", propDef.getTitle());
103         assertEquals("Prop1 Description", propDef.getDescription());
104         QName assoc = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "assoc1");
105         AssociationDefinition assocDef = service.getAssociation(assoc);
106         assertEquals("Assoc1 Title", assocDef.getTitle());
107         assertEquals("Assoc1 Description", assocDef.getDescription());
108         QName datatype = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "datatype");
109         DataTypeDefinition datatypeDef = service.getDataType(datatype);
110         assertEquals("Datatype Analyser", datatypeDef.getAnalyserClassName());
111     }
112     
113     
114     public void testSubClassOf()
115     {
116         QName invalid = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "invalid");
117         QName base = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "base");
118         QName file = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "file");
119         QName folder = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "folder");
120         QName referenceable = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "referenceable");
121
122         // Test invalid args
123
try
124         {
125             service.isSubClass(invalid, referenceable);
126             fail("Failed to catch invalid class parameter");
127         }
128         catch(InvalidTypeException e) {}
129
130         try
131         {
132             service.isSubClass(referenceable, invalid);
133             fail("Failed to catch invalid class parameter");
134         }
135         catch(InvalidTypeException e) {}
136
137         // Test various flavours of subclassof
138
boolean test1 = service.isSubClass(file, referenceable); // type vs aspect
139
assertFalse(test1);
140         boolean test2 = service.isSubClass(file, folder); // seperate hierarchies
141
assertFalse(test2);
142         boolean test3 = service.isSubClass(file, file); // self
143
assertTrue(test3);
144         boolean test4 = service.isSubClass(folder, base); // subclass
145
assertTrue(test4);
146         boolean test5 = service.isSubClass(base, folder); // reversed test
147
assertFalse(test5);
148     }
149     
150     
151 }
152
Popular Tags