You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2020/10/28 20:18:30 UTC

[sling-org-apache-sling-jcr-contentloader] branch master updated (3645791 -> 86ace23)

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

dklco pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git.


    from 3645791  Merge pull request #5 from apache/SLING-9841-jcr-contentloader-include-exclude
     new 712cd4c  Adding tests to the bundle content loader healthcheck
     new 86ace23  Merging changes from master

The 2 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.


Summary of changes:
 .../contentloader/hc/BundleContentLoadedCheck.java |   2 +-
 .../internal/BundleContentLoaderTest.java          |  15 ++-
 .../internal/hc/BundleContentLoadedCheckTest.java  | 139 +++++++++++++++++++++
 3 files changed, 147 insertions(+), 9 deletions(-)
 create mode 100644 src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java


[sling-org-apache-sling-jcr-contentloader] 01/02: Adding tests to the bundle content loader healthcheck

Posted by dk...@apache.org.
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-jcr-contentloader.git

commit 712cd4cc52f95cf2060afc94ee8482355460cad9
Author: Dan Klco <dk...@apache.org>
AuthorDate: Wed Oct 28 16:12:18 2020 -0400

    Adding tests to the bundle content loader healthcheck
---
 .../contentloader/hc/BundleContentLoadedCheck.java |   2 +-
 .../internal/BundleContentLoaderTest.java          |   9 +-
 .../internal/hc/BundleContentLoadedCheckTest.java  | 139 +++++++++++++++++++++
 3 files changed, 144 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/contentloader/hc/BundleContentLoadedCheck.java b/src/main/java/org/apache/sling/jcr/contentloader/hc/BundleContentLoadedCheck.java
