KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > config > TestUniqueElementAttribute


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package hivemind.test.config;
16
17 import java.util.List JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import org.apache.hivemind.ApplicationRuntimeException;
21 import org.apache.hivemind.Registry;
22 import org.apache.hivemind.xml.XmlTestCase;
23
24 /** Test for checking the uniqueness of element attributes.
25  */

26 public class TestUniqueElementAttribute extends XmlTestCase
27 {
28     /**
29      * Test with unique="true"
30      */

31     public void testUniquenessViolated() throws Exception JavaDoc
32     {
33         Registry r =
34             buildFrameworkRegistry(
35                 new String JavaDoc[] { "UniqueAttributeDefinition.xml", "UniqueAttributeBroken.xml" });
36
37         Map JavaDoc elements = (Map JavaDoc) r.getConfiguration("hivemind.test.parse.MyExtensionPoint");
38
39         try
40         {
41             // This constructs the actual backing list
42
elements.size();
43
44             unreachable();
45         }
46         catch (ApplicationRuntimeException ex)
47         {
48             assertExceptionSubstring(
49                 ex,
50                 "already contained in map");
51         }
52
53     }
54
55     /**
56      * Test with unique="false"
57      */

58     public void testFalseUniqueAttributeConstraint() throws Exception JavaDoc
59     {
60         Registry r =
61             buildFrameworkRegistry(
62                 new String JavaDoc[] { "UniqueAttributeDefinition.xml", "UniqueAttributeBroken.xml" });
63
64         List JavaDoc elements = (List JavaDoc) r.getConfiguration("hivemind.test.parse.MyExtensionPoint2");
65
66         assertEquals(3, elements.size());
67     }
68
69     /**
70      * Test with unique unspecified (defaults to false).
71      */

72     public void testNoUniqueAttributeConstraint() throws Exception JavaDoc
73     {
74         Registry r =
75             buildFrameworkRegistry(
76                 new String JavaDoc[] { "UniqueAttributeDefinition.xml", "UniqueAttributeBroken.xml" });
77
78         List JavaDoc elements = (List JavaDoc) r.getConfiguration("hivemind.test.parse.MyExtensionPoint3");
79
80         assertEquals(3, elements.size());
81
82     }
83
84 }
85
Popular Tags