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