You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2017/03/08 00:15:26 UTC
svn commit: r1785906 - in /sling/trunk/tooling/maven/maven-sling-plugin: ./
src/main/java/org/apache/sling/maven/bundlesupport/
src/test/java/org/apache/sling/maven/bundlesupport/
Author: sseifert
Date: Wed Mar 8 00:15:26 2017
New Revision: 1785906
URL: http://svn.apache.org/viewvc?rev=1785906&view=rev
Log:
SLING-6619 maven-sling-plugin: Switch to javax.json + Johnzon
Added:
sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java (with props)
sling/trunk/tooling/maven/maven-sling-plugin/src/test/java/org/apache/sling/maven/bundlesupport/JsonSupportTest.java (with props)
Modified:
sling/trunk/tooling/maven/maven-sling-plugin/pom.xml
sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java
sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java
Modified: sling/trunk/tooling/maven/maven-sling-plugin/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/pom.xml?rev=1785906&r1=1785905&r2=1785906&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/pom.xml (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/pom.xml Wed Mar 8 00:15:26 2017
@@ -107,13 +107,20 @@
<version>2.5</version>
<scope>compile</scope>
</dependency>
-
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.json</artifactId>
- <version>2.0.18</version>
+ <groupId>org.apache.johnzon</groupId>
+ <artifactId>johnzon-core</artifactId>
+ <version>1.0.0</version>
+ <scope>compile</scope>
</dependency>
<dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-json_1.0_spec</artifactId>
+ <version>1.0-alpha-1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.osgi</artifactId>
<version>2.4.0</version>
@@ -149,6 +156,13 @@
<version>3.4</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>15.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java?rev=1785906&r1=1785905&r2=1785906&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java Wed Mar 8 00:15:26 2017
@@ -28,6 +28,10 @@ import java.util.Map;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import javax.json.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
@@ -48,9 +52,6 @@ import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.osgi.ManifestHeader;
import org.apache.sling.commons.osgi.ManifestHeader.Entry;
@@ -734,25 +735,25 @@ abstract class AbstractBundleInstallMojo
}
final String jsonText = get.getResponseBodyAsString();
try {
- JSONArray array = new JSONArray(jsonText);
- for(int i=0; i<array.length(); i++) {
- final JSONObject obj = array.getJSONObject(i);
+ JsonArray array = JsonSupport.parseArray(jsonText);
+ for(int i=0; i<array.size(); i++) {
+ final JsonObject obj = array.getJsonObject(i);
final String pid = obj.getString("pid");
- final JSONObject properties = obj.getJSONObject("properties");
- final String path = properties.getJSONObject("provider.file").optString("value");
+ final JsonObject properties = obj.getJsonObject("properties");
+ final String path = properties.getJsonObject("provider.file").getString("value", null);
final String roots;
- if (properties.has("provider.roots")) {
- roots = properties.getJSONObject("provider.roots").optString("value");
+ if (properties.containsKey("provider.roots")) {
+ roots = properties.getJsonObject("provider.roots").getString("value", null);
}
else {
- roots = properties.getJSONObject("provider.root").optString("value");
+ roots = properties.getJsonObject("provider.root").getString("value", null);
}
if ( path != null && path.startsWith(this.project.getBasedir().getAbsolutePath()) && roots != null ) {
getLog().debug("Found configuration with pid: " + pid + ", path: " + path + ", roots: " + roots);
result.put(pid, new String[] {path, roots});
}
}
- } catch (JSONException ex) {
+ } catch (JsonException ex) {
throw new MojoExecutionException("Reading configuration from " + getUrl
+ " failed, cause: " + ex.getMessage(), ex);
}
@@ -809,10 +810,10 @@ abstract class AbstractBundleInstallMojo
}
final String jsonText = gm.getResponseBodyAsString();
try {
- final JSONObject obj = new JSONObject(jsonText);
- final JSONArray props = obj.getJSONArray("props");
- for(int i=0; i<props.length(); i++) {
- final JSONObject property = props.getJSONObject(i);
+ final JsonObject obj = JsonSupport.parseObject(jsonText);
+ final JsonArray props = obj.getJsonArray("props");
+ for(int i=0; i<props.size(); i++) {
+ final JsonObject property = props.getJsonObject(i);
if ( "Version".equals(property.get("key")) ) {
final String version = property.getString("value");
getLog().debug("Found web console version " + version);
@@ -821,14 +822,14 @@ abstract class AbstractBundleInstallMojo
}
getLog().debug("Version property not found in response. Assuming older version.");
return null;
- } catch (JSONException ex) {
+ } catch (JsonException ex) {
getLog().debug("Converting response to JSON failed. Assuming older version: " + ex.getMessage());
return null;
}
}
getLog().debug("Status code from web console: " + status);
- } catch (HttpException e) {
+ } catch (HttpException e) {
getLog().debug("HttpException: " + e.getMessage());
} catch (IOException e) {
getLog().debug("IOException: " + e.getMessage());
Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java?rev=1785906&r1=1785905&r2=1785906&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java Wed Mar 8 00:15:26 2017
@@ -25,11 +25,17 @@ import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.annotation.Annotation;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.json.Json;
+import javax.json.JsonException;
+import javax.json.JsonWriter;
+
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -41,9 +47,6 @@ import org.apache.maven.plugins.annotati
import org.apache.maven.project.MavenProject;
import org.apache.sling.adapter.annotations.Adaptable;
import org.apache.sling.adapter.annotations.Adaptables;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
-import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Type;
@@ -58,8 +61,6 @@ import org.scannotation.AnnotationDB;
threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE)
public class GenerateAdapterMetadataMojo extends AbstractMojo {
- private static final int JSON_INDENTATION = 4;
-
private static final String ADAPTABLE_DESC = "L" + Adaptable.class.getName().replace('.', '/') + ";";
private static final String ADAPTABLES_DESC = "L" + Adaptables.class.getName().replace('.', '/') + ";";
@@ -96,7 +97,7 @@ public class GenerateAdapterMetadataMojo
public void execute() throws MojoExecutionException, MojoFailureException {
try {
- final JSONObject descriptor = new JSONObject();
+ final Map<String,Object> descriptor = new HashMap<>();
final AnnotationDB annotationDb = new AnnotationDB();
annotationDb.scanArchives(buildOutputDirectory.toURI().toURL());
@@ -133,22 +134,20 @@ public class GenerateAdapterMetadataMojo
final File outputFile = new File(outputDirectory, fileName);
outputFile.getParentFile().mkdirs();
- final FileWriter writer = new FileWriter(outputFile);
- try {
- IOUtil.copy(descriptor.toString(JSON_INDENTATION), writer);
- } finally {
- IOUtil.close(writer);
+ try (FileWriter writer = new FileWriter(outputFile);
+ JsonWriter jsonWriter = Json.createWriter(writer)) {
+ jsonWriter.writeObject(JsonSupport.toJson(descriptor));
}
addResource();
} catch (IOException e) {
throw new MojoExecutionException("Unable to generate metadata", e);
- } catch (JSONException e) {
+ } catch (JsonException e) {
throw new MojoExecutionException("Unable to generate metadata", e);
}
}
-
+
private void addAnnotatedClasses(final AnnotationDB annotationDb, final Set<String> annotatedClassNames, final Class<? extends Annotation> clazz) {
Set<String> classNames = annotationDb.getAnnotationIndex().get(clazz.getName());
if (classNames == null || classNames.isEmpty()) {
@@ -176,7 +175,7 @@ public class GenerateAdapterMetadataMojo
}
private void parseAdaptablesAnnotation(final AnnotationNode annotation, final ClassNode classNode,
- final JSONObject descriptor) throws JSONException {
+ final Map<String,Object> descriptor) throws JsonException {
final Iterator<?> it = annotation.values.iterator();
while (it.hasNext()) {
Object name = it.next();
@@ -195,7 +194,7 @@ public class GenerateAdapterMetadataMojo
@SuppressWarnings("unchecked")
private void parseAdaptableAnnotation(final AnnotationNode annotation, final ClassNode annotatedClass,
- final JSONObject descriptor) throws JSONException {
+ final Map<String,Object> descriptor) throws JsonException {
String adaptableClassName = null;
List<AnnotationNode> adapters = null;
@@ -218,11 +217,11 @@ public class GenerateAdapterMetadataMojo
"Adaptable annotation is malformed. Expecting a classname and a list of adapter annotation.");
}
- JSONObject adaptableDescription;
- if (descriptor.has(adaptableClassName)) {
- adaptableDescription = descriptor.getJSONObject(adaptableClassName);
+ Map<String,Object> adaptableDescription;
+ if (descriptor.containsKey(adaptableClassName)) {
+ adaptableDescription = (Map<String,Object>)descriptor.get(adaptableClassName);
} else {
- adaptableDescription = new JSONObject();
+ adaptableDescription = new HashMap<>();
descriptor.put(adaptableClassName, adaptableDescription);
}
@@ -233,7 +232,7 @@ public class GenerateAdapterMetadataMojo
@SuppressWarnings("unchecked")
private void parseAdapterAnnotation(final AnnotationNode annotation, final ClassNode annotatedClass,
- final JSONObject adaptableDescription) throws JSONException {
+ final Map<String,Object> adaptableDescription) throws JsonException {
String condition = null;
List<Type> adapterClasses = null;
@@ -260,7 +259,8 @@ public class GenerateAdapterMetadataMojo
}
for (final Type adapterClass : adapterClasses) {
- adaptableDescription.accumulate(condition, adapterClass.getClassName());
+ JsonSupport.accumulate(adaptableDescription, condition, adapterClass.getClassName());
}
}
+
}
Added: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java?rev=1785906&view=auto
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java (added)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java Wed Mar 8 00:15:26 2017
@@ -0,0 +1,125 @@
+/*
+ * 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.maven.bundlesupport;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
+import javax.json.JsonReader;
+import javax.json.JsonReaderFactory;
+
+final class JsonSupport {
+
+ private static final JsonReaderFactory JSON_READER_FACTORY;
+ static {
+ // allow comments in JSON files
+ Map<String,Object> jsonFactoryConfig = new HashMap<>();
+ jsonFactoryConfig.put("org.apache.johnzon.supports-comments", true);
+ JSON_READER_FACTORY = Json.createReaderFactory(jsonFactoryConfig);
+ }
+
+ private JsonSupport() {
+ // static methods only
+ }
+
+ /**
+ * Parse String to JSON object.
+ * @param jsonString JSON string
+ * @return JSON object
+ */
+ public static JsonObject parseObject(String jsonString) {
+ try (StringReader reader = new StringReader(jsonString);
+ JsonReader jsonReader = JSON_READER_FACTORY.createReader(reader)) {
+ return jsonReader.readObject();
+ }
+ }
+
+ /**
+ * Parse String to JSON array.
+ * @param jsonString JSON string
+ * @return JSON array
+ */
+ public static JsonArray parseArray(String jsonString) {
+ try (StringReader reader = new StringReader(jsonString);
+ JsonReader jsonReader = JSON_READER_FACTORY.createReader(reader)) {
+ return jsonReader.readArray();
+ }
+ }
+
+ /**
+ * Validate JSON structure
+ * @param jsonString JSON string
+ * @throws javax.json.JsonException when JSON structure is invalid
+ */
+ public static void validateJsonStructure(String jsonString) {
+ try (StringReader reader = new StringReader(jsonString);
+ JsonReader jsonReader = JSON_READER_FACTORY.createReader(reader)) {
+ jsonReader.read();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static void accumulate(Map<String,Object> obj, String name, String value) {
+ Object current = obj.get(name);
+ if (current == null) {
+ obj.put(name, value);
+ }
+ else if (current instanceof List) {
+ List<String> array = new ArrayList<>((List)current);
+ array.add(value);
+ obj.put(name, array);
+ }
+ else {
+ List<String> array = new ArrayList<>();
+ array.add((String)current);
+ array.add(value);
+ obj.put(name, array);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static JsonObject toJson(Map<String,Object> map) {
+ JsonObjectBuilder builder = Json.createObjectBuilder();
+ for (Map.Entry<String,Object> entry : map.entrySet()) {
+ if (entry.getValue() instanceof Map) {
+ builder.add(entry.getKey(), toJson((Map<String,Object>)entry.getValue()));
+ }
+ else if (entry.getValue() instanceof List) {
+ JsonArrayBuilder array = Json.createArrayBuilder();
+ for (String value : (List<String>)entry.getValue()) {
+ array.add(value);
+ }
+ builder.add(entry.getKey(), array.build());
+ }
+ else {
+ builder.add(entry.getKey(), (String)entry.getValue());
+ }
+ }
+ return builder.build();
+ }
+
+}
Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed Mar 8 00:15:26 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java?rev=1785906&r1=1785905&r2=1785906&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java Wed Mar 8 00:15:26 2017
@@ -23,6 +23,8 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
+import javax.json.JsonException;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.CharEncoding;
import org.apache.maven.model.Resource;
@@ -32,8 +34,6 @@ import org.apache.maven.plugins.annotati
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.util.Validator;
import org.codehaus.plexus.util.DirectoryScanner;
/**
@@ -118,10 +118,10 @@ public class ValidationMojo extends Abst
} finally {
IOUtils.closeQuietly(fis);
}
- // first, let's see if this is a json array
+ // validate JSON
try {
- Validator.validate(json);
- } catch (JSONException e) {
+ JsonSupport.validateJsonStructure(json);
+ } catch (JsonException e) {
throw new MojoExecutionException("An Error occured while validating the file '"+fileName+"'", e);
}
}
Added: sling/trunk/tooling/maven/maven-sling-plugin/src/test/java/org/apache/sling/maven/bundlesupport/JsonSupportTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/test/java/org/apache/sling/maven/bundlesupport/JsonSupportTest.java?rev=1785906&view=auto
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/test/java/org/apache/sling/maven/bundlesupport/JsonSupportTest.java (added)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/test/java/org/apache/sling/maven/bundlesupport/JsonSupportTest.java Wed Mar 8 00:15:26 2017
@@ -0,0 +1,109 @@
+/*
+ * 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.maven.bundlesupport;
+
+import static org.apache.sling.maven.bundlesupport.JsonSupport.accumulate;
+import static org.apache.sling.maven.bundlesupport.JsonSupport.parseArray;
+import static org.apache.sling.maven.bundlesupport.JsonSupport.parseObject;
+import static org.apache.sling.maven.bundlesupport.JsonSupport.toJson;
+import static org.apache.sling.maven.bundlesupport.JsonSupport.validateJsonStructure;
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.json.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public class JsonSupportTest {
+
+ @Test
+ public void testParseObject() {
+ JsonObject obj = parseObject("{\"prop1\":123}");
+ assertEquals(123, obj.getInt("prop1"));
+ }
+
+ @Test
+ public void testParseArray() {
+ JsonArray array = parseArray("[{\"prop1\":123}]");
+ assertEquals(1, array.size());
+ assertEquals(123, array.getJsonObject(0).getInt("prop1"));
+ }
+
+ @Test
+ public void testValidateJsonStructure() {
+ validateJsonStructure("{\"prop1\":123}");
+ validateJsonStructure("[{\"prop1\":123}]");
+ }
+
+ @Test(expected=JsonException.class)
+ public void testValidateJsonStructure_Invalid() {
+ validateJsonStructure("wurstbrot");
+ }
+
+ @Test
+ public void testAccumulate_NewValue() {
+ Map<String,Object> map = new HashMap<>();
+ accumulate(map, "prop1", "value1");
+ assertEquals(ImmutableMap.of("prop1", "value1"), map);
+ }
+
+ @Test
+ public void testAccumulate_ExistingValue() {
+ Map<String,Object> map = new HashMap<>();
+ map.put("prop1", "value1");
+ accumulate(map, "prop1", "value2");
+ assertEquals(ImmutableMap.of("prop1", ImmutableList.of("value1", "value2")), map);
+ }
+
+ @Test
+ public void testAccumulate_ExistingArray() {
+ Map<String,Object> map = new HashMap<>();
+ map.put("prop1", ImmutableList.of("value1","value2"));
+ accumulate(map, "prop1", "value3");
+ assertEquals(ImmutableMap.of("prop1", ImmutableList.of("value1", "value2","value3")), map);
+ }
+
+ @Test
+ public void testToJson() {
+ Map<String,Object> map = ImmutableMap.<String, Object>builder()
+ .put("prop1", "value1")
+ .put("prop2", ImmutableList.of("value2","value3"))
+ .put("prop3", ImmutableMap.of("prop4", "value4"))
+ .build();
+ JsonObject obj = toJson(map);
+
+ assertEquals("value1", obj.getString("prop1"));
+
+ JsonArray array = obj.getJsonArray("prop2");
+ assertEquals(2, array.size());
+ assertEquals("value2", array.getString(0));
+ assertEquals("value3", array.getString(1));
+
+ JsonObject prop3 = obj.getJsonObject("prop3");
+ assertEquals("value4", prop3.getString("prop4"));
+ }
+
+}
Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/test/java/org/apache/sling/maven/bundlesupport/JsonSupportTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/test/java/org/apache/sling/maven/bundlesupport/JsonSupportTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed Mar 8 00:15:26 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/test/java/org/apache/sling/maven/bundlesupport/JsonSupportTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain