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.*;
@Autowired
protected ApplicationDataTypeCache dataTypeCache;
+ @Autowired
+ protected InterfaceOperation interfaceOperation;
+
+ @Autowired
+ protected InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+
@javax.annotation.Resource
private UserValidations userValidations;
this.propertyOperation = propertyOperation;
}
+ public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
+ this.interfaceOperation = interfaceOperation;
+ }
+
User validateUserNotEmpty(User user, String ecompErrorContext) {
return userValidations.validateUserNotEmpty(user, ecompErrorContext);
}
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;
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;
@Autowired
private InterfaceOperationValidation interfaceOperationValidation;
- @Autowired
- private InterfaceOperation interfaceOperation;
-
- public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
- this.interfaceOperation = interfaceOperation;
- }
-
public void setInterfaceOperationValidation(InterfaceOperationValidation interfaceOperationValidation) {
this.interfaceOperationValidation = interfaceOperationValidation;
}
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());
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()));
}
}
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());
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 {
}
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());
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()));
}
}
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);
+ }
}
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 {
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()) {
}
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);
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);
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);
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);
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()
.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<>();
}
return Either.left(Boolean.TRUE);
}
-
-
private Either<Boolean, Set<String>> isInputParametersUnique(Operation operationDataDefinition) {
Set<String> inputParamNamesSet = new HashSet<>();
Set<String> duplicateParamNamesToReturn = new HashSet<>();
.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();
}
.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);
}
public static InterfaceOperationDataDefinition convertOperationDataToInterfaceData(Operation operationData){
-
ListDataDefinition<OperationInputDefinition> inputs = operationData.getInputs();
List<InterfaceOperationParamDataDefinition> inputParamList = inputs.getListToscaDataDefinition().stream()
.map(operationInputDefinition -> new InterfaceOperationParamDataDefinition(operationInputDefinition.getName(),
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);
}
}
}
+ 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) {
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)
@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
@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
@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
@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();
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());
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();
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());
}
}
- 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();
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()) {
}
}
- 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();
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);
});
if (!inputs.isEmpty()) {
toscaNodeType.setProperties(inputs);
- addInterfaceDefinitionElement(component, toscaNodeType);
}
}
return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
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 {
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";
* @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);
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);
toscaInterfaceTypes.put(interfaceDefinition.getToscaResourceName(), interfacesAsMap);
}
- return toscaInterfaceTypes;
+ return MapUtils.isNotEmpty(toscaInterfaceTypes) ? toscaInterfaceTypes : null;
}
/**
* @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();
toscaOperation.setImplementation(operationArtifactPath);
}
toscaOperation.setDescription(operationEntry.getValue().getDescription());
- fillToscaOperationInputs(operationEntry.getValue(), toscaOperation, nodeType);
+ fillToscaOperationInputs(operationEntry.getValue(), toscaOperation);
toscaOperations.put(operationEntry.getValue().getName(), toscaOperation);
}
interfaceDefAsMap.putAll(operationsMap);
toscaInterfaceDefinitions.put(getLastPartOfName(toscaResourceName), interfaceDefAsMap);
}
- nodeType.setInterfaces(toscaInterfaceDefinitions);
+ if (MapUtils.isNotEmpty(toscaInterfaceDefinitions)) {
+ nodeType.setInterfaces(toscaInterfaceDefinitions);
+ }
}
/***
}
private static void fillToscaOperationInputs(OperationDataDefinition operation,
- ToscaLifecycleOperationDefinition toscaOperation,
- ToscaNodeType nodeType) {
+ ToscaLifecycleOperationDefinition toscaOperation) {
if (Objects.isNull(operation.getInputs()) || operation.getInputs().isEmpty()) {
toscaOperation.setInputs(null);
return;
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<>();
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-----------------------------
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"
+ }
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;
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;
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
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();
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);
setCanWorkOnResource(resourceCsar);
Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
- responseManager = ResponseFormatManager.getInstance();
}
@Test
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);
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");
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());
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");
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;
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() {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"upgrade");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
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());
}
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList, "");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"input2");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"CREATE");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
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());
}
operationOutputDefinitionList,"create");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
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"));
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
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() {
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
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;
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);
}
@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();
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
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);
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"));
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());
+ }
+ }
}
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();
}
OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
operationInputDefinition.setName(name);
operationInputDefinition.setUniqueId("uniqueId1");
+ operationInputDefinition.setInputId("inputId1");
return operationInputDefinition;
}
OperationOutputDefinition operationOutputDefinition = new OperationOutputDefinition();
operationOutputDefinition.setName(name);
operationOutputDefinition.setUniqueId("uniqueId1");
+ operationOutputDefinition.setInputId("inputId1");
return operationOutputDefinition;
}
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
;
}
"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 {
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;
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;
}
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;
}
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;
private List<PropertyDefinition> attributes;
- private Map<String, InterfaceDefinition> interfaces;
-
private List<String> defaultCapabilities;
public Resource() {
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();
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;
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;
@Override
public String toString() {
return "Resource [derivedFrom=" + derivedFrom + ", properties=" + properties + ", attributes=" + attributes
- + ", interfaces=" + interfaces
+ ", defaultCapabilities=" + defaultCapabilities + ", additionalInformation=" + additionalInformation
+ "Metadata [" + getComponentMetadataDefinition().getMetadataDataDefinition().toString() + "]";
}
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;
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);
}
}
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);
}
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()) {
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);
}
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);
}
}
}
- 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);
operationMap.remove(operationId);
interfaceDef.setOperationsMap(operationMap);
}
- return interfaceDef;
}
}
convertServicePaths(topologyTemplate, service);
+ convertServiceInterfaces(topologyTemplate, service);
+
return service;
}
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) {
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) {
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;
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() {
}
* 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.
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{
private List<PropertyDefinition> attributes;
- private Map<String, InterfaceDefinition> interfaces;
private List<String> defaultCapabilities;
- private Map<String, InterfaceOperationDataDefinition> interfaceOperations;
public UiResourceDataTransfer(){}
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;
}
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;
- }
-
}
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;
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;
}
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) {
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);
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);
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);
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);
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();
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");
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);
PropertyDataDefinition prop1 = new PropertyDataDefinition();
prop1.setName("derived1");
prop1.setDefaultValue("deriveddef1");
-
properties.put("derived1", prop1);
PropertyDataDefinition prop2 = new PropertyDataDefinition();
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");
ownerV.updateMetadataJsonWithCurrentMetadataProperties();
ownerV.setJson(new HashMap<>());
Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV);
- assertTrue(createUserRes.isLeft());
ownerVertex = createUserRes.left().value();
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);
}
}
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);
}
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() {
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);
}