sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject [sling-org-apache-sling-feature-cpconverter] branch master updated: SLING-8384 - Convertion of configs might miss out properties
Date Thu, 02 May 2019 12:02:33 GMT
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-org-apache-sling-feature-cpconverter.git


The following commit(s) were added to refs/heads/master by this push:
     new 16eed31  SLING-8384 - Convertion of configs might miss out properties
16eed31 is described below

commit 16eed311862fb5df9eed1daaf367e0f8c5c6120c
Author: stripodi <stripodi@simos-mbp>
AuthorDate: Thu May 2 14:02:26 2019 +0200

    SLING-8384 - Convertion of configs might miss out properties
---
 .../ContentPackage2FeatureModelConverter.java      |  6 ++
 .../handlers/ConfigEntryHandlerTest.java           | 84 ++++++++++++++++++++++
 ...ion.external.impl.DefaultSyncHandler~ims.config | 21 ++++++
 3 files changed, 111 insertions(+)

diff --git a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
index 64dd006..3a97fba 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
@@ -20,6 +20,7 @@ import static java.util.Objects.requireNonNull;
 
 import java.io.File;
 import java.io.FileWriter;
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -337,6 +338,11 @@ public class ContentPackage2FeatureModelConverter {
         while (keys.hasMoreElements()) {
             String key = keys.nextElement();
             Object value = configurationProperties.get(key);
+
+            if (value != null && Collection.class.isInstance(value)) {
+                value = ((Collection<?>) value).toArray();
+            }
+
             configuration.getProperties().put(key, value);
         }
     }
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java
new file mode 100644
index 0000000..91e65af
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.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.feature.cpconverter.handlers;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+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.StringReader;
+import java.io.StringWriter;
+import java.util.Dictionary;
+
+import org.apache.jackrabbit.vault.fs.io.Archive;
+import org.apache.jackrabbit.vault.fs.io.Archive.Entry;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Configuration;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter;
+import org.apache.sling.feature.io.json.FeatureJSONReader;
+import org.apache.sling.feature.io.json.FeatureJSONWriter;
+import org.junit.Test;
+
+public class ConfigEntryHandlerTest {
+
+    @Test
+    public void collectionValuesIncluded() throws Exception {
+        String resourceConfiguration = "jcr_root/apps/asd/config/org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DefaultSyncHandler~ims.config";
+
+        Archive archive = mock(Archive.class);
+        Entry entry = mock(Entry.class);
+
+        when(entry.getName()).thenReturn(resourceConfiguration.substring(resourceConfiguration.lastIndexOf('/')
+ 1));
+        when(archive.openInputStream(entry)).thenReturn(getClass().getResourceAsStream(resourceConfiguration));
+
+        Feature expected = new Feature(new ArtifactId("org.apache.sling", "org.apache.sling.cp2fm",
"0.0.1", null, null));
+        ContentPackage2FeatureModelConverter converter = spy(ContentPackage2FeatureModelConverter.class);
+        when(converter.getTargetFeature()).thenReturn(expected);
+
+        new ConfigurationEntryHandler().handle(resourceConfiguration, archive, entry, converter);
+
+        verifyConfiguration(expected);
+
+        StringWriter writer = new StringWriter();
+        FeatureJSONWriter.write(writer, expected);
+
+        Feature current = FeatureJSONReader.read(new StringReader(writer.toString()), "fake");
+        verifyConfiguration(current);
+    }
+
+    private void verifyConfiguration(Feature feature) {
+        Configuration configuration = feature.getConfigurations().getConfiguration("org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DefaultSyncHandler~ims");
+        assertNotNull(configuration);
+
+        Dictionary<String, Object> configurationProperties = configuration.getConfigurationProperties();
+        assertNotNull(configurationProperties);
+        assertFalse(configurationProperties.isEmpty());
+        assertEquals(1, configurationProperties.get("user.membershipNestingDepth"));
+        assertArrayEquals(new Object[] { "oauth/oauthid-stage=profile/id", "profile/app-stage=access_token"
}, (Object[]) configurationProperties.get("user.propertyMapping"));
+        assertArrayEquals(new String[] { "Administrators" }, (String[]) configurationProperties.get("user.autoMembership"));
+        assertEquals("ims", configurationProperties.get("handler.name"));
+        assertEquals("ims", configurationProperties.get("user.pathPrefix"));
+        assertTrue((boolean) configurationProperties.get("user.disableMissing"));
+    }
+
+}
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/config/org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DefaultSyncHandler~ims.config
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/config/org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DefaultSyncHandler~ims.config
new file mode 100644
index 0000000..f49dfb7
--- /dev/null
+++ b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/config/org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DefaultSyncHandler~ims.config
@@ -0,0 +1,21 @@
+# 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.
+
+user.membershipNestingDepth=I"1"
+user.propertyMapping=("oauth/oauthid-stage\=profile/id","profile/app-stage\=access_token")
+user.autoMembership=["Administrators"]
+handler.name="ims"
+user.pathPrefix="ims"
+user.disableMissing=B"true"


Mime
View raw message