diff --git a/metacat-common-server/src/main/java/com/netflix/metacat/common/server/properties/ParentChildRelationshipProperties.java b/metacat-common-server/src/main/java/com/netflix/metacat/common/server/properties/ParentChildRelationshipProperties.java index c8152595..39aae354 100644 --- a/metacat-common-server/src/main/java/com/netflix/metacat/common/server/properties/ParentChildRelationshipProperties.java +++ b/metacat-common-server/src/main/java/com/netflix/metacat/common/server/properties/ParentChildRelationshipProperties.java @@ -58,11 +58,9 @@ public ParentChildRelationshipProperties(@Nullable final Environment env) { * @param configStr configString */ public void setMaxAllowPerTablePerRelType(@Nullable final String configStr) { - if (configStr == null || configStr.isEmpty()) { - return; - } try { - this.maxAllowPerTablePerRelType = parseNestedConfigString(configStr); + this.maxAllowPerTablePerRelType = configStr == null || configStr.isEmpty() + ? new HashMap<>() : parseNestedConfigString(configStr); } catch (Exception e) { log.error("Fail to apply configStr = {} for maxAllowPerTablePerRelType", configStr, e); } @@ -74,11 +72,9 @@ public void setMaxAllowPerTablePerRelType(@Nullable final String configStr) { * @param configStr configString */ public void setMaxAllowPerDBPerRelType(@Nullable final String configStr) { - if (configStr == null || configStr.isEmpty()) { - return; - } try { - this.maxAllowPerDBPerRelType = parseNestedConfigString(configStr); + this.maxAllowPerDBPerRelType = configStr == null || configStr.isEmpty() + ? new HashMap<>() : parseNestedConfigString(configStr); } catch (Exception e) { log.error("Fail to apply configStr = {} for maxCloneAllowPerDBPerRelType", configStr); } @@ -89,12 +85,10 @@ public void setMaxAllowPerDBPerRelType(@Nullable final String configStr) { * @param configStr configString */ public void setDefaultMaxAllowPerRelType(@Nullable final String configStr) { - if (configStr == null || configStr.isEmpty()) { - return; - } try { - this.defaultMaxAllowPerRelType = - Arrays.stream(configStr.split(";")) + this.defaultMaxAllowPerRelType = configStr == null || configStr.isEmpty() + ? new HashMap<>() + : Arrays.stream(configStr.split(";")) .map(entry -> entry.split(",")) .collect(Collectors.toMap( parts -> parts[0], diff --git a/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/ParentChildRelMetadataServiceSpec.groovy b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/ParentChildRelMetadataServiceSpec.groovy index c199b12f..101b833c 100644 --- a/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/ParentChildRelMetadataServiceSpec.groovy +++ b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/ParentChildRelMetadataServiceSpec.groovy @@ -618,4 +618,38 @@ class ParentChildRelMetadataServiceSpec extends Specification{ 1 | "CLONE,5" | "CLONE,test,3;OTHER,other,2"| "CLONE,testhive/test/parent,2" | 2 1 | "CLONE,5;Other,3" | "CLONE,test,3;CLONE,other,2"| "CLONE,testhive/test/parent,2;CLONE,testhive/test/other,2" | 2 } + + def "test empty/null input string for config"() { + given: + def parentChildProps = new ParentChildRelationshipProperties(null) + + when: "Setting properties to non empty string" + parentChildProps.setDefaultMaxAllowPerRelType("CLONE,5;Other,3") + parentChildProps.setMaxAllowPerDBPerRelType("CLONE,test,3;CLONE,other,2") + parentChildProps.setMaxAllowPerTablePerRelType("CLONE,testhive/test/parent,2;CLONE,testhive/test/other,2") + + then: + assert parentChildProps.getDefaultMaxAllowPerRelType().size() == 2 + assert parentChildProps.getMaxAllowPerDBPerRelType().size() == 2 + assert parentChildProps.getMaxAllowPerTablePerRelType().size() == 2 + + when: "Setting properties to empty or null based on the isEmpty flag" + if (isEmpty) { + parentChildProps.setDefaultMaxAllowPerRelType("") + parentChildProps.setMaxAllowPerDBPerRelType("") + parentChildProps.setMaxAllowPerTablePerRelType("") + } else { + parentChildProps.setDefaultMaxAllowPerRelType(null) + parentChildProps.setMaxAllowPerDBPerRelType(null) + parentChildProps.setMaxAllowPerTablePerRelType(null) + } + + then: "The properties should be empty" + assert parentChildProps.getDefaultMaxAllowPerRelType().isEmpty() + assert parentChildProps.getMaxAllowPerDBPerRelType().isEmpty() + assert parentChildProps.getMaxAllowPerTablePerRelType().isEmpty() + + where: + isEmpty << [true, false] + } }