You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by tm...@apache.org on 2021/12/18 00:30:48 UTC

[sling-org-apache-sling-distribution-journal] branch SLING-10095-8 created (now 571b9c0)

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

tmaret pushed a change to branch SLING-10095-8
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git.


      at 571b9c0  SLING-10095 - Add negative test cases

This branch includes the following new commits:

     new 571b9c0  SLING-10095 - Add negative test cases

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-distribution-journal] 01/01: SLING-10095 - Add negative test cases

Posted by tm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tmaret pushed a commit to branch SLING-10095-8
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git

commit 571b9c0ca170f33bea234dea26dd39b367a05bdc
Author: tmaret <tm...@adobe.com>
AuthorDate: Sat Dec 18 01:30:27 2021 +0100

    SLING-10095 - Add negative test cases
---
 .../bookkeeper/ContentPackageExtractorTest.java    | 35 ++++++++++++++++++++++
 .../journal/bookkeeper/ErrorListenerTest.java      |  9 ++++++
 2 files changed, 44 insertions(+)

diff --git a/src/test/java/org/apache/sling/distribution/journal/bookkeeper/ContentPackageExtractorTest.java b/src/test/java/org/apache/sling/distribution/journal/bookkeeper/ContentPackageExtractorTest.java
index ecb416f..4fc9f8c 100644
--- a/src/test/java/org/apache/sling/distribution/journal/bookkeeper/ContentPackageExtractorTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/bookkeeper/ContentPackageExtractorTest.java
@@ -19,7 +19,10 @@
 package org.apache.sling.distribution.journal.bookkeeper;
 
 import static java.util.Collections.singletonList;
+import static org.apache.jackrabbit.vault.fs.api.ProgressTrackerListener.Mode.PATHS;
 import static org.apache.sling.api.resource.ResourceUtil.getOrCreateResource;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -51,6 +54,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
 import org.osgi.framework.BundleContext;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -151,6 +155,23 @@ public class ContentPackageExtractorTest {
         extractor.handle(resourceResolver, singletonList(node.getPath()));
     }
 
+    @Test(expected = DistributionException.class)
+    public void testFailedInstallWithError() throws Exception {
+
+        Answer<Void> errorAndThrow = run -> {
+            ImportOptions opts = (ImportOptions) run.getArguments()[0];
+            opts.getListener().onError(PATHS, "Failed due to XYZ", new PackageException());
+            throw new PackageException();
+        };
+
+        doAnswer(errorAndThrow).when(pkg)
+                .install(any(ImportOptions.class));
+
+        Resource node = createImportedPackage();
+        ContentPackageExtractor extractor = new ContentPackageExtractor(packaging, PackageHandling.Install);
+        extractor.handle(resourceResolver, singletonList(node.getPath()));
+    }
+
     @Test
     public void testNotContentPackagePath() throws Exception {
 
@@ -174,6 +195,20 @@ public class ContentPackageExtractorTest {
         verify(pkg, never()).install(Mockito.any(ImportOptions.class));
     }
 
+    @Test
+    public void testNullPath() throws Exception {
+        ContentPackageExtractor extractor = new ContentPackageExtractor(packaging, PackageHandling.Install);
+        extractor.handle(resourceResolver, singletonList(null));
+        verify(pkg, never()).install(Mockito.any(ImportOptions.class));
+    }
+
+    @Test
+    public void testNullPackageNode() throws Exception {
+        ContentPackageExtractor extractor = new ContentPackageExtractor(packaging, PackageHandling.Install);
+        extractor.handle(resourceResolver, singletonList("/does/not/exist"));
+        verify(pkg, never()).install(Mockito.any(ImportOptions.class));
+    }
+
     private Resource createImportedPackage() throws PersistenceException {
         return createImportedPackage(createEtcPackages());
     }
diff --git a/src/test/java/org/apache/sling/distribution/journal/bookkeeper/ErrorListenerTest.java b/src/test/java/org/apache/sling/distribution/journal/bookkeeper/ErrorListenerTest.java
index a1a3295..33b0427 100644
--- a/src/test/java/org/apache/sling/distribution/journal/bookkeeper/ErrorListenerTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/bookkeeper/ErrorListenerTest.java
@@ -63,6 +63,15 @@ public class ErrorListenerTest {
         assertMessage(message);
     }
 
+    @Test
+    public void testOnMessage() {
+        errorListener.onMessage(PATHS, "action", path);
+        errorListener.onError(PATHS, path, exception);
+        String message = errorListener.getLastErrorMessage();
+        assertNotNull(message);
+        assertMessage(message);
+    }
+
     private void assertMessage(String message) {
         assertTrue(message.contains(errorMsg));
         assertTrue(message.contains(path));