001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.gbean;
017:
018: import java.util.Map;
019: import java.util.LinkedHashMap;
020: import java.util.Collections;
021: import java.net.URI;
022:
023: import javax.management.ObjectName;
024:
025: import junit.framework.TestCase;
026: import org.apache.geronimo.kernel.repository.Artifact;
027: import org.apache.geronimo.kernel.repository.Version;
028:
029: /**
030: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
031: */
032: public class AbstractNameTest extends TestCase {
033: public void testSimple() throws Exception {
034: Artifact artifact = new Artifact("groupId", "artifactId",
035: "version", "type");
036:
037: Map nameMap = new LinkedHashMap();
038: nameMap.put("a", "aaa");
039: nameMap.put("b", "bbb");
040: nameMap.put("c", "ccc");
041:
042: AbstractName abstractName = new AbstractName(artifact, nameMap,
043: new ObjectName("test:nothing=true"));
044: URI uri = abstractName.toURI();
045: assertEquals(abstractName, new AbstractName(uri));
046: }
047:
048: public void testMinimalArtifact() throws Exception {
049: Artifact artifact = new Artifact(null, "artifactId",
050: (Version) null, null);
051:
052: Map nameMap = new LinkedHashMap();
053: nameMap.put("a", "aaa");
054: nameMap.put("b", "bbb");
055: nameMap.put("c", "ccc");
056:
057: AbstractName abstractName = new AbstractName(artifact, nameMap,
058: new ObjectName("test:nothing=true"));
059: URI uri = abstractName.toURI();
060: assertEquals(abstractName, new AbstractName(uri));
061: }
062:
063: public void testCreateURI() throws Exception {
064: Artifact artifact = new Artifact("groupId", "artifactId",
065: "version", "type");
066:
067: URI uri = new URI(null, null, artifact.toString(), "a=aaa",
068: null);
069:
070: AbstractName abstractName = new AbstractName(artifact,
071: Collections.singletonMap("a", "aaa"), new ObjectName(
072: "test:nothing=true"));
073: assertEquals(abstractName, new AbstractName(uri));
074: }
075:
076: public void testEmptyName() throws Exception {
077: Artifact artifact = new Artifact("groupId", "artifactId",
078: "version", "type");
079:
080: URI uri = new URI(null, null, artifact.toString(), "", null);
081: try {
082: new AbstractName(uri);
083: fail("expected IllegalArgumentException");
084: } catch (IllegalArgumentException e) {
085: // expected
086: }
087: }
088:
089: public void testNoName() throws Exception {
090: Artifact artifact = new Artifact("groupId", "artifactId",
091: "version", "type");
092:
093: URI uri = new URI(null, null, artifact.toString(), null, null);
094: try {
095: new AbstractName(uri);
096: fail("expected IllegalArgumentException");
097: } catch (IllegalArgumentException e) {
098: // expected
099: }
100: }
101:
102: public void testEmptyArtifact() throws Exception {
103: URI uri = new URI(null, null, "", "a=aaa", null);
104: try {
105: new AbstractName(uri);
106: fail("expected IllegalArgumentException");
107: } catch (IllegalArgumentException e) {
108: // expected
109: }
110: }
111:
112: public void testInvalidArtifact() throws Exception {
113: URI uri = new URI(null, null, "foo", "a=aaa", null);
114: try {
115: new AbstractName(uri);
116: fail("expected IllegalArgumentException");
117: } catch (IllegalArgumentException e) {
118: // expected
119: }
120:
121: uri = new URI(null, null, "foo/", "a=aaa", null);
122: try {
123: new AbstractName(uri);
124: fail("expected IllegalArgumentException");
125: } catch (IllegalArgumentException e) {
126: // expected
127: }
128:
129: uri = new URI(null, null, "/foo/", "a=aaa", null);
130: try {
131: new AbstractName(uri);
132: fail("expected IllegalArgumentException");
133: } catch (IllegalArgumentException e) {
134: // expected
135: }
136:
137: uri = new URI(null, null, "foo////", "a=aaa", null);
138: try {
139: new AbstractName(uri);
140: fail("expected IllegalArgumentException");
141: } catch (IllegalArgumentException e) {
142: // expected
143: }
144: }
145:
146: public void testNoArtifact() throws Exception {
147: URI uri = new URI(null, null, null, "a=aaa", null);
148: try {
149: new AbstractName(uri);
150: fail("expected IllegalArgumentException");
151: } catch (IllegalArgumentException e) {
152: // expected
153: }
154: }
155: }
|