1   package org.andromda.core.translation.library;
2   
3   import java.util.Collection;
4   import java.util.Map;
5   
6   import junit.framework.TestCase;
7   
8   import org.andromda.core.common.ComponentContainer;
9   import org.andromda.core.common.TemplateObject;
10  import org.andromda.core.namespace.NamespaceComponents;
11  
12  
13  /***
14   * Implements the JUnit test suit for
15   * <code>org.andromda.core.translation.library.Library</code>
16   *
17   * @see org.andromda.core.library.LibraryTest
18   * @author Chad Brandon
19   */
20  public class LibraryTest
21      extends TestCase
22  {
23      private Library library;
24  
25      /***
26       * Constructor for LibraryTest.
27       *
28       * @param name
29       */
30      public LibraryTest(String name)
31      {
32          super(name);
33      }
34  
35      /***
36       * @see TestCase#setUp()
37       */
38      protected void setUp()
39          throws Exception
40      {
41          NamespaceComponents.instance().discover();
42          Collection librarys = ComponentContainer.instance().findComponentsOfType(Library.class);
43          assertNotNull(librarys);
44          this.library = (Library)librarys.iterator().next();
45          this.library.initialize();
46      }
47  
48      /***
49       * @see TestCase#tearDown()
50       */
51      protected void tearDown()
52          throws Exception
53      {
54          this.library = null;
55      }
56  
57      public void testGetLibraryTranslations()
58      {
59          Map libraryTranslations = this.library.getLibraryTranslations();
60          assertNotNull(libraryTranslations);
61          assertEquals(
62              2,
63              libraryTranslations.size());
64          LibraryTranslation translationOne = (LibraryTranslation)libraryTranslations.get("TranslationOne");
65          assertNotNull(translationOne);
66          assertNotNull(translationOne.getTemplate());
67          assertEquals(
68              "translations/test/TranslationOne.vsl",
69              translationOne.getTemplate());
70          assertEquals(
71              "element",
72              translationOne.getVariable());
73          assertNotNull(translationOne.getTranslator());
74          assertEquals(
75              "org.andromda.core.translation.library.TestTranslator",
76              translationOne.getTranslator().getClass().getName());
77          LibraryTranslation translationTwo = (LibraryTranslation)libraryTranslations.get("TranslationTwo");
78          assertNotNull(translationTwo);
79          assertNull(translationTwo.getTemplate());
80          assertNull(translationTwo.getVariable());
81          assertNotNull(translationTwo.getTranslator());
82          assertEquals(
83              "org.andromda.core.translation.library.TestSubTranslator",
84              translationTwo.getTranslator().getClass().getName());
85      }
86  
87      public void testGetPropertyReferences()
88      {
89          String[] propertyRefs = this.library.getPropertyReferences();
90          assertNotNull(propertyRefs);
91          assertEquals(
92              2,
93              propertyRefs.length);
94  
95          String propertyReferenceOne = "propertyReferenceOne";
96          String propertyReferenceTwo = "propertyReferenceTwo";
97  
98          assertEquals(propertyReferenceOne, propertyRefs[0]);
99          assertEquals(propertyReferenceTwo, propertyRefs[1]);
100     }
101 
102     public void testGetTemplateObjects()
103     {
104         final Collection templateObjects = this.library.getTemplateObjects();
105         assertNotNull(templateObjects);
106         assertEquals(
107             1,
108             templateObjects.size());
109         TemplateObject templateObject = ((TemplateObject)templateObjects.iterator().next());
110         assertEquals("utils", templateObject.getName());
111         assertEquals("test",templateObject.getNamespace());
112         LibraryTemplateObject object = (LibraryTemplateObject)templateObject.getObject();
113         assertNotNull(object);
114         assertEquals("3", object.getDefinitionOne());
115     }
116 }