[
https://issues.apache.org/jira/browse/SLING-7466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16352480#comment-16352480
]
ASF GitHub Bot commented on SLING-7466:
---------------------------------------
rombert closed pull request #2: SLING-7466 : adding basic unittest
URL: https://github.com/apache/sling-org-apache-sling-installer-core/pull/2
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pom.xml b/pom.xml
index 0d66181..605ba78 100644
--- a/pom.xml
+++ b/pom.xml
@@ -158,5 +158,11 @@
<version>2.5.1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.13.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/src/test/java/org/apache/sling/installer/core/impl/EntityResourceListTest.java
b/src/test/java/org/apache/sling/installer/core/impl/EntityResourceListTest.java
new file mode 100644
index 0000000..6b389a3
--- /dev/null
+++
b/src/test/java/org/apache/sling/installer/core/impl/EntityResourceListTest.java
@@ -0,0 +1,56 @@
+package org.apache.sling.installer.core.impl;
+
+import org.apache.sling.installer.api.event.InstallationListener;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.internal.matchers.Any;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.osgi.framework.Version;
+
+import static org.junit.Assert.assertEquals;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public class EntityResourceListTest {
+
+ private static final String OLD_URI = "old-uri";
+ private static final String OLD_DIGEST = "old-digest";
+ private static final String NEW_URI = "new-uri";
+ private static final String NEW_DIGEST = "new-digest";
+
+ private static final String MOCK_URL = "mock-url";
+ private static final String RESOURCE_ID = "res-id";
+ private static final Version VERSION = new Version("1.0.0");
+
+ @Mock
+ InstallationListener listener;
+
+ @Test
+ public void testAddExistingResourceWithDifferentDataUriAndDigest() {
+ EntityResourceList erl = new EntityResourceList(RESOURCE_ID, listener);
+ RegisteredResourceImpl r1 = mock(RegisteredResourceImpl.class);
+ when(r1.getURL()).thenReturn(MOCK_URL);
+ when(r1.getVersion()).thenReturn((VERSION));
+ when(r1.getDataURI()).thenReturn(OLD_URI);
+ when(r1.getDigest()).thenReturn(OLD_DIGEST);
+ erl.addOrUpdate(r1);
+ assertEquals(OLD_URI,
((RegisteredResourceImpl)erl.getFirstResource()).getDataURI());
+
+ RegisteredResourceImpl r2 = mock(RegisteredResourceImpl.class);
+ when(r2.getURL()).thenReturn(MOCK_URL);
+ when(r2.getVersion()).thenReturn(VERSION);
+ when(r2.getDataURI()).thenReturn(NEW_URI);
+ when(r2.getDigest()).thenReturn(NEW_DIGEST);
+ erl.addOrUpdate(r2);
+ ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
+ verify(r1).updateResourceUri(argument.capture());
+ assertEquals(NEW_URI, argument.getValue());
+ }
+
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> EntityResourceList cleaning up resource instead of updating
> -----------------------------------------------------------
>
> Key: SLING-7466
> URL: https://issues.apache.org/jira/browse/SLING-7466
> Project: Sling
> Issue Type: Bug
> Components: Installer
> Affects Versions: Installer Core 3.8.10
> Reporter: Dominik Süß
> Assignee: Carsten Ziegeler
> Priority: Major
> Fix For: Installer Core 3.8.12
>
>
> In case of a replaced launchpad containing an unchanged resource the
> EntityResourceList is called for "addOrUpdate" of this Resource - in case the
> resource already exists but the digest differs the method currently drops the
> new resource without updating the existing one keeping the old dataUri.
> The issue manifests if these RegisteredResources are currently in INSTALL
> state and the INSTALLED version gets dropped subsequently.
> This isn't just a theoretical case but was observed for cases where a bundle
> in an n-1 version was patched to the same version provided in version n of
> launchpad and launchpad hasn't changed for n+1. If the jcr version is then
> removed the installation of the outdated registeredResource fails because of
> a wrong dataUri.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)