summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-08-22 19:43:16 +0100
committerMichael Morris <michael.morris@est.tech>2022-08-30 10:25:58 +0000
commitae24e28cda8247fdce38330356b63db1377be58f (patch)
treeab48468b2fea5cf0055f2e33acee3b979433468b /catalog-be/src
parentb95ca35cd3fc0f68a6eb2d09bb347d9ba659caf3 (diff)
Fix 'Wrong Inputs creation on (Add Service)'
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Iadfe03718066dafe5a438020c488f5b242fe6a41 Issue-ID: SDC-4097
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java110
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java48
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InputConverter.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java190
7 files changed, 217 insertions, 166 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
index bca901ee8b..763552fcf3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
@@ -213,7 +213,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
component = getComponentEither.left().value();
Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
- if (!op.isPresent()) {
+ if (op.isEmpty()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR, inputId, parentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
@@ -369,7 +369,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
component = getComponentEither.left().value();
Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
- if (!op.isPresent()) {
+ if (op.isEmpty()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR, inputId, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
@@ -664,7 +664,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
filter(input -> input.getUniqueId().equals(inputId)).
// Get the input
findAny();
- if (!optionalInput.isPresent()) {
+ if (optionalInput.isEmpty()) {
throw new ByActionStatusComponentException(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId);
}
InputDefinition inputForDelete = optionalInput.get();
@@ -770,7 +770,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
Component component = getComponentEither.left().value();
Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
- if (!op.isPresent()) {
+ if (op.isEmpty()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR, inputId, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
index 2cccc31ded..577d1f5e32 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -109,8 +109,10 @@ import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInterface;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DistributionStatusEnum;
@@ -189,13 +191,12 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private final ServiceInstantiationTypeValidator serviceInstantiationTypeValidator;
private final ServiceCategoryValidator serviceCategoryValidator;
private final ServiceValidator serviceValidator;
- private final PolicyBusinessLogic policyBusinessLogic;
- private final GroupBusinessLogic groupBusinessLogic;
private ForwardingPathOperation forwardingPathOperation;
private AuditCassandraDao auditCassandraDao;
private ServiceTypeValidator serviceTypeValidator;
private List<ServiceCreationPlugin> serviceCreationPluginList;
private ServiceFunctionValidator serviceFunctionValidator;
+ private final InputsBusinessLogic inputsBusinessLogic;
public ServiceBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
IGroupTypeOperation groupTypeOperation, GroupBusinessLogic groupBusinessLogic, InterfaceOperation interfaceOperation,
@@ -210,7 +211,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
final ServiceRoleValidator serviceRoleValidator,
final ServiceInstantiationTypeValidator serviceInstantiationTypeValidator,
final ServiceCategoryValidator serviceCategoryValidator, final ServiceValidator serviceValidator,
- final PolicyBusinessLogic policyBusinessLogic) {
+ final InputsBusinessLogic inputsBusinessLogic) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation,
interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
@@ -224,8 +225,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
this.serviceInstantiationTypeValidator = serviceInstantiationTypeValidator;
this.serviceCategoryValidator = serviceCategoryValidator;
this.serviceValidator = serviceValidator;
- this.policyBusinessLogic = policyBusinessLogic;
- this.groupBusinessLogic = groupBusinessLogic;
+ this.inputsBusinessLogic = inputsBusinessLogic;
}
@Autowired
@@ -311,7 +311,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
Optional<ComponentInstance> serviceInstanceCandidate = componentInstances.stream()
.filter(instance -> instance.getUniqueId().equals(serviceInstanceId)).findAny();
- if (!serviceInstanceCandidate.isPresent()) {
+ if (serviceInstanceCandidate.isEmpty()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, serviceInstanceId));
}
Map<String, List<ComponentInstanceInterface>> componentInstancesInterfaces = parentService.getComponentInstancesInterfaces();
@@ -324,7 +324,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
ComponentInstance serviceInstance = serviceInstanceCandidate.get();
Optional<InterfaceDefinition> interfaceCandidate = InterfaceOperationUtils.getInterfaceDefinitionFromOperationId(interfaces, operationId);
- if (!interfaceCandidate.isPresent()) {
+ if (interfaceCandidate.isEmpty()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, serviceInstanceId));
}
InterfaceDefinition interfaceDefinition = interfaceCandidate.get();
@@ -336,7 +336,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
Either<Operation, ResponseFormat> operationEither = Either.left(operation);
ListDataDefinition<OperationInputDefinition> inputs = operation.getInputs();
Optional<OperationInputDefinition> inputCandidate = getOperationInputByInputId(serviceConsumptionData, inputs);
- if (!inputCandidate.isPresent()) {
+ if (inputCandidate.isEmpty()) {
return Either.right(new ResponseFormat(HttpStatus.NOT_FOUND.value()));
}
OperationInputDefinition operationInputDefinition = inputCandidate.get();
@@ -419,7 +419,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
.getListToscaDataDefinition();
} else {
Optional<ComponentInstance> getComponentInstance = containerService.getComponentInstanceById(source);
- if (!getComponentInstance.isPresent()) {
+ if (getComponentInstance.isEmpty()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, source));
}
ComponentInstance componentInstance = getComponentInstance.get();
@@ -692,7 +692,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private Either<Service, ResponseFormat> createServiceByDao(final Service service, final User user) {
log.debug("send service {} to dao for create", service.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
- Either<Boolean, ResponseFormat> lockResult = lockComponentByName(service.getSystemName(), service, "Create Service");
+ final Either<Boolean, ResponseFormat> lockResult = lockComponentByName(service.getSystemName(), service, "Create Service");
if (lockResult.isRight()) {
ResponseFormat responseFormat = lockResult.right().value();
componentsUtils.auditComponentAdmin(responseFormat, user, service, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
@@ -710,25 +710,64 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
generateAndAddInputsFromGenericTypeProperties(service, genericType);
}
beforeCreate(service);
- Either<Service, StorageOperationStatus> dataModelResponse = toscaOperationFacade.createToscaComponent(service);
- if (dataModelResponse.isLeft()) {
- log.debug("Service '{}' created successfully", service.getName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ final Either<Service, StorageOperationStatus> dataModelResponse = toscaOperationFacade.createToscaComponent(service);
+ if (dataModelResponse.isRight()) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()), service,
+ ComponentTypeEnum.SERVICE);
+ log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
componentsUtils.auditComponentAdmin(responseFormat, user, service, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
- ASDCKpiApi.countCreatedServicesKPI();
- return Either.left(dataModelResponse.left().value());
+ return Either.right(responseFormat);
}
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()), service,
- ComponentTypeEnum.SERVICE);
- log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
- componentsUtils.auditComponentAdmin(responseFormat, user, service, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
- return Either.right(responseFormat);
+ final Service createdService = dataModelResponse.left().value();
+ if (createdService.isSubstituteCandidate() || genericTypeBusinessLogic.hasMandatorySubstitutionType(createdService)) {
+ updateInputs(createdService);
+ }
+ log.debug("Service '{}' created successfully", createdService.getName());
+ final ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ componentsUtils.auditComponentAdmin(responseFormat, user, createdService, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
+ ASDCKpiApi.countCreatedServicesKPI();
+ return Either.left(createdService);
} finally {
graphLockOperation.unlockComponentByName(service.getSystemName(), service.getUniqueId(), NodeTypeEnum.Service);
}
}
+ private void updateInputs(final Service service) {
+ final List<InputDefinition> genericTypeInputs = service.getInputs();
+ final Either<List<InputDefinition>, ResponseFormat> inputs = inputsBusinessLogic.getInputs(service.getCreatorUserId(), service.getUniqueId());
+ if (inputs.isRight() || CollectionUtils.isEmpty(inputs.left().value())) {
+ log.warn("Failed to declare Generic Type Properties as Inputs");
+ service.setInputs(null);
+ return;
+ }
+ inputs.left().value().forEach(
+ inputDefinition -> inputsBusinessLogic.deleteInput(service.getUniqueId(), service.getCreatorUserId(), inputDefinition.getUniqueId()));
+
+ service.setInputs(null);
+ if (CollectionUtils.isNotEmpty(genericTypeInputs)) {
+ // From SELF
+ final ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ final List<ComponentInstancePropInput> componentInstancePropInputs = genericTypeInputs.stream()
+ .map(prop -> {
+ prop.setInstanceUniqueId(service.getUniqueId());
+ prop.setParentUniqueId(service.getUniqueId());
+ return new ComponentInstancePropInput(new ComponentInstanceProperty(prop));
+ }
+ ).collect(Collectors.toList());
+ componentInstInputsMap.setServiceProperties(Collections.singletonMap(service.getUniqueId(), componentInstancePropInputs));
+
+ final Either<List<InputDefinition>, ResponseFormat> listResponseFormatEither = inputsBusinessLogic.declareProperties(
+ service.getCreatorUserId(), service.getUniqueId(), ComponentTypeEnum.SERVICE, componentInstInputsMap);
+ if (listResponseFormatEither.isRight()) {
+ log.warn("Failed to declare Generic Type Properties as Inputs");
+ service.setInputs(null);
+ return;
+ }
+ service.setInputs(listResponseFormatEither.left().value());
+ }
+ }
+
private void beforeCreate(final Service service) {
if (CollectionUtils.isEmpty(serviceCreationPluginList)) {
return;
@@ -745,10 +784,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
@SuppressWarnings("unchecked")
private void createServiceApiArtifactsData(Service service, User user) {
// create mandatory artifacts
-
- // TODO it must be removed after that artifact uniqueId creation will be
-
- // moved to ArtifactOperation
+ // TODO it must be removed after that artifact uniqueId creation will be moved to ArtifactOperation
String serviceUniqueId = service.getUniqueId();
Map<String, ArtifactDefinition> artifactMap = service.getServiceApiArtifacts();
if (artifactMap == null) {
@@ -1630,13 +1666,13 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
BeEcompErrorManager.getInstance()
.logBeComponentMissingError("markDistributionAsDeployed", ComponentTypeEnum.SERVICE.getValue(), serviceId);
log.debug("service {} not found", serviceId);
- ResponseFormat responseFormat = auditDeployError(did, user, auditAction, null,
+ ResponseFormat responseFormat = auditDeployError(did, user, null,
componentsUtils.convertFromStorageResponse(getServiceResponse.right().value(), ComponentTypeEnum.SERVICE), "");
return Either.right(responseFormat);
}
Service service = getServiceResponse.left().value();
user = validateRoleForDeploy(did, user, auditAction, service);
- return checkDistributionAndDeploy(did, user, auditAction, service);
+ return checkDistributionAndDeploy(did, user, service);
}
public Either<Service, ResponseFormat> generateVfModuleArtifacts(Service service, User modifier, boolean shouldLock, boolean inTransaction) {
@@ -1710,13 +1746,13 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return null;
}
- private synchronized Either<Service, ResponseFormat> checkDistributionAndDeploy(String distributionId, User user, AuditingActionEnum auditAction,
+ private synchronized Either<Service, ResponseFormat> checkDistributionAndDeploy(String distributionId, User user,
Service service) {
boolean isDeployed = isDistributionDeployed(distributionId);
if (isDeployed) {
return Either.left(service);
}
- Either<Boolean, ResponseFormat> distributionSuccess = checkDistributionSuccess(distributionId, user, auditAction, service);
+ Either<Boolean, ResponseFormat> distributionSuccess = checkDistributionSuccess(distributionId, user, service);
if (distributionSuccess.isRight()) {
return Either.right(distributionSuccess.right().value());
}
@@ -1739,20 +1775,20 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return isDeployed;
}
- protected Either<Boolean, ResponseFormat> checkDistributionSuccess(String did, User user, AuditingActionEnum auditAction, Service service) {
+ protected Either<Boolean, ResponseFormat> checkDistributionSuccess(String did, User user, Service service) {
log.trace("checkDistributionSuccess");
// get all "DRequest" records for this distribution
Either<List<ResourceAdminEvent>, ActionStatus> distRequestsResponse = auditCassandraDao
.getDistributionRequest(did, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName());
if (distRequestsResponse.isRight()) {
- ResponseFormat error = auditDeployError(did, user, auditAction, service, distRequestsResponse.right().value());
+ ResponseFormat error = auditDeployError(did, user, service, distRequestsResponse.right().value());
return Either.right(error);
}
List<ResourceAdminEvent> distributionRequests = distRequestsResponse.left().value();
if (distributionRequests.isEmpty()) {
BeEcompErrorManager.getInstance().logBeDistributionMissingError("markDistributionAsDeployed", did);
log.info("distribution {} is not found", did);
- ResponseFormat error = auditDeployError(did, user, auditAction, service, ActionStatus.DISTRIBUTION_REQUESTED_NOT_FOUND);
+ ResponseFormat error = auditDeployError(did, user, service, ActionStatus.DISTRIBUTION_REQUESTED_NOT_FOUND);
return Either.right(error);
}
boolean isRequestSucceeded = false;
@@ -1767,7 +1803,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
Either<List<DistributionNotificationEvent>, ActionStatus> distNotificationsResponse = auditCassandraDao
.getDistributionNotify(did, AuditingActionEnum.DISTRIBUTION_NOTIFY.getName());
if (distNotificationsResponse.isRight()) {
- ResponseFormat error = auditDeployError(did, user, auditAction, service, distNotificationsResponse.right().value());
+ ResponseFormat error = auditDeployError(did, user, service, distNotificationsResponse.right().value());
return Either.right(error);
}
List<DistributionNotificationEvent> distributionNotifications = distNotificationsResponse.left().value();
@@ -1783,13 +1819,13 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
if (!(isRequestSucceeded && isNotificationsSucceeded)) {
log.info("distribution {} has failed", did);
ResponseFormat error = componentsUtils.getResponseFormat(ActionStatus.DISTRIBUTION_REQUESTED_FAILED, did);
- auditDeployError(did, user, auditAction, service, ActionStatus.DISTRIBUTION_REQUESTED_FAILED, did);
+ auditDeployError(did, user, service, ActionStatus.DISTRIBUTION_REQUESTED_FAILED, did);
return Either.right(error);
}
return Either.left(true);
}
- private ResponseFormat auditDeployError(String did, User user, AuditingActionEnum auditAction, Service service, ActionStatus status,
+ private ResponseFormat auditDeployError(String did, User user, Service service, ActionStatus status,
String... params) {
ResponseFormat error = componentsUtils.getResponseFormat(status, params);
String message = "";
@@ -1817,7 +1853,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
validateUserRole(user, service, roles, auditAction, null);
} catch (ByActionStatusComponentException e) {
log.info("role {} is not allowed to perform this action", user.getRole());
- auditDeployError(did, user, auditAction, service, e.getActionStatus());
+ auditDeployError(did, user, service, e.getActionStatus());
throw e;
}
return user;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
index 0412516390..07d5ba0f24 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
@@ -126,7 +126,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
private Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesAsPolicies(Component component, PROPERTYOWNER propertiesOwner,
List<ComponentInstancePropInput> propsToDeclare) {
- PropertiesDeclarationData policyProperties = createPoliciesAndOverridePropertiesValues(propertiesOwner.getUniqueId(), propertiesOwner,
+ PropertiesDeclarationData policyProperties = createPoliciesAndOverridePropertiesValues(propertiesOwner.getUniqueId(),
propsToDeclare);
return updatePropertiesValues(component, propertiesOwner.getUniqueId(), policyProperties.getPropertiesToUpdate()).left()
.map(updatePropsRes -> policyProperties.getPoliciesToCreate());
@@ -144,8 +144,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
.map(updatePropsRes -> inputsProperties.getInputsToCreate());
}
- private PropertiesDeclarationData createPoliciesAndOverridePropertiesValues(String componentId, PROPERTYOWNER propertiesOwner,
- List<ComponentInstancePropInput> propsToDeclare) {
+ private PropertiesDeclarationData createPoliciesAndOverridePropertiesValues(String componentId, List<ComponentInstancePropInput> propsToDeclare) {
List<PROPERTYTYPE> declaredProperties = new ArrayList<>();
List<PolicyDefinition> policies = new ArrayList<>();
propsToDeclare.forEach(property -> policies.add(declarePropertyPolicy(componentId, declaredProperties, property)));
@@ -250,7 +249,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
if (propertyCapability.isPresent()) {
String capName = propertyCapability.get().getName();
if (capName.contains(".")) {
- capName = capName.replaceAll("\\.", UNDERSCORE);
+ capName = capName.replace(".", UNDERSCORE);
}
generatedInputPrefix =
generatedInputPrefix == null || generatedInputPrefix.isEmpty() ? capName : generatedInputPrefix + UNDERSCORE + capName;
@@ -315,12 +314,12 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
input.setInputPath(propertiesName);
input.setInstanceUniqueId(propertiesOwner.getUniqueId());
input.setPropertyId(propInput.getUniqueId());
- if (Objects.isNull(input.getSubPropertyInputPath()) || (Objects.nonNull(propertiesName) && input.getSubPropertyInputPath()
+ if (Objects.isNull(input.getSubPropertyInputPath()) || (StringUtils.isNotEmpty(propertiesName) && input.getSubPropertyInputPath()
.substring(input.getSubPropertyInputPath().lastIndexOf('#')).equals(propertiesName.substring(propertiesName.lastIndexOf('#'))))) {
input.setParentPropertyType(propInput.getType());
input.setSubPropertyInputPath(propertiesName);
}
- changePropertyValueToGetInputValue(inputName, parsedPropNames, input, prop, complexProperty);
+ changePropertyValueToGetInputValue(parsedPropNames, input, prop, complexProperty);
if (prop instanceof IComponentInstanceConnectedElement) {
((IComponentInstanceConnectedElement) prop).setComponentInstanceId(propertiesOwner.getUniqueId());
((IComponentInstanceConnectedElement) prop).setComponentInstanceName(propertiesOwner.getName());
@@ -328,42 +327,43 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
return input;
}
- private void changePropertyValueToGetInputValue(String inputName, String[] parsedPropNames, InputDefinition input, PropertyDataDefinition prop,
+ private void changePropertyValueToGetInputValue(String[] parsedPropNames, InputDefinition input, PropertyDataDefinition prop,
boolean complexProperty) {
JSONObject jsonObject = new JSONObject();
- String value = prop.getValue();
+ final String value = prop.getValue();
+ final String inputName = input.getName();
if (value == null || value.isEmpty()) {
if (complexProperty) {
jsonObject = createJSONValueForProperty(parsedPropNames.length - 1, parsedPropNames, jsonObject, inputName);
prop.setValue(jsonObject.toJSONString());
} else {
- jsonObject.put(GET_INPUT, input.getName());
+ jsonObject.put(GET_INPUT, inputName);
prop.setValue(jsonObject.toJSONString());
}
} else {
- Object objValue = new Yaml().load(value);
+ final Object objValue = new Yaml().load(value);
if (objValue instanceof Map || objValue instanceof List) {
if (!complexProperty) {
- jsonObject.put(GET_INPUT, input.getName());
+ jsonObject.put(GET_INPUT, inputName);
prop.setValue(jsonObject.toJSONString());
} else {
- Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
+ final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
createInputValue(mappedToscaTemplate, 1, parsedPropNames, inputName);
- String json = gson.toJson(mappedToscaTemplate);
+ final String json = gson.toJson(mappedToscaTemplate);
prop.setValue(json);
}
} else {
- jsonObject.put(GET_INPUT, input.getName());
+ jsonObject.put(GET_INPUT, inputName);
prop.setValue(jsonObject.toJSONString());
}
}
if (CollectionUtils.isEmpty(prop.getGetInputValues())) {
prop.setGetInputValues(new ArrayList<>());
}
- List<GetInputValueDataDefinition> getInputValues = prop.getGetInputValues();
- GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
+ final List<GetInputValueDataDefinition> getInputValues = prop.getGetInputValues();
+ final GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
getInputValueDataDefinition.setInputId(input.getUniqueId());
- getInputValueDataDefinition.setInputName(input.getName());
+ getInputValueDataDefinition.setInputName(inputName);
getInputValues.add(getInputValueDataDefinition);
}
@@ -460,8 +460,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
if (result.isLeft()) {
modifiedMappedToscaTemplate = (Map) result.left().value();
} else {
- log.warn("Map cleanup failed -> " + result.right().value()
- .toString()); //continue, don't break operation
+ log.warn("Map cleanup failed -> {}", result.right().value()); //continue, don't break operation
}
value = gson.toJson(modifiedMappedToscaTemplate);
}
@@ -546,11 +545,10 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
boolean isEmpty = true;
if (element != null) {
if (element instanceof Map) {
- if (MapUtils.isEmpty((Map) element)) {
- isEmpty = true;
- } else {
- for (Object key : ((Map) (element)).keySet()) {
- Object value = ((Map) (element)).get(key);
+ final Map map = (Map) element;
+ if (MapUtils.isNotEmpty(map)) {
+ for (final Object key : map.keySet()) {
+ final Object value = map.get(key);
isEmpty &= isEmptyNestedMap(value);
}
}
@@ -560,7 +558,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
}
return isEmpty;
}
- //@returns true iff map nested maps are all empty
+ //@returns true if map nested maps are all empty
private class PropertiesDeclarationData {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 9591e6b1a7..25d0287d54 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -800,11 +800,11 @@ public class ToscaExportHandler {
if (CollectionUtils.isNotEmpty(component.getProperties())) {
List<PropertyDefinition> properties = component.getProperties();
Map<String, ToscaProperty> convertedProperties = properties.stream()
- .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, component.getInputs())).collect(Collectors
- .toMap(PropertyDataDefinition::getName,
- property -> propertyConvertor.convertProperty(dataTypes, property, PropertyConvertor.PropertyType.PROPERTY)));
+ .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, component.getInputs()))
+ .collect(Collectors.toMap(PropertyDataDefinition::getName,
+ property -> propertyConvertor.convertProperty(dataTypes, property, PropertyConvertor.PropertyType.PROPERTY)));
// merge component properties and inputs properties
- mergedProperties.putAll(convertedProperties);
+ convertedProperties.forEach((k, v) -> mergedProperties.putIfAbsent(k, v));
}
if (MapUtils.isNotEmpty(mergedProperties)) {
toscaNodeType.setProperties(mergedProperties);
@@ -938,7 +938,7 @@ public class ToscaExportHandler {
nodeTemplate.setType(componentInstance.getToscaComponentName());
nodeTemplate.setDirectives(componentInstance.getDirectives());
NodeFilter nodeFilter = convertToNodeTemplateNodeFilterComponent(componentInstance.getNodeFilter());
- if(nodeFilter != null && nodeFilter.hasData()){
+ if (nodeFilter != null && nodeFilter.hasData()) {
nodeTemplate.setNode_filter(nodeFilter);
}
final Either<Component, Boolean> originComponentRes = capabilityRequirementConverter
@@ -1767,7 +1767,7 @@ public class ToscaExportHandler {
}
private Map<String, ToscaProperty> convertInputsToProperties(Map<String, DataTypeDefinition> dataTypes, List<InputDefinition> componentInputs,
- String componentUniqueId) {
+ String componentUniqueId) {
if (CollectionUtils.isEmpty(componentInputs)) {
return new HashMap<>();
}
@@ -1788,6 +1788,10 @@ public class ToscaExportHandler {
.ofNullable(interfacesOperationsConverter.getInterfacesMap(proxyComponent, null, proxyComponentInterfaces, dataTypes, false, false));
}
+ private Configuration getConfiguration() {
+ return ConfigurationManager.getConfigurationManager().getConfiguration();
+ }
+
private static class CustomRepresenter extends Representer {
CustomRepresenter() {
@@ -1943,8 +1947,4 @@ public class ToscaExportHandler {
}
}
- private Configuration getConfiguration() {
- return ConfigurationManager.getConfigurationManager().getConfiguration();
- }
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InputConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InputConverter.java
index 55de9e5028..b94a32291e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InputConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InputConverter.java
@@ -56,7 +56,7 @@ public class InputConverter {
* description
* list of properties */
public Map<String, ToscaProperty> convertInputs(List<InputDefinition> inputDef, Map<String, DataTypeDefinition> dataTypes) {
- log.debug("convert inputs to to tosca ");
+ log.debug("convert inputs to tosca");
Map<String, ToscaProperty> inputs = new HashMap<>();
if (inputDef != null) {
inputDef.forEach(i -> {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
index 049f8a5541..f1ee0d4c6c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
@@ -140,6 +140,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class);
public ServiceBusinessLogicBaseTestSetup() {
@@ -172,7 +173,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
user.setRole(Role.ADMIN.name());
when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
- when(userValidations.validateUserExists(eq("jh0003"))).thenReturn(user);
+ when(userValidations.validateUserExists("jh0003")).thenReturn(user);
when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(user);
when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
@@ -204,7 +205,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
interfaceLifecycleTypeOperation, artifactBl, distributionEngine, componentInstanceBusinessLogic, serviceDistributionValidation,
forwardingPathValidator, uiComponentDataConverter, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator,
- modelOperation, serviceRoleValidator, serviceInstantiationTypeValidator, serviceCategoryValidator, serviceValidator, null);
+ modelOperation, serviceRoleValidator, serviceInstantiationTypeValidator, serviceCategoryValidator, serviceValidator, inputsBusinessLogic);
bl.setComponentContactIdValidator(componentContactIdValidator);
bl.setComponentIconValidator(componentIconValidator);
bl.setComponentTagsValidator(componentTagsValidator);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
index 69938cd527..46173a2eb7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
@@ -31,6 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import com.google.common.collect.Lists;
@@ -39,12 +41,12 @@ import fj.data.Either;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
-
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -57,9 +59,11 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInterface;
import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.Model;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.PropertyDefinition;
@@ -86,14 +90,16 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
@Test
void testGetComponentAuditRecordsCertifiedVersion() {
- Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords = bl.getComponentAuditRecords(CERTIFIED_VERSION, COMPONNET_ID, user.getUserId());
+ Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords = bl.getComponentAuditRecords(CERTIFIED_VERSION, COMPONNET_ID,
+ user.getUserId());
assertTrue(componentAuditRecords.isLeft());
assertEquals(3, componentAuditRecords.left().value().size());
}
@Test
void testGetComponentAuditRecordsUnCertifiedVersion() {
- Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords = bl.getComponentAuditRecords(UNCERTIFIED_VERSION, COMPONNET_ID, user.getUserId());
+ Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords = bl.getComponentAuditRecords(UNCERTIFIED_VERSION, COMPONNET_ID,
+ user.getUserId());
assertTrue(componentAuditRecords.isLeft());
assertEquals(4, componentAuditRecords.left().value().size());
}
@@ -186,7 +192,6 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
final Service actualService = createResponse.left().value();
org.hamcrest.MatcherAssert.assertThat("Service should not be null", service, is(notNullValue()));
-
assertEqualsServiceObject(expectedService, actualService);
}
@@ -216,6 +221,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
}
assertEqualsServiceObject(createServiceObject(true), createResponse.left().value());
}
+
private void assertEqualsServiceObject(final Service expectedService, final Service actualService) {
assertEquals(expectedService.getContactId(), actualService.getContactId());
assertEquals(expectedService.getCategories(), actualService.getCategories());
@@ -296,9 +302,9 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
private void testServiceNameEmpty() {
Service serviceExccedsNameLimit = createServiceObject(false);
serviceExccedsNameLimit.setName(null);
- try{
+ try {
bl.createService(serviceExccedsNameLimit, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue());
return;
}
@@ -310,9 +316,9 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
// contains :
String nameWrongFormat = "ljg\\fd";
service.setName(nameWrongFormat);
- try{
+ try {
bl.createService(service, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue());
return;
}
@@ -325,20 +331,21 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
private void testServiceDescriptionEmpty() {
Service serviceExist = createServiceObject(false);
serviceExist.setDescription("");
- try{
+ try {
bl.createService(serviceExist, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
return;
}
fail();
}
+
private void testServiceDescriptionMissing() {
Service serviceExist = createServiceObject(false);
serviceExist.setDescription(null);
- try{
+ try {
bl.createService(serviceExist, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
return;
}
@@ -349,19 +356,20 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
Service serviceExccedsDescLimit = createServiceObject(false);
// 1025 chars, the limit is 1024
String tooLongServiceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
- + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
- + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
- + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
- + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
- + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
- + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
- + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
+ + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
+ + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
+ + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
+ + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
+ + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
+ + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
+ + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
serviceExccedsDescLimit.setDescription(tooLongServiceDesc);
- try{
+ try {
bl.createService(serviceExccedsDescLimit, user);
- } catch(ComponentException e){
- assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(),
+ "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
return;
}
fail();
@@ -372,9 +380,9 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
// Not english
String tooLongServiceDesc = "\uC2B5";
notEnglish.setDescription(tooLongServiceDesc);
- try{
+ try {
bl.createService(notEnglish, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
return;
}
@@ -387,14 +395,15 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
private void testServiceIconEmpty() {
Service serviceExist = createServiceObject(false);
serviceExist.setIcon("");
- Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(serviceExist,user,AuditingActionEnum.CREATE_SERVICE);
+ Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(serviceExist, user, AuditingActionEnum.CREATE_SERVICE);
assertThat(service.left().value().getIcon()).isEqualTo(DEFAULT_ICON);
}
+
private void testServiceIconMissing() {
Service serviceExist = createServiceObject(false);
serviceExist.setIcon(null);
- Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(serviceExist,user,AuditingActionEnum.CREATE_SERVICE);
+ Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(serviceExist, user, AuditingActionEnum.CREATE_SERVICE);
assertThat(service.left().value().getIcon()).isEqualTo(DEFAULT_ICON);
}
@@ -413,9 +422,9 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
List<String> tagsList = new ArrayList<>();
tagsList.add(tag1);
serviceExccedsNameLimit.setTags(tagsList);
- try{
+ try {
bl.createService(serviceExccedsNameLimit, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
return;
}
@@ -428,9 +437,9 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
List<String> tagsList = new ArrayList<>();
tagsList.add(tag1);
serviceExccedsNameLimit.setTags(tagsList);
- try{
+ try {
bl.createService(serviceExccedsNameLimit, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, "Service", "tag");
return;
}
@@ -461,22 +470,23 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
// 59 chars instead of 50
String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
serviceContactId.setContactId(contactIdTooLong);
- try{
+ try {
bl.createService(serviceContactId, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue());
return;
}
fail();
}
+
private void testContactIdWrongFormatCreate() {
Service serviceContactId = createServiceObject(false);
// 3 letters and 3 digits and special characters
String contactIdTooLong = "yrt134!!!";
serviceContactId.setContactId(contactIdTooLong);
- try{
+ try {
bl.createService(serviceContactId, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue());
return;
}
@@ -486,9 +496,9 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
private void testResourceContactIdMissing() {
Service resourceExist = createServiceObject(false);
resourceExist.setContactId(null);
- try{
+ try {
bl.createService(resourceExist, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.SERVICE.getValue());
return;
}
@@ -501,14 +511,15 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
private void testServiceCategoryExist() {
Service serviceExist = createServiceObject(false);
serviceExist.setCategories(null);
- try{
+ try {
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
return;
}
fail();
}
+
@Test
void markDistributionAsDeployedTestAlreadyDeployed() {
String notifyAction = "DNotify";
@@ -529,7 +540,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
resultList.add(event);
Either<List<DistributionDeployEvent>, ActionStatus> eventList = Either.left(resultList);
- Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), Mockito.eq(resultAction), Mockito.anyString())).thenReturn(eventList);
+ Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), eq(resultAction), Mockito.anyString())).thenReturn(eventList);
Either<Service, ResponseFormat> markDeployed = bl.markDistributionAsDeployed(did, did, user);
assertTrue(markDeployed.isLeft());
@@ -561,7 +572,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
setupBeforeDeploy(notifyAction, requestAction, did);
List<ResourceAdminEvent> emptyList = new ArrayList<>();
Either<List<ResourceAdminEvent>, ActionStatus> emptyEventList = Either.left(emptyList);
- Mockito.when(auditingDao.getDistributionRequest(Mockito.anyString(), Mockito.eq(requestAction))).thenReturn(emptyEventList);
+ Mockito.when(auditingDao.getDistributionRequest(Mockito.anyString(), eq(requestAction))).thenReturn(emptyEventList);
Either<Component, StorageOperationStatus> notFound = Either.right(StorageOperationStatus.NOT_FOUND);
Mockito.when(toscaOperationFacade.getToscaElement(did)).thenReturn(notFound);
@@ -581,9 +592,9 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
List<CategoryDefinition> categories = new ArrayList<>();
categories.add(category);
serviceExist.setCategories(categories);
- try{
+ try {
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
return;
}
@@ -600,8 +611,8 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
try {
bl.createService(serviceExist, user);
- } catch(ComponentException exp) {
- assertComponentException(exp, ActionStatus.INVALID_PROJECT_CODE);
+ } catch (ComponentException exp) {
+ assertComponentException(exp, ActionStatus.INVALID_PROJECT_CODE);
return;
}
fail();
@@ -615,7 +626,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
try {
bl.createService(serviceExist, user);
- } catch(ComponentException exp) {
+ } catch (ComponentException exp) {
assertComponentException(exp, ActionStatus.INVALID_PROJECT_CODE);
return;
}
@@ -630,7 +641,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
try {
bl.createService(serviceExist, user);
- } catch(ComponentException exp) {
+ } catch (ComponentException exp) {
assertComponentException(exp, ActionStatus.INVALID_PROJECT_CODE);
return;
}
@@ -679,7 +690,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
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);
}
@@ -687,20 +698,20 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
void testDeleteArchivedService_DeleteServiceSpecificModel() throws ToscaOperationException {
String serviceId = "12345";
String model = "serviceSpecificModel";
- List<String> deletedServcies= new ArrayList<>();
+ List<String> deletedServcies = new ArrayList<>();
deletedServcies.add("54321");
Model normativeExtensionModel = new Model("normativeExtensionModel", ModelTypeEnum.NORMATIVE_EXTENSION);
Either<Component, StorageOperationStatus> eitherService = Either.left(createNewService());
eitherService.left().value().setArchived(true);
eitherService.left().value().setModel(model);
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
- Mockito.when(toscaOperationFacade.deleteService(Mockito.anyString(), Mockito.eq(true))).thenReturn(deletedServcies);
+ Mockito.when(toscaOperationFacade.deleteService(Mockito.anyString(), eq(true))).thenReturn(deletedServcies);
Mockito.when(modelOperation.findModelByName(model)).thenReturn(Optional.of(normativeExtensionModel));
bl.deleteServiceAllVersions(serviceId, user);
Mockito.verify(modelOperation, Mockito.times(1)).deleteModel(normativeExtensionModel, false);
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Test
void testFindGroupInstanceOnRelatedComponentInstance() {
@@ -713,7 +724,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat> findGroupInstanceRes;
Object[] argObjects = {service, componentInstances.get(1).getUniqueId(), componentInstances.get(1).getGroupInstances().get(1).getUniqueId()};
- Class[] argClasses = {Component.class, String.class,String.class};
+ Class[] argClasses = {Component.class, String.class, String.class};
try {
Method method = targetClass.getDeclaredMethod(methodName, argClasses);
method.setAccessible(true);
@@ -721,27 +732,26 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjects);
assertNotNull(findGroupInstanceRes);
assertEquals(findGroupInstanceRes.left().value().getKey().getUniqueId(), componentInstances.get(1)
- .getUniqueId());
+ .getUniqueId());
assertEquals(findGroupInstanceRes.left().value().getValue().getUniqueId(), componentInstances.get(1)
- .getGroupInstances()
- .get(1)
- .getUniqueId());
+ .getGroupInstances()
+ .get(1)
+ .getUniqueId());
- Object[] argObjectsInvalidCiId = {service, invalidId , componentInstances.get(1).getGroupInstances().get(1).getUniqueId()};
+ Object[] argObjectsInvalidCiId = {service, invalidId, componentInstances.get(1).getGroupInstances().get(1).getUniqueId()};
- findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjectsInvalidCiId);
+ findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjectsInvalidCiId);
assertNotNull(findGroupInstanceRes);
assertTrue(findGroupInstanceRes.isRight());
assertEquals("SVC4593", findGroupInstanceRes.right().value().getMessageId());
- Object[] argObjectsInvalidGiId = {service, componentInstances.get(1).getUniqueId() , invalidId};
+ Object[] argObjectsInvalidGiId = {service, componentInstances.get(1).getUniqueId(), invalidId};
- findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjectsInvalidGiId);
+ findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjectsInvalidGiId);
assertNotNull(findGroupInstanceRes);
assertTrue(findGroupInstanceRes.isRight());
assertEquals("SVC4653", findGroupInstanceRes.right().value().getMessageId());
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
}
}
@@ -754,15 +764,15 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
service.setUniqueId("serviceUniqueId");
List<ComponentInstance> componentInstances = new ArrayList<>();
ComponentInstance ci;
- for(int i= 0; i<listSize; ++i){
+ for (int i = 0; i < listSize; ++i) {
ci = new ComponentInstance();
ci.setName("ciName" + i);
ci.setUniqueId("ciId" + i);
- List<GroupInstance> groupInstances= new ArrayList<>();
+ List<GroupInstance> groupInstances = new ArrayList<>();
GroupInstance gi;
- for(int j = 0; j<listSize; ++j){
+ for (int j = 0; j < listSize; ++j) {
gi = new GroupInstance();
- gi.setName(ci.getName( )+ "giName" + j);
+ gi.setName(ci.getName() + "giName" + j);
gi.setUniqueId(ci.getName() + "giId" + j);
groupInstances.add(gi);
}
@@ -774,15 +784,22 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
}
protected Service createNewService() {
- return (Service)createNewComponent();
+ return (Service) createNewComponent();
}
@Test
void testDerivedFromGeneric() {
Service service = createServiceObject(true);
+ Service newService = createServiceObject(false);
+ newService.setInputs(Collections.singletonList(new InputDefinition()));
service.setDerivedFromGenericInfo(genericService);
- when(toscaOperationFacade.createToscaComponent(service)).thenReturn(Either.left(service));
+ newService.setDerivedFromGenericInfo(genericService);
+ when(toscaOperationFacade.createToscaComponent(service)).thenReturn(Either.left(newService));
when(genericTypeBusinessLogic.fetchDerivedFromGenericType(service, null)).thenReturn(Either.left(genericService));
+ when(inputsBusinessLogic.getInputs(any(), any())).thenReturn(Either.left(Collections.singletonList(new InputDefinition())));
+ when(inputsBusinessLogic.declareProperties(any(), any(), eq(ComponentTypeEnum.SERVICE), any(ComponentInstInputsMap.class)))
+ .thenReturn(Either.left(Collections.singletonList(new InputDefinition())));
+
Either<Service, ResponseFormat> createResponse = bl.createService(service, user);
assertTrue(createResponse.isLeft());
service = createResponse.left().value();
@@ -876,7 +893,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
@Test
void testCreateDefaultMetadataServiceFunction() {
Service currentService = createServiceObject(true);
- assertThat(currentService.getServiceFunction()).isEqualTo("");
+ assertThat(currentService.getServiceFunction()).isEmpty();
}
@Test
@@ -906,11 +923,10 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
newService.setServiceFunction(null);
resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
assertThat(resultOfUpdate.isLeft()).isTrue();
- assertThat(updatedService.getServiceFunction()).isEqualTo("");
+ assertThat(updatedService.getServiceFunction()).isEmpty();
}
-
@Test
void testServiceFunctionExceedLength() {
String serviceName = "Service";
@@ -929,7 +945,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
}
@Test
- void testServiceFunctionInvalidCharacter(){
+ void testServiceFunctionInvalidCharacter() {
String serviceName = "Service";
String serviceFunction = "a?";
Service serviceFunctionExceedLength = createServiceObject(false);
@@ -950,8 +966,8 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", "2", "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", "2", "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
@@ -962,8 +978,8 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", "2", "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", "2", "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
@@ -977,8 +993,8 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
String weirdUniqueServiceInstanceId = UUID.randomUUID().toString();
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", weirdUniqueServiceInstanceId, "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", weirdUniqueServiceInstanceId, "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
@@ -991,8 +1007,8 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
@@ -1005,15 +1021,15 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap =
- Maps.newHashMap();
+ Maps.newHashMap();
componentInstancesInterfacesMap.put(aService.getUniqueId(),
- Lists.newArrayList(new ComponentInstanceInterface("1", new InterfaceInstanceDataDefinition())));
+ Lists.newArrayList(new ComponentInstanceInterface("1", new InterfaceInstanceDataDefinition())));
aService.setComponentInstancesInterfaces(componentInstancesInterfacesMap);
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
@@ -1027,10 +1043,10 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
String operationId = "operationId";
ComponentInstanceInterface componentInstanceInterface =
- new ComponentInstanceInterface("interfaceId", new InterfaceInstanceDataDefinition());
+ new ComponentInstanceInterface("interfaceId", new InterfaceInstanceDataDefinition());
Map<String, Operation> operationsMap = Maps.newHashMap();
operationsMap.put(operationId, new Operation(new ArtifactDataDefinition(), "1",
- new ListDataDefinition<>(), new ListDataDefinition<>()));
+ new ListDataDefinition<>(), new ListDataDefinition<>()));
componentInstanceInterface.setOperationsMap(operationsMap);
Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap = Maps.newHashMap();
@@ -1038,8 +1054,8 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
aService.setComponentInstancesInterfaces(componentInstancesInterfacesMap);
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", aService.getUniqueId(), operationId,
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", aService.getUniqueId(), operationId,
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}