summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java215
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java174
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java32
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java44
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java72
5 files changed, 251 insertions, 286 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
index 803cdbf277..2f4519beb9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
@@ -18,18 +18,14 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
+import java.util.Map;
import java.util.Optional;
-import org.apache.commons.lang.StringUtils;
+import java.util.UUID;
import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentParametersView;
+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;
@@ -37,7 +33,8 @@ 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.be.ui.model.UiComponentDataTransfer;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,23 +42,22 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component("interfaceOperationBusinessLogic")
-public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
+public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationBusinessLogic.class);
- public static final String FAILED_TO_LOCK_COMPONENT_RESPONSE_IS = "Failed to lock component {}. Response is {}. ";
+ private static final String FAILED_TO_LOCK_COMPONENT_RESPONSE_IS = "Failed to lock component {}. Response is {}";
+ private static final String EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION = "Exception occurred during {}. Response is {}";
+ private static final String DELETE_INTERFACE_OPERATION = "deleteInterfaceOperation";
+ private static final String GET_INTERFACE_OPERATION = "getInterfaceOperation";
+ private static final String CREATE_INTERFACE_OPERATION = "createInterfaceOperation";
+ private static final String UPDATE_INTERFACE_OPERATION = "updateInterfaceOperation";
@Autowired
private InterfaceOperationValidation interfaceOperationValidation;
@Autowired
- private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
-
- @Autowired
private InterfaceOperation interfaceOperation;
- @Autowired
- private UiComponentDataConverter uiComponentDataConverter;
-
public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
this.interfaceOperation = interfaceOperation;
}
@@ -71,20 +67,16 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
}
public Either<Operation, ResponseFormat> deleteInterfaceOperation(String componentId, String interfaceOperationToDelete, User user, boolean lock) {
- if (StringUtils.isEmpty(interfaceOperationToDelete)){
- LOGGER.debug("Invalid parameter interfaceOperationToDelete was empty");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY));
- }
-
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()){
return Either.right(componentEither.right().value());
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- validateUserAndRole(storedComponent, user, "deleteInterfaceOperation");
+ validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true);
+ Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Delete interface Operation on a storedComponent");
+ 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();
@@ -94,43 +86,49 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
try {
Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
- Either<InterfaceDefinition, ResponseFormat> sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
- if (sValue.isRight()) {
- return Either.right(sValue.right().value());
+ Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
+ if (getInterfaceEither.isRight()) {
+ return Either.right(getInterfaceEither.right().value());
+ }
+ InterfaceDefinition interfaceDefinition = getInterfaceEither.left().value();
+
+ Either<Operation, ResponseFormat> getOperationEither = getOperationFromInterfaceDef(storedComponent, interfaceDefinition, interfaceOperationToDelete);
+ if (getOperationEither.isRight()){
+ return Either.right(getOperationEither.right().value());
}
- InterfaceDefinition interfaceDefinition = sValue.left().value();
Either<Operation, StorageOperationStatus> deleteEither = interfaceOperation.deleteInterfaceOperation(componentId, interfaceDefinition, interfaceOperationToDelete);
if (deleteEither.isRight()){
- LOGGER.error("Failed to delete interface operation from storedComponent {}. Response is {}. ", storedComponent.getName(), deleteEither.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteEither.right().value(), ComponentTypeEnum.RESOURCE)));
+ LOGGER.error("Failed to delete interface operation from component {}. Response is {}", storedComponent.getName(), deleteEither.right().value());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteEither.right().value(), storedComponent.getComponentType())));
}
+
titanDao.commit();
return Either.left(deleteEither.left().value());
- } catch (Exception e){
- LOGGER.error("Exception occurred during delete interface operation : {}", e.getMessage(), e);
+ }
+ catch (Exception e){
+ LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "delete", e);
titanDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- } finally {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
+ }
+ finally {
+ if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+ }
}
}
public Either<Operation, ResponseFormat> getInterfaceOperation(String componentId, String interfaceOperationToGet, User user, boolean lock) {
- if (StringUtils.isEmpty(interfaceOperationToGet)){
- LOGGER.debug("Invalid parameter interfaceOperationToGet was empty");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY));
- }
-
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()){
return Either.right(componentEither.right().value());
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- validateUserAndRole(storedComponent, user, "getInterfaceOperation");
+ validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
+ Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Get interface Operation on a storedComponent");
+ 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();
@@ -140,25 +138,29 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
try {
Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
- Either<InterfaceDefinition, ResponseFormat> sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
- if (sValue.isRight()) {
- return Either.right(sValue.right().value());
+ Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
+ if (getInterfaceEither.isRight()) {
+ return Either.right(getInterfaceEither.right().value());
}
- InterfaceDefinition interfaceDefinition = sValue.left().value();
+ InterfaceDefinition interfaceDefinition = getInterfaceEither.left().value();
- Either<Operation, StorageOperationStatus> getEither = interfaceOperation.getInterfaceOperation(interfaceDefinition, interfaceOperationToGet);
- if (getEither.isRight()){
- LOGGER.error("Failed to get interface operation from storedComponent {}. Response is {}. ", storedComponent.getName(), getEither.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getEither.right().value(), ComponentTypeEnum.RESOURCE)));
+ Either<Operation, ResponseFormat> getOperationEither = getOperationFromInterfaceDef(storedComponent, interfaceDefinition, interfaceOperationToGet);
+ if (getOperationEither.isRight()){
+ return Either.right(getOperationEither.right().value());
}
+
titanDao.commit();
- return Either.left(getEither.left().value());
- } catch (Exception e){
- LOGGER.error("Exception occurred during get interface operation : {}", e.getMessage(), e);
+ return Either.left(getOperationEither.left().value());
+ }
+ catch (Exception e){
+ LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
titanDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- } finally {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
+ }
+ finally {
+ if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+ }
}
}
@@ -171,19 +173,19 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
Either<InterfaceDefinition, StorageOperationStatus> interfaceCreateEither = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
if (interfaceCreateEither.isRight()){
StorageOperationStatus sValue = interfaceCreateEither.right().value();
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(sValue,
- ComponentTypeEnum.RESOURCE), ""));
+ LOGGER.error("Failed to get interface from component {}. Response is {}", component.getName(), sValue);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(sValue, component.getComponentType()), ""));
}
return Either.left(interfaceCreateEither.left().value());
}
}
public Either<Operation, ResponseFormat> createInterfaceOperation(String componentId, Operation operation, User user, boolean lock) {
- return createOrUpdateInterfaceOperation(componentId, operation, user, false, "createInterfaceOperation", lock);
+ return createOrUpdateInterfaceOperation(componentId, operation, user, false, CREATE_INTERFACE_OPERATION, lock);
}
public Either<Operation, ResponseFormat> updateInterfaceOperation(String componentId, Operation operation, User user, boolean lock) {
- return createOrUpdateInterfaceOperation(componentId, operation, user, true, "updateInterfaceOperation", lock);
+ return createOrUpdateInterfaceOperation(componentId, operation, user, true, UPDATE_INTERFACE_OPERATION, lock);
}
private Either<Operation, ResponseFormat> createOrUpdateInterfaceOperation(String componentId, Operation operation, User user, boolean isUpdate, String errorContext, boolean lock) {
@@ -192,18 +194,18 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
return Either.right(componentEither.right().value());
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- validateUserAndRole(storedComponent, user, errorContext);
+ validateUserExists(user.getUserId(), errorContext, true);
- InterfaceUtils.createInputOutput(operation, storedComponent.getInputs());
+ InterfaceUtils.createInputOutput(operation, storedComponent.getInputs(), storedComponent.getInputs());
Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither = interfaceOperationValidation
- .validateInterfaceOperations(Arrays.asList(operation), componentId, isUpdate);
+ .validateInterfaceOperations(Arrays.asList(operation), storedComponent, isUpdate);
if(interfaceOperationValidationResponseEither.isRight()) {
return Either.right(interfaceOperationValidationResponseEither.right().value());
}
Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
- lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Create or Update interface Operation on Component");
+ 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();
@@ -211,24 +213,32 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
}
}
- Either<Operation, StorageOperationStatus> result;
try {
Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
- Either<InterfaceDefinition, ResponseFormat> sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
- if (sValue.isRight()) {
- return Either.right(sValue.right().value());
+ Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
+ if (getInterfaceEither.isRight()) {
+ return Either.right(getInterfaceEither.right().value());
}
- InterfaceDefinition interfaceDefinition = sValue.left().value();
+ InterfaceDefinition interfaceDefinition = getInterfaceEither.left().value();
- if (isUpdate) {
- result = interfaceOperation.updateInterfaceOperation(componentId, interfaceDefinition, operation);
- } else {
+ Either<Operation, StorageOperationStatus> result;
+ if(!isUpdate){
+ initNewOperation(operation);
result = interfaceOperation.addInterfaceOperation(componentId, interfaceDefinition, operation);
}
+ else {
+ Either<Operation, ResponseFormat> getOperationEither = getOperationFromInterfaceDef(storedComponent, interfaceDefinition, operation.getUniqueId());
+ if (getOperationEither.isRight()){
+ return Either.right(getOperationEither.right().value());
+ }
+ operation.setImplementation(getOperationEither.left().value().getImplementation());
+ result = interfaceOperation.updateInterfaceOperation(componentId, interfaceDefinition, operation);
+ }
+
if (result.isRight()) {
titanDao.rollback();
- LOGGER.debug("Failed to add/update interface operation on component {}. Response is {}. ", storedComponent.getName(), result.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value(), ComponentTypeEnum.RESOURCE)));
+ LOGGER.debug("Failed to addOrUpdate interface operation on component {}. Response is {}", storedComponent.getName(), result.right().value());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value(), storedComponent.getComponentType())));
}
titanDao.commit();
@@ -236,64 +246,45 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
}
catch (Exception e) {
titanDao.rollback();
- LOGGER.error("Exception occurred during add or update interface operation property values:{}", e.getMessage(), e);
+ LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "addOrUpdate", e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
finally {
if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource);
+ graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
}
- private void validateUserAndRole(org.openecomp.sdc.be.model.Component component, User user, String errorContext) {
- user = validateUser(user, errorContext, component, null, false);
- validateUserRole(user, component, new ArrayList<>(), null, null);
- }
-
private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> getComponentDetails(String componentId){
Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId);
if (componentStorageOperationStatusEither.isRight()) {
StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value();
- LOGGER.error("Failed to fetch component information by component id {}, error {}", componentId, errorStatus);
+ LOGGER.error("Failed to fetch component information by component id {}, Response is {}", componentId, errorStatus);
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
}
return Either.left(componentStorageOperationStatusEither.left().value());
}
- @Override
- public Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String componentId, List<String> dataParamsToReturn) {
- ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentResultEither = toscaOperationFacade.getToscaElement(componentId, paramsToRetuen);
-
- if (componentResultEither.isRight()) {
- if (componentResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
- LOGGER.error("Failed to found component with id {} ", componentId);
- Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, componentId));
- }
- LOGGER.error("failed to get component by id {} with filters {}", componentId, dataParamsToReturn);
- return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(componentResultEither.right().value()), ""));
+ private Either<Operation, ResponseFormat> getOperationFromInterfaceDef(
+ org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDefinition, String operationToFetch) {
+ Optional<Map.Entry<String, Operation>> operationMap = interfaceDefinition.getOperationsMap().entrySet().stream()
+ .filter(entry -> entry.getValue().getUniqueId().equals(operationToFetch)).findAny();
+ if (!operationMap.isPresent()) {
+ LOGGER.error("Failed to get interface operation from component {}. Response is {}", component.getUniqueId(), ActionStatus.INTERFACE_OPERATION_NOT_FOUND);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, component.getUniqueId()));
}
-
- org.openecomp.sdc.be.model.Component component = componentResultEither.left().value();
- UiComponentDataTransfer dataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams((Resource)component, dataParamsToReturn);
- return Either.left(dataTransfer);
+ return Either.left(operationMap.get().getValue());
}
- @Override
- public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(
- String componentId, String userId) {
- return null;
+ private void initNewOperation(Operation operation){
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ String artifactUUID = UUID.randomUUID().toString();
+ artifactDefinition.setArtifactUUID(artifactUUID);
+ artifactDefinition.setUniqueId(artifactUUID);
+ artifactDefinition.setArtifactType(ArtifactTypeEnum.PLAN.getType());
+ artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.LIFE_CYCLE);
+ operation.setUniqueId(UUID.randomUUID().toString());
+ operation.setImplementation(artifactDefinition);
}
-
- @Override
- public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
- return deleteMarkedComponents(ComponentTypeEnum.RESOURCE);
- }
-
- @Override
- public ComponentInstanceBusinessLogic getComponentInstanceBL() {
- return componentInstanceBusinessLogic;
- }
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
index 9225f36a06..affafaed12 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
@@ -17,45 +17,43 @@
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.model.ComponentParametersView;
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.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.*;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
@Component("interfaceOperationValidation")
public class InterfaceOperationValidation {
- @Autowired
- private ToscaOperationFacade toscaOperationFacade;
private static final String TYPE_VALIDATION_REGEX = "^[a-zA-Z]{1,200}$";
private static final int DESCRIPTION_MAX_LENGTH = 200;
private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationValidation.class);
public Either<Boolean, ResponseFormat> validateInterfaceOperations(
- Collection<Operation> interfaceOperations,
- String resourceId, boolean isUpdate) {
+ Collection<Operation> interfaceOperations, org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
for(Operation interfaceOperation : interfaceOperations) {
Either<Boolean, ResponseFormat> interfaceOperationValidatorResponse = validateInterfaceOperation(
- interfaceOperation, resourceId, isUpdate);
+ interfaceOperation, component, isUpdate);
if (interfaceOperationValidatorResponse.isRight()) {
return interfaceOperationValidatorResponse;
}
@@ -64,29 +62,29 @@ public class InterfaceOperationValidation {
}
private Either<Boolean, ResponseFormat> validateInterfaceOperation(Operation interfaceOperation,
- String resourceId, boolean isUpdate) {
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
ResponseFormatManager responseFormatManager = getResponseFormatManager();
Either<Boolean, ResponseFormat> interfaceOperationTypeResponse = isInterfaceOperationTypeValid(interfaceOperation,
- responseFormatManager, resourceId, isUpdate);
+ responseFormatManager, component, isUpdate);
if (interfaceOperationTypeResponse.isRight()) {
return Either.right(interfaceOperationTypeResponse.right().value());
}
Either<Boolean, ResponseFormat> descriptionResponseEither = isValidDescription(responseFormatManager,
- interfaceOperation.getDescription());
+ interfaceOperation.getDescription());
if (descriptionResponseEither.isRight()) {
return Either.right(descriptionResponseEither.right().value());
}
Either<Boolean, ResponseFormat> inputParametersResponse = validateInputParameters(interfaceOperation,
- responseFormatManager);
+ responseFormatManager);
if(inputParametersResponse.isRight()) {
return Either.right(inputParametersResponse.right().value());
}
Either<Boolean, ResponseFormat> outputParametersResponse = validateOutputParameters(interfaceOperation,
- responseFormatManager);
+ responseFormatManager);
if(outputParametersResponse.isRight()) {
return Either.right(outputParametersResponse.right().value());
}
@@ -95,64 +93,64 @@ public class InterfaceOperationValidation {
}
private Either<Boolean, ResponseFormat> isInterfaceOperationTypeValid(Operation interfaceOperation,
- ResponseFormatManager responseFormatManager,
- String resourceId, boolean isUpdate) {
+ ResponseFormatManager responseFormatManager,
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
- Either<Boolean, ResponseFormat> operationTypeEmptyEither = isOperationTypeEmpty(responseFormatManager,
- interfaceOperation.getName()); // treating name as type for now
+ Either<Boolean, ResponseFormat> operationTypeEmptyEither =
+ isOperationTypeEmpty(responseFormatManager, interfaceOperation.getName());
if (operationTypeEmptyEither.isRight()) {
return Either.right(operationTypeEmptyEither.right().value());
}
Either<Boolean, ResponseFormat> operationTypeRegexValidationResponse =
- isOperationTypeRegexValid(responseFormatManager, interfaceOperation.getName());
+ isOperationTypeRegexValid(responseFormatManager, interfaceOperation.getName());
if (operationTypeRegexValidationResponse.isRight()) {
return Either.right(operationTypeRegexValidationResponse.right().value());
}
Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation,
- resourceId, isUpdate, responseFormatManager );
+ component, isUpdate, responseFormatManager );
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_TYPE_ALREADY_IN_USE, interfaceOperation.getName());
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
private Either<Boolean, ResponseFormat> isOperationTypeRegexValid(ResponseFormatManager responseFormatManager,
- String operationType) {
+ String operationType) {
if (!isValidOperationType(operationType)) {
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);
+ "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_TYPE_INVALID, operationType);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
private Either<Boolean, ResponseFormat> isOperationTypeEmpty(ResponseFormatManager responseFormatManager,
- String operationType) {
+ String operationType) {
if (StringUtils.isEmpty(operationType)) {
LOGGER.error("Interface Operation type is mandatory");
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_TYPE_MANDATORY);
+ .INTERFACE_OPERATION_TYPE_MANDATORY);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
private Either<Boolean, ResponseFormat> isValidDescription(ResponseFormatManager responseFormatManager,
- String description) {
+ String description) {
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);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -163,63 +161,57 @@ public class InterfaceOperationValidation {
}
private Either<Boolean, ResponseFormat> validateOperationTypeUnique(
- Operation interfaceOperation,
- String resourceId,
- boolean isUpdate,
- ResponseFormatManager responseFormatManager) {
+ Operation interfaceOperation,
+ org.openecomp.sdc.be.model.Component component,
+ boolean isUpdate,
+ ResponseFormatManager responseFormatManager) {
boolean isOperationTypeUnique = false;
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreInterfaces(false);
- Either<Resource, StorageOperationStatus> interfaceOperationOrigin = toscaOperationFacade
- .getToscaElement(resourceId, filter);
- if (interfaceOperationOrigin.isRight()){
- LOGGER.error("Failed to fetch interface operation information by resource id {} ", resourceId);
- return Either.right(responseFormatManager.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- Collection<InterfaceDefinition> interfaceDefinitions = interfaceOperationOrigin.left().value()
- .getInterfaces().values();
- if(CollectionUtils.isEmpty(interfaceDefinitions)){
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = ((Resource)component).getInterfaces();
+ if(interfaceDefinitionMap.isEmpty()){
isOperationTypeUnique = true;
return Either.left(isOperationTypeUnique);
}
- Collection<Operation> allOperations = interfaceDefinitions.stream()
- .filter(a -> MapUtils.isNotEmpty(a.getOperationsMap()))
- .map(a -> a.getOperationsMap().values()).flatMap(Collection::stream)
- .collect(Collectors.toList());
+
+ Collection<Operation> allOperations = interfaceDefinitionMap.values().stream()
+ .filter(a -> MapUtils.isNotEmpty(a.getOperationsMap()))
+ .map(a -> a.getOperationsMap().values()).flatMap(Collection::stream)
+ .collect(Collectors.toList());
if(CollectionUtils.isEmpty(allOperations)){
isOperationTypeUnique = true;
return Either.left(isOperationTypeUnique);
}
Map<String, String> operationTypes = new HashMap<>();
- allOperations.forEach(operationType -> operationTypes.put(operationType.getUniqueId(),
- operationType.getName()) );
+ allOperations.forEach(operationType -> operationTypes.put(operationType.getUniqueId(), operationType.getName()));
- if (isUpdate){
- isOperationTypeUnique = validateOperationTypeUniqueForUpdate(interfaceOperation, operationTypes);
- }
- else
if (!operationTypes.values().contains(interfaceOperation.getName())){
isOperationTypeUnique = true;
}
+ if (!isOperationTypeUnique && isUpdate){
+ 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;
+ }
+ }
+
return Either.left(isOperationTypeUnique);
}
private Either<Boolean, ResponseFormat> validateInputParameters(Operation interfaceOperation,
- ResponseFormatManager responseFormatManager) {
+ ResponseFormatManager responseFormatManager) {
if (isInputParameterNameEmpty(interfaceOperation)) {
- LOGGER.error("Interface operation input parameter name can't be empty");
- ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_INPUT_NAME_MANDATORY);
+ LOGGER.error("Interface operation input parameter name can't be empty");
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_NAME_MANDATORY);
return Either.right(inputResponse);
}
Either<Boolean, Set<String>> validateInputParametersUniqueResponse = isInputParametersUnique(interfaceOperation);
if(validateInputParametersUniqueResponse.isRight()) {
- LOGGER.error("Interface operation input parameter names {} already in use",
- validateInputParametersUniqueResponse.right().value().toString());
+ LOGGER.error("Interface operation input parameter names {} already in use",
+ validateInputParametersUniqueResponse.right().value());
ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, validateInputParametersUniqueResponse.right().value().toString());
+ .INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, validateInputParametersUniqueResponse.right().value().toString());
return Either.right(inputResponse);
}
return Either.left(Boolean.TRUE);
@@ -227,20 +219,19 @@ public class InterfaceOperationValidation {
private Either<Boolean, ResponseFormat> validateOutputParameters(Operation interfaceOperation,
- ResponseFormatManager responseFormatManager) {
+ ResponseFormatManager responseFormatManager) {
if (isOutputParameterNameEmpty(interfaceOperation)) {
- LOGGER.error("Interface operation output parameter name can't be empty");
- ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY);
+ LOGGER.error("Interface operation output parameter name can't be empty");
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY);
return Either.right(inputResponse);
}
Either<Boolean, Set<String>> validateOutputParametersUniqueResponse = isOutputParametersUnique(interfaceOperation);
if(validateOutputParametersUniqueResponse.isRight()) {
- LOGGER.error("Interface operation output parameter names {} already in use",
- validateOutputParametersUniqueResponse.right().value().toString());
+ LOGGER.error("Interface operation output parameter names {} already in use",
+ validateOutputParametersUniqueResponse.right().value());
ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE, validateOutputParametersUniqueResponse.right().value().toString());
+ .INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE, validateOutputParametersUniqueResponse.right().value().toString());
return Either.right(inputResponse);
}
return Either.left(Boolean.TRUE);
@@ -251,11 +242,11 @@ public class InterfaceOperationValidation {
Set<String> inputParamNamesSet = new HashSet<>();
Set<String> duplicateParamNamesToReturn = new HashSet<>();
operationDataDefinition.getInputs().getListToscaDataDefinition()
- .forEach(inputParam -> {
- if(!inputParamNamesSet.add(inputParam.getName().trim())) {
- duplicateParamNamesToReturn.add(inputParam.getName().trim());
- }
- });
+ .forEach(inputParam -> {
+ if(!inputParamNamesSet.add(inputParam.getName().trim())) {
+ duplicateParamNamesToReturn.add(inputParam.getName().trim());
+ }
+ });
if(!duplicateParamNamesToReturn.isEmpty()) {
return Either.right(duplicateParamNamesToReturn);
}
@@ -266,11 +257,11 @@ public class InterfaceOperationValidation {
Set<String> outputParamNamesSet = new HashSet<>();
Set<String> duplicateParamNamesToReturn = new HashSet<>();
operationDataDefinition.getOutputs().getListToscaDataDefinition()
- .forEach(outputParam -> {
- if(!outputParamNamesSet.add(outputParam.getName().trim())) {
- duplicateParamNamesToReturn.add(outputParam.getName().trim());
- }
- });
+ .forEach(outputParam -> {
+ if(!outputParamNamesSet.add(outputParam.getName().trim())) {
+ duplicateParamNamesToReturn.add(outputParam.getName().trim());
+ }
+ });
if(!duplicateParamNamesToReturn.isEmpty()) {
return Either.right(duplicateParamNamesToReturn);
}
@@ -279,26 +270,19 @@ public class InterfaceOperationValidation {
private Boolean isInputParameterNameEmpty(Operation operationDataDefinition) {
return operationDataDefinition.getInputs().getListToscaDataDefinition().stream()
- .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
+ .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
}
private Boolean isOutputParameterNameEmpty(Operation operationDataDefinition) {
return operationDataDefinition.getInputs().getListToscaDataDefinition().stream()
- .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
+ .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
}
- private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation,
- Map<String, String> operationTypes) {
+ private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation, Map<String, String> operationTypes) {
boolean isOperationTypeUnique = false;
- for(Map.Entry<String, String> entry : operationTypes.entrySet()){
- if (entry.getKey().equals(interfaceOperation.getUniqueId()) && entry.getValue().
- equals(interfaceOperation.getName())) {
- isOperationTypeUnique = true;
- }
-
- if(entry.getKey().equals(interfaceOperation.getUniqueId()) && !operationTypes.values()
- .contains(interfaceOperation.getName())){
- isOperationTypeUnique = true;
- }
+ 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;
}
return isOperationTypeUnique;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java
index 4d84e2c1a0..3e43dd7a91 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java
@@ -139,17 +139,14 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
modifier.setUserId(userId);
log.debug("Start get request of {} with modifier id {}", url, userId);
- Response response;
-
try {
String resourceIdLower = resourceId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
Either<Operation, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
if (actionResponse.isRight()) {
- log.debug("failed to get interface operation");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
+ log.error("failed to get interface operation");
+ return buildErrorResponse(actionResponse.right().value());
}
InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value());
@@ -158,7 +155,7 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource interface operations");
- log.debug("get resource interface operations failed with exception", e);
+ log.error("get resource interface operations failed with exception", e);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
@@ -173,17 +170,14 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
modifier.setUserId(userId);
log.debug("Start delete request of {} with modifier id {}", url, userId);
- Response response;
-
try {
String resourceIdLower = resourceId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
Either<Operation, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
if (actionResponse.isRight()) {
- log.debug("failed to delete interface operation");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
+ log.error("failed to delete interface operation");
+ return buildErrorResponse(actionResponse.right().value());
}
InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value());
@@ -192,9 +186,8 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Interface Operation");
- log.debug("Delete interface operation with an error", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
+ log.error("Delete interface operation with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
@@ -206,7 +199,6 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
modifier.setUserId(userId);
log.debug("Start create or update request of {} with modifier id {}", url, userId);
- Response response;
try {
String resourceIdLower = resourceId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
@@ -220,9 +212,8 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
if (actionResponse.isRight()) {
- log.debug("failed to update or create interface operation");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
+ log.error("failed to update or create interface operation");
+ return buildErrorResponse(actionResponse.right().value());
}
InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value());
@@ -231,9 +222,8 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Interface Operation Creation or update");
- log.debug("create or update interface Operation with an error", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
+ log.error("create or update interface Operation with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
index b9e0b594ea..eb17d56154 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
@@ -16,7 +16,22 @@
package org.openecomp.sdc.be.components.impl;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyCollection;
+import static org.mockito.ArgumentMatchers.anyObject;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.servlet.ServletContext;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -25,7 +40,6 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
-import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
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;
@@ -40,10 +54,19 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
-import org.openecomp.sdc.be.model.*;
+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;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
-import org.openecomp.sdc.be.model.jsontitan.operations.*;
-import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils;
+import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -55,16 +78,9 @@ import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
import org.springframework.web.context.WebApplicationContext;
-import javax.servlet.ServletContext;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.when;
-
public class InterfaceOperationBusinessLogicTest {
public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
@@ -166,12 +182,11 @@ public class InterfaceOperationBusinessLogicTest {
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
//InterfaceOperation
- when(operationValidator.validateInterfaceOperations(anyCollection(), anyString(), anyBoolean())).thenReturn(Either.left(true));
+ 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.getInterfaceOperation(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.updateInterface(any(),any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
@@ -185,7 +200,6 @@ public class InterfaceOperationBusinessLogicTest {
bl.setComponentsUtils(componentsUtils);
bl.setGraphLockOperation(graphLockOperation);
bl.setTitanGenericDao(mockTitanDao);
- bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
bl.setToscaOperationFacade(toscaOperationFacade);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
index 3d3447d88b..d41294b4c2 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
@@ -16,57 +16,49 @@
package org.openecomp.sdc.be.components.validation;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
import com.google.common.collect.Sets;
import fj.data.Either;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
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.*;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+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.exception.ResponseFormat;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
+import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
public class InterfaceOperationValidationTest {
- private Resource resource = (Resource) getToscaFullElement().left().value();
-
- ResponseFormatManager mock;
- @Mock
- ToscaOperationFacade toscaOperationFacade;
+ private Resource resource = setUpResourceMock();
+ ResponseFormatManager responseFormatManagerMock;
- @InjectMocks
InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest();
- private static final String RESOURCE_ID = "resource1";
ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
+
@Before
public void init() {
MockitoAnnotations.initMocks(this);
- mock = Mockito.mock(ResponseFormatManager.class);
- when(toscaOperationFacade.getToscaElement(any(), any(ComponentParametersView.class))).thenReturn(Either.left(resource));
- when(mock.getResponseFormat(any())).thenReturn(new ResponseFormat());
- when(mock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
- when(mock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
+ responseFormatManagerMock = Mockito.mock(ResponseFormatManager.class);
+ when(responseFormatManagerMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+ when(responseFormatManagerMock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
+ when(responseFormatManagerMock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
}
-
@Test
public void testValidInterfaceOperation() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
@@ -75,7 +67,7 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"upgrade");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ .validateInterfaceOperations(operations, resource, false);
Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
@@ -89,7 +81,7 @@ public class InterfaceOperationValidationTest {
"with web, data access (relational and NoSQL datastores), cloud, or messaging support",
new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ .validateInterfaceOperations(operations, resource, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -103,7 +95,7 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList, "");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ .validateInterfaceOperations(operations, resource, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -115,7 +107,7 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"input2");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ .validateInterfaceOperations(operations, resource, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -127,7 +119,7 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"CREATE");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ .validateInterfaceOperations(operations, resource, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -142,7 +134,7 @@ public class InterfaceOperationValidationTest {
"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");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ .validateInterfaceOperations(operations, resource, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -159,7 +151,7 @@ public class InterfaceOperationValidationTest {
operationOutputDefinitionList,"create");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ .validateInterfaceOperations(operations, resource, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -174,7 +166,7 @@ public class InterfaceOperationValidationTest {
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ .validateInterfaceOperations(operations, resource, false);
Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
@@ -189,7 +181,7 @@ public class InterfaceOperationValidationTest {
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ .validateInterfaceOperations(operations, resource, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -199,15 +191,9 @@ public class InterfaceOperationValidationTest {
return Sets.newHashSet(InterfaceOperationTestUtils.createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, outputs, name));
}
- private <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement() {
-
- return Either.left((T) setUpResourceMock());
- }
-
private Resource setUpResourceMock(){
Resource resource = new Resource();
resource.setInterfaces(createMockInterfaceDefinition());
-
return resource;
}
@@ -223,7 +209,7 @@ public class InterfaceOperationValidationTest {
private class InterfaceOperationValidationUtilTest extends InterfaceOperationValidation {
protected ResponseFormatManager getResponseFormatManager() {
- return mock;
+ return responseFormatManagerMock;
}
}
}