import fj.data.Either;
import java.util.List;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
* @return
*/
private Either<String, ResponseFormat> validateValue(String value) {
- boolean isNonEmptyString = ValidationUtils.validateStringNotEmpty(value);
- if (!isNonEmptyString) {
+ if (StringUtils.isEmpty(value)) {
return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED));
}
boolean valid = StringValidator.getInstance().isValid(value, null);
AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
additionalInfoParameterInfo.setKey(key);
String normKey = ValidationUtils.normalizeAdditionalInformation(key);
- boolean isNonEmptyString = ValidationUtils.validateStringNotEmpty(normKey);
- if (!isNonEmptyString) {
+ if (StringUtils.isEmpty(normKey)) {
return Either.right(componentsUtils
.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, null, null,
AdditionalInformationEnum.Label));
}
private Either<Boolean, ResponseFormat> validateAndServiceApiUrl(ArtifactDefinition artifactInfo) {
- if (!ValidationUtils.validateStringNotEmpty(artifactInfo.getApiUrl())) {
+ if (StringUtils.isEmpty(artifactInfo.getApiUrl())) {
log.debug("Artifact url cannot be empty.");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_URL));
}
List<HeatParameterDefinition> empltyHeatValues = new ArrayList<>();
for (HeatParameterDefinition heatParameterDefinition : heatParameters) {
String heatValue = heatParameterDefinition.getCurrentValue();
- if (!ValidationUtils.validateStringNotEmpty(heatValue)) {
+ if (StringUtils.isEmpty(heatValue)) {
heatValue = heatParameterDefinition.getDefaultValue();
- if (!ValidationUtils.validateStringNotEmpty(heatValue)) {
+ if (StringUtils.isEmpty(heatValue)) {
empltyHeatValues.add(heatParameterDefinition);
continue;
}
log.debug("validate Icon");
ComponentTypeEnum type = component.getComponentType();
String icon = component.getIcon();
- if (!ValidationUtils.validateStringNotEmpty(icon)) {
+ if (StringUtils.isEmpty(icon)) {
log.info("icon is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
import fj.data.Either;
import java.util.Date;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
private Either<ConsumerDefinition, ResponseFormat> validateConsumerName(ConsumerDefinition consumer) {
String name = consumer.getConsumerName();
- if (!ValidationUtils.validateStringNotEmpty(name)) {
+ if (StringUtils.isEmpty(name)) {
log.debug("Consumer name cannot be empty.");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, CONSUMER_NAME));
}
private Either<ConsumerDefinition, ResponseFormat> validateConsumerPassword(ConsumerDefinition consumer) {
String password = consumer.getConsumerPassword();
- if (!ValidationUtils.validateStringNotEmpty(password)) {
+ if (StringUtils.isEmpty(password)) {
log.debug("Consumer password cannot be empty.");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, CONSUMER_PW));
}
private Either<ConsumerDefinition, ResponseFormat> validateConsumerSalt(ConsumerDefinition consumer) {
String salt = consumer.getConsumerSalt();
- if (!ValidationUtils.validateStringNotEmpty(salt)) {
+ if (StringUtils.isEmpty(salt)) {
log.debug("Consumer salt cannot be empty.");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, CONSUMER_SALT));
}
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
// remove duplicated entries
for (CategoryDefinition cat : categories) {
String catName = cat.getName();
- if (!ValidationUtils.validateStringNotEmpty(catName)) {
+ if (StringUtils.isEmpty(catName)) {
// error missing cat name
log.debug("Missing category name for product: {}", product.getName());
ResponseFormat responseFormat = componentsUtils
}
for (SubCategoryDefinition subcat : subcategories) {
String subCatName = subcat.getName();
- if (!ValidationUtils.validateStringNotEmpty(subCatName)) {
+ if (StringUtils.isEmpty(subCatName)) {
// error missing sub cat name for cat
log.debug("Missing or empty sub-category for category {} in product {}", catName, product.getName());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
List<GroupingDefinition> groupings = subcat.getGroupings();
for (GroupingDefinition group : groupings) {
String groupName = group.getName();
- if (!ValidationUtils.validateStringNotEmpty(groupName)) {
+ if (StringUtils.isEmpty(groupName)) {
// error missing grouping for sub cat name and cat
log.debug("Missing or empty groupng name for sub-category: {} for categor: {} in product: {}", subCatName, catName,
product.getName());
private Either<Boolean, ResponseFormat> validateProductFullNameAndCleanup(User user, Product product, AuditingActionEnum actionEnum) {
String fullName = product.getFullName();
- if (!ValidationUtils.validateStringNotEmpty(fullName)) {
+ if (StringUtils.isEmpty(fullName)) {
ResponseFormat errorResponse = componentsUtils
.getResponseFormat(ActionStatus.MISSING_ONE_OF_COMPONENT_NAMES, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_FULL_NAME);
componentsUtils.auditComponentAdmin(errorResponse, user, product, actionEnum, ComponentTypeEnum.PRODUCT);
private Either<Boolean, ResponseFormat> validateProductNameAndCleanup(User user, Product product, AuditingActionEnum actionEnum) {
String name = product.getName();
- if (!ValidationUtils.validateStringNotEmpty(name)) {
+ if (StringUtils.isEmpty(name)) {
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.MISSING_ONE_OF_COMPONENT_NAMES, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_ABBREVIATED_NAME);
componentsUtils.auditComponentAdmin(responseFormat, user, product, actionEnum, ComponentTypeEnum.PRODUCT);
throw new ByActionStatusComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
}
SubCategoryDefinition subcategory = subcategories.get(0);
- if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+ if (StringUtils.isEmpty(category.getName())) {
log.debug(CATEGORY_IS_EMPTY);
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
}
- if (!ValidationUtils.validateStringNotEmpty(subcategory.getName())) {
+ if (StringUtils.isEmpty(subcategory.getName())) {
log.debug(CATEGORY_IS_EMPTY);
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
public void validateVendorReleaseName(User user, Resource resource, AuditingActionEnum actionEnum) {
String vendorRelease = resource.getVendorRelease();
log.debug("validate vendor relese name");
- if (!ValidationUtils.validateStringNotEmpty(vendorRelease)) {
+ if (StringUtils.isEmpty(vendorRelease)) {
log.info("vendor relese name is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_RELEASE);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
private void validateVendorName(User user, Resource resource, AuditingActionEnum actionEnum) {
String vendorName = resource.getVendorName();
- if (!ValidationUtils.validateStringNotEmpty(vendorName)) {
+ if (StringUtils.isEmpty(vendorName)) {
log.info("vendor name is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_NAME);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
public void validateVendorReleaseName(User user, Resource resource, AuditingActionEnum actionEnum) {
String vendorRelease = resource.getVendorRelease();
log.debug("validate vendor relese name");
- if (!ValidationUtils.validateStringNotEmpty(vendorRelease)) {
+ if (StringUtils.isEmpty(vendorRelease)) {
log.info("vendor relese name is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_RELEASE);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
throw new ComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
}
SubCategoryDefinition subcategory = subcategories.get(0);
- if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+ if (StringUtils.isEmpty(category.getName())) {
log.debug(CATEGORY_IS_EMPTY);
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
throw new ComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
}
- if (!ValidationUtils.validateStringNotEmpty(subcategory.getName())) {
+ if (StringUtils.isEmpty(subcategory.getName())) {
log.debug(CATEGORY_IS_EMPTY);
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
protected void validateVendorName(User user, Resource resource, AuditingActionEnum actionEnum) {
String vendorName = resource.getVendorName();
- if (!ValidationUtils.validateStringNotEmpty(vendorName)) {
+ if (StringUtils.isEmpty(vendorName)) {
log.info("vendor name is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_NAME);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
if (LifeCycleTransitionEnum.CERTIFY == transitionEnum || LifeCycleTransitionEnum.CHECKIN == transitionEnum
// import?
) {
- if (!ValidationUtils.validateStringNotEmpty(comment)) {
+ if (StringUtils.isEmpty(comment)) {
log.debug("user comment cannot be empty or null.");
ResponseFormat errorResponse = componentUtils.getResponseFormat(ActionStatus.MISSING_DATA, COMMENT);
return Either.right(errorResponse);
*/
package org.openecomp.sdc.be.components.validation.component;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
log.debug("validate component contactId");
ComponentTypeEnum type = component.getComponentType();
String contactId = component.getContactId();
- if (!ValidationUtils.validateStringNotEmpty(contactId)) {
+ if (StringUtils.isEmpty(contactId)) {
log.info("contact is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
*/
package org.openecomp.sdc.be.components.validation.component;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
ComponentTypeEnum type = component.getComponentType();
String description = component.getDescription();
- if (!ValidationUtils.validateStringNotEmpty(description)) {
+ if (StringUtils.isEmpty(description)) {
auditErrorAndThrow(user, component, actionEnum, ActionStatus.COMPONENT_MISSING_DESCRIPTION);
}
description = ValidationUtils.cleanUpText(description);
*/
package org.openecomp.sdc.be.components.validation.component;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
}
log.debug("validate ProjectCode name ");
String projectCode = component.getProjectCode();
- if (!ValidationUtils.validateStringNotEmpty(projectCode)) {
+ if (StringUtils.isEmpty(projectCode)) {
log.info("projectCode is empty is allowed CR.");
return;
}
import fj.data.Either;
import java.util.List;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CANNOT_CONTAIN_SUBCATEGORY);
return Either.right(responseFormat);
}
- if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+ if (StringUtils.isEmpty(category.getName())) {
log.debug("Resource category is empty");
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
throw new ByActionStatusComponentException(ActionStatus.MISSING_ECOMP_GENERATED_NAMING);
}
if (isEcompGeneratedCurr) {
+ if (StringUtils.isEmpty(namingPolicyUpdate)) {
+ return;
+ }
if (!ValidationUtils.validateServiceNamingPolicyLength(namingPolicyUpdate)) {
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.NAMING_POLICY_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_NAMING_POLICY_MAX_SIZE);
throw new ByResponseFormatComponentException(responseFormat);
}
- if (StringUtils.isEmpty(namingPolicyUpdate)) {
- service.setNamingPolicy("");
- return;
- }
if (!ValidationUtils.validateCommentPattern(namingPolicyUpdate)) {
throw new ByActionStatusComponentException(ActionStatus.INVALID_NAMING_POLICY);
}
- service.setNamingPolicy(namingPolicyUpdate);
} else {
- if (!StringUtils.isEmpty(namingPolicyUpdate)) {
+ if (StringUtils.isNotEmpty(namingPolicyUpdate)) {
log.warn("NamingPolicy must be empty for EcompGeneratedNaming=false");
}
service.setNamingPolicy("");
@Override
public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
log.debug("validate service role");
- String serviceRole = service.getServiceRole();
- if (serviceRole != null) {
- validateServiceRole(serviceRole);
- }
+ validateServiceRole(service.getServiceRole());
}
private void validateServiceRole(String serviceRole) {
if (StringUtils.isEmpty(serviceRole)) {
return;
- } else {
- if (!ValidationUtils.validateServiceRoleLength(serviceRole)) {
- log.info("service role exceeds limit.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_EXCEEDS_LIMIT, "" + SERVICE_ROLE);
- throw new ByResponseFormatComponentException(errorResponse);
- }
- if (!ValidationUtils.validateServiceMetadata(serviceRole)) {
- log.info("service role is not valid.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERY, "" + SERVICE_ROLE);
- throw new ByResponseFormatComponentException(errorResponse);
- }
+ }
+ if (!ValidationUtils.validateServiceRoleLength(serviceRole)) {
+ log.info("service role exceeds limit.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_EXCEEDS_LIMIT, "" + SERVICE_ROLE);
+ throw new ByResponseFormatComponentException(errorResponse);
+ }
+ if (!ValidationUtils.validateServiceMetadata(serviceRole)) {
+ log.info("service role is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERY, "" + SERVICE_ROLE);
+ throw new ByResponseFormatComponentException(errorResponse);
}
}
}
*/
package org.openecomp.sdc.be.components.validation.service;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
private static final Logger log = Logger.getLogger(ServiceTypeValidator.class.getName());
private static final String SERVICE_TYPE = JsonPresentationFields.SERVICE_TYPE.getPresentation();
- private ComponentsUtils componentsUtils;
-
- public ServiceTypeValidator(ComponentsUtils componentsUtils) {
- this.componentsUtils = componentsUtils;
- }
@Override
public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
log.debug("validate service type");
- String serviceType = service.getServiceType();
- if (serviceType == null) {
- log.info("service type is not valid.");
- throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY, "" + SERVICE_TYPE);
- }
- validateServiceType(serviceType);
+ validateServiceType(service.getServiceType());
}
private void validateServiceType(String serviceType) {
- if (serviceType.isEmpty()) {
+ if (StringUtils.isEmpty(serviceType)) {
return;
}
if (!ValidationUtils.validateServiceTypeLength(serviceType)) {
return responseFormat;
}
- public boolean validateStringNotEmpty(String value) {
- return value != null && !value.trim().isEmpty();
- }
-
public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
ActionStatus responseEnum;
switch (storageResponse) {
}
private List<Map<String, Map<String, String>>> getDefaultToscaImports(final String modelId) {
- if (modelId == null) {
+ if (StringUtils.isEmpty(modelId)) {
return getDefaultToscaImportConfig();
}
protected ResourceAdminEvent auditArchive2 = Mockito.mock(ResourceAdminEvent.class);
protected ResourceAdminEvent auditRestore = Mockito.mock(ResourceAdminEvent.class);
protected ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
- protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator(componentsUtils);
+ protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator();
protected ServiceRoleValidator serviceRoleValidator = new ServiceRoleValidator(componentsUtils);
protected ServiceFunctionValidator serviceFunctionValidator = new ServiceFunctionValidator(componentsUtils);
protected ServiceInstantiationTypeValidator serviceInstantiationTypeValidator = new ServiceInstantiationTypeValidator(componentsUtils);
assertTrue(createResponse.isLeft());
}
-
@Test
void testCreateServiceWhenGenericTypeHasProperties() {
final Service service = createServiceObject(false);
actualService.getProperties(), is(expectedService.getProperties()));
}
-
-
/* CREATE validations - start ***********************/
// Service name - start
fail();
}
-
private void testProjectCodeTooShort() {
Service serviceExist = createServiceObject(false);
eitherService.left().value().setArchived(false);
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
final ComponentException actualException = assertThrows(ComponentException.class, () -> bl.deleteServiceAllVersions(serviceId, user));
- assertEquals(actualException.getActionStatus(), ActionStatus.COMPONENT_NOT_ARCHIVED);
+ assertEquals(ActionStatus.COMPONENT_NOT_ARCHIVED, actualException.getActionStatus());
assertEquals(actualException.getParams()[0], serviceId);
}
newService.setServiceType("");
resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
- //null is invalid
+ //null is valid
newService.setServiceType(null);
resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
- assertThat(resultOfUpdate.isRight()).isTrue();
+ assertThat(resultOfUpdate.isLeft()).isTrue();
}
@Test
void testCreateDefaultMetadataServiceFunction() {
Service currentService = createServiceObject(true);
- assertThat(currentService.getServiceFunction()).isEqualTo("");
+ assertThat(currentService.getServiceFunction()).isEmpty();
}
@Test
newService.setServiceFunction(null);
resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
- assertThat(updatedService.getServiceFunction()).isEqualTo("");
+ assertThat(updatedService.getServiceFunction()).isEmpty();
}
-
@Test
void testServiceFunctionExceedLength() {
String serviceName = "Service";
return propertyList;
}
-
@Test
void testCreateService_withMultitenancyValidTenant_Success() {
Assert.assertTrue(MULTITENANCY_ENABLED);
assertEqualsServiceObject(createServiceObject(true), createResponse.left().value());
}
-
@Test
void testCreateService_withMultitenancyInvalidTenant_Failure() {
Service service = createServiceObject(false);
protected UserValidations userValidations = mock(UserValidations.class);
protected CatalogOperation catalogOperation = mock(CatalogOperation.class);
protected ServiceImportParseLogic serviceImportParseLogic = mock(ServiceImportParseLogic.class);
- protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator(componentsUtils);
+ protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator();
protected ServiceRoleValidator serviceRoleValidator = new ServiceRoleValidator(componentsUtils);
protected ServiceFunctionValidator serviceFunctionValidator = new ServiceFunctionValidator(componentsUtils);
protected ServiceInstantiationTypeValidator serviceInstantiationTypeValidator = new ServiceInstantiationTypeValidator(componentsUtils);
testSubject.auditComponent(responseFormat, modifier, component, actionEnum, type, prevComponent);
}
- @Test
- void testValidateStringNotEmpty() {
- ComponentsUtils testSubject;
- String value = "";
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.validateStringNotEmpty(value);
- assertThat(result).isFalse();
- }
-
@Test
void testConvertFromStorageResponseForAdditionalInformation() {
ComponentsUtils testSubject;
String instanceNewName, boolean generateUid,
ToscaElement originToscaElement) {
String ciOriginComponentUid = resourceInstance.getComponentUid();
- if (!ValidationUtils.validateStringNotEmpty(resourceInstance.getCustomizationUUID())) {
+ if (StringUtils.isEmpty(resourceInstance.getCustomizationUUID())) {
resourceInstance.setCustomizationUUID(generateCustomizationUUID());
}
ComponentInstanceDataDefinition dataDefinition = new ComponentInstanceDataDefinition(resourceInstance);
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
protected StorageOperationStatus associateComponentToModel(final GraphVertex nodeTypeVertex, final ToscaElement nodeType,
final EdgeLabelEnum edgeLabelEnum) {
- if (nodeType.getMetadataValue(JsonPresentationFields.MODEL) == null) {
+ Object metadataValue = nodeType.getMetadataValue(JsonPresentationFields.MODEL);
+ if (metadataValue == null || StringUtils.isEmpty((String) metadataValue)) {
return StorageOperationStatus.OK;
}
- final String model = ((String) nodeType.getMetadataValue(JsonPresentationFields.MODEL));
+ final String model = ((String) metadataValue);
final JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(getModelVertex(model), nodeTypeVertex, edgeLabelEnum, new HashMap<>());
if (createEdge != JanusGraphOperationStatus.OK) {
log.trace("Failed to associate resource {} to model {}", nodeType.getUniqueId(), model);
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
- @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"));
assertFalse(result);
}
- @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";