1   // Copyright 2006, by the California Institute of 
2   // Technology. ALL RIGHTS RESERVED. United States Government 
3   // Sponsorship acknowledged. Any commercial use must be negotiated with 
4   // the Office of Technology Transfer at the California Institute of 
5   // Technology.
6   //
7   // This software may be subject to U.S. export control laws. By 
8   // accepting this software, the user agrees to comply with all 
9   // applicable U.S. export laws and regulations. User has the 
10  // responsibility to obtain export licenses, or other export authority 
11  // as may be required before exporting such information to foreign 
12  // countries or providing access to foreign persons.
13  //
14  // $Id: DictionaryTest.java 1705 2006-08-01 15:40:18Z pramirez $ 
15  //
16  
17  package gov.nasa.pds.tools.dict;
18  
19  import gov.nasa.pds.tools.dict.Dictionary;
20  import gov.nasa.pds.tools.dict.ElementDefinition;
21  import gov.nasa.pds.tools.dict.GroupDefinition;
22  import gov.nasa.pds.tools.dict.ObjectDefinition;
23  import junit.framework.*;
24  
25  /***
26   * JUnit test for dictionary class. The dictionary class represents a PDS
27   * Compliant data dictionary.
28   * @author pramirez
29   * @version $Revision: 1705 $
30   * 
31   */
32  public class DictionaryTest extends TestCase {
33      
34      public DictionaryTest(String name) {
35          super(name);
36      }
37      
38      public void testNoArgsCtor() {
39          Dictionary dictionary = new Dictionary();
40          assertEquals("", dictionary.getInformation());
41          assertEquals(0, dictionary.getDefinitions().size());
42      }
43  
44      public void testSetters() {
45          Dictionary dictionary = new Dictionary();
46          dictionary.setInformation("INFORMATION");
47          assertEquals("INFORMATION", dictionary.getInformation());
48      }
49      
50      public void testObjectMethods() {
51          Dictionary dictionary = new Dictionary();
52          ElementDefinition element = new ElementDefinition("TARGET_NAME");
53          GroupDefinition group = new GroupDefinition("PARAMETERS");
54          ObjectDefinition object = new ObjectDefinition("TABLE");
55          
56          dictionary.addDefinition(element);
57          dictionary.addDefinition(group);
58          dictionary.addDefinition(object);
59          
60          assertEquals(3, dictionary.getDefinitions().size());  
61          assertEquals(element, dictionary.getDefinition("TARGET_NAME"));
62          assertEquals(element, dictionary.getElementDefinition("TARGET_NAME"));  
63          assertEquals(group, dictionary.getDefinition("PARAMETERS"));
64          assertEquals(group, dictionary.getGroupDefinition("PARAMETERS"));
65          assertEquals(object, dictionary.getDefinition("TABLE"));
66          assertEquals(object, dictionary.getObjectDefinition("TABLE"));
67          
68          Dictionary mergeDictionary = new Dictionary();
69          ElementDefinition dataset = new ElementDefinition("DATA_SET_NAME");
70          mergeDictionary.addDefinition(dataset);
71          
72          dictionary.merge(mergeDictionary);
73          assertEquals(dictionary.getDefinition(dataset.getIdentifier()),dataset);
74          
75          assertTrue(dictionary.containsDefinition(dataset.getIdentifier()));
76          assertTrue(dictionary.containsElementDefinition(element.getIdentifier()));
77          assertTrue(dictionary.containsGroupDefinition(group.getIdentifier()));
78          assertTrue(dictionary.containsObjectDefinition(object.getIdentifier()));
79          
80          dictionary.addDefinition(new ObjectDefinition("IMAGE"));
81          dictionary.addDefinition(new ElementDefinition("ABCD_IMAGE"));
82          assertEquals("IMAGE", dictionary.findObjectClassDefinition("XYZ_IMAGE").getIdentifier());
83      }
84  }