1 17 package org.alfresco.repo.dictionary; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 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 TEST_MODEL = "org/alfresco/repo/dictionary/dictionarydaotest_model.xml"; 38 private static final String TEST_BUNDLE = "org/alfresco/repo/dictionary/dictionarydaotest_model"; 39 private DictionaryService service; 40 41 42 @Override 43 public void setUp() 44 { 45 NamespaceDAO namespaceDAO = new NamespaceDAOImpl(); 47 DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO); 48 49 DictionaryBootstrap bootstrap = new DictionaryBootstrap(); 51 List <String > bootstrapModels = new ArrayList <String >(); 52 bootstrapModels.add("alfresco/model/dictionaryModel.xml"); 53 bootstrapModels.add(TEST_MODEL); 54 List <String > labels = new ArrayList <String >(); 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 <String > bootstrapModels = new ArrayList <String >(); 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 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 boolean test1 = service.isSubClass(file, referenceable); assertFalse(test1); 140 boolean test2 = service.isSubClass(file, folder); assertFalse(test2); 142 boolean test3 = service.isSubClass(file, file); assertTrue(test3); 144 boolean test4 = service.isSubClass(folder, base); assertTrue(test4); 146 boolean test5 = service.isSubClass(base, folder); assertFalse(test5); 148 } 149 150 151 } 152 | Popular Tags |