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/12 17:57:05 UTC

[sling-whiteboard] branch master updated: [cp2fm] added ContentPackage2FeatureModelConverter#convert() main test

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 43cf311  [cp2fm] added ContentPackage2FeatureModelConverter#convert() main test
43cf311 is described below

commit 43cf311840280a89d3a544f8229b97415dd30ab6
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Tue Mar 12 18:36:48 2019 +0100

    [cp2fm] added ContentPackage2FeatureModelConverter#convert() main test
---
 .../ContentPackage2FeatureModelConverter.java      |  14 +--
 .../AbstractConfigurationEntryHandler.java         |   3 -
 .../ContentPackage2FeatureModelConverterTest.java  |  95 ++++++++++++++++++++-
 .../apache/sling/cp2fm/test-content-package.zip    | Bin 0 -> 46393 bytes
 4 files changed, 103 insertions(+), 9 deletions(-)

diff --git a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java
index b02fab4..56b54c5 100644
--- a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java
+++ b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java
@@ -197,9 +197,13 @@ public class ContentPackage2FeatureModelConverter {
 
             PackageProperties packageProperties = vaultPackage.getProperties();
 
-            targetFeature = new Feature(new ArtifactId(packageProperties.getProperty(NAME_GROUP_ID), 
-                                                       packageProperties.getProperty(NAME_ARTIFACT_ID),
-                                                       packageProperties.getProperty(PackageProperties.NAME_VERSION),
+            String groupId = packageProperties.getProperty(NAME_GROUP_ID);
+            String artifactId = packageProperties.getProperty(NAME_ARTIFACT_ID);
+            String version = packageProperties.getProperty(PackageProperties.NAME_VERSION);
+
+            targetFeature = new Feature(new ArtifactId(groupId,
+                                                       artifactId,
+                                                       version,
                                                        FEATURE_CLASSIFIER,
                                                        SLING_OSGI_FEATURE_TILE_TYPE));
 
@@ -218,8 +222,8 @@ public class ContentPackage2FeatureModelConverter {
                 copyProperty(PackageProperties.NAME_GROUP, packageProperties, properties);
                 properties.setProperty(PackageProperties.NAME_NAME, packageProperties.getProperty(PackageProperties.NAME_NAME) + ' ' + FEATURE_CLASSIFIER);
                 copyProperty(PackageProperties.NAME_VERSION, packageProperties, properties);
-                properties.setProperty(NAME_GROUP_ID, packageProperties.getProperty(NAME_GROUP_ID));
-                properties.setProperty(NAME_ARTIFACT_ID, packageProperties.getProperty(NAME_ARTIFACT_ID));
+                copyProperty(NAME_GROUP_ID, packageProperties, properties);
+                copyProperty(NAME_ARTIFACT_ID, packageProperties, properties);
                 properties.setProperty(NAME_CLASSIFIER, FEATURE_CLASSIFIER);
                 properties.setProperty(PackageProperties.NAME_DEPENDENCIES, dependencies.stream().collect(Collectors.joining(",")));
                 properties.setProperty(PackageProperties.NAME_CREATED_BY, userName);
diff --git a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/AbstractConfigurationEntryHandler.java b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/AbstractConfigurationEntryHandler.java
index fabefb4..9e891b3 100644
--- a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/AbstractConfigurationEntryHandler.java
+++ b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/AbstractConfigurationEntryHandler.java
@@ -18,14 +18,11 @@ package org.apache.sling.cp2fm.handlers;
 
 import java.io.InputStream;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.regex.Matcher;
 
 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.feature.Configuration;
-import org.apache.sling.feature.Feature;
 
 abstract class AbstractConfigurationEntryHandler extends AbstractRegexEntryHandler {
 
diff --git a/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverterTest.java b/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverterTest.java
index 99637b0..72834ad 100644
--- a/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverterTest.java
+++ b/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverterTest.java
@@ -16,12 +16,26 @@
  */
 package org.apache.sling.cp2fm;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 
 import java.io.File;
+import java.io.FileReader;
 import java.io.InputStream;
-
+import java.io.Reader;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.io.json.FeatureJSONReader;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -101,4 +115,83 @@ public class ContentPackage2FeatureModelConverterTest {
         converter.deployLocallyAndAttach(null, mock(InputStream.class), "org.apache.sling", "org.apache.sling.cm2fm", "0.0.1", null, null);
     }
 
+    @Test
+    public void convertContentPackage() throws Exception {
+        URL packageUrl = getClass().getResource("test-content-package.zip");
+        File packageFile = FileUtils.toFile(packageUrl);
+
+        File outputDirectory = new File(System.getProperty("testDirectory"), getClass().getName() + '_' + System.currentTimeMillis());
+
+        converter.setBundlesStartOrder(5).setOutputDirectory(outputDirectory).convert(packageFile);
+
+        verifyFeatureFile(outputDirectory,
+                          "asd.retail.all.json",
+                          "org.apache.sling:asd.retail.all:slingosgifeature:cp2fm-converted-feature:0.0.1",
+                          Arrays.asList("org.apache.felix:org.apache.felix.framework:6.0.1", "org.apache.sling:asd.retail.all:zip:cp2fm-converted-feature:0.0.1"),
+                          Arrays.asList("org.apache.sling.commons.log.LogManager.factory.config-asd-retail"));
+        verifyFeatureFile(outputDirectory,
+                          "asd.retail.all-author.json",
+                          "org.apache.sling:asd.retail.all:slingosgifeature:cp2fm-converted-feature-author:0.0.1",
+                          Arrays.asList("org.apache.sling:org.apache.sling.api:2.20.0"),
+                          Collections.emptyList());
+        verifyFeatureFile(outputDirectory,
+                          "asd.retail.all-publish.json",
+                          "org.apache.sling:asd.retail.all:slingosgifeature:cp2fm-converted-feature-publish:0.0.1",
+                          Arrays.asList("org.apache.sling:org.apache.sling.models.api:1.3.8"),
+                          Arrays.asList("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-asd-retail"));
+    }
+
+    private void verifyFeatureFile(File outputDirectory,
+                                   String name,
+                                   String expectedArtifactId,
+                                   List<String> expectedBundles,
+                                   List<String> expectedConfigurations) throws Exception {
+        File featureFile = new File(outputDirectory, name);
+        assertTrue(featureFile + " was not correctly created", featureFile.exists());
+
+        try (Reader reader = new FileReader(featureFile)) {
+            Feature feature = FeatureJSONReader.read(reader, featureFile.getAbsolutePath());
+
+            assertEquals(expectedArtifactId, feature.getId().toMvnId());
+
+            for (String expectedBundle : expectedBundles) {
+                assertTrue(expectedBundle + " not found in Feature " + expectedArtifactId, feature.getBundles().containsExact(ArtifactId.fromMvnId(expectedBundle)));
+                verifyInstalledBundle(outputDirectory, expectedBundle);
+            }
+
+            for (String expectedConfiguration : expectedConfigurations) {
+                assertNotNull(expectedConfiguration + " not found in Feature " + expectedArtifactId, feature.getConfigurations().getConfiguration(expectedConfiguration));
+            }
+        }
+    }
+
+    private void verifyInstalledBundle(File outputDirectory, String coordinates) {
+        ArtifactId bundleId = ArtifactId.fromMvnId(coordinates);
+
+        File bundleDirectory = new File(outputDirectory, "bundles");
+
+        StringTokenizer tokenizer = new StringTokenizer(bundleId.getGroupId(), ".");
+        while (tokenizer.hasMoreTokens()) {
+            bundleDirectory = new File(bundleDirectory, tokenizer.nextToken());
+        }
+
+        bundleDirectory = new File(bundleDirectory, bundleId.getArtifactId());
+        bundleDirectory = new File(bundleDirectory, bundleId.getVersion());
+
+        StringBuilder bundleFileName = new StringBuilder()
+                                       .append(bundleId.getArtifactId())
+                                       .append('-')
+                                       .append(bundleId.getVersion());
+        if (bundleId.getClassifier() != null) {
+            bundleFileName.append('-').append(bundleId.getClassifier());
+        }
+        bundleFileName.append('.').append(bundleId.getType());
+
+        File bundleFile = new File(bundleDirectory, bundleFileName.toString());
+        assertTrue("Bundle " + bundleFile + " does not exist", bundleFile.exists());
+
+        File pomFile = new File(bundleDirectory, String.format("%s-%s.pom", bundleId.getArtifactId(), bundleId.getVersion()));
+        assertTrue("POM file " + pomFile + " does not exist", pomFile.exists());
+    }
+
 }
diff --git a/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/test-content-package.zip b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/test-content-package.zip
new file mode 100644
index 0000000..cfe6a94
Binary files /dev/null and b/content-package-2-feature-model/src/test/resources/org/apache/sling/cp2fm/test-content-package.zip differ