index 2fe432b..17c855b 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/hc/BundleContentLoadedCheck.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/hc/BundleContentLoadedCheck.java
@@ -92,7 +92,7 @@ public class BundleContentLoadedCheck implements HealthCheck {
     private SlingRepository repository;
 
     @Activate
-    protected void activate(BundleContext bundleContext, Config config) {
+    public void activate(BundleContext bundleContext, Config config) {
         this.bundleContext = bundleContext;
         this.includesRegex = Pattern.compile(config.includesRegex());
         String excludesRegex2 = config.excludesRegex();
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
index a985701..44f6571 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
@@ -67,7 +67,7 @@ public class BundleContentLoaderTest {
     @Test
     public void loadContentWithSpecificPath() throws Exception {
 
-        Bundle mockBundle = newBundleWithInitialContent("SLING-INF/libs/app;path:=/libs/app");
+        Bundle mockBundle = newBundleWithInitialContent(context, "SLING-INF/libs/app;path:=/libs/app");
 
         contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
 
@@ -80,7 +80,7 @@ public class BundleContentLoaderTest {
     @Test
     public void loadContentWithRootPath() throws Exception {
 
-        Bundle mockBundle = newBundleWithInitialContent("SLING-INF/");
+        Bundle mockBundle = newBundleWithInitialContent(context, "SLING-INF/");
 
         contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
 
@@ -96,7 +96,7 @@ public class BundleContentLoaderTest {
 
         dumpRepo("/", 2);
 
-        Bundle mockBundle = newBundleWithInitialContent("SLING-INF/libs/app;path:=/libs/app;ignoreImportProviders:=xml");
+        Bundle mockBundle = newBundleWithInitialContent(context, "SLING-INF/libs/app;path:=/libs/app;ignoreImportProviders:=xml");
 
         contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
 
@@ -113,8 +113,7 @@ public class BundleContentLoaderTest {
 
     }
 
-    private MockBundle newBundleWithInitialContent(String initialContentHeader) {
-
+    public static MockBundle newBundleWithInitialContent(SlingContext context, String initialContentHeader) {
         MockBundle mockBundle = new MockBundle(context.bundleContext());
         mockBundle.setHeaders(singletonMap("Sling-Initial-Content", initialContentHeader));
         return mockBundle;
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java
new file mode 100644
index 0000000..b85e746
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.contentloader.internal.hc;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.annotation.Annotation;
+
+import javax.jcr.Session;
+
+import org.apache.felix.hc.api.Result;
+import org.apache.sling.jcr.contentloader.hc.BundleContentLoadedCheck;
+import org.apache.sling.jcr.contentloader.hc.BundleContentLoadedCheck.Config;
+import org.apache.sling.jcr.contentloader.internal.BundleContentLoader;
+import org.apache.sling.jcr.contentloader.internal.BundleContentLoaderTest;
+import org.apache.sling.jcr.contentloader.internal.BundleHelper;
+import org.apache.sling.jcr.contentloader.internal.ContentLoaderService;
+import org.apache.sling.jcr.contentloader.internal.ContentReaderWhiteboard;
+import org.apache.sling.jcr.contentloader.internal.readers.JsonReader;
+import org.apache.sling.jcr.contentloader.internal.readers.XmlReader;
+import org.apache.sling.jcr.contentloader.internal.readers.ZipReader;
+import org.apache.sling.testing.mock.osgi.MockBundle;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+public class BundleContentLoadedCheckTest {
+
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+    private MockBundle bundle;
+    private Mockery mock = new Mockery();
+    private BundleContentLoader contentLoader;
+    private BundleContentLoadedCheck check;
+
+    @Before
+    public void setup() {
+        bundle = BundleContentLoaderTest.newBundleWithInitialContent(context, "SLING-INF/libs/app;path:=/libs/app");
+
+        // prepare content readers
+        context.registerInjectActivateService(new JsonReader());
+        context.registerInjectActivateService(new XmlReader());
+        context.registerInjectActivateService(new ZipReader());
+
+        // whiteboard which holds readers
+        context.registerInjectActivateService(new ContentReaderWhiteboard());
+
+        // register the content loader service
+        BundleHelper bundleHelper = context.registerInjectActivateService(new ContentLoaderService());
+
+        ContentReaderWhiteboard whiteboard = context.getService(ContentReaderWhiteboard.class);
+
+        contentLoader = new BundleContentLoader(bundleHelper, whiteboard);
+
+        BundleContext bundleContext = mock.mock(BundleContext.class);
+        mock.checking(new Expectations() {
+            {
+                oneOf(bundleContext).getBundles();
+                will(returnValue(new Bundle[] { bundle }));
+            }
+        });
+        check = context.registerInjectActivateService(new BundleContentLoadedCheck());
+        check.activate(bundleContext, new Config() {
+
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return null;
+            }
+
+            @Override
+            public String hc_name() {
+                return "Unity";
+            }
+
+            @Override
+            public String[] hc_tags() {
+                return new String[] { "test" };
+            }
+
+            @Override
+            public String includesRegex() {
+                return ".*";
+            }
+
+            @Override
+            public String excludesRegex() {
+                return "";
+            }
+
+            @Override
+            public boolean useCriticalForNotLoaded() {
+                return false;
+            }
+
+            @Override
+            public String webconsole_configurationFactory_nameHint() {
+                return null;
+            }
+
+        });
+    }
+
+    @Test
+    public void testNotInstalled() {
+        Result result = check.execute();
+        assertFalse(result.isOk());
+    }
+
+    @Test
+    public void testInstalled() {
+        contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), bundle, false);
+        Result result = check.execute();
+        assertTrue(result.isOk());
+    }
+
+}


[sling-org-apache-sling-jcr-contentloader] 02/02: Merging changes from master

Posted by dk...@apache.org.
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-jcr-contentloader.git

commit 86ace23092ee5316a1c437d18020409d3f029060
Merge: 712cd4c 3645791
Author: Dan Klco <dk...@apache.org>
AuthorDate: Wed Oct 28 16:18:18 2020 -0400

    Merging changes from master

 .../contentloader/hc/BundleContentLoadedCheck.java |   8 +-
 .../internal/BundleContentLoader.java              | 131 +++++++++++++-----
 .../internal/BundleContentLoaderConfiguration.java |  32 +++++
 ...rvice.java => BundleContentLoaderListener.java} | 148 ++++++++++-----------
 src/main/resources/OSGI-INF/l10n/bundle.properties |  33 +++++
 ...t.java => BundleContentLoaderListenerTest.java} |  32 ++---
 .../internal/BundleContentLoaderTest.java          | 124 +++++++++++++++--
 .../internal/hc/BundleContentLoadedCheckTest.java  |   6 +-
 8 files changed, 362 insertions(+), 152 deletions(-)

diff --cc src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
index 44f6571,368bfc7..6f6303c
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
@@@ -66,8 -70,9 +70,9 @@@ public class BundleContentLoaderTest 
      @Test
      public void loadContentWithSpecificPath() throws Exception {
  
+         BundleContentLoader contentLoader = new BundleContentLoader(bundleHelper, whiteboard, null);
+ 
 -        Bundle mockBundle = newBundleWithInitialContent("SLING-INF/libs/app;path:=/libs/app");
 +        Bundle mockBundle = newBundleWithInitialContent(context, "SLING-INF/libs/app;path:=/libs/app");
  
          contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
  
@@@ -78,9 -83,103 +83,103 @@@
      }
  
      @Test
+     public void loadContentWithExcludes() throws Exception {
+ 
+         BundleContentLoader contentLoader = new BundleContentLoader(bundleHelper, whiteboard,
+                 new BundleContentLoaderConfiguration() {
+                     @Override
+                     public Class<? extends Annotation> annotationType() {
+                         return null;
+                     }
+ 
+                     @Override
+                     public String[] includedTargets() {
+                         return new String[] { "^/.*$" };
+                     }
+ 
+                     @Override
+                     public String[] excludedTargets() {
+                         return new String[] { "^/libs.*$" };
+                     }
+ 
+                 });
+ 
 -        Bundle mockBundle = newBundleWithInitialContent(
++        Bundle mockBundle = newBundleWithInitialContent(context, 
+                 "SLING-INF/libs/app;path:=/libs/app,SLING-INF/content/app;path:=/content/app");
+ 
+         contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
+ 
+         assertThat("Excluded resource imported", context.resourceResolver().getResource("/libs/app"), nullValue());
+     }
+ 
+ 
+     @Test
+     public void loadContentWithNullValue() throws Exception {
+ 
+         BundleContentLoader contentLoader = new BundleContentLoader(bundleHelper, whiteboard,
+                 new BundleContentLoaderConfiguration() {
+                     @Override
+                     public Class<? extends Annotation> annotationType() {
+                         return null;
+                     }
+ 
+                     @Override
+                     public String[] includedTargets() {
+                         return new String[] { "^/.*$" };
+                     }
+ 
+                     @Override
+                     public String[] excludedTargets() {
+                         return null;
+                     }
+ 
+                 });
+ 
 -        Bundle mockBundle = newBundleWithInitialContent(
++        Bundle mockBundle = newBundleWithInitialContent(context,
+                 "SLING-INF/libs/app;path:=/libs/app,SLING-INF/content/app;path:=/content/app");
+ 
+         contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
+ 
+         assertThat("Excluded resource imported", context.resourceResolver().getResource("/libs/app"), notNullValue());
+     }
+ 
+ 
+     @Test
+     public void loadContentWithIncludes() throws Exception {
+ 
+         BundleContentLoader contentLoader = new BundleContentLoader(bundleHelper, whiteboard,
+                 new BundleContentLoaderConfiguration() {
+                     @Override
+                     public Class<? extends Annotation> annotationType() {
+                         return null;
+                     }
+ 
+                     @Override
+                     public String[] includedTargets() {
+                         return new String[] { "^/.*$" };
+                     }
+ 
+                     @Override
+                     public String[] excludedTargets() {
+                         return new String[] { "^/app.*$" };
+                     }
+ 
+                 });
+ 
 -        Bundle mockBundle = newBundleWithInitialContent(
++        Bundle mockBundle = newBundleWithInitialContent(context, 
+                 "SLING-INF/libs/app;path:=/libs/app");
+ 
+         contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
+ 
+         assertThat("Included resource not imported", context.resourceResolver().getResource("/libs/app"), notNullValue());
+     }
+ 
+     @Test
      public void loadContentWithRootPath() throws Exception {
  
+         BundleContentLoader contentLoader = new BundleContentLoader(bundleHelper, whiteboard, null);
+ 
 -        Bundle mockBundle = newBundleWithInitialContent("SLING-INF/");
 +        Bundle mockBundle = newBundleWithInitialContent(context, "SLING-INF/");
  
          contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
  
@@@ -94,9 -193,12 +193,12 @@@
      @Ignore("TODO - unregister or somehow ignore the XmlReader component for this test")
      public void loadXmlAsIs() throws Exception {
  
+         BundleContentLoader contentLoader = new BundleContentLoader(bundleHelper, whiteboard, null);
+ 
          dumpRepo("/", 2);
  
-         Bundle mockBundle = newBundleWithInitialContent(context, "SLING-INF/libs/app;path:=/libs/app;ignoreImportProviders:=xml");
 -        Bundle mockBundle = newBundleWithInitialContent(
++        Bundle mockBundle = newBundleWithInitialContent(context, 
+                 "SLING-INF/libs/app;path:=/libs/app;ignoreImportProviders:=xml");
  
          contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
  
diff --cc src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java
index b85e746,0000000..cddbd68
mode 100644,000000..100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java
@@@ -1,139 -1,0 +1,139 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *   http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing,
 + * software distributed under the License is distributed on an
 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 + * KIND, either express or implied.  See the License for the
 + * specific language governing permissions and limitations
 + * under the License.
 + */
 +package org.apache.sling.jcr.contentloader.internal.hc;
 +
 +import static org.junit.Assert.assertFalse;
 +import static org.junit.Assert.assertTrue;
 +
 +import java.lang.annotation.Annotation;
 +
 +import javax.jcr.Session;
 +
 +import org.apache.felix.hc.api.Result;
 +import org.apache.sling.jcr.contentloader.hc.BundleContentLoadedCheck;
 +import org.apache.sling.jcr.contentloader.hc.BundleContentLoadedCheck.Config;
 +import org.apache.sling.jcr.contentloader.internal.BundleContentLoader;
++import org.apache.sling.jcr.contentloader.internal.BundleContentLoaderListener;
 +import org.apache.sling.jcr.contentloader.internal.BundleContentLoaderTest;
 +import org.apache.sling.jcr.contentloader.internal.BundleHelper;
- import org.apache.sling.jcr.contentloader.internal.ContentLoaderService;
 +import org.apache.sling.jcr.contentloader.internal.ContentReaderWhiteboard;
 +import org.apache.sling.jcr.contentloader.internal.readers.JsonReader;
 +import org.apache.sling.jcr.contentloader.internal.readers.XmlReader;
 +import org.apache.sling.jcr.contentloader.internal.readers.ZipReader;
 +import org.apache.sling.testing.mock.osgi.MockBundle;
 +import org.apache.sling.testing.mock.sling.ResourceResolverType;
 +import org.apache.sling.testing.mock.sling.junit.SlingContext;
 +import org.jmock.Expectations;
 +import org.jmock.Mockery;
 +import org.junit.Before;
 +import org.junit.Rule;
 +import org.junit.Test;
 +import org.osgi.framework.Bundle;
 +import org.osgi.framework.BundleContext;
 +
 +public class BundleContentLoadedCheckTest {
 +
 +    @Rule
 +    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
 +    private MockBundle bundle;
 +    private Mockery mock = new Mockery();
 +    private BundleContentLoader contentLoader;
 +    private BundleContentLoadedCheck check;
 +
 +    @Before
 +    public void setup() {
 +        bundle = BundleContentLoaderTest.newBundleWithInitialContent(context, "SLING-INF/libs/app;path:=/libs/app");
 +
 +        // prepare content readers
 +        context.registerInjectActivateService(new JsonReader());
 +        context.registerInjectActivateService(new XmlReader());
 +        context.registerInjectActivateService(new ZipReader());
 +
 +        // whiteboard which holds readers
 +        context.registerInjectActivateService(new ContentReaderWhiteboard());
 +
 +        // register the content loader service
-         BundleHelper bundleHelper = context.registerInjectActivateService(new ContentLoaderService());
++        BundleHelper bundleHelper = context.registerInjectActivateService(new BundleContentLoaderListener());
 +
 +        ContentReaderWhiteboard whiteboard = context.getService(ContentReaderWhiteboard.class);
 +
-         contentLoader = new BundleContentLoader(bundleHelper, whiteboard);
++        contentLoader = new BundleContentLoader(bundleHelper, whiteboard, null);
 +
 +        BundleContext bundleContext = mock.mock(BundleContext.class);
 +        mock.checking(new Expectations() {
 +            {
 +                oneOf(bundleContext).getBundles();
 +                will(returnValue(new Bundle[] { bundle }));
 +            }
 +        });
 +        check = context.registerInjectActivateService(new BundleContentLoadedCheck());
 +        check.activate(bundleContext, new Config() {
 +
 +            @Override
 +            public Class<? extends Annotation> annotationType() {
 +                return null;
 +            }
 +
 +            @Override
 +            public String hc_name() {
 +                return "Unity";
 +            }
 +
 +            @Override
 +            public String[] hc_tags() {
 +                return new String[] { "test" };
 +            }
 +
 +            @Override
 +            public String includesRegex() {
 +                return ".*";
 +            }
 +
 +            @Override
 +            public String excludesRegex() {
 +                return "";
 +            }
 +
 +            @Override
 +            public boolean useCriticalForNotLoaded() {
 +                return false;
 +            }
 +
 +            @Override
 +            public String webconsole_configurationFactory_nameHint() {
 +                return null;
 +            }
 +
 +        });
 +    }
 +
 +    @Test
 +    public void testNotInstalled() {
 +        Result result = check.execute();
 +        assertFalse(result.isOk());
 +    }
 +
 +    @Test
 +    public void testInstalled() {
 +        contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), bundle, false);
 +        Result result = check.execute();
 +        assertTrue(result.isOk());
 +    }
 +
 +}