geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r378738 - in /geronimo/branches/configid/modules/kernel/src: java/org/apache/geronimo/kernel/repository/ test/org/apache/geronimo/kernel/repository/
Date Sat, 18 Feb 2006 16:38:46 GMT
Author: dain
Date: Sat Feb 18 08:38:44 2006
New Revision: 378738

URL: http://svn.apache.org/viewcvs?rev=378738&view=rev
Log:
Added tests for ArtifactResolver

Added:
    geronimo/branches/configid/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java
Modified:
    geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java
    geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
    geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/Environment.java

Modified: geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java?rev=378738&r1=378737&r2=378738&view=diff
==============================================================================
--- geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java
(original)
+++ geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java
Sat Feb 18 08:38:44 2006
@@ -26,4 +26,8 @@
     LinkedHashSet resolve(LinkedHashSet artifacts) throws MissingDependencyException;
 
     LinkedHashSet resolve(Collection parentConfigurations, LinkedHashSet artifacts) throws
MissingDependencyException;
+
+    Artifact resolve(Artifact artifact) throws MissingDependencyException;
+
+    Artifact resolve(Collection parentConfigurations, Artifact artifact) throws MissingDependencyException;
 }

Modified: geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java?rev=378738&r1=378737&r2=378738&view=diff
==============================================================================
--- geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
(original)
+++ geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
Sat Feb 18 08:38:44 2006
@@ -16,7 +16,6 @@
  */
 package org.apache.geronimo.kernel.repository;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -35,6 +34,11 @@
     private final ArtifactManager artifactManager;
     private final Collection repositories;
 
+    public DefaultArtifactResolver(ArtifactManager artifactManager, ListableRepository repository)
{
+        this.artifactManager = artifactManager;
+        this.repositories = Collections.singleton(repository);
+    }
+
     public DefaultArtifactResolver(ArtifactManager artifactManager, Collection repositories)
{
         this.artifactManager = artifactManager;
         this.repositories = repositories;
@@ -49,14 +53,18 @@
         for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) {
             Artifact artifact = (Artifact) iterator.next();
             if (!artifact.isResolved()) {
-                artifact = resolveArtifact(parentConfigurations, artifact);
+                artifact = resolve(parentConfigurations, artifact);
             }
             resolvedArtifacts.add(artifact);
         }
         return resolvedArtifacts;
     }
 
