diff options
author | vasraz <vasyl.razinkov@est.tech> | 2023-08-29 15:29:59 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-09-05 09:50:12 +0000 |
commit | 438650c3a958c9176db3720204ec1ff9af94fc3a (patch) | |
tree | f0dc5b6b5bd837a6f689245e8a41d36d0a488f9b /common-app-api | |
parent | 0c47a1b7118b45eecbbb0064b635efb026173ec4 (diff) |
Improve handling 'empty'/null string in Service fields
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Ib301280fe1be2896e2d80e208349ac3c4ff763ec
Issue-ID: SDC-4608
Diffstat (limited to 'common-app-api')
3 files changed, 14 insertions, 47 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java b/common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java index a0403de8ff..7c5e5fc1eb 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java @@ -215,7 +215,7 @@ public class ValidationUtils { } public static boolean validateResourceInstanceNameLength(String resourceInstanceName) { - return resourceInstanceName.length() <= RSI_NAME_MAX_LENGTH; + return StringUtils.isEmpty(resourceInstanceName) || resourceInstanceName.length() <= RSI_NAME_MAX_LENGTH; } public static boolean validateResourceInstanceName(String resourceInstanceName) { @@ -223,7 +223,7 @@ public class ValidationUtils { } public static boolean validateUrlLength(String url) { - return url.length() <= API_URL_LENGTH; + return StringUtils.isEmpty(url) || url.length() <= API_URL_LENGTH; } public static boolean validateArtifactNameLength(String artifactName) { @@ -235,7 +235,7 @@ public class ValidationUtils { } public static boolean validateComponentNameLength(String componentName) { - return componentName.length() <= COMPONENT_NAME_MAX_LENGTH; + return StringUtils.isEmpty(componentName) || componentName.length() <= COMPONENT_NAME_MAX_LENGTH; } public static boolean validateIcon(String icon) { @@ -243,7 +243,7 @@ public class ValidationUtils { } public static boolean validateIconLength(String icon) { - return icon.length() <= ICON_MAX_LENGTH; + return StringUtils.isEmpty(icon) || icon.length() <= ICON_MAX_LENGTH; } public static boolean validateProjectCode(String projectCode) { @@ -251,7 +251,7 @@ public class ValidationUtils { } public static boolean validateProjectCodeLegth(String projectCode) { - return projectCode.length() <= PROJECT_CODE_MAX_LEGTH; + return StringUtils.isEmpty(projectCode) || projectCode.length() <= PROJECT_CODE_MAX_LEGTH; } public static boolean validateContactId(String contactId) { @@ -340,14 +340,7 @@ public class ValidationUtils { } public static boolean validateDescriptionLength(String description) { - return description.length() <= COMPONENT_DESCRIPTION_MAX_LENGTH; - } - - public static boolean validateStringNotEmpty(String value) { - if ((value == null) || (value.isEmpty())) { - return false; - } - return true; + return StringUtils.isEmpty(description) || description.length() <= COMPONENT_DESCRIPTION_MAX_LENGTH; } public static boolean validateListNotEmpty(List<?> list) { @@ -362,35 +355,35 @@ public class ValidationUtils { } public static boolean validateVendorNameLength(String vendorName) { - return vendorName.length() <= VENDOR_NAME_MAX_LENGTH; + return StringUtils.isEmpty(vendorName) || vendorName.length() <= VENDOR_NAME_MAX_LENGTH; } public static boolean validateResourceVendorModelNumberLength(String resourceVendorModelNumber) { - return resourceVendorModelNumber.length() <= RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH; + return StringUtils.isEmpty(resourceVendorModelNumber) || resourceVendorModelNumber.length() <= RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH; } public static boolean validateVendorRelease(String vendorRelease) { - return VENDOR_RELEASE_PATTERN.matcher(vendorRelease).matches(); + return StringUtils.isEmpty(vendorRelease) || VENDOR_RELEASE_PATTERN.matcher(vendorRelease).matches(); } public static boolean validateVendorReleaseLength(String vendorRelease) { - return vendorRelease.length() <= VENDOR_RELEASE_MAX_LENGTH; + return StringUtils.isEmpty(vendorRelease) || vendorRelease.length() <= VENDOR_RELEASE_MAX_LENGTH; } public static boolean validateServiceTypeLength(String serviceType) { - return serviceType.length() <= SERVICE_TYPE_MAX_LENGTH; + return StringUtils.isEmpty(serviceType) || serviceType.length() <= SERVICE_TYPE_MAX_LENGTH; } public static boolean validateServiceRoleLength(String serviceRole) { - return serviceRole.length() <= SERVICE_ROLE_MAX_LENGTH; + return StringUtils.isEmpty(serviceRole) || serviceRole.length() <= SERVICE_ROLE_MAX_LENGTH; } public static boolean validateServiceFunctionLength(String serviceFunction) { - return serviceFunction.length() <= SERVICE_FUNCTION_MAX_LENGTH; + return StringUtils.isEmpty(serviceFunction) || serviceFunction.length() <= SERVICE_FUNCTION_MAX_LENGTH; } public static boolean validateServiceNamingPolicyLength(String namingPolicy) { - return namingPolicy.length() <= SERVICE_NAMING_POLICY_MAX_SIZE; + return StringUtils.isEmpty(namingPolicy) || namingPolicy.length() <= SERVICE_NAMING_POLICY_MAX_SIZE; } public static boolean hasBeenCertified(String version) { diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/test/CommonUtilsTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/test/CommonUtilsTest.java index 73d8c116e2..ca9cc0b068 100644 --- a/common-app-api/src/test/java/org/openecomp/sdc/common/test/CommonUtilsTest.java +++ b/common-app-api/src/test/java/org/openecomp/sdc/common/test/CommonUtilsTest.java @@ -225,14 +225,6 @@ public class CommonUtilsTest { } @Test - public void validateStringNotEmptyTest() { - assertTrue(ValidationUtils.validateStringNotEmpty("fsdlfsdlk")); - assertFalse(ValidationUtils.validateStringNotEmpty("")); - assertFalse(!ValidationUtils.validateStringNotEmpty(" ")); - assertFalse(!ValidationUtils.validateStringNotEmpty(" ")); - } - - @Test public void validateVendorNameTest() { assertTrue(ValidationUtils.validateVendorName("fsdlfsdlk")); assertTrue(ValidationUtils.validateVendorName("fsdlfsdlk.sdsd;")); diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java index e7aad96f60..3408c684de 100644 --- a/common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java +++ b/common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java @@ -526,24 +526,6 @@ public class ValidationUtilsTest { } @Test - public void checkValidateStringNotEmptyReturnsFalseIfStringIsNotEmpty() { - final String testString = "test"; - - boolean result = ValidationUtils.validateStringNotEmpty(testString); - - assertTrue(result); - } - - @Test - public void checkValidateStringNotEmptyReturnsFTrueIfStringIsEmpty() { - final String testString = ""; - - boolean result = ValidationUtils.validateStringNotEmpty(testString); - - assertFalse(result); - } - - @Test public void checkValidateVendorNameReturnsTrueIfNameFitsPattern() { final String testVendorName = "testVendor"; |