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