-    private Artifact resolveArtifact(Collection parentConfigurations, Artifact artifact)
throws MissingDependencyException {
+    public Artifact resolve(Artifact artifact) throws MissingDependencyException {
+        return this.resolve(Collections.EMPTY_SET, artifact);
+    }
+
+    public Artifact resolve(Collection parentConfigurations, Artifact artifact) throws MissingDependencyException
{
         if (artifact.getType() == null) {
             throw new IllegalArgumentException("Type not set " + artifact);
         }
@@ -94,7 +102,7 @@
 
         // if we have no existing loaded artifacts grab the highest version from the repository
         if (existingArtifacts.size() == 0) {
-            SortedSet list = (SortedSet) new ArrayList();
+            SortedSet list = new TreeSet();
             for (Iterator iterator = repositories.iterator(); iterator.hasNext();) {
                 ListableRepository repository = (ListableRepository) iterator.next();
                 list.addAll(repository.list(groupId, artifactId, type));

Modified: geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/Environment.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/Environment.java?rev=378738&r1=378737&r2=378738&view=diff
==============================================================================
--- geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/Environment.java
(original)
+++ geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/Environment.java
Sat Feb 18 08:38:44 2006
@@ -77,6 +77,10 @@
         return imports;
     }
 
+    public void addImport(Artifact importArtifact) {
+        this.imports.add(importArtifact);
+    }
+
     public void addImports(Collection imports) {
         this.imports.addAll(imports);
     }
@@ -90,6 +94,10 @@
         return references;
     }
 
+    public void addReference(Artifact reference) {
+        this.references.add(reference);
+    }
+
     public void addReferences(Collection references) {
         this.references.addAll(references);
     }
@@ -103,6 +111,10 @@
         return dependencies;
     }
 
+    public void addDependency(Artifact dependency) {
+        this.dependencies.add(dependency);
+    }
+
     public void addDependencies(Collection dependencies) {
         this.dependencies.addAll(dependencies);
     }
@@ -114,6 +126,10 @@
 
     public LinkedHashSet getIncludes() {
         return includes;
+    }
+
+    public void addInclude(Artifact include) {
+        this.includes.add(include);
     }
 
     public void addIncludes(Collection includes) {

Added: geronimo/branches/configid/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java?rev=378738&view=auto
==============================================================================
--- geronimo/branches/configid/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java
(added)
+++ geronimo/branches/configid/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java
Sat Feb 18 08:38:44 2006
@@ -0,0 +1,131 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.kernel.repository;
+
+import java.io.File;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.Collections;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.ConfigurationModuleType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ArtifactResolverTest extends TestCase {
+    private final Artifact loader = new Artifact("loader", "loader", "1", "car");
+    private final Artifact version1 = new Artifact("version", "version", "1", "jar");
+    private final Artifact version2 = new Artifact("version", "version", "2", "jar");
+    private final Artifact version3 = new Artifact("version", "version", "3", "jar");
+
+    public void testSelectHighestFromRepo() throws Exception {
+        ArtifactManager artifactManager = new DefaultArtifactManager();
+        MockRepository mockRepository = new MockRepository();
+        ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager,
mockRepository);
+
+        Artifact unresolvedArtifact = new Artifact("version", "version", (Version) null,
"jar");
+        Artifact artifact = artifactResolver.resolve(unresolvedArtifact);
+        assertEquals(version3, artifact);
+    }
+
+    public void testAlreadyLoaded() throws Exception {
+        ArtifactManager artifactManager = new DefaultArtifactManager();
+        artifactManager.loadArtifacts(loader, Collections.singleton(version2));
+
+        MockRepository mockRepository = new MockRepository();
+        ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager,
mockRepository);
+
+        Artifact unresolvedArtifact = new Artifact("version", "version", (Version) null,
"jar");
+        Artifact artifact = artifactResolver.resolve(unresolvedArtifact);
+        assertEquals(version2, artifact);
+    }
+
+    public void testMultipleSelected() throws Exception {
+        ArtifactManager artifactManager = new DefaultArtifactManager();
+        Set loaded = new HashSet();
+        loaded.add(version1);
+        loaded.add(version2);
+        artifactManager.loadArtifacts(loader, loaded);
+
+        MockRepository mockRepository = new MockRepository();
+        ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager,
mockRepository);
+
+        Artifact unresolvedArtifact = new Artifact("version", "version", (Version) null,
"jar");
+        Artifact artifact = artifactResolver.resolve(unresolvedArtifact);
+        assertEquals(version2, artifact);
+    }
+
+    public void testParentLoaded() throws Exception {
+        MockRepository mockRepository = new MockRepository();
+
+        ArtifactManager artifactManager = new DefaultArtifactManager();
+        Set loaded = new HashSet();
+        loaded.add(version1);
+        loaded.add(version2);
+        artifactManager.loadArtifacts(loader, loaded);
+
+        ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager,
mockRepository);
+
+        // create parent which uses version1 explicitly
+        Environment environment = new Environment();
+        environment.addDependency(version1);
+        Configuration parent = new Configuration(null,
+                Configuration.getConfigurationObjectName(loader).getCanonicalName(),
+                ConfigurationModuleType.SERVICE,
+                environment,
+                null,
+                null,
+                null,
+                Collections.singleton(mockRepository),
+                null,
+                artifactManager,
+                artifactResolver);
+        LinkedHashSet parents = new LinkedHashSet();
+        parents.add(parent);
+
+        Artifact unresolvedArtifact = new Artifact("version", "version", (Version) null,
"jar");
+        Artifact artifact = artifactResolver.resolve(parents, unresolvedArtifact);
+        assertEquals(version1, artifact);
+    }
+
+    private class MockRepository implements ListableRepository {
+        public SortedSet list() {
+            throw new UnsupportedOperationException();
+        }
+
+        public SortedSet list(String groupId, String artifactId, String type) {
+            TreeSet set = new TreeSet();
+            set.add(version1);
+            set.add(version2);
+            set.add(version3);
+            return set;
+        }
+
+        public boolean contains(Artifact artifact) {
+            return true;
+        }
+
+        public File getLocation(Artifact artifact) {
+            return new File(".");
+        }
+    }
+}



Mime
View raw message