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

Added test for deploy method
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@1718671 13f79535-47bb-0310-9956-ffa450edef68
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 3ec9288..8fae531 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
@@ -18,8 +18,10 @@
  */
 package org.apache.felix.bundlerepository.impl;
 
+import java.io.InputStream;
 import java.net.URL;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.Hashtable;
 
 import junit.framework.TestCase;
@@ -34,10 +36,7 @@
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
 import org.easymock.internal.matchers.Captures;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.ServiceListener;
+import org.osgi.framework.*;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.resource.Capability;
 
@@ -134,6 +133,29 @@
 
     }
 
+    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);
+        EasyMock.expect(resource.getSymbolicName()).andReturn("com.test.bundleA").anyTimes();
+        EasyMock.expect(resource.getRequirements()).andReturn(null).anyTimes();
+        EasyMock.expect(resource.getURI()).andReturn("http://test.com").anyTimes();
+        EasyMock.replay(resource);
+
+        resolver.add(resource);
+
+        boolean exceptionThrown = false;
+        try {
+            resolver.resolve();
+        } catch (Exception e) {
+            exceptionThrown = true;
+        }
+        assertFalse(exceptionThrown);
+    }
+
     public static void main(String[] args) throws Exception
     {
         new ResolverImplTest().testReferral1();
@@ -150,7 +172,10 @@
                     .andReturn(getClass().getResource("/referred.xml").toExternalForm());
         EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
         EasyMock.expect(bundleContext.getBundle(0)).andReturn(systemBundle);
-        EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable());
+        EasyMock.expect(bundleContext.installBundle((String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(systemBundle);
+        EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable()).anyTimes();
+        systemBundle.start();
+        EasyMock.expectLastCall().anyTimes();
         EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
         EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
         EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);