001package org.andromda.core.profile; 002 003import java.net.URL; 004import java.util.Collection; 005import junit.framework.TestCase; 006import org.andromda.core.common.ComponentContainer; 007import org.andromda.core.configuration.Namespace; 008import org.andromda.core.configuration.NamespaceProperties; 009import org.andromda.core.configuration.Namespaces; 010import org.andromda.core.configuration.Property; 011import org.andromda.core.namespace.NamespaceComponents; 012 013/** 014 * Tests {@link org.andromda.core.profile.Profile} 015 * @author Chad Brandon 016 */ 017public class ProfileTest 018 extends TestCase 019{ 020 /** 021 * @see TestCase#setUp() 022 */ 023 protected void setUp() 024 throws Exception 025 { 026 NamespaceComponents.instance().discover(); 027 Collection<Profile> profiles = ComponentContainer.instance().findComponentsOfType(Profile.class); 028 assertNotNull(profiles); 029 assertEquals( 030 1, 031 profiles.size()); 032 Profile profile = profiles.iterator().next(); 033 Profile.instance().setNamespace(profile.getNamespace()); 034 } 035 036 /** 037 * 038 */ 039 public void testGet() 040 { 041 assertEquals( 042 "Entity", 043 Profile.instance().get("ENTITY")); 044 assertEquals( 045 "andromda_tagged_value", 046 Profile.instance().get("ANDROMDA_TAGGED_VALUE")); 047 assertEquals( 048 "datatype::String", 049 Profile.instance().get("STRING_TYPE")); 050 } 051 052 /** 053 * 054 */ 055 public void testOverride() 056 { 057 Namespace namespace = new Namespace(); 058 namespace.setName(Namespaces.DEFAULT); 059 Namespaces.instance().addNamespace(namespace); 060 URL profileOverrideResource = ProfileTest.class.getResource("/META-INF/profile/andromda-profile-override.xml"); 061 assertNotNull(profileOverrideResource); 062 Property property = new Property(); 063 property.setName(NamespaceProperties.PROFILE_MAPPINGS_URI); 064 property.setValue(profileOverrideResource.toString()); 065 namespace.addProperty(property); 066 Profile.instance().refresh(); 067 assertEquals( 068 "New Entity", 069 Profile.instance().get("ENTITY")); 070 assertEquals( 071 "TestFromOverride", 072 Profile.instance().get("TEST_FROM_OVERRIDE")); 073 // - shutdown the profile instance so that we don't affect other tests. 074 Profile.instance().shutdown(); 075 } 076}