diff options
25 files changed, 749 insertions, 515 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index e7ae0612f4..fee386ab29 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -40,6 +40,7 @@ import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations; +import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.*; @@ -122,6 +123,12 @@ public abstract class BaseBusinessLogic { @Autowired protected ApplicationDataTypeCache dataTypeCache; + @Autowired + protected InterfaceOperation interfaceOperation; + + @Autowired + protected InterfaceOperationBusinessLogic interfaceOperationBusinessLogic; + @javax.annotation.Resource private UserValidations userValidations; @@ -156,6 +163,10 @@ public abstract class BaseBusinessLogic { this.propertyOperation = propertyOperation; } + public void setInterfaceOperation(InterfaceOperation interfaceOperation) { + this.interfaceOperation = interfaceOperation; + } + User validateUserNotEmpty(User user, String ecompErrorContext) { return userValidations.validateUserNotEmpty(user, ecompErrorContext); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index 2f4519beb9..792e23af3b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -18,7 +18,7 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; -import java.util.Arrays; +import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -28,9 +28,7 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; -import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation; import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; @@ -55,13 +53,6 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { @Autowired private InterfaceOperationValidation interfaceOperationValidation; - @Autowired - private InterfaceOperation interfaceOperation; - - public void setInterfaceOperation(InterfaceOperation interfaceOperation) { - this.interfaceOperation = interfaceOperation; - } - public void setInterfaceOperationValidation(InterfaceOperationValidation interfaceOperationValidation) { this.interfaceOperationValidation = interfaceOperationValidation; } @@ -74,18 +65,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true); - Either<Boolean, ResponseFormat> lockResult = null; - if (lock) { - lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, DELETE_INTERFACE_OPERATION); - if (lockResult.isRight()) { - LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage()); - titanDao.rollback(); - return Either.right(lockResult.right().value()); - } + Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION); + if (lockResult.isRight()) { + return Either.right(lockResult.right().value()); } try { - Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName()); + Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName()); Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null)); if (getInterfaceEither.isRight()) { return Either.right(getInterfaceEither.right().value()); @@ -112,7 +98,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED)); } finally { - if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) { + if (lockResult.isLeft() && lockResult.left().value()) { graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); } } @@ -126,18 +112,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true); - Either<Boolean, ResponseFormat> lockResult = null; - if (lock) { - lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, GET_INTERFACE_OPERATION); - if (lockResult.isRight()) { - LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage()); - titanDao.rollback(); - return Either.right(lockResult.right().value()); - } + Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION); + if (lockResult.isRight()) { + return Either.right(lockResult.right().value()); } try { - Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName()); + Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName()); Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null)); if (getInterfaceEither.isRight()) { return Either.right(getInterfaceEither.right().value()); @@ -158,13 +139,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId)); } finally { - if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) { + if (lockResult.isLeft() && lockResult.left().value()) { graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); } } } - public Either<InterfaceDefinition, ResponseFormat> getInterfaceDefinition(org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDef) { + private Either<InterfaceDefinition, ResponseFormat> getInterfaceDefinition(org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDef) { if (interfaceDef != null){ return Either.left(interfaceDef); } else { @@ -195,26 +176,19 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); validateUserExists(user.getUserId(), errorContext, true); - - InterfaceUtils.createInputOutput(operation, storedComponent.getInputs(), storedComponent.getInputs()); Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither = interfaceOperationValidation - .validateInterfaceOperations(Arrays.asList(operation), storedComponent, isUpdate); + .validateInterfaceOperations(Collections.singletonList(operation), storedComponent, isUpdate); if(interfaceOperationValidationResponseEither.isRight()) { return Either.right(interfaceOperationValidationResponseEither.right().value()); } - Either<Boolean, ResponseFormat> lockResult = null; - if (lock) { - lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, errorContext); - if (lockResult.isRight()) { - LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage()); - titanDao.rollback(); - return Either.right(lockResult.right().value()); - } + Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, errorContext); + if (lockResult.isRight()) { + return Either.right(lockResult.right().value()); } try { - Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName()); + Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName()); Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null)); if (getInterfaceEither.isRight()) { return Either.right(getInterfaceEither.right().value()); @@ -250,7 +224,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); } finally { - if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) { + if (lockResult.isLeft() && lockResult.left().value()) { graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); } } @@ -287,4 +261,16 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { operation.setUniqueId(UUID.randomUUID().toString()); operation.setImplementation(artifactDefinition); } + + private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock, org.openecomp.sdc.be.model.Component component, String action){ + if (lock) { + Either<Boolean, ResponseFormat> lockResult = lockComponent(component.getUniqueId(), component, action); + if (lockResult.isRight()) { + LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, component.getName(), lockResult.right().value().getFormattedMessage()); + titanDao.rollback(); + return Either.right(lockResult.right().value()); + } + } + return Either.left(true); + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java index affafaed12..8c90501140 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java @@ -17,29 +17,33 @@ package org.openecomp.sdc.be.components.validation; import fj.data.Either; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import org.elasticsearch.common.Strings; import org.openecomp.sdc.be.components.impl.ResponseFormatManager; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; +import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; -import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + @Component("interfaceOperationValidation") public class InterfaceOperationValidation { @@ -77,6 +81,13 @@ public class InterfaceOperationValidation { return Either.right(descriptionResponseEither.right().value()); } + Either<Boolean, ResponseFormat> inputPropertyExistInComponent = validateInputPropertyExistInComponent(interfaceOperation, + component.getInputs(), responseFormatManager); + if(inputPropertyExistInComponent.isRight()) { + return Either.right(inputPropertyExistInComponent.right().value()); + + } + Either<Boolean, ResponseFormat> inputParametersResponse = validateInputParameters(interfaceOperation, responseFormatManager); if(inputParametersResponse.isRight()) { @@ -109,14 +120,14 @@ public class InterfaceOperationValidation { } Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation, - component, isUpdate, responseFormatManager ); + component, isUpdate ); if(operationTypeUniqueResponse.isRight()) { return Either.right(operationTypeUniqueResponse.right().value()); } if (!operationTypeUniqueResponse.left().value()) { LOGGER.error("Interface Operation type {} already in use ", interfaceOperation.getName()); ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus - .INTERFACE_OPERATION_TYPE_ALREADY_IN_USE, interfaceOperation.getName()); + .INTERFACE_OPERATION_NAME_ALREADY_IN_USE, interfaceOperation.getName()); return Either.right(errorResponse); } return Either.left(Boolean.TRUE); @@ -128,7 +139,7 @@ public class InterfaceOperationValidation { LOGGER.error("Interface Operation type {} is invalid, Operation type should not contain" + "Special character, space, numbers and should not be greater than 200 characters", operationType); ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus - .INTERFACE_OPERATION_TYPE_INVALID, operationType); + .INTERFACE_OPERATION_NAME_INVALID, operationType); return Either.right(errorResponse); } return Either.left(Boolean.TRUE); @@ -139,7 +150,7 @@ public class InterfaceOperationValidation { if (StringUtils.isEmpty(operationType)) { LOGGER.error("Interface Operation type is mandatory"); ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus - .INTERFACE_OPERATION_TYPE_MANDATORY); + .INTERFACE_OPERATION_NAME_MANDATORY); return Either.right(errorResponse); } return Either.left(Boolean.TRUE); @@ -150,7 +161,7 @@ public class InterfaceOperationValidation { if (!Strings.isNullOrEmpty(description) && description.length() > DESCRIPTION_MAX_LENGTH) { LOGGER.error("Interface Operation description {} is invalid, maximum 200 characters allowed", description); ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus - .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH); + .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH, description); return Either.right(errorResponse); } return Either.left(Boolean.TRUE); @@ -163,14 +174,12 @@ public class InterfaceOperationValidation { private Either<Boolean, ResponseFormat> validateOperationTypeUnique( Operation interfaceOperation, org.openecomp.sdc.be.model.Component component, - boolean isUpdate, - ResponseFormatManager responseFormatManager) { + boolean isUpdate) { boolean isOperationTypeUnique = false; - Map<String, InterfaceDefinition> interfaceDefinitionMap = ((Resource)component).getInterfaces(); + Map<String, InterfaceDefinition> interfaceDefinitionMap = component.getInterfaces(); if(interfaceDefinitionMap.isEmpty()){ - isOperationTypeUnique = true; - return Either.left(isOperationTypeUnique); + return Either.left(true); } Collection<Operation> allOperations = interfaceDefinitionMap.values().stream() @@ -178,8 +187,7 @@ public class InterfaceOperationValidation { .map(a -> a.getOperationsMap().values()).flatMap(Collection::stream) .collect(Collectors.toList()); if(CollectionUtils.isEmpty(allOperations)){ - isOperationTypeUnique = true; - return Either.left(isOperationTypeUnique); + return Either.left(true); } Map<String, String> operationTypes = new HashMap<>(); @@ -236,8 +244,6 @@ public class InterfaceOperationValidation { } return Either.left(Boolean.TRUE); } - - private Either<Boolean, Set<String>> isInputParametersUnique(Operation operationDataDefinition) { Set<String> inputParamNamesSet = new HashSet<>(); Set<String> duplicateParamNamesToReturn = new HashSet<>(); @@ -277,17 +283,32 @@ public class InterfaceOperationValidation { .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY)); } - private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation, Map<String, String> operationTypes) { - boolean isOperationTypeUnique = false; - Optional<String> id = operationTypes.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), interfaceOperation.getName())) - .map(Map.Entry::getKey).findAny(); - if(id.isPresent() && id.get().equalsIgnoreCase(interfaceOperation.getUniqueId())){ - isOperationTypeUnique = true; + private Either<Boolean, ResponseFormat> validateInputPropertyExistInComponent(Operation operation, + List<InputDefinition> inputs, + ResponseFormatManager responseFormatManager) { + ListDataDefinition<OperationInputDefinition> inputDefinitionListDataDefinition = operation.getInputs(); + if (inputDefinitionListDataDefinition == null) { + return Either.left(Boolean.TRUE); + } + List<OperationInputDefinition> inputListToscaDataDefinition = inputDefinitionListDataDefinition.getListToscaDataDefinition(); + + for(OperationInputDefinition inputDefinition : inputListToscaDataDefinition ) { + if(!validateInputExistsInComponent(inputDefinition, inputs)) { + String missingPropertyName = inputDefinition.getInputId().contains(".") ? inputDefinition.getInputId().substring(inputDefinition.getInputId().indexOf(".") + 1) : inputDefinition.getInputId(); + LOGGER.error("Interface operation input property {} not found in component input properties", missingPropertyName); + ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT, missingPropertyName); + return Either.right(inputResponse); + } } - return isOperationTypeUnique; + return Either.left(Boolean.TRUE); + } + + private boolean validateInputExistsInComponent(OperationInputDefinition input, + List<InputDefinition> inputs) { + return inputs.stream().anyMatch(inp -> inp.getUniqueId().equals(input.getInputId())); } - protected ResponseFormatManager getResponseFormatManager() { + private ResponseFormatManager getResponseFormatManager() { return ResponseFormatManager.getInstance(); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java index f0cdf3ec70..bdbf20a2b7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java @@ -40,7 +40,7 @@ public class InterfaceUIDataConverter { .map(interfaceOperationParamDataDefinition -> new OperationInputDefinition( interfaceOperationParamDataDefinition.getName(), interfaceOperationParamDataDefinition.getProperty(), - interfaceOperationParamDataDefinition.getMandatory(), + interfaceOperationParamDataDefinition.getMandatory() == null ? false : interfaceOperationParamDataDefinition.getMandatory(), interfaceOperationParamDataDefinition.getType() )).collect(Collectors.toList()); inputList.forEach(inputs::add); @@ -70,7 +70,6 @@ public class InterfaceUIDataConverter { } public static InterfaceOperationDataDefinition convertOperationDataToInterfaceData(Operation operationData){ - ListDataDefinition<OperationInputDefinition> inputs = operationData.getInputs(); List<InterfaceOperationParamDataDefinition> inputParamList = inputs.getListToscaDataDefinition().stream() .map(operationInputDefinition -> new InterfaceOperationParamDataDefinition(operationInputDefinition.getName(), diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java index a3731dd9b9..899a7b1cb8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java @@ -339,6 +339,9 @@ public class UiComponentDataConverter { UiServiceMetadata metadata = new UiServiceMetadata(service.getCategories(), (ServiceMetadataDataDefinition) service.getComponentMetadataDefinition().getMetadataDataDefinition()); dataTransfer.setMetadata(metadata); break; + case INTERFACES: + setInterfaces(service, dataTransfer); + break; default: setUiTranferDataByFieldName(dataTransfer, service, fieldName); } @@ -362,6 +365,13 @@ public class UiComponentDataConverter { } } + private void setInterfaces(Service service, UiServiceDataTransfer dataTransfer) { + if (service.getInterfaces() == null) { + dataTransfer.setInterfaces(new HashMap<>()); + } else { + dataTransfer.setInterfaces(service.getInterfaces()); + } + } public static UiComponentMetadata convertToUiComponentMetadata(Component component) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java index 3e43dd7a91..815f9763f9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java @@ -49,21 +49,21 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; -import org.openecomp.sdc.be.ui.model.UiResourceDataTransfer; +import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) -@Path("/v1/catalog/resources/{resourceId}/interfaceOperations") +@Path("/v1/catalog/{componentType}/{componentId}/interfaceOperations") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Api(value = "Interface Operation", description = "Interface Operation Servlet") @Singleton -public class ResourceInterfaceOperationServlet extends AbstractValidationsServlet { +public class InterfaceOperationServlet extends AbstractValidationsServlet { - private static final Logger log = LoggerFactory.getLogger(ResourceInterfaceOperationServlet.class); + private static final Logger log = LoggerFactory.getLogger(InterfaceOperationServlet.class); @POST @Consumes(MediaType.APPLICATION_JSON) @@ -76,10 +76,11 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle @ApiResponse(code = 409, message = "Interface Operation already exist")}) public Response createInterfaceOperation( @ApiParam(value = "Interface Operation to create", required = true) String data, - @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId, + @ApiParam(value = "Component type") @PathParam("componentType") String componentType, + @ApiParam(value = "Component Id") @PathParam("componentId") String componentId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - return createOrUpdate(data, resourceId, request, userId, false); + return createOrUpdate(data, componentType ,componentId, request, userId, false); } @PUT @@ -92,10 +93,11 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle @ApiResponse(code = 400, message = "Invalid content / Missing content")}) public Response updateInterfaceOperation( @ApiParam(value = "Interface Operation to update", required = true) String data, - @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId, + @ApiParam(value = "Component type") @PathParam("componentType") String componentType, + @ApiParam(value = "Component Id") @PathParam("componentId") String componentId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - return createOrUpdate(data, resourceId, request, userId, true); + return createOrUpdate(data, componentType,componentId, request, userId, true); } @DELETE @@ -108,10 +110,10 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle @ApiResponse(code = 400, message = "Invalid content / Missing content")}) public Response deleteInterfaceOperation( @ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId, - @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId, + @ApiParam(value = "Component Id") @PathParam("componentId") String componentId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - return delete(interfaceOperationId, resourceId, request, userId); + return delete(interfaceOperationId, componentId, request, userId); } @GET @@ -124,14 +126,14 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle @ApiResponse(code = 400, message = "Invalid content / Missing content")}) public Response getInterfaceOperation( @ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId, - @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId, + @ApiParam(value = "Component Id") @PathParam("componentId") String componentId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - return get(interfaceOperationId, resourceId, request, userId); + return get(interfaceOperationId, componentId, request, userId); } - private Response get (String interfaceOperationId, String resourceId, HttpServletRequest request, String userId){ + private Response get (String interfaceOperationId, String componentId, HttpServletRequest request, String userId){ ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); @@ -140,10 +142,10 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle log.debug("Start get request of {} with modifier id {}", url, userId); try { - String resourceIdLower = resourceId.toLowerCase(); + String componentIdLower = componentId.toLowerCase(); InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - Either<Operation, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true); + Either<Operation, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation(componentIdLower, interfaceOperationId, modifier, true); if (actionResponse.isRight()) { log.error("failed to get interface operation"); return buildErrorResponse(actionResponse.right().value()); @@ -154,13 +156,13 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); } catch (Exception e) { - BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource interface operations"); - log.error("get resource interface operations failed with exception", e); + BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component interface operations"); + log.error("get component interface operations failed with exception", e); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } } - private Response delete (String interfaceOperationId, String resourceId, HttpServletRequest + private Response delete (String interfaceOperationId, String componentId, HttpServletRequest request, String userId){ ServletContext context = request.getSession().getServletContext(); @@ -171,10 +173,10 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle log.debug("Start delete request of {} with modifier id {}", url, userId); try { - String resourceIdLower = resourceId.toLowerCase(); + String componentIdLower = componentId.toLowerCase(); InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - Either<Operation, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true); + Either<Operation, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation(componentIdLower, interfaceOperationId, modifier, true); if (actionResponse.isRight()) { log.error("failed to delete interface operation"); return buildErrorResponse(actionResponse.right().value()); @@ -191,7 +193,7 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle } } - private Response createOrUpdate (String data, String resourceId, HttpServletRequest request, String userId, boolean isUpdate) { + private Response createOrUpdate (String data, String componentType, String componentId, HttpServletRequest request, String userId, boolean isUpdate) { ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); @@ -200,15 +202,15 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle log.debug("Start create or update request of {} with modifier id {}", url, userId); try { - String resourceIdLower = resourceId.toLowerCase(); + String componentIdLower = componentId.toLowerCase(); InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - Operation operation = getMappedOperationData(data, isUpdate, modifier); + Operation operation = getMappedOperationData(data, isUpdate, modifier, ComponentTypeEnum.findByParamName(componentType)); Either<Operation, ResponseFormat> actionResponse ; if (isUpdate) { - actionResponse = businessLogic.updateInterfaceOperation(resourceIdLower, operation, modifier, true); + actionResponse = businessLogic.updateInterfaceOperation(componentIdLower, operation, modifier, true); } else { - actionResponse = businessLogic.createInterfaceOperation(resourceIdLower, operation, modifier, true); + actionResponse = businessLogic.createInterfaceOperation(componentIdLower, operation, modifier, true); } if (actionResponse.isRight()) { @@ -227,9 +229,9 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle } } - private Operation getMappedOperationData(String inputJson, boolean isUpdate, User user){ - Either<UiResourceDataTransfer, ResponseFormat> uiResourceEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, UiResourceDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.RESOURCE); - Optional<InterfaceOperationDataDefinition> opDef = uiResourceEither.left().value().getInterfaceOperations().values().stream().findFirst(); + private Operation getMappedOperationData(String inputJson, boolean isUpdate, User user, ComponentTypeEnum componentTypeEnum){ + Either<UiComponentDataTransfer, ResponseFormat> uiComponentEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, UiComponentDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum); + Optional<InterfaceOperationDataDefinition> opDef = uiComponentEither.left().value().getInterfaceOperations().values().stream().findFirst(); InterfaceOperationDataDefinition interfaceOperationDataDefinition = new InterfaceOperationDataDefinition(); if(opDef.isPresent()) { interfaceOperationDataDefinition = opDef.get(); 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 e5e5f1648a..d62c2c64eb 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 @@ -561,7 +561,7 @@ public class ToscaExportHandler { List<InputDefinition> inputDef = component.getInputs(); Map<String, ToscaProperty> inputs = new HashMap<>(); - + addInterfaceDefinitionElement(component, toscaNodeType); if (inputDef != null) { inputDef.forEach(i -> { ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false); @@ -569,7 +569,6 @@ public class ToscaExportHandler { }); if (!inputs.isEmpty()) { toscaNodeType.setProperties(inputs); - addInterfaceDefinitionElement(component, toscaNodeType); } } return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java index 75a65f95da..5370a7849e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java @@ -18,29 +18,25 @@ package org.openecomp.sdc.be.tosca.utils; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; + import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Product; -import org.openecomp.sdc.be.model.Resource; -import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition; import org.openecomp.sdc.be.tosca.model.ToscaInterfaceNodeType; import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; import org.openecomp.sdc.be.tosca.model.ToscaProperty; -/** - * @author KATYR - * @since March 20, 2018 - */ public class InterfacesOperationsToscaUtil { @@ -50,7 +46,6 @@ public class InterfacesOperationsToscaUtil { private static final String DEFAULT = "default"; private static final String DEFAULT_HAS_UNDERSCORE = "_default"; private static final String DOT = "."; - private static final String DEFAULT_INPUT_TYPE = "string"; private static final String SELF = "SELF"; private static final String GET_PROPERTY = "get_property"; private static final String DEFAULTP = "defaultp"; @@ -65,16 +60,11 @@ public class InterfacesOperationsToscaUtil { * @return the added element */ public static Map<String, Object> addInterfaceTypeElement(Component component) { - Map<String, Object> toscaInterfaceTypes = new HashMap<>(); - if ((component instanceof Service) || (component instanceof Product)) { - return null; - } - - final Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces(); - if (MapUtils.isEmpty(interfaces)) { + if (component instanceof Product) { return null; } - + final Map<String, InterfaceDefinition> interfaces = component.getInterfaces(); + Map<String, Object> toscaInterfaceTypes = new HashMap<>(); for (InterfaceDefinition interfaceDefinition : interfaces.values()) { ToscaInterfaceNodeType toscaInterfaceType = new ToscaInterfaceNodeType(); toscaInterfaceType.setDerived_from(DERIVED_FROM_STANDARD_INTERFACE); @@ -86,8 +76,6 @@ public class InterfacesOperationsToscaUtil { toscaOperations.put(operationEntry.getValue().getName(), null); //currently not initializing any of the operations' fields as it is not needed } - - toscaInterfaceType.setOperations(toscaOperations); Map<String, Object> interfacesAsMap = getObjectAsMap(toscaInterfaceType); Map<String, Object> operationsMap = (Map<String, Object>) interfacesAsMap.remove(OPERATIONS_KEY); @@ -95,7 +83,7 @@ public class InterfacesOperationsToscaUtil { toscaInterfaceTypes.put(interfaceDefinition.getToscaResourceName(), interfacesAsMap); } - return toscaInterfaceTypes; + return MapUtils.isNotEmpty(toscaInterfaceTypes) ? toscaInterfaceTypes : null; } /** @@ -105,16 +93,14 @@ public class InterfacesOperationsToscaUtil { * @param nodeType to which the interfaces element will be added */ public static void addInterfaceDefinitionElement(Component component, ToscaNodeType nodeType) { - Map<String, Object> toscaInterfaceDefinitions = new HashMap<>(); - - if ((component instanceof Service) || (component instanceof Product)) { + if (component instanceof Product) { return; } - - final Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces(); + final Map<String, InterfaceDefinition> interfaces = component.getInterfaces(); if (MapUtils.isEmpty(interfaces)) { return; } + Map<String, Object> toscaInterfaceDefinitions = new HashMap<>(); for (InterfaceDefinition interfaceDefinition : interfaces.values()) { ToscaInterfaceDefinition toscaInterfaceDefinition = new ToscaInterfaceDefinition(); final String toscaResourceName = interfaceDefinition.getToscaResourceName(); @@ -133,7 +119,7 @@ public class InterfacesOperationsToscaUtil { toscaOperation.setImplementation(operationArtifactPath); } toscaOperation.setDescription(operationEntry.getValue().getDescription()); - fillToscaOperationInputs(operationEntry.getValue(), toscaOperation, nodeType); + fillToscaOperationInputs(operationEntry.getValue(), toscaOperation); toscaOperations.put(operationEntry.getValue().getName(), toscaOperation); } @@ -145,7 +131,9 @@ public class InterfacesOperationsToscaUtil { interfaceDefAsMap.putAll(operationsMap); toscaInterfaceDefinitions.put(getLastPartOfName(toscaResourceName), interfaceDefAsMap); } - nodeType.setInterfaces(toscaInterfaceDefinitions); + if (MapUtils.isNotEmpty(toscaInterfaceDefinitions)) { + nodeType.setInterfaces(toscaInterfaceDefinitions); + } } /*** @@ -180,8 +168,7 @@ public class InterfacesOperationsToscaUtil { } private static void fillToscaOperationInputs(OperationDataDefinition operation, - ToscaLifecycleOperationDefinition toscaOperation, - ToscaNodeType nodeType) { + ToscaLifecycleOperationDefinition toscaOperation) { if (Objects.isNull(operation.getInputs()) || operation.getInputs().isEmpty()) { toscaOperation.setInputs(null); return; @@ -192,22 +179,15 @@ public class InterfacesOperationsToscaUtil { ToscaProperty toscaInput = new ToscaProperty(); toscaInput.setDescription(input.getDescription()); String mappedPropertyName = getLastPartOfName(input.getInputId()); - toscaInput.setType(getOperationInputType(mappedPropertyName, nodeType)); + toscaInput.setType(input.getType()); toscaInput.setDefaultp(createDefaultValue(mappedPropertyName)); + toscaInput.setRequired(input.isRequired()); toscaInputs.put(input.getName(), toscaInput); } toscaOperation.setInputs(toscaInputs); } - private static String getOperationInputType(String inputName, ToscaNodeType nodeType) { - if (nodeType.getProperties() != null - && nodeType.getProperties().containsKey(inputName)) { - return nodeType.getProperties().get(inputName).getType(); - } - return DEFAULT_INPUT_TYPE; - } - private static Map<String, List<String>> createDefaultValue(String propertyName) { Map<String, List<String>> getPropertyMap = new HashMap<>(); List<String> values = new ArrayList<>(); diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml index 26fee5b28e..6156090df3 100644 --- a/catalog-be/src/main/resources/config/error-configuration.yaml +++ b/catalog-be/src/main/resources/config/error-configuration.yaml @@ -2025,50 +2025,50 @@ errors: messageId: "SVC4694" } #---------SVC4695----------------------------- -# %1 - Interface operation type - INTERFACE_OPERATION_TYPE_ALREADY_IN_USE: { +# %1 - Interface Operation Name + INTERFACE_OPERATION_NAME_ALREADY_IN_USE: { code: 400, - message: "Error: Interface Operation type %1 already in use", + message: "Error: Interface Operation name '%1' already in use, Your current changes will not be saved.", messageId: "SVC4695" } #---------SVC4696----------------------------- -# %1 - workflow operation type - INTERFACE_OPERATION_TYPE_INVALID: { +# %1 - Interface Operation Name + INTERFACE_OPERATION_NAME_INVALID: { code: 400, - message: "Error: Interface Operation type %1 is Invalid, Operation type should not contain - special character, space, numbers and should not be greater than 200 characters ", + message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space, numbers and should not be greater than 200 characters.", messageId: "SVC4696" } #---------SVC4697----------------------------- - INTERFACE_OPERATION_TYPE_MANDATORY: { + INTERFACE_OPERATION_NAME_MANDATORY: { code: 404, - message: "Error: Interface Operation type is mandatory, Operation type can't be empty", + message: "Error: Interface Operation name is mandatory, Operation name can't be empty.", messageId: "SVC4697" } #---------SVC4698----------------------------- -# %1 - workflow operation description +# %1 - Interface Operation description INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH: { code: 400, - message: "Error: Interface Operation description %1 is invalid, maximum 200 characters allowed", + message: "Error: Interface Operation description '%1' is invalid, maximum 200 characters allowed.", messageId: "SVC4698" } #---------SVC4699----------------------------- +# %1 - Interface Operation input parameter name INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE: { code: 400, - message: "Error: Interface Operation input parameter names %1 already in use", + message: "Error: Interface Operation input parameter name '%1' already in use, Your current changes will not be saved.", messageId: "SVC4699" } #---------SVC4700----------------------------- - INTERFACE_OPERATION_OUTPUT_NAME_INVALID: { - code: 400, - message: "Error: Interface Operation output parameters invalid, should be unique and mandatory", - messageId: "SVC4700" + INTERFACE_OPERATION_INPUT_NAME_MANDATORY: { + code: 404, + message: "Error: Interface operation input parameter name should not be empty.", + messageId: "SVC4700" } #---------SVC4701----------------------------- # %1 - resource Id INTERFACE_OPERATION_NOT_FOUND: { code: 404, - message: "Error: Interface operations not found in the resource %1", + message: "Error: Interface operation not found in the resource '%1'.", messageId: "SVC4701" } #---------SVC4702----------------------------- @@ -2127,10 +2127,24 @@ errors: message: "Error: CSAR packaging failed for %1 %2.", messageId: "SVC4706" } -#---------SVC46708----------------------------- - INTERFACE_OPERATION_INPUT_NAME_MANDATORY: { - code: 404, - message: "Error: Interface operation input parameter name should not be empty", - messageId: "SVC46707" - } +#---------SVC4704----------------------------- +# %1 - Interface Operation input property name + INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT: { + code: 404, + message: "Error: Interface operation input parameter property '%1' not found in component input properties.", + messageId: "SVC4704" + } +#---------SVC4705----------------------------- +# %1 - Interface Operation output parameter name + INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE: { + code: 400, + message: "Error: Interface Operation output parameter name '%1' already in use, Your current changes will not be saved.", + messageId: "SVC4705" + } +#---------SVC4706----------------------------- + INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY: { + code: 404, + message: "Error: Interface operation output parameter name should not be empty.", + messageId: "SVC4706" + } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java index eb17d56154..e8a698fec1 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java @@ -40,7 +40,6 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.ElementOperationMock; import org.openecomp.sdc.be.auditing.impl.AuditingManager; -import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic; import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -56,7 +55,6 @@ import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.DataTypeDefinition; -import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.Resource; @@ -83,42 +81,37 @@ import org.springframework.web.context.WebApplicationContext; public class InterfaceOperationBusinessLogicTest { - public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3"; - public static final String RESOURCE_SUBCATEGORY = "Router"; - - private String resourceId = "resourceId1"; - private String operationId = "uniqueId1"; - Resource resourceUpdate; - Operation operation; - - public static final String RESOURCE_NAME = "My-Resource_Name with space"; - - final ServletContext servletContext = Mockito.mock(ServletContext.class); - IElementOperation mockElementDao; - TitanDao mockTitanDao = Mockito.mock(TitanDao.class); - UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class); - ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class); - NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class); - NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class); - TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class); - final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class); - final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class); - WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class); - UserValidations userValidations = Mockito.mock(UserValidations.class); - WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class); - ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class); - InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class); - InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class); - - ResponseFormatManager responseManager = null; - GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class); - User user = null; - Resource resourceResponse = null; - ComponentsUtils componentsUtils; - ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(); - private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class); + private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3"; + private static final String RESOURCE_SUBCATEGORY = "Router"; + + private final String resourceId = "resourceId1"; + private final String operationId = "uniqueId1"; + private Operation operation; + + private static final String RESOURCE_NAME = "My-Resource_Name with space"; + + private final ServletContext servletContext = Mockito.mock(ServletContext.class); + private final TitanDao mockTitanDao = Mockito.mock(TitanDao.class); + private final UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class); + private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class); + private final NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class); + private final NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class); + private final TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class); + private final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class); + private final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class); + private final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class); + private final UserValidations userValidations = Mockito.mock(UserValidations.class); + private final WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class); + private final ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class); + private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class); + private final InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class); + + private final GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class); + private User user = null; + private final ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(); @InjectMocks + private InterfaceOperationBusinessLogic bl = new InterfaceOperationBusinessLogic(); @Before @@ -132,10 +125,10 @@ public class InterfaceOperationBusinessLogicTest { String appConfigDir = "src/test/resources/config/catalog-be"; ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); - componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); + ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); // Elements - mockElementDao = new ElementOperationMock(); + IElementOperation mockElementDao = new ElementOperationMock(); // User data and management user = new User(); @@ -172,23 +165,22 @@ public class InterfaceOperationBusinessLogicTest { when(graphLockOperation.lockComponentByName(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK); // createResource - resourceResponse = createResourceObject(true); + Resource resourceResponse = createResourceObject(true); Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse); - Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null); when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate); //TODO Remove if passes /*when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);*/ - Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>(); + Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>(); when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes)); //InterfaceOperation when(operationValidator.validateInterfaceOperations(anyCollection(), anyObject(), anyBoolean())).thenReturn(Either.left(true)); when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); - when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); - when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); - when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); - when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK); @@ -210,7 +202,6 @@ public class InterfaceOperationBusinessLogicTest { setCanWorkOnResource(resourceCsar); Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar); when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes); - responseManager = ResponseFormatManager.getInstance(); } @Test @@ -260,37 +251,13 @@ public class InterfaceOperationBusinessLogicTest { private void validateUserRoles(Role... roles) { List<Role> listOfRoles = Stream.of(roles).collect(Collectors.toList()); - } + } - private Resource setCanWorkOnResource(Resource resource) { + private void setCanWorkOnResource(Resource resource) { resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); resource.setLastUpdaterUserId(user.getUserId()); - return resource; - } - - private Resource setUpResourceMock(){ - Resource resource = new Resource(); - resource.setUniqueId(resourceId); - resource.setName(RESOURCE_NAME); - resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY); - resource.setDescription("My short description"); - resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinition(RESOURCE_NAME)); - - List<InputDefinition> inputDefinitionList = new ArrayList<>(); - inputDefinitionList.add(createInputDefinition("uniqueId1")); - resource.setInputs(inputDefinitionList); - - return resource; } - private InputDefinition createInputDefinition(String inputId) { - InputDefinition inputDefinition = new InputDefinition(); - inputDefinition.setInputId(inputId); - inputDefinition.setDescription("Input Description"); - - return inputDefinition; - - } private Resource createResourceForInterfaceOperation() { Resource resource = new Resource(); resource.setUniqueId(resourceId); @@ -306,11 +273,11 @@ public class InterfaceOperationBusinessLogicTest { resource.setName(RESOURCE_NAME); resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY); resource.setDescription("My short description"); - List<String> tgs = new ArrayList<String>(); + List<String> tgs = new ArrayList<>(); tgs.add("test"); tgs.add(resource.getName()); resource.setTags(tgs); - List<String> template = new ArrayList<String>(); + List<String> template = new ArrayList<>(); template.add("Root"); resource.setDerivedFrom(template); resource.setVendorName("Motorola"); @@ -324,7 +291,6 @@ public class InterfaceOperationBusinessLogicTest { if (afterCreate) { resource.setName(resource.getName()); resource.setVersion("0.1"); - resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion()); resource.setCreatorUserId(user.getUserId()); resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName()); @@ -338,11 +304,11 @@ public class InterfaceOperationBusinessLogicTest { resource.setName(RESOURCE_NAME); resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY); resource.setDescription("My short description"); - List<String> tgs = new ArrayList<String>(); + List<String> tgs = new ArrayList<>(); tgs.add("test"); tgs.add(resource.getName()); resource.setTags(tgs); - List<String> template = new ArrayList<String>(); + List<String> template = new ArrayList<>(); template.add("Root"); resource.setDerivedFrom(template); resource.setVendorName("Motorola"); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java index d41294b4c2..6fe2f1308c 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java @@ -21,8 +21,11 @@ import static org.mockito.Mockito.when; import com.google.common.collect.Sets; import fj.data.Either; + +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import org.junit.Assert; @@ -35,20 +38,23 @@ import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.ComponentInstanceInput; +import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.exception.ResponseFormat; import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils; public class InterfaceOperationValidationTest { - private Resource resource = setUpResourceMock(); - ResponseFormatManager responseFormatManagerMock; + private final Component component = setUpComponentMock(); + private ResponseFormatManager responseFormatManagerMock; - InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest(); - ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>(); - ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>(); + private final InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest(); + private final ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>(); + private final ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>(); @Before public void init() { @@ -67,7 +73,7 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"upgrade"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isLeft()); } @@ -78,10 +84,10 @@ public class InterfaceOperationValidationTest { Collection<Operation> operations = createInterfaceOperationData("op2", "interface operation2 - The Spring Initializer provides a project generator to make you " + "productive with the certain technology stack from the beginning. You can create a skeleton project" + - "with web, data access (relational and NoSQL datastores), cloud, or messaging support", + "with web, data access (relational and NoSQL data stores), cloud, or messaging support", new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -95,7 +101,7 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList, ""); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -107,7 +113,7 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"input2"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -119,7 +125,7 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"CREATE"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -132,9 +138,9 @@ public class InterfaceOperationValidationTest { operationOutputDefinitionList, "interface operation2 - The Spring Initializer provides a project generator to make you " + "productive with the certain technology stack from the beginning. You can create a skeleton project" + - "with web, data access (relational and NoSQL datastores), cloud, or messaging support"); + "with web, data access (relational and NoSQL data stores), cloud, or messaging support"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -151,7 +157,7 @@ public class InterfaceOperationValidationTest { operationOutputDefinitionList,"create"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -166,12 +172,12 @@ public class InterfaceOperationValidationTest { Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isLeft()); } @Test - public void testInterfaceOperationeInputParamNameEmpty() { + public void testInterfaceOperationInputParamNameEmpty() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(" ")); operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); @@ -181,7 +187,7 @@ public class InterfaceOperationValidationTest { Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -191,10 +197,33 @@ public class InterfaceOperationValidationTest { return Sets.newHashSet(InterfaceOperationTestUtils.createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, outputs, name)); } - private Resource setUpResourceMock(){ - Resource resource = new Resource(); - resource.setInterfaces(createMockInterfaceDefinition()); - return resource; + private Component setUpComponentMock(){ + Component component = new Resource(); + + List<InputDefinition> inputs = new ArrayList<>(); + InputDefinition inputDefinition = new InputDefinition(); + InputDefinition inputDefinition1 = new InputDefinition(); + + List<ComponentInstanceInput> componentInstanceInputs = new ArrayList<>(); + ComponentInstanceInput componentInstanceInput1 = new ComponentInstanceInput(); + componentInstanceInput1.setComponentInstanceName("componentInstance1"); + componentInstanceInput1.setUniqueId("inputId1"); + ComponentInstanceInput componentInstanceInput2 = new ComponentInstanceInput(); + componentInstanceInput2.setComponentInstanceName("componentInstance2"); + componentInstanceInput2.setUniqueId("inputId2"); + + componentInstanceInputs.add(componentInstanceInput1); + componentInstanceInputs.add(componentInstanceInput2); + + inputDefinition.setUniqueId("inputId1"); + inputDefinition.setInputs(componentInstanceInputs); + inputDefinition1.setUniqueId("uniqueId3"); + + inputs.add(inputDefinition); + inputs.add(inputDefinition1); + component.setInputs(inputs); + component.setInterfaces(createMockInterfaceDefinition()); + return component; } private Map<String, InterfaceDefinition> createMockInterfaceDefinition() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java index b158ddf5da..0c02e71bd2 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java @@ -1,38 +1,104 @@ package org.openecomp.sdc.be.datamodel.utils; -import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.IO_INPUT_PARAMETERS; - -import java.util.LinkedList; - +import org.junit.Assert; import org.junit.Test; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationParamDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.model.Operation; +import static org.openecomp.sdc.test.utils.InterfaceOperationTestUtils.createMockOperationInputDefinition; +import static org.openecomp.sdc.test.utils.InterfaceOperationTestUtils.createMockOperationOutputDefinition; + public class InterfaceUIDataConverterTest { @Test - public void testConvertInterfaceDataToOperationData() throws Exception { - InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition(); + public void testConvertInterfaceDataToOperationData() { + InterfaceOperationDataDefinition interfaceOperation = createIODD("test", + "test description", + createParamDataList("inpName", "property", true, "String"), + createParamDataList("OutName", null, true, "String"), + "workflowId", + "workflowVersionId"); + Operation result; + result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation); + Assert.assertNotNull(result); + } + + @Test + public void testConvertInterfaceDataToOperationDataWithoutMandatory() { + ListDataDefinition<InterfaceOperationParamDataDefinition> iopd = new ListDataDefinition<>(); + iopd.add(createParamData("test", "property", "String")); + InterfaceOperationDataDefinition interfaceOperation = createIODD("test", + "test description", iopd, iopd, + "workflowId", + "workflowVersionId"); Operation result; + result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation); + Assert.assertNotNull(result); + } - // default test + @Test + public void testConvertInterfaceDataToOperationDataWithoutOptionalFields() { + InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition(); + interfaceOperation.setOperationType("operationType"); + Operation result; result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation); + Assert.assertNotNull(result); } @Test - public void testConvertOperationDataToInterfaceData() throws Exception { + public void testConvertOperationDataToInterfaceData() { Operation operationData = new Operation(); InterfaceOperationDataDefinition result; ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>(); + inputs.add(createMockOperationInputDefinition("Inp1")); ListDataDefinition<OperationOutputDefinition> outputs = new ListDataDefinition<>(); + outputs.add(createMockOperationOutputDefinition("out1")); operationData.setInputs(inputs); operationData.setOutputs(outputs); operationData.setImplementation(new ArtifactDataDefinition()); - // default test result = InterfaceUIDataConverter.convertOperationDataToInterfaceData(operationData); + Assert.assertNotNull(result); + } + + private InterfaceOperationDataDefinition createIODD(String operationType, String description, + ListDataDefinition<InterfaceOperationParamDataDefinition> inputParams, + ListDataDefinition<InterfaceOperationParamDataDefinition> outputParams, + String workflowId, + String workflowVersionId) { + InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition(); + interfaceOperation.setOperationType(operationType); + interfaceOperation.setDescription(description); + interfaceOperation.setInputParams(inputParams); + interfaceOperation.setOutputParams(outputParams); + interfaceOperation.setWorkflowId(workflowId); + interfaceOperation.setWorkflowVersionId(workflowVersionId); + return interfaceOperation; + } + + private InterfaceOperationParamDataDefinition createParamData(String name, String property, boolean mandatory, String type) { + InterfaceOperationParamDataDefinition definition = createParamData(name, property, type); + definition.setMandatory(mandatory); + return definition; + } + + private InterfaceOperationParamDataDefinition createParamData(String name, String property, String type) { + InterfaceOperationParamDataDefinition definition = new InterfaceOperationParamDataDefinition(); + definition.setName(name); + definition.setProperty(property); + definition.setType(type); + return definition; } + + private ListDataDefinition<InterfaceOperationParamDataDefinition> createParamDataList(String name, + String property, boolean mandatory, String type) { + ListDataDefinition<InterfaceOperationParamDataDefinition> list = new ListDataDefinition<>(); + list.add(createParamData(name, property, mandatory, type)); + return list; + } + }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java index bebfbd19d8..7a88d0a9d3 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java @@ -16,6 +16,12 @@ package org.openecomp.sdc.be.tosca.utils; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.HashMap; +import java.util.Map; + import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -27,31 +33,41 @@ import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.tosca.ToscaExportHandler; import org.openecomp.sdc.be.tosca.ToscaRepresentation; +import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; +import org.openecomp.sdc.be.tosca.model.ToscaProperty; import org.openecomp.sdc.be.tosca.model.ToscaTemplate; - -import java.util.HashMap; -import java.util.Map; +import org.openecomp.sdc.common.util.YamlToObjectConverter; public class InterfacesOperationsToscaUtilTest { + private static final String MAPPED_PROPERTY_NAME = "mapped_property"; + private static final String INPUT_NAME_PREFIX = "input_"; + private static final String NODE_TYPE_NAME = "test"; + private String[] inputTypes = {"string", "integer", "float", "boolean"}; + private static ObjectMapper mapper; + @BeforeClass public static void setUp() { new DummyConfigurationManager(); + mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } - @Test() - public void addInterfaceTypeElement() { + + @Test + public void addInterfaceTypeElementToResource() { Component component = new Resource(); component.setNormalizedName("normalizedComponentName"); InterfaceDefinition addedInterface = new InterfaceDefinition(); addedInterface.setToscaResourceName("interface.types.test_resource_name"); addOperationsToInterface(addedInterface, 5, 3, true); final String interfaceType = "normalizedComponentName-interface"; - ((Resource) component).setInterfaces(new HashMap<>()); - ((Resource) component).getInterfaces().put(interfaceType, addedInterface); + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); final Map<String, Object> interfaceTypeElement = InterfacesOperationsToscaUtil.addInterfaceTypeElement(component); @@ -65,7 +81,29 @@ public class InterfacesOperationsToscaUtilTest { } @Test - public void addInterfaceDefinitionElement() { + public void addInterfaceTypeElementToService() { + Component component = new Service(); + component.setNormalizedName("normalizedServiceComponentName"); + InterfaceDefinition addedInterface = new InterfaceDefinition(); + addedInterface.setToscaResourceName("interface.types.test_service_name"); + addOperationsToInterface(addedInterface, 5, 3, true); + final String interfaceType = "normalizedServiceComponentName-interface"; + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); + final Map<String, Object> interfaceTypeElement = + InterfacesOperationsToscaUtil.addInterfaceTypeElement(component); + + ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); + ToscaTemplate template = new ToscaTemplate("testService"); + template.setInterface_types(interfaceTypeElement); + final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); + + Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("interface.types.test_service_name")); + } + + @Test + public void addInterfaceDefinitionElementToResource() { Component component = new Resource(); component.setNormalizedName("normalizedComponentName"); InterfaceDefinition addedInterface = new InterfaceDefinition(); @@ -73,25 +111,58 @@ public class InterfacesOperationsToscaUtilTest { addOperationsToInterface(addedInterface, 3, 2, true); final String interfaceType = "normalizedComponentName-interface"; - ((Resource) component).setInterfaces(new HashMap<>()); - ((Resource) component).getInterfaces().put(interfaceType, addedInterface); + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); ToscaNodeType nodeType = new ToscaNodeType(); InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); - ToscaTemplate template = new ToscaTemplate("test"); + ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME); Map<String, ToscaNodeType> nodeTypes = new HashMap<>(); - nodeTypes.put("test", nodeType); + nodeTypes.put(NODE_TYPE_NAME, nodeType); template.setNode_types(nodeTypes); final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); - Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("resourceName:")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("inputs:")); - Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("has description")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("naming_function_")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.resource.or.other.resourceName")); + String mainYaml = toscaRepresentation.getMainYaml(); + Assert.assertFalse(mainYaml.contains("operations")); + Assert.assertTrue(mainYaml.contains("resourceName:")); + Assert.assertTrue(mainYaml.contains("inputs:")); + validateOperationInputs(mainYaml); + Assert.assertFalse(mainYaml.contains("defaultp")); + Assert.assertTrue(mainYaml.contains("has description")); + Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME)); + Assert.assertTrue(mainYaml.contains("com.some.resource.or.other.resourceName")); + } + + @Test + public void addInterfaceDefinitionElementToService() { + Component component = new Service(); + component.setNormalizedName("normalizedServiceComponentName"); + InterfaceDefinition addedInterface = new InterfaceDefinition(); + addedInterface.setToscaResourceName("com.some.service.or.other.serviceName"); + + addOperationsToInterface(addedInterface, 3, 2, true); + final String interfaceType = "normalizedServiceComponentName-interface"; + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); + ToscaNodeType nodeType = new ToscaNodeType(); + InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); + + ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); + ToscaTemplate template = new ToscaTemplate("testService"); + Map<String, ToscaNodeType> nodeTypes = new HashMap<>(); + nodeTypes.put(NODE_TYPE_NAME, nodeType); + template.setNode_types(nodeTypes); + final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); + String mainYaml = toscaRepresentation.getMainYaml(); + Assert.assertFalse(mainYaml.contains("operations")); + Assert.assertTrue(mainYaml.contains("serviceName:")); + Assert.assertTrue(mainYaml.contains("inputs:")); + validateOperationInputs(mainYaml); + Assert.assertFalse(mainYaml.contains("defaultp")); + Assert.assertTrue(mainYaml.contains("has description")); + Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME)); + Assert.assertTrue(mainYaml.contains("com.some.service.or.other.serviceName")); } @Test @@ -103,8 +174,8 @@ public class InterfacesOperationsToscaUtilTest { addOperationsToInterface(addedInterface, 3, 3, false); final String interfaceType = "normalizedComponentName-interface"; - ((Resource) component).setInterfaces(new HashMap<>()); - ((Resource) component).getInterfaces().put(interfaceType, addedInterface); + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); ToscaNodeType nodeType = new ToscaNodeType(); InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); @@ -116,7 +187,7 @@ public class InterfacesOperationsToscaUtilTest { final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations")); - Assert.assertFalse(toscaRepresentation.getMainYaml().contains("input_")); + Assert.assertFalse(toscaRepresentation.getMainYaml().contains(INPUT_NAME_PREFIX)); Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp")); Assert.assertTrue(toscaRepresentation.getMainYaml().contains("resourceNameNoInputs:")); Assert.assertTrue(toscaRepresentation.getMainYaml().contains("has description")); @@ -146,17 +217,48 @@ public class InterfacesOperationsToscaUtilTest { private ListDataDefinition<OperationInputDefinition> createInputs(int numOfInputs) { ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>(); for (int i = 0; i < numOfInputs; i++) { - operationInputDefinitionList.add(createMockOperationInputDefinition("input_" + i, - java.util.UUID.randomUUID().toString() + "." + "naming_function_" + i)); + operationInputDefinitionList.add(createMockOperationInputDefinition( + INPUT_NAME_PREFIX + inputTypes[i] + "_" + i, + java.util.UUID.randomUUID().toString() + "." + MAPPED_PROPERTY_NAME, i)); } return operationInputDefinitionList; } - private OperationInputDefinition createMockOperationInputDefinition(String name, String id) { + private OperationInputDefinition createMockOperationInputDefinition(String name, String id, int index) { OperationInputDefinition operationInputDefinition = new OperationInputDefinition(); operationInputDefinition.setName(name); operationInputDefinition.setInputId(id); + operationInputDefinition.setType(inputTypes[index]); + operationInputDefinition.setRequired(index % 2 == 0); return operationInputDefinition; } + + private void validateOperationInputs(String mainYaml) { + String nodeTypeKey = NODE_TYPE_NAME + ":"; + String nodeTypesRepresentation = mainYaml.substring(mainYaml.indexOf(nodeTypeKey) + nodeTypeKey.length(), + mainYaml.lastIndexOf(MAPPED_PROPERTY_NAME) + MAPPED_PROPERTY_NAME.length()); + YamlToObjectConverter objectConverter = new YamlToObjectConverter(); + ToscaNodeType toscaNodeType = objectConverter.convert(nodeTypesRepresentation.getBytes(), ToscaNodeType.class); + Map<String, Object> interfaces = toscaNodeType.getInterfaces(); + for (Object interfaceVal : interfaces.values()) { + Map<String, Object> interfaceDefinition = mapper.convertValue(interfaceVal, Map.class); + for (Object operationVal : interfaceDefinition.values()) { + if (operationVal instanceof Map) { + validateOperationInputDefinition(operationVal); + } + } + } + } + + private void validateOperationInputDefinition(Object operationVal) { + ToscaLifecycleOperationDefinition operation = + mapper.convertValue(operationVal, ToscaLifecycleOperationDefinition.class); + Map<String, ToscaProperty> inputs = operation.getInputs(); + for (Map.Entry<String, ToscaProperty> inputEntry : inputs.entrySet()) { + Assert.assertEquals(inputEntry.getKey().split("_")[1], inputEntry.getValue().getType()); + Boolean expectedIsRequired = Integer.parseInt(inputEntry.getKey().split("_")[2]) % 2 == 0; + Assert.assertEquals(expectedIsRequired, inputEntry.getValue().getRequired()); + } + } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java index 76e73bab75..10acd69a79 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java @@ -51,13 +51,13 @@ public class InterfaceOperationTestUtils { return operation; } - public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceNamme) { + public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceName) { Map<String, Operation> operationMap = createMockOperationMap(); return createInterface("int1", "Interface 1", - "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceNamme, operationMap); + "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceName, operationMap); } - public static Operation mockOperationToReturn(String resourceNamme) { + public static Operation mockOperationToReturn() { return createMockOperation(); } @@ -93,6 +93,7 @@ public class InterfaceOperationTestUtils { OperationInputDefinition operationInputDefinition = new OperationInputDefinition(); operationInputDefinition.setName(name); operationInputDefinition.setUniqueId("uniqueId1"); + operationInputDefinition.setInputId("inputId1"); return operationInputDefinition; } @@ -100,6 +101,7 @@ public class InterfaceOperationTestUtils { OperationOutputDefinition operationOutputDefinition = new OperationOutputDefinition(); operationOutputDefinition.setName(name); operationOutputDefinition.setUniqueId("uniqueId1"); + operationOutputDefinition.setInputId("inputId1"); return operationOutputDefinition; } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java index 50dbf570f4..7acd65fbbb 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java @@ -118,9 +118,9 @@ public enum ActionStatus { ARCHIVED_ORIGINS_FOUND, //InterfaceOperation - INTERFACE_OPERATION_NOT_FOUND, INTERFACE_OPERATION_TYPE_ALREADY_IN_USE, INTERFACE_OPERATION_TYPE_MANDATORY, INTERFACE_OPERATION_TYPE_INVALID, - INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH, INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE,INTERFACE_OPERATION_NOT_DELETED, INTERFACE_OPERATION_INPUT_NAME_MANDATORY, - INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY - + INTERFACE_OPERATION_NOT_FOUND, INTERFACE_OPERATION_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_NAME_MANDATORY, INTERFACE_OPERATION_NAME_INVALID, + INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH, INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE,INTERFACE_OPERATION_NOT_DELETED, + INTERFACE_OPERATION_INPUT_NAME_MANDATORY, INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY, + INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT ; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java index 9e0b104986..6ba7a35836 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java @@ -10,6 +10,7 @@ import org.springframework.context.annotation.Configuration; "org.openecomp.sdc.be.model.cache", "org.openecomp.sdc.be.model.jsontitan.utils", "org.openecomp.sdc.be.model.jsontitan.operations", + "org.openecomp.sdc.be.dao.cassandra" }) public class CatalogModelSpringConfig { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java index 579dcdb074..115f084dbc 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java @@ -66,6 +66,15 @@ public abstract class Component { private String derivedFromGenericVersion; private String toscaType; protected List<AdditionalInformationDefinition> additionalInformation; + private Map<String, InterfaceDefinition> interfaces; + + public Map<String, InterfaceDefinition> getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map<String, InterfaceDefinition> interfaces) { + this.interfaces = interfaces; + } public Component(ComponentMetadataDefinition componentMetadataDefinition) { this.componentMetadataDefinition = componentMetadataDefinition; @@ -545,6 +554,7 @@ public abstract class Component { result = prime * result + ((policies == null) ? 0 : policies.hashCode()); result = prime * result + ((derivedFromGenericType == null) ? 0 : derivedFromGenericType.hashCode()); result = prime * result + ((derivedFromGenericVersion == null) ? 0 : derivedFromGenericVersion.hashCode()); + result = prime * result + ((interfaces == null) ? 0 : interfaces.hashCode()); return result; } @@ -673,6 +683,14 @@ public abstract class Component { else if (!derivedFromGenericVersion.equals(other.derivedFromGenericVersion)) { return false; } + if (interfaces == null) { + if (other.interfaces != null) { + return false; + } + } + else if (!interfaces.equals(other.interfaces)) { + return false; + } return true; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java index 766cae4432..f3996ed42b 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java @@ -23,7 +23,6 @@ package org.openecomp.sdc.be.model; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.utils.MapUtil; import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; @@ -43,8 +42,6 @@ public class Resource extends Component { private List<PropertyDefinition> attributes; - private Map<String, InterfaceDefinition> interfaces; - private List<String> defaultCapabilities; public Resource() { @@ -104,14 +101,6 @@ public class Resource extends Component { this.attributes = attributes; } - public Map<String, InterfaceDefinition> getInterfaces() { - return interfaces; - } - - public void setInterfaces(Map<String, InterfaceDefinition> interfaces) { - this.interfaces = interfaces; - } - public Boolean isAbstract() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) .isAbstract(); @@ -158,7 +147,6 @@ public class Resource extends Component { result = prime * result + ((attributes == null) ? 0 : attributes.hashCode()); result = prime * result + ((defaultCapabilities == null) ? 0 : defaultCapabilities.hashCode()); result = prime * result + ((derivedFrom == null) ? 0 : derivedFrom.hashCode()); - result = prime * result + ((interfaces == null) ? 0 : interfaces.hashCode()); result = prime * result + ((properties == null) ? 0 : properties.hashCode()); result = prime * result + ((derivedList == null) ? 0 : derivedList.hashCode()); return result; @@ -194,11 +182,6 @@ public class Resource extends Component { return false; } else if (!derivedList.equals(other.derivedList)) return false; - if (interfaces == null) { - if (other.interfaces != null) - return false; - } else if (!interfaces.equals(other.interfaces)) - return false; if (properties == null) { if (other.properties != null) return false; @@ -210,7 +193,6 @@ public class Resource extends Component { @Override public String toString() { return "Resource [derivedFrom=" + derivedFrom + ", properties=" + properties + ", attributes=" + attributes - + ", interfaces=" + interfaces + ", defaultCapabilities=" + defaultCapabilities + ", additionalInformation=" + additionalInformation + "Metadata [" + getComponentMetadataDefinition().getMetadataDataDefinition().toString() + "]"; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java index 18bd13dce3..916a34c0f3 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java @@ -17,7 +17,7 @@ package org.openecomp.sdc.be.model.jsontitan.operations; import fj.data.Either; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -71,7 +71,8 @@ public class InterfaceOperation extends BaseOperation { if (!isUpdateAction) { interfaceDefinition.setUniqueId(UUID.randomUUID().toString()); } - statusRes = performUpdateToscaAction(isUpdateAction, componentVertex, Arrays.asList(interfaceDefinition), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE); + statusRes = performUpdateToscaAction(isUpdateAction, componentVertex, + Collections.singletonList(interfaceDefinition), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE); if (!statusRes.equals(StorageOperationStatus.OK)) { return Either.right(statusRes); } @@ -107,8 +108,8 @@ public class InterfaceOperation extends BaseOperation { } GraphVertex interfaceVertex = getToscaElementInt.left().value(); - statusRes = performUpdateToscaAction(isUpdateAction, interfaceVertex, Arrays.asList(operation), - EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION); + statusRes = performUpdateToscaAction(isUpdateAction, interfaceVertex, + Collections.singletonList(operation), EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION); if (!statusRes.equals(StorageOperationStatus.OK)) { return Either.right(statusRes); } @@ -126,7 +127,7 @@ public class InterfaceOperation extends BaseOperation { Either<GraphVertex, TitanOperationStatus> getInterfaceVertex; Either<GraphVertex, TitanOperationStatus> getComponentVertex; Operation operation = new Operation(); - StorageOperationStatus status = null; + StorageOperationStatus status; getComponentVertex = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); if (getComponentVertex.isRight()) { @@ -144,14 +145,16 @@ public class InterfaceOperation extends BaseOperation { Map.Entry<String, Operation> stringOperationEntry = operationToRemove.get(); operation = stringOperationEntry.getValue(); ArtifactDefinition implementationArtifact = operation.getImplementationArtifact(); - String artifactUUID = implementationArtifact.getArtifactUUID(); - CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID); - if (cassandraStatus != CassandraOperationStatus.OK) { - return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus)); + if(implementationArtifact != null){ + String artifactUUID = implementationArtifact.getArtifactUUID(); + CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID); + if (cassandraStatus != CassandraOperationStatus.OK) { + return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus)); + } } if(interfaceDef.getOperationsMap().size() > 1){ - status = deleteToscaDataElements(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, Arrays.asList(operationToDelete)); + status = deleteToscaDataElements(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, Collections.singletonList(operationToDelete)); if (status != StorageOperationStatus.OK) { return Either.right(status); } @@ -164,7 +167,7 @@ public class InterfaceOperation extends BaseOperation { getUpdatedInterfaceDef(interfaceDef, null, operationToDelete); if (interfaceDef.getOperations().isEmpty()) { - status = deleteToscaDataElements(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, Arrays.asList(interfaceDef.getUniqueId())); + status = deleteToscaDataElements(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, Collections.singletonList(interfaceDef.getUniqueId())); if (status != StorageOperationStatus.OK) { return Either.right(status); } @@ -192,7 +195,7 @@ public class InterfaceOperation extends BaseOperation { } } - private InterfaceDefinition getUpdatedInterfaceDef(InterfaceDefinition interfaceDef, Operation operation, String operationId){ + private void getUpdatedInterfaceDef(InterfaceDefinition interfaceDef, Operation operation, String operationId){ Map<String, Operation> operationMap = interfaceDef.getOperationsMap(); if(operation != null){ operationMap.put(operationId, operation); @@ -202,7 +205,6 @@ public class InterfaceOperation extends BaseOperation { operationMap.remove(operationId); interfaceDef.setOperationsMap(operationMap); } - return interfaceDef; } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java index 3b2cb97132..82dcfef1ee 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java @@ -143,6 +143,8 @@ public class ModelConverter { convertServicePaths(topologyTemplate, service); + convertServiceInterfaces(topologyTemplate, service); + return service; } @@ -207,6 +209,17 @@ public class ModelConverter { resource.setInterfaces(copy); } + private static void convertServiceInterfaces(TopologyTemplate toscaElement, Service service) { + Map<String, InterfaceDataDefinition> interfaces = toscaElement.getInterfaces(); + Map<String, InterfaceDefinition> copy; + if (interfaces != null) { + copy = interfaces.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new InterfaceDefinition(e.getValue()))); + } else { + copy = new HashMap<>(); + } + service.setInterfaces(copy); + } + private static void convertAttributes(NodeType nodeType, Resource resource) { Map<String, PropertyDataDefinition> attributes = nodeType.getAttributes(); if (attributes != null) { @@ -922,10 +935,21 @@ public class ModelConverter { topologyTemplate.setInterfaces(copy); } } + + private static void convertServiceInterfaces(Service service, TopologyTemplate topologyTemplate) { + Map<String, InterfaceDefinition> interfaces = service.getInterfaces(); + if (interfaces != null && !interfaces.isEmpty()) { + Map<String, InterfaceDataDefinition> copy = interfaces.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> new InterfaceDataDefinition(e.getValue()))); + topologyTemplate.setInterfaces(copy); + } + } + private static void convertServiceSpecificEntities(Service service, TopologyTemplate topologyTemplate) { convertServiceMetaData(service, topologyTemplate); convertServiceApiArtifacts(service, topologyTemplate); convertServicePaths(service,topologyTemplate); + convertServiceInterfaces(service, topologyTemplate); } private static void convertServicePaths(Service service, TopologyTemplate topologyTemplate) { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java index f324cf83ad..0090f86f0e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java @@ -20,8 +20,20 @@ package org.openecomp.sdc.be.ui.model; +import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.AdditionalInformationDefinition; +import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.ComponentInstanceInput; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.InputDefinition; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.PolicyDefinition; +import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; +import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.be.model.category.CategoryDefinition; import java.util.List; @@ -66,6 +78,25 @@ public class UiComponentDataTransfer { protected List<AdditionalInformationDefinition> additionalInformation; + private Map<String, InterfaceOperationDataDefinition> interfaceOperations; + private Map<String, InterfaceDefinition> interfaces; + + public Map<String, InterfaceOperationDataDefinition> getInterfaceOperations() { + return interfaceOperations; + } + + public void setInterfaceOperations(Map<String, InterfaceOperationDataDefinition> interfaceOperations) { + this.interfaceOperations = interfaceOperations; + } + + public Map<String, InterfaceDefinition> getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map<String, InterfaceDefinition> interfaces) { + this.interfaces = interfaces; + } + public UiComponentDataTransfer() { } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java index 32e4b1002d..b3afd9617b 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,13 +20,10 @@ package org.openecomp.sdc.be.ui.model; -import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.model.AdditionalInformationDefinition; -import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import java.util.List; -import java.util.Map; public class UiResourceDataTransfer extends UiComponentDataTransfer{ @@ -40,11 +37,9 @@ public class UiResourceDataTransfer extends UiComponentDataTransfer{ private List<PropertyDefinition> attributes; - private Map<String, InterfaceDefinition> interfaces; private List<String> defaultCapabilities; - private Map<String, InterfaceOperationDataDefinition> interfaceOperations; public UiResourceDataTransfer(){} @@ -96,14 +91,6 @@ public class UiResourceDataTransfer extends UiComponentDataTransfer{ this.attributes = attributes; } - public Map<String, InterfaceDefinition> getInterfaces() { - return interfaces; - } - - public void setInterfaces(Map<String, InterfaceDefinition> interfaces) { - this.interfaces = interfaces; - } - public List<String> getDefaultCapabilities() { return defaultCapabilities; } @@ -111,12 +98,4 @@ public class UiResourceDataTransfer extends UiComponentDataTransfer{ public void setDefaultCapabilities(List<String> defaultCapabilities) { this.defaultCapabilities = defaultCapabilities; } - public Map<String, InterfaceOperationDataDefinition> getInterfaceOperations() { - return interfaceOperations; - } - - public void setInterfaceOperations(Map<String, InterfaceOperationDataDefinition> interfaceOperations) { - this.interfaceOperations = interfaceOperations; - } - } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java index f2aefa0aa3..375208d24e 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java @@ -1,15 +1,25 @@ package org.openecomp.sdc.be.model.jsontitan.operations; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.TitanVertex; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import fj.data.Either; -import org.junit.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Resource; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.junit.runner.RunWith; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.dao.titan.TitanGraphClient; import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; @@ -19,145 +29,180 @@ import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.ModelTestBase; +import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType; import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate; import org.openecomp.sdc.be.model.jsontitan.utils.GraphTestUtils; -import org.openecomp.sdc.be.model.operations.api.IElementOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.common.util.ValidationUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import javax.annotation.Resource; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.util.*; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application-context-test.xml") -public class InterfacesOperationTest extends ModelTestBase{ +public class InterfacesOperationTest extends ModelTestBase { @Resource protected TitanDao titanDao; + @Resource private InterfaceOperation interfaceOperation; - @Autowired - protected TitanGraphClient titanGraphClient; - @Resource protected NodeTypeOperation nodeTypeOperation; - @Autowired - protected ToscaOperationFacade toscaOperationFacade; @Resource protected TopologyTemplateOperation topologyTemplateOperation; - @Autowired - protected IElementOperation elementDao; - @Resource private ToscaElementLifecycleOperation lifecycleOperation; - protected static final String USER_ID = "jh0003"; - protected static final String VF_NAME = "VF_NAME"; - protected User user; + private static final String RESOURCE_NAME = "Resource Name"; + private static final String RESOURCE_ID = "resourceID"; - public static final String RESOURCE_CATEGORY = "Network Layer 2-3"; - public static final String RESOURCE_SUBCATEGORY = "Router"; - public static final String RESOURCE_NAME = "Resource Name"; + private static final String SERVICE_NAME = "Service Name"; + private static final String SERVICE_ID = "serviceID"; - private CategoryDefinition categoryDefinition; - private SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(); - protected static final String RESOURCE_ID = "resourceID"; - protected static final String WORKFLOW_OPERATION_ID = "workflowOperationId"; - public static final String DERIVED_NAME = "derivedName"; - public static final String CSAR_UUID = "bla bla"; + private final String categoryName = "category"; + private final String subcategory = "mycategory"; + private GraphVertex ownerVertex; - String categoryName = "category"; - String subcategory = "mycategory"; - String outputDirectory = "C:\\Output"; + private final Service service = createService(); + private final org.openecomp.sdc.be.model.Resource resource = createResource(); @BeforeClass public static void initInterfacesOperation() { init(); } - private GraphVertex ownerVertex; - private GraphVertex modifierVertex; - private GraphVertex vfVertex; - private GraphVertex serviceVertex; - private GraphVertex rootVertex; - @Before public void setupBefore() { - clearGraph(); + GraphTestUtils.clearGraph(titanDao); createUsers(); createResourceCategory(); createServiceCategory(); GraphTestUtils.createRootCatalogVertex(titanDao); - rootVertex = createRootNodeType(); - createNodeType("firstVf"); - serviceVertex = createTopologyTemplate("firstService"); + createRootNodeType(); + createNodeType("resource", RESOURCE_ID); + createNodeType("service", SERVICE_ID); + createTopologyTemplate("firstService"); } @After public void cleanAfter() { - clearGraph(); + GraphTestUtils.clearGraph(titanDao); } @Test - public void testAddInterface() { - org.openecomp.sdc.be.model.Resource resource = createResource(); + public void testAddInterface_Service(){testAddInterface(service);} + + @Test + public void testAddInterface_Resource(){testAddInterface(resource);} + + @Test + public void testUpdateInterface_Service(){testUpdateInterface(service);} + + @Test + public void testUpdateInterface_Resource(){testUpdateInterface(resource);} + + @Test + public void testAddInterfaceOperation_Service(){testAddInterfaceOperation(service);} + + @Test + public void testAddInterfaceOperation_Resource(){testAddInterfaceOperation(resource);} + + @Test + public void testUpdateInterfaceOperation_Service(){testUpdateInterfaceOperation(service);} + + @Test + public void testUpdateInterfaceOperation_Resource(){testUpdateInterfaceOperation(resource);} + + @Test + public void testDeleteInterfaceOperation_Service(){testDeleteInterfaceOperation(service);} + + @Test + public void testDeleteInterfaceOperation_Resource(){testDeleteInterfaceOperation(resource);} + + @Test + public void testUpdateInterfaceShouldFailWhenNOtCreatedFirst() { + Component component = createResource(); InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); - Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(resource.getUniqueId(), + interfaceDefinition.setOperationsMap(createMockOperationMap()); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.updateInterface(component.getUniqueId(), + interfaceDefinition); + Assert.assertTrue(res.isRight()); + } + + private void testAddInterface(Component component) { + InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); Assert.assertTrue(res.isLeft()); } - @Test - public void testUpdateInterface() { - org.openecomp.sdc.be.model.Resource resource = createResource(); + private void testUpdateInterface(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); interfaceDefinition.setOperationsMap(createMockOperationMap()); - Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(resource.getUniqueId(), - interfaceDefinition); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); Assert.assertTrue(res.isLeft()); InterfaceDefinition value = res.left().value(); String new_description = "New Description"; value.setDescription(new_description); - res = interfaceOperation.updateInterface(resource.getUniqueId(), - interfaceDefinition); + res = interfaceOperation.updateInterface(component.getUniqueId(), interfaceDefinition); assertTrue(res.isLeft()); assertEquals(new_description,res.left().value().getDescription()); } - @Test - public void testUpdateInterfaceShouldFailWhenNOtCreatedFirst() { - org.openecomp.sdc.be.model.Resource resource = createResource(); + private void testAddInterfaceOperation(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); - interfaceDefinition.setOperationsMap(createMockOperationMap()); - Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.updateInterface(resource.getUniqueId(), - interfaceDefinition); - Assert.assertTrue(res.isRight()); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); + Assert.assertTrue(res.isLeft()); + InterfaceDefinition value = res.left().value(); + Operation op = createMockOperation(); + Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op); + assertTrue(addInterfaceOperationRes.isLeft()); + } + + private void testUpdateInterfaceOperation(Component component) { + InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); + Assert.assertTrue(res.isLeft()); + InterfaceDefinition value = res.left().value(); + Operation op = createMockOperation(); + Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op); + Assert.assertTrue(addInterfaceOperationRes.isLeft()); + Operation resultOp = addInterfaceOperationRes.left().value(); + resultOp.setName("New_Create"); + Either<Operation, StorageOperationStatus> updateInterfaceOperationRes = interfaceOperation.updateInterfaceOperation(component.getUniqueId(), value, resultOp); + assertTrue(updateInterfaceOperationRes.isLeft()); + assertEquals("New_Create", updateInterfaceOperationRes.left().value().getName()); + } + + private void testDeleteInterfaceOperation(Component component) { + InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); + Assert.assertTrue(res.isLeft()); + InterfaceDefinition value = res.left().value(); + Operation op = createMockOperation(); + Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op); + Assert.assertTrue(addInterfaceOperationRes.isLeft()); + Operation resultOp = addInterfaceOperationRes.left().value(); + Either<Operation, StorageOperationStatus> deleteInterfaceOperationRes = interfaceOperation.deleteInterfaceOperation(component.getUniqueId(), value, resultOp.getUniqueId()); + assertTrue(deleteInterfaceOperationRes.isLeft()); } private InterfaceDefinition buildInterfaceDefinition() { InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); interfaceDefinition.setType("tosca.interfaces.standard"); - interfaceDefinition.setCreationDate(new Long(101232)); - - + interfaceDefinition.setCreationDate(101232L); return interfaceDefinition; } @@ -165,12 +210,19 @@ public class InterfacesOperationTest extends ModelTestBase{ org.openecomp.sdc.be.model.Resource resource = new org.openecomp.sdc.be.model.Resource(); resource.setUniqueId(RESOURCE_ID); resource.setName(RESOURCE_NAME); - resource.addCategory(RESOURCE_CATEGORY, RESOURCE_SUBCATEGORY); resource.setDescription("My short description"); resource.setInterfaces(createMockInterfaceDefinition()); return resource; } + private Service createService() { + Service service = new Service(); + service.setUniqueId(SERVICE_ID); + service.setName(SERVICE_NAME); + service.setDescription("My short description"); + service.setInterfaces(createMockInterfaceDefinition()); + return service; + } private InterfaceDefinition createInterface(String uniqueID, String description, String type, String toscaResourceName, Map<String, Operation> op) { @@ -188,24 +240,24 @@ public class InterfacesOperationTest extends ModelTestBase{ Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>(); interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1", "lifecycle", "tosca", operationMap)); - return interfaceDefinitionMap; } private Map<String, Operation> createMockOperationMap() { - Operation operation = new Operation(); - operation.setDefinition(false); - operation.setName("create"); Map<String, Operation> operationMap = new HashMap<>(); - operationMap.put("op1", operation); + operationMap.put("op1", createMockOperation()); return operationMap; } - - + private Operation createMockOperation() { + Operation operation = new Operation(); + operation.setDefinition(false); + operation.setName("create"); + operation.setUniqueId("op1"); + return operation; + } private void createResourceCategory() { - GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY); Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>(); String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY); @@ -229,15 +281,11 @@ public class InterfacesOperationTest extends ModelTestBase{ subCat.updateMetadataJsonWithCurrentMetadataProperties(); Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat); - Either<GraphVertex, TitanOperationStatus> subCatRes = titanDao.createVertex(subCat); - - TitanOperationStatus status = titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>()); - assertEquals(TitanOperationStatus.OK, status); + titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>()); } private void createServiceCategory() { - GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY); Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>(); String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY); @@ -248,14 +296,10 @@ public class InterfacesOperationTest extends ModelTestBase{ metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName)); cat.setMetadataProperties(metadataProperties); cat.updateMetadataJsonWithCurrentMetadataProperties(); - - Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat); - - assertTrue(catRes.isLeft()); + titanDao.createVertex(cat); } - private GraphVertex createTopologyTemplate(String name) { - + private void createTopologyTemplate(String name) { TopologyTemplate service = new TopologyTemplate(); String uniqueId = UniqueIdBuilder.buildResourceUniqueId(); service.setUniqueId(uniqueId); @@ -273,20 +317,13 @@ public class InterfacesOperationTest extends ModelTestBase{ service.setComponentType(ComponentTypeEnum.SERVICE); Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service); - assertTrue(createRes.isLeft()); - Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createRes.left().value().getUniqueId()); - assertTrue(getNodeTyeRes.isLeft()); - // serviceVertex = getNodeTyeRes.left().value(); - - return getNodeTyeRes.left().value(); + getNodeTyeRes.left().value(); } - private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) { - + private <T extends ToscaDataDefinition> void createNodeType(String nodeTypeName, String uniqueId) { NodeType vf = new NodeType(); - String uniqueId = RESOURCE_ID; // UniqueIdBuilder.buildResourceUniqueId(); vf.setUniqueId(uniqueId); vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID)); vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName); @@ -308,15 +345,13 @@ public class InterfacesOperationTest extends ModelTestBase{ List<String> derivedFrom = new ArrayList<>(); derivedFrom.add("root"); vf.setDerivedFrom(derivedFrom); - vf.setComponentType(ComponentTypeEnum.RESOURCE); + vf.setComponentType(ComponentTypeEnum.RESOURCE); Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf); - assertTrue(createVFRes.isLeft()); Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId()); - assertTrue(getNodeTyeRes.isLeft()); - vfVertex = getNodeTyeRes.left().value(); + GraphVertex vfVertex = getNodeTyeRes.left().value(); List<PropertyDataDefinition> addProperties = new ArrayList<>(); PropertyDataDefinition prop11 = new PropertyDataDefinition(); @@ -331,21 +366,21 @@ public class InterfacesOperationTest extends ModelTestBase{ addProperties.add(prop22); StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME); - assertTrue(status == StorageOperationStatus.OK); + assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition prop33 = new PropertyDataDefinition(); prop33.setName("prop33"); prop33.setDefaultValue("def33"); status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME); - assertTrue(status == StorageOperationStatus.OK); + assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition prop44 = new PropertyDataDefinition(); prop44.setName("prop44"); prop44.setDefaultValue("def44"); status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME); - assertTrue(status == StorageOperationStatus.OK); + assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition capProp = new PropertyDataDefinition(); capProp.setName("capProp"); @@ -354,20 +389,19 @@ public class InterfacesOperationTest extends ModelTestBase{ MapDataDefinition dataToCreate = new MapPropertiesDataDefinition(); dataToCreate.put("capProp", capProp); - Map<String, MapDataDefinition> capProps = new HashMap(); + Map<String, MapDataDefinition> capProps = new HashMap<>(); capProps.put("capName", dataToCreate); - Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps); + nodeTypeOperation.associateElementToData( + vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps); List<String> pathKeys = new ArrayList<>(); pathKeys.add("capName"); capProp.setDefaultValue("BBBB"); - status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME); - return vf; + nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME); } - private GraphVertex createRootNodeType() { - + private void createRootNodeType() { NodeType vf = new NodeType(); String uniqueId = UniqueIdBuilder.buildResourceUniqueId(); vf.setUniqueId(uniqueId); @@ -399,7 +433,6 @@ public class InterfacesOperationTest extends ModelTestBase{ PropertyDataDefinition prop1 = new PropertyDataDefinition(); prop1.setName("derived1"); prop1.setDefaultValue("deriveddef1"); - properties.put("derived1", prop1); PropertyDataDefinition prop2 = new PropertyDataDefinition(); @@ -415,15 +448,12 @@ public class InterfacesOperationTest extends ModelTestBase{ vf.setProperties(properties); vf.setComponentType(ComponentTypeEnum.RESOURCE); Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf); - assertTrue(createVFRes.isLeft()); Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId()); - assertTrue(getNodeTyeRes.isLeft()); - return getNodeTyeRes.left().value(); + getNodeTyeRes.left().value(); } private void createUsers() { - GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER); ownerV.setUniqueId("user1"); @@ -435,7 +465,6 @@ public class InterfacesOperationTest extends ModelTestBase{ ownerV.updateMetadataJsonWithCurrentMetadataProperties(); ownerV.setJson(new HashMap<>()); Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV); - assertTrue(createUserRes.isLeft()); ownerVertex = createUserRes.left().value(); @@ -450,33 +479,14 @@ public class InterfacesOperationTest extends ModelTestBase{ modifierV.updateMetadataJsonWithCurrentMetadataProperties(); modifierV.setJson(new HashMap<>()); createUserRes = titanDao.createVertex(modifierV); - assertTrue(createUserRes.isLeft()); - - modifierVertex = createUserRes.left().value(); - - Either<GraphVertex, TitanOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId()); - assertTrue(getOwnerRes.isLeft()); + createUserRes.left().value(); + lifecycleOperation.findUser(ownerVertex.getUniqueId()); } @After public void teardown() { - clearGraph(); - } - - private void clearGraph() { - Either<TitanGraph, TitanOperationStatus> graphResult = titanDao.getGraph(); - TitanGraph graph = graphResult.left().value(); - - Iterable<TitanVertex> vertices = graph.query().vertices(); - if (vertices != null) { - Iterator<TitanVertex> iterator = vertices.iterator(); - while (iterator.hasNext()) { - TitanVertex vertex = iterator.next(); - vertex.remove(); - } - } - titanDao.commit(); + GraphTestUtils.clearGraph(titanDao); } } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/InterfaceOperationParamDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/InterfaceOperationParamDataDefinition.java index e2de5f0d64..b8372d6793 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/InterfaceOperationParamDataDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/InterfaceOperationParamDataDefinition.java @@ -41,18 +41,18 @@ public class InterfaceOperationParamDataDefinition extends ToscaDataDefinition i setType(iopdd.getType()); } - public InterfaceOperationParamDataDefinition(String paramName, String paramId, boolean mandatory, String type) { + public InterfaceOperationParamDataDefinition(String name, String property, boolean mandatory, String type) { super(); - setName(paramName); - setProperty(paramId); + setName(name); + setProperty(property); setMandatory(mandatory); setType(type); } //used for OperationOutputDefinition - public InterfaceOperationParamDataDefinition(String paramName, boolean mandatory, String type) { + public InterfaceOperationParamDataDefinition(String name, boolean mandatory, String type) { super(); - setName(paramName); + setName(name); setMandatory(mandatory); setType(type); } @@ -60,15 +60,15 @@ public class InterfaceOperationParamDataDefinition extends ToscaDataDefinition i public String getName() { return (String) getToscaPresentationValue(IO_NAME); } - public void setName(String paramName) { - setToscaPresentationValue(IO_NAME, paramName); + public void setName(String name) { + setToscaPresentationValue(IO_NAME, name); } public String getProperty() { return (String) getToscaPresentationValue(IO_PROPERTY); } - public void setProperty(String paramId) { - setToscaPresentationValue(IO_PROPERTY, paramId); + public void setProperty(String property) { + setToscaPresentationValue(IO_PROPERTY, property); } public Boolean getMandatory() { diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/OperationInputDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/OperationInputDefinition.java index 4c941574ae..35b760a677 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/OperationInputDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/OperationInputDefinition.java @@ -33,10 +33,10 @@ public class OperationInputDefinition extends InputDataDefinition { setName(name); } - public OperationInputDefinition(String paramName, String paramId, Boolean mandatory, String type) { + public OperationInputDefinition(String name, String property, Boolean mandatory, String type) { super(); - setName(paramName); - setInputId(paramId); + setName(name); + setInputId(property); setRequired(mandatory); setType(type); } |