FELIX-5112 ClassCastException when deploying an OBR Resource already present in the runtime

Updated test to return local resource.
Committed on behalf of @skahmann with many thanks. Contributed via https://github.com/apache/felix/pull/44


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1718672 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/pom.xml b/bundlerepository/pom.xml
index 3158466..0f0a207 100644
--- a/bundlerepository/pom.xml
+++ b/bundlerepository/pom.xml
@@ -91,7 +91,7 @@
     <dependency>
         <groupId>org.easymock</groupId>
         <artifactId>easymock</artifactId>
-        <version>2.4</version>
+        <version>3.4</version>
     </dependency>
   </dependencies>
   <build>
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
index 813f4a3..071c13d 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
@@ -123,7 +123,7 @@
         throw new IllegalStateException("The resources have not been resolved.");
     }
 
-    private LocalResource[] getLocalResources()
+    protected LocalResource[] getLocalResources()
     {
         List<LocalResource> resources = new ArrayList<LocalResource>();
         for (Resource resource : getResources())
@@ -154,8 +154,8 @@
         List<Resource> resources = new ArrayList<Resource>();
         for (int repoIdx = 0; (m_repositories != null) && (repoIdx < m_repositories.length); repoIdx++)
         {
-            boolean isLocal = m_repositories[repoIdx] instanceof LocalRepositoryImpl;
-            boolean isSystem = m_repositories[repoIdx] instanceof SystemRepositoryImpl;
+            boolean isLocal = m_repositories[repoIdx].getURI().equals(Repository.LOCAL);
+            boolean isSystem = m_repositories[repoIdx].getURI().equals(Repository.SYSTEM);
             if (isLocal && (m_resolutionFlags & NO_LOCAL_RESOURCES) != 0) {
                 continue;
             }
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
index 8fae531..5d3e5c2 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
@@ -21,17 +21,14 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Collections;
-import java.util.Dictionary;
 import java.util.Hashtable;
 
 import junit.framework.TestCase;
 
-import org.apache.felix.bundlerepository.Repository;
-import org.apache.felix.bundlerepository.Requirement;
-import org.apache.felix.bundlerepository.Resolver;
-import org.apache.felix.bundlerepository.Resource;
+import org.apache.felix.bundlerepository.*;
 import org.apache.felix.utils.filter.FilterImpl;
 import org.apache.felix.utils.log.Logger;
+
 import org.easymock.Capture;
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
@@ -134,22 +131,39 @@
     }
 
     public void testFindUpdatableLocalResource() throws Exception {
-        RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
-        repoAdmin.addRepository(getClass().getResource("/repo_for_mandatory.xml"));
-
-        Resolver resolver = repoAdmin.resolver();
-
-        Resource resource = EasyMock.createMock(Resource.class);
+        LocalResource resource = EasyMock.createMock(LocalResource.class);
         EasyMock.expect(resource.getSymbolicName()).andReturn("com.test.bundleA").anyTimes();
         EasyMock.expect(resource.getRequirements()).andReturn(null).anyTimes();
+        EasyMock.expect(resource.getCapabilities()).andReturn(null).anyTimes();
         EasyMock.expect(resource.getURI()).andReturn("http://test.com").anyTimes();
-        EasyMock.replay(resource);
+        EasyMock.expect(resource.isLocal()).andReturn(true).anyTimes();
+
+        Repository localRepo = EasyMock.createMock(Repository.class);
+
+        Repository[] localRepos = { localRepo };
+        final LocalResource[] localResources = { resource };
+
+        EasyMock.expect(localRepo.getResources()).andReturn(localResources).anyTimes();
+        EasyMock.expect(localRepo.getURI()).andReturn(Repository.LOCAL).anyTimes();
+        EasyMock.expect(localRepo.getLastModified()).andReturn(System.currentTimeMillis()).anyTimes();
+
+        BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
+
+        EasyMock.replay(resource, localRepo);
+
+        ResolverImpl resolver = new ResolverImpl(bundleContext, localRepos, new Logger(bundleContext)) {
+            @Override
+            public LocalResource[] getLocalResources() {
+                return localResources;
+            }
+        };
 
         resolver.add(resource);
 
         boolean exceptionThrown = false;
         try {
             resolver.resolve();
+            resolver.deploy(Resolver.START);
         } catch (Exception e) {
             exceptionThrown = true;
         }