01: package org.andromda.core.profile;
02:
03: import java.net.URL;
04: import java.util.Collection;
05:
06: import junit.framework.TestCase;
07:
08: import org.andromda.core.common.ComponentContainer;
09: import org.andromda.core.configuration.Namespace;
10: import org.andromda.core.configuration.NamespaceProperties;
11: import org.andromda.core.configuration.Namespaces;
12: import org.andromda.core.configuration.Property;
13: import org.andromda.core.namespace.NamespaceComponents;
14:
15: /**
16: * Tests {@link org.andromda.core.profile.Profile}
17: * @author Chad Brandon
18: */
19: public class ProfileTest extends TestCase {
20: /**
21: * @see TestCase#setUp()
22: */
23: protected void setUp() throws Exception {
24: NamespaceComponents.instance().discover();
25: Collection profiles = ComponentContainer.instance()
26: .findComponentsOfType(Profile.class);
27: assertNotNull(profiles);
28: assertEquals(1, profiles.size());
29: Profile profile = (Profile) profiles.iterator().next();
30: Profile.instance().setNamespace(profile.getNamespace());
31: }
32:
33: public void testGet() {
34: assertEquals("Entity", Profile.instance().get("ENTITY"));
35: assertEquals("@andromda.tagged.value", Profile.instance().get(
36: "ANDROMDA_TAGGED_VALUE"));
37: assertEquals("datatype::String", Profile.instance().get(
38: "STRING_TYPE"));
39: }
40:
41: public void testOverride() {
42: Namespace namespace = new Namespace();
43: namespace.setName(Namespaces.DEFAULT);
44: Namespaces.instance().addNamespace(namespace);
45: URL profileOverrideResource = ProfileTest.class
46: .getResource("/META-INF/profile/andromda-profile-override.xml");
47: assertNotNull(profileOverrideResource);
48: Property property = new Property();
49: property.setName(NamespaceProperties.PROFILE_MAPPINGS_URI);
50: property.setValue(profileOverrideResource.toString());
51: namespace.addProperty(property);
52: Profile.instance().refresh();
53: assertEquals("New Entity", Profile.instance().get("ENTITY"));
54: assertEquals("TestFromOverride", Profile.instance().get(
55: "TEST_FROM_OVERRIDE"));
56: // - shutdown the profile instance so that we don't affect other tests.
57: Profile.instance().shutdown();
58: }
59: }
|