KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > gbean > AbstractNameTest


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

17 package org.apache.geronimo.gbean;
18
19 import java.util.Map JavaDoc;
20 import java.util.LinkedHashMap JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.net.URI JavaDoc;
23
24 import javax.management.ObjectName JavaDoc;
25
26 import junit.framework.TestCase;
27 import org.apache.geronimo.kernel.repository.Artifact;
28 import org.apache.geronimo.kernel.repository.Version;
29
30 /**
31  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
32  */

33 public class AbstractNameTest extends TestCase {
34     public void testSimple() throws Exception JavaDoc {
35         Artifact artifact = new Artifact("groupId", "artifactId", "version", "type");
36
37         Map JavaDoc nameMap = new LinkedHashMap JavaDoc();
38         nameMap.put("a", "aaa");
39         nameMap.put("b", "bbb");
40         nameMap.put("c", "ccc");
41
42         AbstractName abstractName = new AbstractName(artifact, nameMap, new ObjectName JavaDoc("test:nothing=true"));
43         URI JavaDoc uri = abstractName.toURI();
44         assertEquals(abstractName, new AbstractName(uri));
45     }
46
47     public void testMinimalArtifact() throws Exception JavaDoc {
48         Artifact artifact = new Artifact(null, "artifactId", (Version)null, null);
49
50         Map JavaDoc nameMap = new LinkedHashMap JavaDoc();
51         nameMap.put("a", "aaa");
52         nameMap.put("b", "bbb");
53         nameMap.put("c", "ccc");
54
55         AbstractName abstractName = new AbstractName(artifact, nameMap, new ObjectName JavaDoc("test:nothing=true"));
56         URI JavaDoc uri = abstractName.toURI();
57         assertEquals(abstractName, new AbstractName(uri));
58     }
59
60     public void testCreateURI() throws Exception JavaDoc {
61         Artifact artifact = new Artifact("groupId", "artifactId", "version", "type");
62
63         URI JavaDoc uri = new URI JavaDoc(null, null, artifact.toString(), "a=aaa", null);
64
65         AbstractName abstractName = new AbstractName(artifact,
66                 Collections.singletonMap("a", "aaa"),
67                 new ObjectName JavaDoc("test:nothing=true"));
68         assertEquals(abstractName, new AbstractName(uri));
69     }
70
71     public void testEmptyName() throws Exception JavaDoc {
72         Artifact artifact = new Artifact("groupId", "artifactId", "version", "type");
73
74         URI JavaDoc uri = new URI JavaDoc(null, null, artifact.toString(), "", null);
75         try {
76             new AbstractName(uri);
77             fail("expected IllegalArgumentException");
78         } catch (IllegalArgumentException JavaDoc e) {
79             // expected
80
}
81     }
82
83     public void testNoName() throws Exception JavaDoc {
84         Artifact artifact = new Artifact("groupId", "artifactId", "version", "type");
85
86         URI JavaDoc uri = new URI JavaDoc(null, null, artifact.toString(), null, null);
87         try {
88             new AbstractName(uri);
89             fail("expected IllegalArgumentException");
90         } catch (IllegalArgumentException JavaDoc e) {
91             // expected
92
}
93     }
94
95     public void testEmptyArtifact() throws Exception JavaDoc {
96         URI JavaDoc uri = new URI JavaDoc(null, null, "", "a=aaa", null);
97         try {
98             new AbstractName(uri);
99             fail("expected IllegalArgumentException");
100         } catch (IllegalArgumentException JavaDoc e) {
101             // expected
102
}
103     }
104
105     public void testInvalidArtifact() throws Exception JavaDoc {
106         URI JavaDoc uri = new URI JavaDoc(null, null, "foo", "a=aaa", null);
107         try {
108             new AbstractName(uri);
109             fail("expected IllegalArgumentException");
110         } catch (IllegalArgumentException JavaDoc e) {
111             // expected
112
}
113
114         uri = new URI JavaDoc(null, null, "foo/", "a=aaa", null);
115         try {
116             new AbstractName(uri);
117             fail("expected IllegalArgumentException");
118         } catch (IllegalArgumentException JavaDoc e) {
119             // expected
120
}
121
122         uri = new URI JavaDoc(null, null, "/foo/", "a=aaa", null);
123         try {
124             new AbstractName(uri);
125             fail("expected IllegalArgumentException");
126         } catch (IllegalArgumentException JavaDoc e) {
127             // expected
128
}
129
130         uri = new URI JavaDoc(null, null, "foo////", "a=aaa", null);
131         try {
132             new AbstractName(uri);
133             fail("expected IllegalArgumentException");
134         } catch (IllegalArgumentException JavaDoc e) {
135             // expected
136
}
137     }
138
139     public void testNoArtifact() throws Exception JavaDoc {
140         URI JavaDoc uri = new URI JavaDoc(null, null, null, "a=aaa", null);
141         try {
142             new AbstractName(uri);
143             fail("expected IllegalArgumentException");
144         } catch (IllegalArgumentException JavaDoc e) {
145             // expected
146
}
147     }
148 }
149
150
Popular Tags