felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1718672 - in /felix/trunk/bundlerepository: pom.xml src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
Date Tue, 08 Dec 2015 18:45:12 GMT
Author: davidb
Date: Tue Dec  8 18:45:11 2015
New Revision: 1718672

URL: http://svn.apache.org/viewvc?rev=1718672&view=rev
Log:
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

Modified:
    felix/trunk/bundlerepository/pom.xml
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
    felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java

Modified: felix/trunk/bundlerepository/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/pom.xml?rev=1718672&r1=1718671&r2=1718672&view=diff
==============================================================================
--- felix/trunk/bundlerepository/pom.xml (original)
+++ felix/trunk/bundlerepository/pom.xml Tue Dec  8 18:45:11 2015
@@ -91,7 +91,7 @@
     <dependency>
         <groupId>org.easymock</groupId>
         <artifactId>easymock</artifactId>
-        <version>2.4</version>
+        <version>3.4</version>
     </dependency>
   </dependencies>
   <build>

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java?rev=1718672&r1=1718671&r2=1718672&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
Tue Dec  8 18:45:11 2015
@@ -123,7 +123,7 @@ public class ResolverImpl implements Res
         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 @@ public class ResolverImpl implements Res
         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;
             }

Modified: felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java?rev=1718672&r1=1718671&r2=1718672&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
(original)
+++ felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
Tue Dec  8 18:45:11 2015
@@ -21,17 +21,14 @@ package org.apache.felix.bundlerepositor
 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 class ResolverImplTest extends Te
     }
 
     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;
         }



Mime
View raw message