This is an automated email from the ASF dual-hosted git repository.

ldywicki pushed a commit to branch karaf-4.1.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.1.x by this push:
     new 33e8a2e  [KARAF-5533] Make sure KarArtifactInstaller does not install 
same KAR twice.
33e8a2e is described below

commit 33e8a2e258a567650a692833c8d5e448f13aa1f5
Author: Ɓukasz Dywicki <l...@code-house.org>
AuthorDate: Wed Dec 13 01:56:00 2017 +0100

    [KARAF-5533] Make sure KarArtifactInstaller does not install same KAR twice.
---
 .../karaf/deployer/kar/KarArtifactInstaller.java   | 10 +++---
 .../deployer/kar/KarArtifactInstallerTest.java     | 37 +++++++++++++++++++++-
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git 
a/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/KarArtifactInstaller.java
 
b/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/KarArtifactInstaller.java
index 15feb56..8ed983d 100644
--- 
a/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/KarArtifactInstaller.java
+++ 
b/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/KarArtifactInstaller.java
@@ -40,7 +40,7 @@ public class KarArtifactInstaller implements 
ArtifactInstaller {
 
        public void install(File file) throws Exception {
         // check if the KAR is not already installed
-        if (karService.list().contains(file.getName())) {
+        if (karService.list().contains(getKarName(file))) {
             LOGGER.info("KAR {} is already installed. Please uninstall it 
first.", file.getName());
             return;
         }
@@ -61,12 +61,12 @@ public class KarArtifactInstaller implements 
ArtifactInstaller {
         karService.uninstall(getKarName(file));
         karService.install(file.toURI());
        }
-       
-       private String getKarName(File karFile) {
-           String karName = karFile.getName();
+
+    String getKarName(File karFile) {
+        String karName = karFile.getName();
         karName = karName.substring(0, karName.lastIndexOf("."));
         return karName;
-       }
+    }
 
     public boolean canHandle(File file) {
                // If the file ends with .kar, then we can handle it!
diff --git 
a/deployer/kar/src/test/java/org/apache/karaf/deployer/kar/KarArtifactInstallerTest.java
 
b/deployer/kar/src/test/java/org/apache/karaf/deployer/kar/KarArtifactInstallerTest.java
index f455a05..1ef4190 100644
--- 
a/deployer/kar/src/test/java/org/apache/karaf/deployer/kar/KarArtifactInstallerTest.java
+++ 
b/deployer/kar/src/test/java/org/apache/karaf/deployer/kar/KarArtifactInstallerTest.java
@@ -18,12 +18,14 @@
  */
 package org.apache.karaf.deployer.kar;
 
-import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.*;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.net.URI;
+import java.util.Collections;
+import java.util.List;
 
 import org.apache.karaf.kar.KarService;
 import org.junit.Before;
@@ -72,4 +74,37 @@ public class KarArtifactInstallerTest {
                assertFalse(karArtifactInstaller.canHandle(new 
File(badZipFile)));
        }
 
+    /**
+     * This is test for KARAF-5533. Issue comes from fact that internally KAR 
service process file in it's own way.
+     *
+     * Because of that artifact installer must follow the same logic of 
service it calls, as returned list of installed.
+     * KAR files is not list of full file names, but files with stripped 
extensions.
+     *
+     * @throws Exception Any exception causes test failure.
+     */
+    @Test
+    public void shouldNotInstallSameFileTwice() throws Exception {
+        File file = new File(goodKarFile);
+        URI uri = file.toURI();
+
+        // make sure we have clean state.
+        presentKarList(Collections.emptyList());
+        karService.install(uri);
+
+        replay(karService);
+
+        karArtifactInstaller.install(file);
+        verify(karService);
+
+        // once again,
+        reset(karService);
+        
presentKarList(Collections.singletonList(karArtifactInstaller.getKarName(file)));
+        replay(karService);
+        karArtifactInstaller.install(file);
+        verify(karService);
+    }
+
+    private void presentKarList(List<String> deployedKars) throws Exception {
+        expect(karService.list()).andReturn(deployedKars).once();
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@karaf.apache.org" <commits@karaf.apache.org>'].

Reply via email to