1 17 package org.apache.geronimo.kernel.repository; 18 19 import java.util.Set ; 20 import java.util.HashSet ; 21 import java.util.SortedSet ; 22 import java.util.Collections ; 23 24 import junit.framework.TestCase; 25 26 29 public class ArtifactManagerTest extends TestCase { 30 public void testGetLoadeArtifacts() { 31 DefaultArtifactManager artifactManager = new DefaultArtifactManager(); 32 33 Artifact loader1 = new Artifact("loaderGroup", "loaderArtifact1", "1", "car"); 34 Set artifacts1 = new HashSet (); 35 Artifact private1 = new Artifact("private1", "artifact", "1", "jar"); 36 artifacts1.add(private1); 37 artifactManager.loadArtifacts(loader1, artifacts1); 38 39 Artifact loader2 = new Artifact("loaderGroup", "loaderArtifact2", "1", "car"); 40 Set artifacts2 = new HashSet (); 41 Artifact private2 = new Artifact("private2", "artifact", "1", "jar"); 42 artifacts2.add(private2); 43 artifactManager.loadArtifacts(loader2, artifacts2); 44 45 SortedSet loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("private1", "artifact", (Version)null, "jar")); 46 assertEquals(Collections.singleton(private1), loadedArtifacts); 47 48 loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("loaderGroup", "loaderArtifact1", (Version)null, "car")); 49 assertEquals(Collections.singleton(loader1), loadedArtifacts); 50 51 loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("private2", "artifact", (Version)null, "jar")); 52 assertEquals(Collections.singleton(private2), loadedArtifacts); 53 54 loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("loaderGroup", "loaderArtifact2", (Version)null, "car")); 55 assertEquals(Collections.singleton(loader2), loadedArtifacts); 56 57 artifactManager.unloadAllArtifacts(loader1); 58 59 loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("private1", "artifact", (Version)null, "jar")); 60 assertEquals(Collections.EMPTY_SET, loadedArtifacts); 61 62 loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("loaderGroup", "loaderArtifact1", (Version)null, "car")); 63 assertEquals(Collections.EMPTY_SET, loadedArtifacts); 64 65 loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("private2", "artifact", (Version)null, "jar")); 66 assertEquals(Collections.singleton(private2), loadedArtifacts); 67 68 loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("loaderGroup", "loaderArtifact2", (Version)null, "car")); 69 assertEquals(Collections.singleton(loader2), loadedArtifacts); 70 } 71 72 public void testMultipleVersions() { 73 DefaultArtifactManager artifactManager = new DefaultArtifactManager(); 74 75 Artifact version1 = new Artifact("version", "version", "1", "jar"); 76 Artifact version2 = new Artifact("version", "version", "2", "jar"); 77 78 Artifact loader1 = new Artifact("loaderGroup", "loaderArtifact1", "1", "car"); 79 artifactManager.loadArtifacts(loader1, Collections.singleton(version1)); 80 81 Artifact loader2 = new Artifact("loaderGroup", "loaderArtifact2", "1", "car"); 82 artifactManager.loadArtifacts(loader2, Collections.singleton(version2)); 83 84 85 Set artifacts = new HashSet (); 86 artifacts.add(version1); 87 artifacts.add(version2); 88 89 SortedSet loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("version", "version", (Version)null, "jar")); 90 assertEquals(artifacts, loadedArtifacts); 91 92 artifactManager.unloadAllArtifacts(loader1); 93 loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("version", "version", (Version)null, "jar")); 94 assertEquals(Collections.singleton(version2), loadedArtifacts); 95 } 96 97 public void testDupe() { 98 DefaultArtifactManager artifactManager = new DefaultArtifactManager(); 99 100 Artifact artifact = new Artifact("dupe", "dupe", "1", "jar"); 101 102 Artifact loader1 = new Artifact("loaderGroup", "loaderArtifact1", "1", "car"); 103 artifactManager.loadArtifacts(loader1, Collections.singleton(artifact)); 104 105 Artifact loader2 = new Artifact("loaderGroup", "loaderArtifact2", "1", "car"); 106 artifactManager.loadArtifacts(loader2, Collections.singleton(artifact)); 107 108 SortedSet loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("dupe", "dupe", (Version)null, "jar")); 109 assertEquals(Collections.singleton(artifact), loadedArtifacts); 110 111 artifactManager.unloadAllArtifacts(loader1); 112 113 loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("dupe", "dupe", (Version)null, "jar")); 114 assertEquals(Collections.singleton(artifact), loadedArtifacts); 115 } 116 } 117 | Popular Tags |