1 17 package org.apache.geronimo.gbean; 18 19 import java.util.Map ; 20 import java.util.LinkedHashMap ; 21 import java.util.Collections ; 22 import java.net.URI ; 23 24 import javax.management.ObjectName ; 25 26 import junit.framework.TestCase; 27 import org.apache.geronimo.kernel.repository.Artifact; 28 import org.apache.geronimo.kernel.repository.Version; 29 30 33 public class AbstractNameTest extends TestCase { 34 public void testSimple() throws Exception { 35 Artifact artifact = new Artifact("groupId", "artifactId", "version", "type"); 36 37 Map nameMap = new LinkedHashMap (); 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 ("test:nothing=true")); 43 URI uri = abstractName.toURI(); 44 assertEquals(abstractName, new AbstractName(uri)); 45 } 46 47 public void testMinimalArtifact() throws Exception { 48 Artifact artifact = new Artifact(null, "artifactId", (Version)null, null); 49 50 Map nameMap = new LinkedHashMap (); 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 ("test:nothing=true")); 56 URI uri = abstractName.toURI(); 57 assertEquals(abstractName, new AbstractName(uri)); 58 } 59 60 public void testCreateURI() throws Exception { 61 Artifact artifact = new Artifact("groupId", "artifactId", "version", "type"); 62 63 URI uri = new URI (null, null, artifact.toString(), "a=aaa", null); 64 65 AbstractName abstractName = new AbstractName(artifact, 66 Collections.singletonMap("a", "aaa"), 67 new ObjectName ("test:nothing=true")); 68 assertEquals(abstractName, new AbstractName(uri)); 69 } 70 71 public void testEmptyName() throws Exception { 72 Artifact artifact = new Artifact("groupId", "artifactId", "version", "type"); 73 74 URI uri = new URI (null, null, artifact.toString(), "", null); 75 try { 76 new AbstractName(uri); 77 fail("expected IllegalArgumentException"); 78 } catch (IllegalArgumentException e) { 79 } 81 } 82 83 public void testNoName() throws Exception { 84 Artifact artifact = new Artifact("groupId", "artifactId", "version", "type"); 85 86 URI uri = new URI (null, null, artifact.toString(), null, null); 87 try { 88 new AbstractName(uri); 89 fail("expected IllegalArgumentException"); 90 } catch (IllegalArgumentException e) { 91 } 93 } 94 95 public void testEmptyArtifact() throws Exception { 96 URI uri = new URI (null, null, "", "a=aaa", null); 97 try { 98 new AbstractName(uri); 99 fail("expected IllegalArgumentException"); 100 } catch (IllegalArgumentException e) { 101 } 103 } 104 105 public void testInvalidArtifact() throws Exception { 106 URI uri = new URI (null, null, "foo", "a=aaa", null); 107 try { 108 new AbstractName(uri); 109 fail("expected IllegalArgumentException"); 110 } catch (IllegalArgumentException e) { 111 } 113 114 uri = new URI (null, null, "foo/", "a=aaa", null); 115 try { 116 new AbstractName(uri); 117 fail("expected IllegalArgumentException"); 118 } catch (IllegalArgumentException e) { 119 } 121 122 uri = new URI (null, null, "/foo/", "a=aaa", null); 123 try { 124 new AbstractName(uri); 125 fail("expected IllegalArgumentException"); 126 } catch (IllegalArgumentException e) { 127 } 129 130 uri = new URI (null, null, "foo////", "a=aaa", null); 131 try { 132 new AbstractName(uri); 133 fail("expected IllegalArgumentException"); 134 } catch (IllegalArgumentException e) { 135 } 137 } 138 139 public void testNoArtifact() throws Exception { 140 URI uri = new URI (null, null, null, "a=aaa", null); 141 try { 142 new AbstractName(uri); 143 fail("expected IllegalArgumentException"); 144 } catch (IllegalArgumentException e) { 145 } 147 } 148 } 149 150 | Popular Tags |