001package org.andromda.core.configuration; 002 003import java.net.URL; 004import junit.framework.TestCase; 005 006/** 007 * JUnit test for {@link org.andromda.core.configuration.Configuration} 008 * 009 * @author Chad Brandon 010 */ 011public class ConfigurationTest 012 extends TestCase 013{ 014 /** 015 * 016 */ 017 public void testGetInstance() 018 { 019 URL uri = ConfigurationTest.class.getResource("configuration.xml"); 020 assertNotNull(uri); 021 Configuration configuration = Configuration.getInstance(uri); 022 assertNotNull(configuration); 023 024 // initialize the configuration 025 configuration.initialize(); 026 027 // properties 028 assertEquals(2, configuration.getProperties().length); 029 final Property property1 = configuration.getProperties()[0]; 030 assertEquals( 031 "modelValidation", 032 property1.getName()); 033 assertEquals( 034 "true", 035 property1.getValue()); 036 final Property property2 = configuration.getProperties()[1]; 037 assertEquals( 038 "cartridgeFilter", 039 property2.getName()); 040 assertEquals( 041 "${filter}", 042 property2.getValue()); 043 044 // server 045 final Server server = configuration.getServer(); 046 assertNotNull(server); 047 assertEquals( 048 "localhost", 049 server.getHost()); 050 assertEquals( 051 4444, 052 server.getPort()); 053 assertEquals( 054 5000, 055 server.getLoadInterval()); 056 assertEquals( 057 50, 058 server.getMaximumFailedLoadAttempts()); 059 060 // repositories 061 assertEquals(1, configuration.getRepositories().length); 062 final Repository repository = configuration.getRepositories()[0]; 063 assertNotNull(repository); 064 assertEquals("test", repository.getName()); 065 066 // models 067 assertEquals(3, repository.getModels().length); 068 final Model model1 = repository.getModels()[0]; 069 assertNotNull(model1); 070 assertEquals(2, model1.getUris().length); 071 assertEquals( 072 "file:model1Uri1.xmi", 073 model1.getUris()[0]); 074 assertEquals( 075 "file:model1Uri2.xmi", 076 model1.getUris()[1]); 077 assertTrue(model1.isLastModifiedCheck()); 078 assertEquals(2, model1.getModuleSearchLocations().length); 079 080 // module search locations 081 final Location[] moduleLocations = model1.getModuleSearchLocations(); 082 assertNotNull(moduleLocations); 083 assertEquals(2, moduleLocations.length); 084 assertEquals("/path/to/model/modules1", moduleLocations[0].getPath()); 085 assertEquals("*.xmi, *.xml.zip", moduleLocations[0].getPatterns()); 086 assertEquals("/path/to/model/modules2", moduleLocations[1].getPath()); 087 assertNull(moduleLocations[1].getPatterns()); 088 assertEquals(2, model1.getModuleSearchLocationPaths().length); 089 assertEquals("/path/to/model/modules1", model1.getModuleSearchLocationPaths()[0]); 090 assertEquals("/path/to/model/modules2", model1.getModuleSearchLocationPaths()[1]); 091 092 // modelPackages 093 assertNotNull(model1.getPackages()); 094 assertFalse(model1.getPackages().isApply("some::package")); 095 assertFalse(model1.getPackages().isApply("org::andromda::metafacades::uml")); 096 assertTrue(model1.getPackages().isApply("org::andromda::cartridges::test")); 097 098 assertNotNull(model1.getConstraints()); 099 assertFalse(model1.getConstraints().isApply("org::andromda::uml::metafacades::Entity::constraint name")); 100 assertFalse(model1.getConstraints().isApply("org::andromda::uml::somepackage::anotherpackage::andanotherpackage::SomeClass")); 101 assertFalse(model1.getConstraints().isApply("org::project::package::somepackage::anotherpackage::andanotherpackage::SomeClass")); 102 assertTrue(model1.getConstraints().isApply("org::project::package::some2package::anotherpackage::SomeClass")); 103 assertFalse(model1.getConstraints().isApply("andromda::com::package::somepackage")); 104 assertFalse(model1.getConstraints().isApply("com::package::SomeClass")); 105 assertTrue(model1.getConstraints().isApply("com::apackage::SomeClass")); 106 assertTrue(model1.getConstraints().isApply("org::andromda::uml::metafacades::Service")); 107 assertTrue(model1.getConstraints().isApply("some:Entity")); 108 109 // transformations 110 assertEquals(2, model1.getTransformations().length); 111 final Transformation transformation1 = model1.getTransformations()[0]; 112 assertNotNull(transformation1); 113 assertEquals( 114 "file:transformation1.xsl", 115 transformation1.getUri()); 116 assertEquals( 117 "path/to/some/directory/transformed-model.xmi", 118 transformation1.getOutputLocation()); 119 final Transformation transformation2 = model1.getTransformations()[1]; 120 assertNotNull(transformation2); 121 assertEquals( 122 "file:transformation2.xsl", 123 transformation2.getUri()); 124 125 final Model model2 = repository.getModels()[1]; 126 assertNotNull(model2); 127 assertEquals(1, model2.getUris().length); 128 assertEquals( 129 "file:model2.xmi", 130 model2.getUris()[0]); 131 assertEquals(0, model2.getModuleSearchLocations().length); 132 assertFalse(model2.isLastModifiedCheck()); 133 134 final Model model3 = repository.getModels()[2]; 135 assertNotNull(model3); 136 assertEquals(1, model3.getUris().length); 137 assertEquals( 138 "file:model3.xmi", 139 model3.getUris()[0]); 140 assertNotNull(model3.getPackages()); 141 assertTrue(model3.getPackages().isApply("some::package")); 142 assertFalse(model3.getPackages().isApply("org::andromda::metafacades::uml")); 143 144 // namespaces 145 final Namespace namespace1 = Namespaces.instance().getNamespace("default"); 146 final Property namespace1Property1 = namespace1.getProperty("languageMappingsUri"); 147 148 assertNotNull(namespace1Property1); 149 assertEquals( 150 "Java", 151 namespace1Property1.getValue()); 152 assertFalse(namespace1Property1.isIgnore()); 153 final Property namespace1Property2 = namespace1.getProperty("wrapperMappingsUri"); 154 assertEquals( 155 "JavaWrapper", 156 namespace1Property2.getValue()); 157 assertNotNull(namespace1Property2); 158 final Property namespace1Property3 = namespace1.getProperty("enumerationLiteralNameMask"); 159 assertNotNull(namespace1Property3); 160 assertEquals( 161 "upperunderscore", 162 namespace1Property3.getValue()); 163 final Property namespace1Property4 = namespace1.getProperty("maxSqlNameLength"); 164 assertNotNull(namespace1Property4); 165 assertTrue(namespace1Property4.isIgnore()); 166 final Namespace namespace2 = Namespaces.instance().getNamespace("spring"); 167 assertNotNull(namespace2); 168 final Property namespace2Property1 = namespace2.getProperty("hibernateQueryUseNamedParameters"); 169 assertNotNull(namespace2Property1); 170 assertEquals( 171 "true", 172 namespace2Property1.getValue()); 173 174 // mappings search locations 175 assertEquals(2, configuration.getMappingsSearchLocations().length); 176 assertEquals("/path/to/mappings/location1", configuration.getMappingsSearchLocations()[0].getPath()); 177 assertEquals("/path/to/mappings/location2", configuration.getMappingsSearchLocations()[1].getPath()); 178 } 179}