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 <[email protected]> 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()); + } + +}
