Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/acs/damsel/srvr/schema/TestMetaDataTag.java


1   package org.acs.damsel.srvr.schema;
2   
3   import junit.framework.*;
4   import org.apache.log4j.*;
5   
6   public class TestMetaDataTag extends TestCase {
7     private MetaDataTag metaDataTag = null;
8     private static Logger log = Logger.getLogger(TestMetaDataTag.class);
9   
10    public TestMetaDataTag(String name) {
11      super(name);
12      BasicConfigurator.resetConfiguration();
13      BasicConfigurator.configure();
14    }
15  
16    protected void setUp() throws Exception {
17      super.setUp();
18      metaDataTag = new MetaDataTag();
19    }
20  
21    protected void tearDown() throws Exception {
22      metaDataTag = null;
23      super.tearDown();
24    }
25  
26    /* Test adding vocabulary words to the MetaDataTag */
27    public void testAddVocabulary() {
28      String foo = "foo";
29      String bar = "bar";
30      String baz = "baz";
31      try {
32        try {
33          metaDataTag.addVocabularyWord(foo);
34        }
35        catch (ControlledVocabularyException cvex) {
36          log.debug("Expected ControlledVocabularyException caught");
37        }
38        metaDataTag.setControlledVocabulary(true);
39        metaDataTag.addVocabularyWord(foo);
40        if(!metaDataTag.isInVocabulary(foo)) {
41          this.fail("Word foo not found in vocabulary");
42        }
43        metaDataTag.addVocabularyWord(bar);
44        if(!metaDataTag.isInVocabulary(bar)) {
45          this.fail("Word bar not found in vocabulary");
46        }
47        metaDataTag.addVocabularyWord(baz);
48        if(!metaDataTag.isInVocabulary(baz)) {
49          this.fail("Word baz not found in vocabulary");
50        }
51        try {
52          metaDataTag.addVocabularyWord(baz);
53        }
54        catch (ControlledVocabularyException ex) {
55          log.debug("Expected ControlledVocabularyException caught");
56        }
57        if(!metaDataTag.isInVocabulary(baz)) {
58          this.fail("Word baz not found in vocabulary after attempted double add");
59        }
60  
61      }
62      catch (Exception ex1) {
63        log.error("Unexpected exception: " + ex1.getMessage());
64      }
65    }
66  
67    /* Test removing vocabulary words from the MetaDataTag */
68    public void testRemoveVocabulary() {
69      metaDataTag.setControlledVocabulary(true);
70      try {
71        metaDataTag.addVocabularyWord("foo");
72        metaDataTag.addVocabularyWord("bar");
73        metaDataTag.addVocabularyWord("baz");
74      }
75      catch (ControlledVocabularyException ex) {
76        log.error("Unexpected exception: " + ex.getMessage());
77      }
78      try {
79        metaDataTag.removeVocabularyWord("foo");
80        if (metaDataTag.isInVocabulary("foo")) {
81          this.fail("Word foo should not be in vocabulary after remove.");
82        }
83        metaDataTag.removeVocabularyWord("bar");
84        if (metaDataTag.isInVocabulary("bar")) {
85          this.fail("Word bar should not be in vocabulary after remove.");
86        }
87  
88        metaDataTag.removeVocabularyWord("baz");
89        if (metaDataTag.isInVocabulary("baz")) {
90          this.fail("Word baz should not be in vocabulary after remove.");
91        }
92      }
93      catch (ControlledVocabularyException ex2) {
94        this.fail("Caught unexpected ControlledVocabulary exception.");
95      }
96      try {
97        metaDataTag.removeVocabularyWord("baz");
98      }
99      catch (ControlledVocabularyException ex1) {
100       log.debug(
101           "Caught expected ControlledVocabularyException after double remove");
102     }
103   }
104 }