Ate Douma pushed to branch release/1.0 at cms-community / hippo-configuration-management
Commits: eb6665d1 by Peter Centgraf at 2017-09-28T16:40:20+02:00 HCM-216 Handle case of explicit .meta:category: config on a property with empty array value; more in-line comments about category validation logic (cherry picked from commit 02e9fcb316314146bc7edee1dfae1c46e1a18443) - - - - - 2 changed files: - model/src/main/java/org/onehippo/cm/model/impl/tree/ConfigurationTreeBuilder.java - model/src/test/java/org/onehippo/cm/model/impl/ConfigurationTreeBuilderTest.java Changes: ===================================== model/src/main/java/org/onehippo/cm/model/impl/tree/ConfigurationTreeBuilder.java ===================================== --- a/model/src/main/java/org/onehippo/cm/model/impl/tree/ConfigurationTreeBuilder.java +++ b/model/src/main/java/org/onehippo/cm/model/impl/tree/ConfigurationTreeBuilder.java @@ -550,16 +550,14 @@ public class ConfigurationTreeBuilder { if (category != null) { if (category == ConfigurationItemCategory.CONFIG) { - if (definitionProperty.getType() != PropertyType.SINGLE && definitionProperty.getValues().length==0) { - // Defining a property as config with no values is an error - throw new IllegalStateException(String.format( - "Missing required value(s) for config property '%s', defined in '%s'.", - definitionProperty.getJcrPath(), definitionProperty.getOrigin())); - } + // we're recategorizing back to config -- reset previous category info + // note: value(s) will be processed below, and the case of an unspecified value is blocked by both + // the parser and the object model impl. parent.clearChildPropertyCategorySettings(name); } else if (category == ConfigurationItemCategory.CONTENT) { // it doesn't make sense to define a single property as content - // TODO: shouldn't this be an IllegalStateException??? + // this case is blocked by both the parser and the object model impl, but we check here just to be + // extra paranoid about safety logger.warn("Trying to define a property on a config node as content '{}', defined in '{}'. Skipping.", definitionProperty.getJcrPath(), definitionProperty.getOrigin()); return this; ===================================== model/src/test/java/org/onehippo/cm/model/impl/ConfigurationTreeBuilderTest.java ===================================== --- a/model/src/test/java/org/onehippo/cm/model/impl/ConfigurationTreeBuilderTest.java +++ b/model/src/test/java/org/onehippo/cm/model/impl/ConfigurationTreeBuilderTest.java @@ -1136,6 +1136,34 @@ public class ConfigurationTreeBuilderTest { assertEquals("bla4", property2.getValues()[1].getString()); } + + @Test + public void empty_list_property_with_explicit_config_category() throws Exception { + final String yaml = "definitions:\n" + + " config:\n" + + " /a:\n" + + " jcr:primaryType: foo\n" + + " property1: bla1\n" + + " /b:\n" + + " jcr:primaryType: foo\n" + + " property2: \n" + + " .meta:category: config\n" + + " value: []\n"; + + final List<AbstractDefinitionImpl> definitions = ModelTestUtils.parseNoSort(yaml); + + builder.push((ContentDefinitionImpl)definitions.get(0)); + final ConfigurationNodeImpl root = builder.finishModule().build(); + + final ConfigurationNodeImpl a = root.getNode("a[1]"); + final ConfigurationNodeImpl b = a.getNode("b[1]"); + assertEquals("[jcr:primaryType, property2]", sortedCollectionToString(b.getProperties())); + final ConfigurationPropertyImpl property2 = b.getProperty("property2"); + assertEquals(PropertyType.LIST, property2.getType()); + assertEquals(ValueType.STRING, property2.getValueType()); + assertEquals(0, property2.getValues().length); + } + @Test public void replace_list_property_with_equal_values() throws Exception { final String yaml = "definitions:\n" View it on GitLab: https://code.onehippo.org/cms-community/hippo-configuration-management/commit/eb6665d12c5338688473cd9f631c0d1aa82d7241 --- View it on GitLab: https://code.onehippo.org/cms-community/hippo-configuration-management/commit/eb6665d12c5338688473cd9f631c0d1aa82d7241 You're receiving this email because of your account on code.onehippo.org.
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn