sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [sling-org-apache-sling-app-cms] branch master updated: Fixing flagged bug and adding test coverage
Date Wed, 23 Sep 2020 19:49:42 GMT
This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git


The following commit(s) were added to refs/heads/master by this push:
     new ff58163  Fixing flagged bug and adding test coverage
ff58163 is described below

commit ff58163b95af774740c8c667be85bdb19a208048
Author: Dan Klco <dklco@apache.org>
AuthorDate: Wed Sep 23 15:49:25 2020 -0400

    Fixing flagged bug and adding test coverage
---
 .../core/publication/BulkPublicationJobTest.java   | 87 ++++++++++++++++++++++
 .../java/org/apache/sling/cms/feature/Main.java    | 11 +--
 2 files changed, 93 insertions(+), 5 deletions(-)

diff --git a/core/src/test/java/org/apache/sling/cms/core/publication/BulkPublicationJobTest.java
b/core/src/test/java/org/apache/sling/cms/core/publication/BulkPublicationJobTest.java
new file mode 100644
index 0000000..25e594e
--- /dev/null
+++ b/core/src/test/java/org/apache/sling/cms/core/publication/BulkPublicationJobTest.java
@@ -0,0 +1,87 @@
+package org.apache.sling.cms.core.publication;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.sling.cms.core.helpers.SlingCMSTestHelper;
+import org.apache.sling.cms.publication.PublicationException;
+import org.apache.sling.cms.publication.PublicationManager;
+import org.apache.sling.cms.publication.PublicationManagerFactory;
+import org.apache.sling.cms.publication.PublicationType;
+import org.apache.sling.event.jobs.Job;
+import org.apache.sling.event.jobs.consumer.JobExecutionContext;
+import org.apache.sling.event.jobs.consumer.JobExecutionContext.ResultBuilder;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class BulkPublicationJobTest {
+
+    @Rule
+    public final SlingContext context = new SlingContext();
+    private PublicationManager publicationManager;
+
+    @Before
+    public void init() {
+        SlingCMSTestHelper.initContext(context);
+
+        PublicationManagerFactory publicationManagerFactory = Mockito.mock(PublicationManagerFactory.class);
+        publicationManager = Mockito.mock(PublicationManager.class);
+        Mockito.when(publicationManagerFactory.getPublicationManager()).thenReturn(publicationManager);
+        context.registerService(PublicationManagerFactory.class, publicationManagerFactory);
+    }
+
+    @Test
+    public void testShallow() throws PublicationException {
+
+        BulkPublicationJob pubJob = context.registerInjectActivateService(new BulkPublicationJob());
+
+        JobExecutionContext jobContext = Mockito.mock(JobExecutionContext.class);
+        ResultBuilder result = Mockito.mock(ResultBuilder.class);
+        Mockito.when(jobContext.result()).thenReturn(result);
+        Job job = Mockito.mock(Job.class);
+
+        Mockito.when(job.getProperty(Mockito.matches("paths"), Mockito.any())).thenReturn(new
String[] { "/content" });
+        Mockito.when(job.getProperty(Mockito.matches("type"), Mockito.any()))
+                .thenReturn(PublicationType.ADD.toString());
+        Mockito.when(job.getProperty(Mockito.matches("deep"), Mockito.anyBoolean())).thenReturn(false);
+
+        pubJob.doProcess(job, jobContext, context.resourceResolver());
+
+        Mockito.verify(publicationManager).publish(Mockito.any());
+        Mockito.verify(result).succeeded();
+    }
+
+    @Test
+    public void testDeep() throws PublicationException {
+
+        BulkPublicationJob pubJob = context.registerInjectActivateService(new BulkPublicationJob());
+
+        JobExecutionContext jobContext = Mockito.mock(JobExecutionContext.class);
+        ResultBuilder result = Mockito.mock(ResultBuilder.class);
+        Mockito.when(jobContext.result()).thenReturn(result);
+        Job job = Mockito.mock(Job.class);
+
+        Mockito.when(job.getProperty(Mockito.matches("paths"), Mockito.any())).thenReturn(new
String[] { "/content" });
+        Mockito.when(job.getProperty(Mockito.matches("type"), Mockito.any()))
+                .thenReturn(PublicationType.ADD.toString());
+        Mockito.when(job.getProperty(Mockito.matches("deep"), Mockito.anyBoolean())).thenReturn(true);
+
+        pubJob.doProcess(job, jobContext, context.resourceResolver());
+
+        Mockito.verify(publicationManager, Mockito.atLeast(5)).publish(Mockito.any());
+        Mockito.verify(result).succeeded();
+    }
+
+    @Test
+    public void testMethods() throws PublicationException {
+        BulkPublicationJob pubJob = context.registerInjectActivateService(new BulkPublicationJob());
+        assertEquals("/mnt/overlay/sling-cms/content/publication/bulk", pubJob.getConfigurationPath());
+        assertNotNull(pubJob.getResolverFactory());
+        assertEquals("slingcms.bulkpublication.title", pubJob.getTitleKey());
+        assertEquals(BulkPublicationJob.TOPIC, pubJob.getTopic());
+    }
+
+}
diff --git a/feature/src/main/java/org/apache/sling/cms/feature/Main.java b/feature/src/main/java/org/apache/sling/cms/feature/Main.java
index 0780738..d4482d9 100644
--- a/feature/src/main/java/org/apache/sling/cms/feature/Main.java
+++ b/feature/src/main/java/org/apache/sling/cms/feature/Main.java
@@ -28,7 +28,10 @@ public class Main {
         System.out.println("Bootstraping Sling CMS Feature Model");
         URL propertiesUrl =  Main.class.getClassLoader().getResource("slingcms.properties");
         Properties properties = new Properties();
-        properties.load(propertiesUrl.openStream());
+        try(InputStream is = propertiesUrl.openStream()){
+            properties.load(is);
+        }
+        
 
         String version = properties.getProperty("version");
         System.out.println("Version "+version);
@@ -36,10 +39,8 @@ public class Main {
         URL farUrl = Main.class.getClassLoader().getResource("lib/slingcms.far");
         List<String> arguments = new ArrayList<>();
         arguments.addAll(Arrays.asList(args));
-        if(!arguments.contains("-f")){
-            arguments.add("-f");
-            arguments.add(farUrl.toString());
-        }
+        arguments.add("-f");
+        arguments.add(farUrl.toString());
 
         org.apache.sling.feature.launcher.impl.Main.main(arguments.toArray(new String[arguments.size()]));
     }


Mime
View raw message