From commits-return-79619-archive-asf-public=cust-asf.ponee.io@sling.apache.org Thu May 2 12:02:39 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 966BB180671 for ; Thu, 2 May 2019 14:02:39 +0200 (CEST) Received: (qmail 50452 invoked by uid 500); 2 May 2019 12:02:38 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 50441 invoked by uid 99); 2 May 2019 12:02:38 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 May 2019 12:02:38 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 3DE1D871D3; Thu, 2 May 2019 12:02:33 +0000 (UTC) Date: Thu, 02 May 2019 12:02:33 +0000 To: "commits@sling.apache.org" Subject: [sling-org-apache-sling-feature-cpconverter] branch master updated: SLING-8384 - Convertion of configs might miss out properties MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <155679855320.19498.9990237534459331544@gitbox.apache.org> From: simonetripodi@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: sling-org-apache-sling-feature-cpconverter X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: c06dd911b0449bc71e90f42b96b06e76c19ef44f X-Git-Newrev: 16eed311862fb5df9eed1daaf367e0f8c5c6120c X-Git-Rev: 16eed311862fb5df9eed1daaf367e0f8c5c6120c X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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 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"