KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > kernel > repository > ArtifactManagerTest


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.kernel.repository;
18
19 import java.util.Set JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.SortedSet JavaDoc;
22 import java.util.Collections JavaDoc;
23
24 import junit.framework.TestCase;
25
26 /**
27  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
28  */

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 JavaDoc artifacts1 = new HashSet JavaDoc();
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 JavaDoc artifacts2 = new HashSet JavaDoc();
41         Artifact private2 = new Artifact("private2", "artifact", "1", "jar");
42         artifacts2.add(private2);
43         artifactManager.loadArtifacts(loader2, artifacts2);
44
45         SortedSet JavaDoc 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 JavaDoc artifacts = new HashSet JavaDoc();
86         artifacts.add(version1);
87         artifacts.add(version2);
88
89         SortedSet JavaDoc 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 JavaDoc 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