bosschaert closed pull request #1: SLING-7677 - FeatureJSONWriter uses isOptional instead of isRequired URL: https://github.com/apache/sling-org-apache-sling-feature-io/pull/1
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/src/main/java/org/apache/sling/feature/io/json/JSONWriterBase.java b/src/main/java/org/apache/sling/feature/io/json/JSONWriterBase.java index cfb6d9b..388bc69 100644 --- a/src/main/java/org/apache/sling/feature/io/json/JSONWriterBase.java +++ b/src/main/java/org/apache/sling/feature/io/json/JSONWriterBase.java @@ -218,7 +218,7 @@ protected void writeExtensions(final JsonObjectBuilder ob, final List<Extension> extensions, final Configurations allConfigs) { for(final Extension ext : extensions) { - final String key = ext.getName() + ":" + ext.getType().name() + "|" + ext.isOptional(); + final String key = ext.getName() + ":" + ext.getType().name() + "|" + ext.isRequired(); if ( ext.getType() == ExtensionType.JSON ) { final JsonStructure struct; try ( final StringReader reader = new StringReader(ext.getJSON()) ) { diff --git a/src/test/java/org/apache/sling/feature/io/json/ArtifactsExtensions.java b/src/test/java/org/apache/sling/feature/io/json/ArtifactsExtensions.java new file mode 100644 index 0000000..bdd34f1 --- /dev/null +++ b/src/test/java/org/apache/sling/feature/io/json/ArtifactsExtensions.java @@ -0,0 +1,56 @@ +package org.apache.sling.feature.io.json; + +import org.apache.sling.feature.ArtifactId; +import org.apache.sling.feature.Extension; +import org.apache.sling.feature.Extensions; +import org.apache.sling.feature.Feature; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/* + * 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. + */ +public class ArtifactsExtensions { + + public static void testReadArtifactsExtensions(Feature feature) { + Extensions extensions = feature.getExtensions(); + + assertEquals(2, extensions.size()); + + Extension extension1 = extensions.getByName("my-extension1"); + assertNotNull(extension1); + assertEquals(extension1.getName(), "my-extension1"); + assertEquals(extension1.isRequired(), false); + assertEquals(1, extension1.getArtifacts().size()); + + ArtifactId artifactId1 = extension1.getArtifacts().get(0).getId(); + assertEquals(artifactId1.getGroupId(), "org.apache.sling"); + assertEquals(artifactId1.getArtifactId(), "my-extension1"); + assertEquals(artifactId1.getVersion(), "1.2.3"); + + Extension extension2 = extensions.getByName("my-extension2"); + assertNotNull(extension2); + assertEquals(extension2.getName(), "my-extension2"); + assertEquals(extension2.isRequired(), true); + assertEquals(1, extension2.getArtifacts().size()); + + ArtifactId artifactId2 = extension2.getArtifacts().get(0).getId(); + assertEquals(artifactId2.getGroupId(), "org.apache.sling"); + assertEquals(artifactId2.getArtifactId(), "my-extension2"); + assertEquals(artifactId2.getVersion(), "1.2.3"); + } +} diff --git a/src/test/java/org/apache/sling/feature/io/json/FeatureJSONReaderTest.java b/src/test/java/org/apache/sling/feature/io/json/FeatureJSONReaderTest.java index 6acd293..aa7559c 100644 --- a/src/test/java/org/apache/sling/feature/io/json/FeatureJSONReaderTest.java +++ b/src/test/java/org/apache/sling/feature/io/json/FeatureJSONReaderTest.java @@ -213,6 +213,11 @@ } } + @Test public void testReadArtifactsExtensions() throws Exception { + final Feature feature = U.readFeature("artifacts-extension", SubstituteVariables.NONE); + ArtifactsExtensions.testReadArtifactsExtensions(feature); + } + private void setPrivateField(Object obj, String name, Object value) throws Exception { Field field = obj.getClass().getDeclaredField(name); field.setAccessible(true); diff --git a/src/test/java/org/apache/sling/feature/io/json/FeatureJSONWriterTest.java b/src/test/java/org/apache/sling/feature/io/json/FeatureJSONWriterTest.java index 81db5e6..79609f2 100644 --- a/src/test/java/org/apache/sling/feature/io/json/FeatureJSONWriterTest.java +++ b/src/test/java/org/apache/sling/feature/io/json/FeatureJSONWriterTest.java @@ -47,4 +47,17 @@ U.findCapability(rf.getCapabilities(), "osgi.service").getAttributes().get("objectClass")); } + @Test public void testExtensionsWriteRead() throws Exception { + final Feature f = U.readFeature("artifacts-extension"); + final Feature rf; + try ( final StringWriter writer = new StringWriter() ) { + FeatureJSONWriter.write(writer, f); + try ( final StringReader reader = new StringReader(writer.toString()) ) { + rf = FeatureJSONReader.read(reader, null, SubstituteVariables.RESOLVE); + } + } + + ArtifactsExtensions.testReadArtifactsExtensions(rf); + } + } diff --git a/src/test/resources/features/artifacts-extension.json b/src/test/resources/features/artifacts-extension.json new file mode 100644 index 0000000..3bcd47a --- /dev/null +++ b/src/test/resources/features/artifacts-extension.json @@ -0,0 +1,9 @@ +{ + "id": "test/artifacts-extension/1.0.0", + "my-extension1:ARTIFACTS|false":[ + "org.apache.sling/my-extension1/1.2.3" + ], + "my-extension2:ARTIFACTS|true":[ + "org.apache.sling/my-extension2/1.2.3" + ] +} \ No newline at end of file ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services