This is an automated email from the ASF dual-hosted git repository. anatole pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tamaya-sandbox.git
commit 8468093a82f8d48d780dc30987f17b626de65de6 Author: Anatole Tresch <[email protected]> AuthorDate: Fri Dec 14 22:48:58 2018 +0100 Added hjson support. --- .../tamaya/commons/IniConfigurationFormat.java | 2 +- hjson/pom.xml | 97 ++++++++++ .../org/apache/tamaya/hjson/HJSONDataBuilder.java | 116 ++++++++++++ .../java/org/apache/tamaya/hjson/HJSONFormat.java | 63 +++++++ .../apache/tamaya/hjson/HJSONPropertySource.java | 130 +++++++++++++ .../PathBasedHJSONPropertySourceProvider.java | 58 ++++++ .../org.apache.tamaya.format.ConfigurationFormat | 19 ++ .../hjson/CommonHJSONTestCaseCollection.java | 206 +++++++++++++++++++++ .../org/apache/tamaya/hjson/HJSONFormatIT.java | 48 +++++ .../org/apache/tamaya/hjson/HJSONFormatTest.java | 75 ++++++++ .../tamaya/hjson/HJSONPropertySourceTest.java | 55 ++++++ .../org/apache/tamaya/hjson/HJSONVisitorTest.java | 92 +++++++++ .../PathBasedHJSONPropertySourceProviderTest.java | 66 +++++++ .../META-INF/javaconfiguration.properties | 22 +++ .../src/test/resources/configs/invalid/array.hjson | 21 +++ .../resources/configs/invalid/empty-file.hjson | 18 ++ .../configs/invalid/only-opening-bracket.hjson | 19 ++ .../resources/configs/invalid/with-array.hjson | 27 +++ .../test/resources/configs/valid/cyrillic.hjson | 22 +++ .../configs/valid/empty-object-config.hjson | 20 ++ hjson/src/test/resources/configs/valid/kanji.hjson | 21 +++ .../valid/simple-flat-string-only-config.hjson | 23 +++ .../valid/simple-nested-string-only-config-1.hjson | 27 +++ .../valid/simple-nested-string-only-config-2.hjson | 26 +++ .../configs/valid/with-explicit-priority.hjson | 25 +++ pom.xml | 3 +- .../org/apache/tamaya/usagetracker/UsageStat.java | 4 +- .../tamaya/usagetracker/spi/ConfigUsageSpi.java | 2 +- 28 files changed, 1302 insertions(+), 5 deletions(-) diff --git a/apache-commons/src/main/java/org/apache/tamaya/commons/IniConfigurationFormat.java b/apache-commons/src/main/java/org/apache/tamaya/commons/IniConfigurationFormat.java index 7c86d65..bf03fcf 100644 --- a/apache-commons/src/main/java/org/apache/tamaya/commons/IniConfigurationFormat.java +++ b/apache-commons/src/main/java/org/apache/tamaya/commons/IniConfigurationFormat.java @@ -64,7 +64,7 @@ public class IniConfigurationFormat implements ConfigurationFormat { } for (String section : commonIniConfiguration.getSections()) { SubnodeConfiguration sectionConfig = commonIniConfiguration.getSection(section); - PropertyValue sectionNode = ((ObjectValue) data).getOrSetField(section, + PropertyValue sectionNode = ((ObjectValue) data).getOrSetValue(section, () -> PropertyValue.createObject(section)); Map<String, String> properties = new HashMap<>(); Iterator<String> keyIter = sectionConfig.getKeys(); diff --git a/hjson/pom.xml b/hjson/pom.xml new file mode 100644 index 0000000..27d6546 --- /dev/null +++ b/hjson/pom.xml @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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 current 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-sandbox</artifactId> + <version>0.4-incubating-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <artifactId>tamaya-hjson_beta</artifactId> + <name>Apache Tamaya Modules - HJSON Support</name> + <packaging>jar</packaging> + + <inceptionYear>2018</inceptionYear> + + <description> + This modules provides format support + for using hjson files with Apache Tamaya. + </description> + + <properties> + <hjson.version>3.0.0</hjson.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-api</artifactId> + <version>${project.parent.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-core</artifactId> + <version>${project.parent.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-formats</artifactId> + <version>${project.parent.version}</version> + </dependency> + <dependency> + <groupId>org.hjson</groupId> + <artifactId>hjson</artifactId> + <version>${hjson.version}</version> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-formats</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>java-hamcrest</artifactId> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> + </dependencies> + +</project> diff --git a/hjson/src/main/java/org/apache/tamaya/hjson/HJSONDataBuilder.java b/hjson/src/main/java/org/apache/tamaya/hjson/HJSONDataBuilder.java new file mode 100644 index 0000000..2cf4fa5 --- /dev/null +++ b/hjson/src/main/java/org/apache/tamaya/hjson/HJSONDataBuilder.java @@ -0,0 +1,116 @@ +/* + * 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.tamaya.hjson; + +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.spi.ListValue; +import org.apache.tamaya.spi.ObjectValue; +import org.apache.tamaya.spi.PropertyValue; +import org.hjson.JsonArray; +import org.hjson.JsonObject; +import org.hjson.JsonValue; + +import java.util.Objects; + +/** + * Visitor implementation to read a HJSON asString input source. + */ +class HJSONDataBuilder { + + private String resource; + private PropertyValue data; + private JsonValue root; + + HJSONDataBuilder(String resource, JsonValue root) { + this.resource = Objects.requireNonNull(resource); + this.root = root; + } + + private void addJsonObject(JsonObject jsonObject, ObjectValue dataNode){ + jsonObject.forEach((m) -> { + switch(m.getValue().getType()) { + case BOOLEAN: + dataNode.setValue(m.getName(), String.valueOf(m.getValue().asBoolean())); + break; + case NUMBER: + dataNode.setValue(m.getName(), String.valueOf(m.getValue().asDouble())); + break; + case STRING: + dataNode.setValue(m.getName(), m.getValue().asString()); + break; + case NULL: + dataNode.setValue(m.getName(), null); + break; + case OBJECT: + ObjectValue oval = dataNode.setObject(m.getName()); + addJsonObject((JsonObject)m.getValue(), oval); + break; + case ARRAY: + ListValue aval = dataNode.setList(m.getName()); + addArray((JsonArray)m.getValue(), aval); + break; + default: + throw new ConfigException("Internal failure while processing JSON document."); + } + }); + } + + private void addArray(JsonArray array, ListValue dataNode) { + array.forEach(val -> { + switch(val.getType()) { + case NULL: + break; + case BOOLEAN: + dataNode.addValue(String.valueOf(val.asBoolean())); + break; + case NUMBER: + case STRING: + dataNode.addValue(val.toString()); + break; + case OBJECT: + ObjectValue oval = dataNode.addObject(); + addJsonObject((JsonObject)val, oval); + break; + case ARRAY: + ListValue aval = dataNode.addList(); + addArray((JsonArray)val, aval); + break; + default: + throw new ConfigException("Internal failure while processing JSON document."); + } + }); + } + + public PropertyValue build() { + if (root instanceof JsonObject) { + data = PropertyValue.createObject(""); + addJsonObject((JsonObject)root, (ObjectValue) data); + } else if (root instanceof JsonArray) { + JsonArray array = (JsonArray)root; + data = PropertyValue.createList(""); + addArray(array, (ListValue)data); + } else { + throw new ConfigException("Unknown JsonType encountered: " + root.getClass().getName()); + } + data.setMeta("resource", resource); + data.setMeta("format", "json"); + return data; + } + +} diff --git a/hjson/src/main/java/org/apache/tamaya/hjson/HJSONFormat.java b/hjson/src/main/java/org/apache/tamaya/hjson/HJSONFormat.java new file mode 100644 index 0000000..3e7f3ed --- /dev/null +++ b/hjson/src/main/java/org/apache/tamaya/hjson/HJSONFormat.java @@ -0,0 +1,63 @@ +/* + * 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.tamaya.hjson; + +import org.apache.tamaya.format.ConfigurationData; +import org.apache.tamaya.format.ConfigurationFormat; +import org.hjson.JsonValue; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Implementation of the {@link ConfigurationFormat} + * able to read configuration properties with comments represented in HJSON + * + * @see <a href="http://www.hjson.org">JSON format specification</a> + */ +public class HJSONFormat implements ConfigurationFormat { + + @Override + public String getName() { + return "hjson"; + } + + @Override + public boolean accepts(URL url) { + return Objects.requireNonNull(url).getPath().endsWith(".hjson"); + } + + @Override + public ConfigurationData readConfiguration(String resource, InputStream inputStream) + throws IOException{ + try{ + JsonValue root = JsonValue.readHjson(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); + HJSONDataBuilder dataBuilder = new HJSONDataBuilder(resource, root); + return new ConfigurationData(resource, this, dataBuilder.build()); + } catch(Exception e) { + throw new IOException("Failed to read data from " + resource, e); + } + } +} diff --git a/hjson/src/main/java/org/apache/tamaya/hjson/HJSONPropertySource.java b/hjson/src/main/java/org/apache/tamaya/hjson/HJSONPropertySource.java new file mode 100644 index 0000000..c086e29 --- /dev/null +++ b/hjson/src/main/java/org/apache/tamaya/hjson/HJSONPropertySource.java @@ -0,0 +1,130 @@ +/* + * 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.tamaya.hjson; + +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; +import org.hjson.JsonValue; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +import static java.lang.String.format; + +/** + * Property source based on a HJSON file. + */ +public class HJSONPropertySource implements PropertySource { + /** The underlying resource. */ + private final URL urlResource; + /** The values read. */ + private final Map<String, PropertyValue> values; + /** The evaluated ordinal. */ + private int ordinal; + + + /** + * Constructor, hereby using 0 as the default ordinal. + * @param resource the resource modelled as URL, not null. + * @throws IOException if reading the resource fails. + */ + public HJSONPropertySource(URL resource)throws IOException { + this(resource, 0); + } + + /** + * Constructor. + * @param resource the resource modelled as URL, not null. + * @param defaultOrdinal the defaultOrdinal to be used. + * @throws IOException if reading the resource fails. + */ + public HJSONPropertySource(URL resource, int defaultOrdinal)throws IOException { + urlResource = Objects.requireNonNull(resource); + this.ordinal = defaultOrdinal; // may be overriden by read... + this.values = readConfig(urlResource); + if (this.values.containsKey(TAMAYA_ORDINAL)) { + this.ordinal = Double.valueOf(this.values.get(TAMAYA_ORDINAL).getValue()).intValue(); + } + } + + + public int getOrdinal() { + PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL); + if(configuredOrdinal!=null){ + try{ + return Integer.parseInt(configuredOrdinal.getValue()); + } catch(Exception e){ + Logger.getLogger(getClass().getName()).log(Level.WARNING, + "Configured Ordinal is not an int number: " + configuredOrdinal, e); + } + } + return ordinal; + } + + @Override + public String getName() { + return urlResource.toExternalForm(); + } + + @Override + public PropertyValue get(String key) { + return getProperties().get(key); + } + + @Override + public Map<String, PropertyValue> getProperties() { + + return Collections.unmodifiableMap(values); + } + + /** + * Reads the configuration. + * @param urlResource soure of the configuration. + * @return the configuration read from the given resource URL. + * @throws ConfigException if resource URL cannot be read. + * @throws IOException if reading the urlResource fails. + */ + protected Map<String, PropertyValue> readConfig(URL urlResource) throws IOException{ + try (InputStream is = urlResource.openStream()) { + JsonValue root = JsonValue.readHjson(new InputStreamReader(is, Charset.forName("UTF-8"))); + HJSONDataBuilder visitor = new HJSONDataBuilder(urlResource.toString(), root); + Map<String, String> values = visitor.build().toMap(); + Map<String, PropertyValue> result = new HashMap<>(); + for(Map.Entry<String,String> en:values.entrySet()){ + result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); + } + return result; + }catch(IOException ioe){ + throw ioe; + }catch (Exception t) { + throw new IOException(format("Failed to read properties from %s", urlResource.toExternalForm()), t); + } + } + +} diff --git a/hjson/src/main/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProvider.java b/hjson/src/main/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProvider.java new file mode 100644 index 0000000..f6fa174 --- /dev/null +++ b/hjson/src/main/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProvider.java @@ -0,0 +1,58 @@ +/* + * 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.tamaya.hjson; + +import org.apache.tamaya.resource.AbstractPathPropertySourceProvider; +import org.apache.tamaya.spi.PropertySource; + +import java.io.IOException; +import java.net.URL; +import java.util.Collection; +import java.util.Collections; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Path based default provider for hjson formatted config files. + */ +public class PathBasedHJSONPropertySourceProvider extends AbstractPathPropertySourceProvider{ + + private static final Logger LOG = Logger.getLogger(PathBasedHJSONPropertySourceProvider.class.getName()); + private HJSONFormat jsonFormat = new HJSONFormat(); + + public PathBasedHJSONPropertySourceProvider(String... paths) { + super(paths); + } + + @Override + protected Collection<PropertySource> getPropertySources(URL url) { + if(jsonFormat.accepts(url)){ + try { + return Collections.singletonList( + jsonFormat.readConfiguration(url.toString(), url.openStream()).toPropertySource()); + } catch (IOException e) { + LOG.log(Level.SEVERE, "Failed to read yaml file: " +url, e); + } + } + return Collections.emptyList(); + } + +} + + diff --git a/hjson/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat b/hjson/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat new file mode 100644 index 0000000..e8f9bd4 --- /dev/null +++ b/hjson/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat @@ -0,0 +1,19 @@ +# +# 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 current 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. +# +org.apache.tamaya.hjson.HJSONFormat \ No newline at end of file diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/CommonHJSONTestCaseCollection.java b/hjson/src/test/java/org/apache/tamaya/hjson/CommonHJSONTestCaseCollection.java new file mode 100644 index 0000000..8bc7c88 --- /dev/null +++ b/hjson/src/test/java/org/apache/tamaya/hjson/CommonHJSONTestCaseCollection.java @@ -0,0 +1,206 @@ +/* + * 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.tamaya.hjson; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; +import org.apache.tamaya.spisupport.PropertySourceComparator; +import org.hamcrest.CoreMatchers; +import org.hamcrest.Matchers; +import org.junit.Test; + +import java.io.IOException; +import java.net.URL; + +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Class with a collection of common test cases each JSON processing + * class must be able to pass. + */ +public abstract class CommonHJSONTestCaseCollection { + + abstract PropertySource getPropertiesFrom(URL source) throws Exception; + + @Test + public void canReadNonLatinCharacters() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class + .getResource("/configs/valid/cyrillic.hjson"); + + assertThat(configURL, Matchers.notNullValue()); + + PropertySource propertySource = getPropertiesFrom(configURL); + + assertThat(propertySource.get("name"), Matchers.notNullValue()); + assertThat(propertySource.get("name").getValue(), equalTo("\u041e\u043b\u0438\u0432\u0435\u0440")); + assertThat(propertySource.get("\u0444\u0430\u043c\u0438\u043b\u0438\u044f"), Matchers.notNullValue()); + assertThat(propertySource.get("\u0444\u0430\u043c\u0438\u043b\u0438\u044f").getValue(), Matchers.equalTo("Fischer")); + } + + @Test + public void canReadUnicodeCharacters() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class + .getResource("/configs/valid/kanji.hjson"); + + assertThat(configURL, Matchers.notNullValue()); + + PropertySource propertySource = getPropertiesFrom(configURL); + + assertThat(propertySource.get("onamae"), Matchers.notNullValue()); + // 霊屋 = Tamaya + assertThat(propertySource.get("onamae").getValue(), equalTo("\u970a\u5c4b")); + } + + @Test + public void canReadNestedStringOnlyJSONConfigFile2() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class + .getResource("/configs/valid/simple-nested-string-only-config-1.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + PropertySource properties = getPropertiesFrom(configURL); + + System.out.println("simple-nested-string-only-config-1.json -> " + properties.getProperties().values()); + + assertTrue(properties.getProperties().keySet().size()>=5); + + PropertyValue keyB = properties.get("b"); + PropertyValue keyDO = properties.get("d.o"); + PropertyValue keyDP = properties.get("d.p"); + + assertThat(keyB, notNullValue()); + assertThat(keyB.getValue(), equalTo("B")); + assertThat(keyDO, notNullValue()); + assertThat(keyDO.getValue(), equalTo("O")); + assertThat(keyDP, Matchers.notNullValue()); + assertThat(keyDP.getValue(), is("P")); + } + + @Test + public void canReadNestedStringOnlyJSONConfigFileWithObjectInTheMiddle() + throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class + .getResource("/configs/valid/simple-nested-string-only-config-2.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + PropertySource properties = getPropertiesFrom(configURL); + + assertTrue(properties.getProperties().keySet().size()>=4); + + PropertyValue keyA = properties.get("a"); + PropertyValue keyDO = properties.get("b.o"); + PropertyValue keyDP = properties.get("b.p"); + PropertyValue keyC = properties.get("c"); + + assertThat(keyA, notNullValue()); + assertThat(keyA.getValue(), is("A")); + assertThat(keyC, notNullValue()); + assertThat(keyC.getValue(), equalTo("C")); + assertThat(keyDO, notNullValue()); + assertThat(keyDO.getValue(), equalTo("O")); + assertThat(keyDP, notNullValue()); + assertThat(keyDP.getValue(), is("P")); + } + + @Test + public void canHandleIllegalJSONFileWhichContainsAnArray() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/invalid/with-array.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + getPropertiesFrom(configURL).getProperties(); + } + + @Test(expected = IOException.class) + public void canHandleIllegalJSONFileConsistingOfOneOpeningBracket() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/invalid/only-opening-bracket.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + getPropertiesFrom(configURL).getProperties(); + } + + @Test + public void canHandleIllegalJSONFileWhichIsEmpty() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/invalid/empty-file.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + getPropertiesFrom(configURL).getProperties(); + } + + @Test + public void priorityInConfigFileOverwriteExplicitlyGivenPriority() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/valid/with-explicit-priority.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + PropertySource properties = getPropertiesFrom(configURL); + + assertThat(PropertySourceComparator.getOrdinal(properties), is(16784)); + } + + @Test + public void canReadFlatStringOnlyJSONConfigFile() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/valid/simple-flat-string-only-config.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + PropertySource properties = getPropertiesFrom(configURL); + + assertEquals(3, properties.getProperties().size()); + + PropertyValue keyA = properties.get("a"); + PropertyValue keyB = properties.get("b"); + PropertyValue keyC = properties.get("c"); + + assertThat(keyA, notNullValue()); + assertThat(keyA.getValue(), equalTo("A")); + assertThat(keyB, notNullValue()); + assertThat(keyB.getValue(), is("B")); + assertThat(keyC, notNullValue()); + assertThat(keyC.getValue(), is("C")); + } + + @Test + public void emptyJSONFileResultsInConfigException() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/invalid/empty-file.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + PropertySource properties = getPropertiesFrom(configURL); + + properties.getProperties(); + } + + @Test + public void canHandleEmptyJSONObject() throws Exception { + URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/valid/empty-object-config.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + PropertySource properties = getPropertiesFrom(configURL); + + assertTrue(properties.getProperties().keySet().size()>=0); + } +} diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatIT.java b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatIT.java new file mode 100644 index 0000000..976c781 --- /dev/null +++ b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatIT.java @@ -0,0 +1,48 @@ +/* + * 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.tamaya.hjson; + +import org.apache.tamaya.format.ConfigurationFormat; +import org.apache.tamaya.spi.ServiceContextManager; +import org.junit.Test; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.notNullValue; + +/** + * Integration tests for {@link HJSONFormat}. + */ +public class HJSONFormatIT { + @Test + public void jsonFormatCanBeFoundViaServiceLoader() throws Exception { + List<ConfigurationFormat> formats = ServiceContextManager.getServiceContext() + .getServices(ConfigurationFormat.class); + + ConfigurationFormat format = null; + for (ConfigurationFormat f : formats) { + if (f instanceof HJSONFormat) { + format = f; + break; + } + } + assertThat(format, notNullValue()); + } +} diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatTest.java b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatTest.java new file mode 100644 index 0000000..2713b0f --- /dev/null +++ b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatTest.java @@ -0,0 +1,75 @@ +/* + * 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.tamaya.hjson; + + +import org.apache.tamaya.format.ConfigurationData; +import org.apache.tamaya.format.MappedConfigurationDataPropertySource; +import org.apache.tamaya.spi.PropertySource; +import org.junit.Test; + +import java.io.InputStream; +import java.net.URL; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +public class HJSONFormatTest extends CommonHJSONTestCaseCollection { + private final HJSONFormat format = new HJSONFormat(); + + @Test(expected = NullPointerException.class) + public void acceptsNeedsNonNullParameter() throws Exception { + format.accepts(null); + } + + @Test + public void aNonJSONFileBasedURLIsNotAccepted() throws Exception { + URL url = new URL("file:///etc/service/conf.conf"); + + assertThat(format.accepts(url), is(false)); + } + + @Test + public void aJSONFileBasedURLIsAccepted() throws Exception { + URL url = new URL("file:///etc/service/conf.hjson"); + + assertThat(format.accepts(url), is(true)); + } + + @Test + public void aHTTPBasedURLIsNotAccepted() throws Exception { + URL url = new URL("http://nowhere.somewhere/conf.hjson"); + assertThat(format.accepts(url), is(true)); + } + + @Test + public void aFTPBasedURLIsNotAccepted() throws Exception { + URL url = new URL("ftp://nowhere.somewhere/a/b/c/d/conf.hjson"); + + assertThat(format.accepts(url), is(true)); + } + + @Override + PropertySource getPropertiesFrom(URL source) throws Exception { + try (InputStream is = source.openStream()) { + ConfigurationData data = format.readConfiguration(source.toString(), is); + return new MappedConfigurationDataPropertySource(data); + } + } +} \ No newline at end of file diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONPropertySourceTest.java b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONPropertySourceTest.java new file mode 100644 index 0000000..25c9f6d --- /dev/null +++ b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONPropertySourceTest.java @@ -0,0 +1,55 @@ +/* + * 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.tamaya.hjson; + +import org.apache.tamaya.spi.PropertySource; +import org.hamcrest.CoreMatchers; +import org.junit.Test; + +import java.net.URL; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; + +public class HJSONPropertySourceTest extends CommonHJSONTestCaseCollection { + + @Test + public void tamayaOrdinalKeywordIsNotPropagatedAsNormalProperty() throws Exception { + URL configURL = HJSONPropertySourceTest.class.getResource("/configs/valid/with-explicit-priority.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + HJSONPropertySource source = new HJSONPropertySource(configURL, 4); + assertEquals(source.getOrdinal(), 16784); + } + + @Test + public void testAcceptJsonArrays() throws Exception { + URL configURL = HJSONPropertySourceTest.class.getResource("/configs/invalid/array.hjson"); + + assertThat(configURL, CoreMatchers.notNullValue()); + + new HJSONPropertySource(configURL); + } + + @Override + PropertySource getPropertiesFrom(URL source) throws Exception { + return new HJSONPropertySource(source); + } +} diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONVisitorTest.java b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONVisitorTest.java new file mode 100644 index 0000000..a662dc8 --- /dev/null +++ b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONVisitorTest.java @@ -0,0 +1,92 @@ +/* + * 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.tamaya.hjson; + +import org.apache.tamaya.spi.ObjectValue; +import org.apache.tamaya.spi.PropertyValue; +import org.hjson.JsonArray; +import org.hjson.JsonObject; +import org.hjson.JsonValue; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class HJSONVisitorTest { + + @Test + public void ensureJSONisParsedProperlyWithDifferentValueTypesFilteringOutEmptyValues() { + JsonObject startNode = new JsonObject().// + add("key.sub", "createValue").// + add("anotherKey", true).// + add("notAnotherKey", false).// + add("number", 4711).// + add("null", JsonValue.NULL).// + add("empty", ""); + HJSONDataBuilder visitor = new HJSONDataBuilder("Test:ensureJSONisParsedProperlyWithDifferentValueTypesFilteringOutEmptyValues", startNode); + + PropertyValue data = visitor.build(); + assertThat(data).isNotNull(); + + ObjectValue ov = data.toObjectValue(); + assertThat(ov.getValues().size()).isEqualTo(6); + assertThat(data.toMap()).containsKeys("key.sub", "anotherKey", "notAnotherKey", "number", "null"); + assertThat(data.toMap()).containsEntry("key.sub", "createValue"); + assertThat(data.toMap()).containsEntry("null", null); + assertThat(data.toMap()).containsEntry("anotherKey", "true"); + assertThat(data.toMap()).doesNotContainEntry("empty", null); + } + + @Test + public void parsingWorksOnEmptyObject() { + JsonObject startNode = new JsonObject(); + + Map<String, String> targetStore = new HashMap<>(); + + HJSONDataBuilder visitor = new HJSONDataBuilder("Test:parsingWorksOnEmptyObject", startNode); + PropertyValue data = visitor.build(); + assertThat(data).isNotNull(); + assertThat(data.isLeaf()); + } + + @Test + public void arrayInObject() { + JsonObject startNode = new JsonObject(). + add("arrayKey", new JsonArray()); + HJSONDataBuilder visitor = new HJSONDataBuilder("Test:array", startNode); + PropertyValue data = visitor.build(); + assertThat(data).isNotNull(); + System.out.println(data.asString()); + } + + @Test + public void array() { + JsonArray startNode = new JsonArray(). + add(new JsonObject().add("k1", 1).add("k2", 2)). + add(new JsonObject().add("k1", 1).add("k2", 2)). + add(new JsonArray().add(new JsonObject().add("k31", "v31").add("k32", false))); + HJSONDataBuilder visitor = new HJSONDataBuilder("Test:array", startNode); + PropertyValue data = visitor.build(); + assertThat(data).isNotNull(); + System.out.println(data.asString()); + } + +} diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProviderTest.java b/hjson/src/test/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProviderTest.java new file mode 100644 index 0000000..ab9c5d2 --- /dev/null +++ b/hjson/src/test/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProviderTest.java @@ -0,0 +1,66 @@ +/* + * 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.tamaya.hjson; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * Tests for {@link PathBasedHJSONPropertySourceProvider}. + */ +public class PathBasedHJSONPropertySourceProviderTest { + + @Test + public void getPropertySources() { + PathBasedHJSONPropertySourceProvider provider = new PathBasedHJSONPropertySourceProvider( + "configs/valid/*.hjson" + ); + assertNotNull(provider.getPropertySources()); + assertEquals(7, provider.getPropertySources().size()); + } + + @Test + public void getPropertySources_one() { + PathBasedHJSONPropertySourceProvider provider = new PathBasedHJSONPropertySourceProvider( + "configs/valid/cyril*.hjson" + ); + assertNotNull(provider.getPropertySources()); + assertEquals(1, provider.getPropertySources().size()); + } + + @Test + public void getPropertySources_two() { + PathBasedHJSONPropertySourceProvider provider = new PathBasedHJSONPropertySourceProvider( + "configs/valid/simple-*.hjson" + ); + assertNotNull(provider.getPropertySources()); + assertEquals(3, provider.getPropertySources().size()); + } + + @Test + public void getPropertySources_none() { + PathBasedHJSONPropertySourceProvider provider = new PathBasedHJSONPropertySourceProvider( + "configs/valid/foo*.hjson", "configs/valid/*.HJSON" + ); + assertNotNull(provider.getPropertySources()); + assertEquals(0, provider.getPropertySources().size()); + } +} \ No newline at end of file diff --git a/hjson/src/test/resources/META-INF/javaconfiguration.properties b/hjson/src/test/resources/META-INF/javaconfiguration.properties new file mode 100644 index 0000000..e66e448 --- /dev/null +++ b/hjson/src/test/resources/META-INF/javaconfiguration.properties @@ -0,0 +1,22 @@ +# 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. + +# The space before the actual date is intended! +dateTimeValue= 2010-08-08T14:00:15.5+10:00 +dateTimeZoneValueA=UTC +dateTimeZoneValueB=+01:00 +periodValueA=P1Y1M1W1DT1H1M1S diff --git a/hjson/src/test/resources/configs/invalid/array.hjson b/hjson/src/test/resources/configs/invalid/array.hjson new file mode 100644 index 0000000..0c2058a --- /dev/null +++ b/hjson/src/test/resources/configs/invalid/array.hjson @@ -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. +*/ +[ + +] \ No newline at end of file diff --git a/hjson/src/test/resources/configs/invalid/empty-file.hjson b/hjson/src/test/resources/configs/invalid/empty-file.hjson new file mode 100644 index 0000000..f396085 --- /dev/null +++ b/hjson/src/test/resources/configs/invalid/empty-file.hjson @@ -0,0 +1,18 @@ +/* +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. +*/ \ No newline at end of file diff --git a/hjson/src/test/resources/configs/invalid/only-opening-bracket.hjson b/hjson/src/test/resources/configs/invalid/only-opening-bracket.hjson new file mode 100644 index 0000000..b936f69 --- /dev/null +++ b/hjson/src/test/resources/configs/invalid/only-opening-bracket.hjson @@ -0,0 +1,19 @@ +/* +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. +*/ +{ \ No newline at end of file diff --git a/hjson/src/test/resources/configs/invalid/with-array.hjson b/hjson/src/test/resources/configs/invalid/with-array.hjson new file mode 100644 index 0000000..e623e49 --- /dev/null +++ b/hjson/src/test/resources/configs/invalid/with-array.hjson @@ -0,0 +1,27 @@ +/* +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. +*/ +{ + "a" : "A", + "b" : { + "c" : "C", + "d" : [ + "1", "2" + ] + } +} \ No newline at end of file diff --git a/hjson/src/test/resources/configs/valid/cyrillic.hjson b/hjson/src/test/resources/configs/valid/cyrillic.hjson new file mode 100644 index 0000000..da86e77 --- /dev/null +++ b/hjson/src/test/resources/configs/valid/cyrillic.hjson @@ -0,0 +1,22 @@ +/* +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. +*/ +{ + name : "Оливер", + фамилия : "Fischer" +} \ No newline at end of file diff --git a/hjson/src/test/resources/configs/valid/empty-object-config.hjson b/hjson/src/test/resources/configs/valid/empty-object-config.hjson new file mode 100644 index 0000000..103c28d --- /dev/null +++ b/hjson/src/test/resources/configs/valid/empty-object-config.hjson @@ -0,0 +1,20 @@ +/* +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. +*/ +{ +} \ No newline at end of file diff --git a/hjson/src/test/resources/configs/valid/kanji.hjson b/hjson/src/test/resources/configs/valid/kanji.hjson new file mode 100644 index 0000000..1d1c54a --- /dev/null +++ b/hjson/src/test/resources/configs/valid/kanji.hjson @@ -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. +*/ +{ + onamae : 霊屋 +} \ No newline at end of file diff --git a/hjson/src/test/resources/configs/valid/simple-flat-string-only-config.hjson b/hjson/src/test/resources/configs/valid/simple-flat-string-only-config.hjson new file mode 100644 index 0000000..d961b62 --- /dev/null +++ b/hjson/src/test/resources/configs/valid/simple-flat-string-only-config.hjson @@ -0,0 +1,23 @@ +/* +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. +*/ +{ + a : A + b : B + c : C +} \ No newline at end of file diff --git a/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-1.hjson b/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-1.hjson new file mode 100644 index 0000000..622cf29 --- /dev/null +++ b/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-1.hjson @@ -0,0 +1,27 @@ +/* +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. +*/ +{ + a: A + b: B + c: C + d: { + o: O + p: P + } +} diff --git a/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-2.hjson b/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-2.hjson new file mode 100644 index 0000000..a43aee6 --- /dev/null +++ b/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-2.hjson @@ -0,0 +1,26 @@ +/* +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. +*/ +{ + a : A + b : { + o : O + p : P + } + c : C +} diff --git a/hjson/src/test/resources/configs/valid/with-explicit-priority.hjson b/hjson/src/test/resources/configs/valid/with-explicit-priority.hjson new file mode 100644 index 0000000..aa0d8e1 --- /dev/null +++ b/hjson/src/test/resources/configs/valid/with-explicit-priority.hjson @@ -0,0 +1,25 @@ +/* +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. +*/ +{ + /* + some useful comment here + */ + tamaya.ordinal : 16784 + a : A // another comment +} diff --git a/pom.xml b/pom.xml index 167366d..54e1de2 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ under the License. <json.spec.version>1.0</json.spec.version> <johnzon.version>1.1.8</johnzon.version> <junit.version>4.12</junit.version> - <assertj.version>3.8.0</assertj.version> + <assertj.version>3.10.0</assertj.version> <surefire.version>2.21.0</surefire.version> <!-- Java EE modules for compiling on JDK9+ --> @@ -810,6 +810,7 @@ under the License. <module>vertx</module> <module>configjsr</module> <module>documentation</module> + <module>hjson</module> <!-- Once the API is officially available ... --> <!-- module>configjsr</module--> </modules> diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java index 43e88f6..6c60983 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java @@ -117,7 +117,7 @@ public final class UsageStat { /** * Access access details for a given class. - * @param type class to getField usage access stats for, not null. + * @param type class to getValue usage access stats for, not null. * @return the usage ref, if present, or null. */ public Collection<AccessStats> getAccessDetails(Class type){ @@ -126,7 +126,7 @@ public final class UsageStat { /** * Access access details for a given package. - * @param pack package to getField usage access stats for, not null. + * @param pack package to getValue usage access stats for, not null. * @return the usage ref, if present, or null. */ public Collection<AccessStats> getAccessDetails(Package pack){ diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java index cdaad4f..e691ec6 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java @@ -84,7 +84,7 @@ public interface ConfigUsageSpi { void recordAllPropertiesAccess(ConfigurationContext context); /** - * Track the access of {@code Configuration#getField(String)} for + * Track the access of {@code Configuration#getValue(String)} for * usage statistics. * @param context the corresponding context. * @param value createValue to track for
