You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by si...@apache.org on 2019/03/07 00:18:29 UTC

[sling-whiteboard] branch master updated: [cp2fm] added DefaultEntryHandler unit test + sample resources

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 2583b62  [cp2fm] added DefaultEntryHandler unit test + sample resources
2583b62 is described below

commit 2583b62171b29fc07dc33d1e847940b9096a7fa8
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Thu Mar 7 01:18:18 2019 +0100

    [cp2fm] added DefaultEntryHandler unit test + sample resources
---
 .../sling/cp2fm/handlers/DefaultEntryHandler.java  |  6 ++
 .../cp2fm/handlers/DefaultEntryHandlerTest.java    | 84 ++++++++++++++++++++++
 .../sling/cp2fm/handlers/jcr_root/.content.xml     | 22 ++++++
 .../sling/cp2fm/handlers/jcr_root/asd/.content.xml | 20 ++++++
 .../handlers/jcr_root/asd/public/.content.xml      | 19 +++++
 .../handlers/jcr_root/asd/public/_rep_policy.xml   | 24 +++++++
 .../cp2fm/handlers/jcr_root/asd/public/license.txt | 14 ++++
 7 files changed, 189 insertions(+)

diff --git a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/DefaultEntryHandler.java b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/DefaultEntryHandler.java
index 9eece3f..fbc76f4 100644
--- a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/DefaultEntryHandler.java
+++ b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/DefaultEntryHandler.java
@@ -26,11 +26,15 @@ import org.apache.jackrabbit.vault.fs.io.Archive;
 import org.apache.jackrabbit.vault.fs.io.Archive.Entry;
 import org.apache.sling.cp2fm.ContentPackage2FeatureModelConverter;
 import org.apache.sling.cp2fm.spi.EntryHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public final class DefaultEntryHandler implements EntryHandler {
 
     public static final String TMP_DEFLATED = "tmp-deflated";
 
+    private final Logger logger = LoggerFactory.getLogger(getClass());
+
     @Override
     public boolean matches(String path) {
         return true;
@@ -45,6 +49,8 @@ public final class DefaultEntryHandler implements EntryHandler {
 
         try (InputStream input = archive.openInputStream(entry);
                 OutputStream output = new FileOutputStream(target)) {
+            logger.info("Copying {} archived resource to {}...", path, target);
+
             IOUtils.copy(input, output);
         }
     }
diff --git a/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/handlers/DefaultEntryHandlerTest.java b/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/handlers/DefaultEntryHandlerTest.java
new file mode 100644
index 0000000..3d7e643
--- /dev/null
+++ b/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/handlers/DefaultEntryHandlerTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.cp2fm.handlers;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.jackrabbit.vault.fs.io.Archive;
+import org.apache.jackrabbit.vault.fs.io.Archive.Entry;
+import org.apache.sling.cp2fm.ContentPackage2FeatureModelConverter;
+import org.apache.sling.cp2fm.spi.EntryHandler;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class DefaultEntryHandlerTest {
+
+    private final String resourceLocation;
+
+    private final EntryHandler defaultEntryHandler;
+
+    public DefaultEntryHandlerTest(String recourceLocation, EntryHandler defaultEntryHandler) {
+        this.resourceLocation = recourceLocation;
+        this.defaultEntryHandler = defaultEntryHandler;
+    }
+
+    @Test
+    public void matchAll() {
+        assertTrue(defaultEntryHandler.matches(resourceLocation));
+    }
+
+    @Test
+    public void copyEverything() throws Exception {
+        Archive archive = mock(Archive.class);
+        Entry entry = mock(Entry.class);
+        when(archive.openInputStream(entry)).thenReturn(getClass().getResourceAsStream(resourceLocation));
+
+        ContentPackage2FeatureModelConverter converter = spy(ContentPackage2FeatureModelConverter.class);
+
+        File testDirectory = new File(System.getProperty("testDirectory"), getClass().getName());
+        when(converter.getOutputDirectory()).thenReturn(testDirectory);
+
+        defaultEntryHandler.handle(resourceLocation, archive, entry, converter);
+
+        File targetDirectory = new File(testDirectory, "tmp-deflated");
+        File targetFile = new File(targetDirectory, resourceLocation);
+        assertTrue(targetFile.exists());
+    }
+
+    @Parameters
+    public static Collection<Object[]> data() {
+        EntryHandler defaultEntryHandler = new DefaultEntryHandler();
+
+        return Arrays.asList(new Object[][] {
+            { "jcr_root/.content.xml", defaultEntryHandler },
+            { "jcr_root/asd/.content.xml", defaultEntryHandler },
+            { "jcr_root/asd/public/_rep_policy.xml", defaultEntryHandler },
+            { "jcr_root/asd/public/license.txt", defaultEntryHandler }
+        });
+    }
+
+}
diff --git a/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/.content.xml b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/.content.xml
new file mode 100644
index 0000000..54fbe67
--- /dev/null
+++ b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/.content.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+    jcr:mixinTypes="[rep:AccessControllable,rep:RepoAccessControllable]"
+    jcr:primaryType="rep:root"
+    sling:resourceType="sling:redirect"
+    sling:target="/index.html"/>
diff --git a/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/.content.xml b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/.content.xml
new file mode 100644
index 0000000..0d5ab1d
--- /dev/null
+++ b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/.content.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+    jcr:mixinTypes="[rep:AccessControllable]"
+    jcr:primaryType="sling:Folder"/>
diff --git a/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/public/.content.xml b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/public/.content.xml
new file mode 100644
index 0000000..0589bcb
--- /dev/null
+++ b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/public/.content.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
+    jcr:primaryType="sling:Folder"/>
diff --git a/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/public/_rep_policy.xml b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/public/_rep_policy.xml
new file mode 100644
index 0000000..2b1119a
--- /dev/null
+++ b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/public/_rep_policy.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<jcr:root xmlns:crx="http://www.day.com/crx/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+    jcr:primaryType="rep:ACL">
+    <allow
+        jcr:primaryType="rep:GrantACE"
+        rep:principalName="everyone"
+        rep:privileges="{Name}[jcr:read]"/>
+</jcr:root>
\ No newline at end of file
diff --git a/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/public/license.txt b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/public/license.txt
new file mode 100644
index 0000000..805f6a4
--- /dev/null
+++ b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/handlers/jcr_root/asd/public/license.txt
@@ -0,0 +1,14 @@
+ 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.