You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2021/08/26 08:16:50 UTC

[sling-org-apache-sling-feature-cpconverter] branch SLING-10754 created (now dcefe20)

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

angela pushed a change to branch SLING-10754
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git.


      at dcefe20  SLING-10754 : Missing entries in filter.xml (test-case illustrating the problem)

This branch includes the following new commits:

     new dcefe20  SLING-10754 : Missing entries in filter.xml (test-case illustrating the problem)

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-feature-cpconverter] 01/01: SLING-10754 : Missing entries in filter.xml (test-case illustrating the problem)

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

angela pushed a commit to branch SLING-10754
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git

commit dcefe20eb571d5438332a2d2dd22e013f9792530
Author: angela <an...@adobe.com>
AuthorDate: Thu Aug 26 10:16:34 2021 +0200

    SLING-10754 : Missing entries in filter.xml (test-case illustrating the problem)
---
 .../feature/cpconverter/AbstractConverterTest.java |  13 +++
 .../feature/cpconverter/AdjustedFilterTest.java    | 100 +++++++++++++++++++++
 .../ConverterUserAndPermissionTest.java            |  11 ---
 .../feature/cpconverter/subtree_in_contentxml.zip  | Bin 0 -> 4556 bytes
 4 files changed, 113 insertions(+), 11 deletions(-)

diff --git a/src/test/java/org/apache/sling/feature/cpconverter/AbstractConverterTest.java b/src/test/java/org/apache/sling/feature/cpconverter/AbstractConverterTest.java
index 6b23576..72dd7d8 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/AbstractConverterTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/AbstractConverterTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.feature.cpconverter;
 
+import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
 import org.apache.jackrabbit.vault.util.Constants;
 import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Artifacts;
@@ -171,4 +172,16 @@ public abstract class AbstractConverterTest {
         File pomFile = new File(outputDirectory, String.format("%s-%s.pom", bundleId.getArtifactId(), bundleId.getVersion()));
         assertTrue("POM file " + pomFile + " does not exist", pomFile.exists());
     }
+    
+    @NotNull
+    static DefaultWorkspaceFilter getWorkspaceFilter(@NotNull File contentPackage) throws Exception {
+        DefaultWorkspaceFilter filter;
+        try (ZipFile zipFile = new ZipFile(contentPackage)) {
+            filter = new DefaultWorkspaceFilter();
+            ZipEntry entry = zipFile.getEntry("META-INF/vault/filter.xml");
+            assertNotNull(entry);
+            filter.load(zipFile.getInputStream(entry));
+        }
+        return filter;
+    }
 }
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/AdjustedFilterTest.java b/src/test/java/org/apache/sling/feature/cpconverter/AdjustedFilterTest.java
new file mode 100644
index 0000000..744e76a
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/cpconverter/AdjustedFilterTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.feature.cpconverter;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter;
+import org.apache.sling.feature.cpconverter.accesscontrol.AclManager;
+import org.apache.sling.feature.cpconverter.accesscontrol.DefaultAclManager;
+import org.apache.sling.feature.cpconverter.artifacts.LocalMavenRepositoryArtifactsDeployer;
+import org.apache.sling.feature.cpconverter.features.DefaultFeaturesManager;
+import org.apache.sling.feature.cpconverter.features.FeaturesManager;
+import org.apache.sling.feature.cpconverter.handlers.DefaultEntryHandlersManager;
+import org.apache.sling.feature.cpconverter.handlers.EntryHandlersManager;
+import org.apache.sling.feature.cpconverter.shared.ConverterConstants;
+import org.apache.sling.feature.cpconverter.vltpkg.DefaultPackagesEventsEmitter;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runners.Parameterized;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class AdjustedFilterTest extends AbstractConverterTest {
+
+    private ContentPackage2FeatureModelConverter converter;
+
+    private File outputDirectory;
+    private FeaturesManager featuresManager;
+
+    @Before
+    public void setUp() throws Exception {
+        AclManager aclManager = new DefaultAclManager();
+        EntryHandlersManager handlersManager = new DefaultEntryHandlersManager(Collections.emptyMap(), false, ContentPackage2FeatureModelConverter.SlingInitialContentPolicy.KEEP, ConverterConstants.SYSTEM_USER_REL_PATH_DEFAULT);
+
+        converter = new ContentPackage2FeatureModelConverter()
+                .setEntryHandlersManager(handlersManager)
+                .setAclManager(aclManager);
+
+        outputDirectory = new File(System.getProperty("java.io.tmpdir"), getClass().getName() + '_' + System.currentTimeMillis());
+        featuresManager = new DefaultFeaturesManager(true, 5, outputDirectory, null, null, null, aclManager);
+
+        converter.setFeaturesManager(featuresManager)
+                .setBundlesDeployer(new LocalMavenRepositoryArtifactsDeployer(outputDirectory))
+                .setEmitter(DefaultPackagesEventsEmitter.open(outputDirectory));
+    }
+
+    @After
+    public void tearDown() throws IOException {
+        deleteDirTree(outputDirectory);
+        converter.close();
+    }
+    
+    @Test
+    public void testSubTreeInContentXml() throws Exception {
+        URL packageUrl = getClass().getResource("subtree_in_contentxml.zip");
+        File packageFile = FileUtils.toFile(packageUrl);
+        converter.convert(packageFile);
+
+        File converted = new File(outputDirectory, "subtree_in_contentxml/0.0.0/subtree_in_contentxml-0.0.0-cp2fm-converted.zip");
+        WorkspaceFilter filter = getWorkspaceFilter(converted);
+        
+        assertFalse(filter.covers("/"));
+        assertFalse(filter.covers("/oak:index"));
+        assertFalse(filter.covers("/oak:index/uuid"));
+        
+        assertTrue(filter.contains("/oak:index/custom"));
+        assertTrue(filter.covers("/oak:index/custom/indexRules"));
+        assertTrue(filter.covers("/oak:index/custom/indexRules/nt:unstructured"));
+        assertTrue(filter.covers("/oak:index/custom/indexRules/nt:unstructured/properties"));
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/ConverterUserAndPermissionTest.java b/src/test/java/org/apache/sling/feature/cpconverter/ConverterUserAndPermissionTest.java
index 7aaac89..0f3d382 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/ConverterUserAndPermissionTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/ConverterUserAndPermissionTest.java
@@ -429,15 +429,4 @@ public class ConverterUserAndPermissionTest  extends AbstractConverterTest {
                 pathFilterEntry.getFilter().matches("/home/users/demo-cp/rep:policy")).count());
         return filter;
     }
-    
-    private static DefaultWorkspaceFilter getWorkspaceFilter(@NotNull File contentPackage) throws Exception {
-        DefaultWorkspaceFilter filter;
-        try (ZipFile zipFile = new ZipFile(contentPackage)) {
-            filter = new DefaultWorkspaceFilter();
-            ZipEntry entry = zipFile.getEntry("META-INF/vault/filter.xml");
-            assertNotNull(entry);
-            filter.load(zipFile.getInputStream(entry));
-        }
-        return filter;
-    }
 }
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/subtree_in_contentxml.zip b/src/test/resources/org/apache/sling/feature/cpconverter/subtree_in_contentxml.zip
new file mode 100644
index 0000000..6a3a717
Binary files /dev/null and b/src/test/resources/org/apache/sling/feature/cpconverter/subtree_in_contentxml.zip differ