001: package org.andromda.core.translation.library;
002:
003: import java.util.Collection;
004: import java.util.Map;
005:
006: import junit.framework.TestCase;
007:
008: import org.andromda.core.common.ComponentContainer;
009: import org.andromda.core.common.TemplateObject;
010: import org.andromda.core.namespace.NamespaceComponents;
011:
012: /**
013: * Implements the JUnit test suit for
014: * <code>org.andromda.core.translation.library.Library</code>
015: *
016: * @see org.andromda.core.library.LibraryTest
017: * @author Chad Brandon
018: */
019: public class LibraryTest extends TestCase {
020: private Library library;
021:
022: /**
023: * Constructor for LibraryTest.
024: *
025: * @param name
026: */
027: public LibraryTest(String name) {
028: super (name);
029: }
030:
031: /**
032: * @see TestCase#setUp()
033: */
034: protected void setUp() throws Exception {
035: NamespaceComponents.instance().discover();
036: Collection librarys = ComponentContainer.instance()
037: .findComponentsOfType(Library.class);
038: assertNotNull(librarys);
039: this .library = (Library) librarys.iterator().next();
040: this .library.initialize();
041: }
042:
043: /**
044: * @see TestCase#tearDown()
045: */
046: protected void tearDown() throws Exception {
047: this .library = null;
048: }
049:
050: public void testGetLibraryTranslations() {
051: Map libraryTranslations = this .library.getLibraryTranslations();
052: assertNotNull(libraryTranslations);
053: assertEquals(2, libraryTranslations.size());
054: LibraryTranslation translationOne = (LibraryTranslation) libraryTranslations
055: .get("TranslationOne");
056: assertNotNull(translationOne);
057: assertNotNull(translationOne.getTemplate());
058: assertEquals("translations/test/TranslationOne.vsl",
059: translationOne.getTemplate());
060: assertEquals("element", translationOne.getVariable());
061: assertNotNull(translationOne.getTranslator());
062: assertEquals(
063: "org.andromda.core.translation.library.TestTranslator",
064: translationOne.getTranslator().getClass().getName());
065: LibraryTranslation translationTwo = (LibraryTranslation) libraryTranslations
066: .get("TranslationTwo");
067: assertNotNull(translationTwo);
068: assertNull(translationTwo.getTemplate());
069: assertNull(translationTwo.getVariable());
070: assertNotNull(translationTwo.getTranslator());
071: assertEquals(
072: "org.andromda.core.translation.library.TestSubTranslator",
073: translationTwo.getTranslator().getClass().getName());
074: }
075:
076: public void testGetPropertyReferences() {
077: String[] propertyRefs = this .library.getPropertyReferences();
078: assertNotNull(propertyRefs);
079: assertEquals(2, propertyRefs.length);
080:
081: String propertyReferenceOne = "propertyReferenceOne";
082: String propertyReferenceTwo = "propertyReferenceTwo";
083:
084: assertEquals(propertyReferenceOne, propertyRefs[0]);
085: assertEquals(propertyReferenceTwo, propertyRefs[1]);
086: }
087:
088: public void testGetTemplateObjects() {
089: final Collection templateObjects = this .library
090: .getTemplateObjects();
091: assertNotNull(templateObjects);
092: assertEquals(1, templateObjects.size());
093: TemplateObject templateObject = ((TemplateObject) templateObjects
094: .iterator().next());
095: assertEquals("utils", templateObject.getName());
096: assertEquals("test", templateObject.getNamespace());
097: LibraryTemplateObject object = (LibraryTemplateObject) templateObject
098: .getObject();
099: assertNotNull(object);
100: assertEquals("3", object.getDefinitionOne());
101: }
102: }
|