diff options
Diffstat (limited to 'catalog-be/src')
2 files changed, 58 insertions, 7 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java index 02d6e0b565..6b5878ee4b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java @@ -93,6 +93,8 @@ public class InputsBusinessLogic extends BaseBusinessLogic { private static final String FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR = "Failed to found input {} under component {}, error: {}"; private static final String GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP = "Going to execute rollback on create group."; private static final String GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP = "Going to execute commit on create group."; + private static final String GOING_TO_EXECUTE_ROLLBACK_ON_UPDATE_INPUT = "Going to execute rollback on update input."; + private static final String GOING_TO_EXECUTE_COMMIT_ON_UPDATE_INPUT = "Going to execute commit on update input."; public LoggerSupportability loggerSupportability=LoggerSupportability.getLogger(InputsBusinessLogic.class.getName()); private final PropertyDeclarationOrchestrator propertyDeclarationOrchestrator; @@ -307,7 +309,8 @@ public class InputsBusinessLogic extends BaseBusinessLogic { if (shouldLockComp) { try { lockComponent(component, UPDATE_INPUT); - }catch (ComponentException e){ + } catch (ComponentException e) { + log.error("Failed to lock component", e); result = Either.right(e.getResponseFormat()); return result; } @@ -337,6 +340,9 @@ public class InputsBusinessLogic extends BaseBusinessLogic { String updateInputObjectValue = updateInputObjectValue(currInput, newInput, dataTypes); currInput.setDefaultValue(updateInputObjectValue); currInput.setOwnerId(userId); + if (newInput.isRequired() != null) { + currInput.setRequired(newInput.isRequired()); + } Either<InputDefinition, StorageOperationStatus> status = toscaOperationFacade.updateInputOfComponent(component, currInput); if(status.isRight()){ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status.right().value()); @@ -347,13 +353,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } } result = Either.left(returnInputs); - }catch (ComponentException e) { - log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP); + } catch (ComponentException e) { + log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_UPDATE_INPUT); unlockRollbackWithException(component, e); } catch (Exception e){ + log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_UPDATE_INPUT); unlockRollbackWithException(component, new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR)); } - log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP); + log.debug(GOING_TO_EXECUTE_COMMIT_ON_UPDATE_INPUT); unlockWithCommit(component); return result; diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java index 66e6cd3e81..337ea77ef1 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java @@ -91,13 +91,16 @@ public class InputsBusinessLogicTest { private static final String COMPONENT_INSTANCE_ID = "instanceId"; private static final String COMPONENT_ID = "componentId"; private static final String USER_ID = "userId"; - public static final String INSTANCE_INPUT_ID = "inputId"; + private static final String INPUT_ID = "inputId"; + private static final String INPUT_TYPE = "string"; private static final String LISTINPUT_NAME = "listInput"; private static final String LISTINPUT_SCHEMA_TYPE = "org.onap.datatypes.listinput"; private static final String LISTINPUT_PROP1_NAME = "prop1"; private static final String LISTINPUT_PROP1_TYPE = "string"; private static final String LISTINPUT_PROP2_NAME = "prop2"; private static final String LISTINPUT_PROP2_TYPE = "integer"; + private static final String OLD_VALUE = "old value"; + private static final String NEW_VALUE = "new value"; static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"); static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); @@ -169,8 +172,8 @@ public class InputsBusinessLogicTest { instanceInputMap = new HashMap<>(); ComponentInstanceInput componentInstanceInput = new ComponentInstanceInput(); - componentInstanceInput.setInputId(INSTANCE_INPUT_ID); - componentInstanceInput.setName(INSTANCE_INPUT_ID); + componentInstanceInput.setInputId(INPUT_ID); + componentInstanceInput.setName(INPUT_ID); inputsList = Collections.singletonList(componentInstanceInput); instanceInputMap.put(COMPONENT_INSTANCE_ID, inputsList); instanceInputMap.put("someInputId", Collections.singletonList(new ComponentInstanceInput())); @@ -752,4 +755,45 @@ public class InputsBusinessLogicTest { verify(propertyDeclarationOrchestrator, times(1)).unDeclarePropertiesAsInputs(service, listInput); } + + @Test + public void test_updateInputsValue() throws Exception { + List<InputDefinition> oldInputDefs = new ArrayList<>(); + InputDefinition oldInputDef = new InputDefinition(); + oldInputDef.setUniqueId(INPUT_ID); + oldInputDef.setType(INPUT_TYPE); + oldInputDef.setDefaultValue(OLD_VALUE); + oldInputDef.setRequired(Boolean.FALSE); + oldInputDefs.add(oldInputDef); + service.setInputs(oldInputDefs); + + List<InputDefinition> newInputDefs = new ArrayList<>(); + InputDefinition inputDef = new InputDefinition(); + inputDef.setUniqueId(INPUT_ID); + inputDef.setType(INPUT_TYPE); + inputDef.setDefaultValue(NEW_VALUE); // update value + inputDef.setRequired(Boolean.TRUE); // update value + newInputDefs.add(inputDef); + + // used in validateComponentExists + when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service)); + // used in lockComponent + when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK); + // used in validateInputValueConstraint + Map<String, DataTypeDefinition> dataTypeMap = new HashMap<>(); + when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypeMap)); // don't use Collections.emptyMap + // used in updateInputObjectValue + when(propertyOperation.validateAndUpdatePropertyValue(INPUT_TYPE, NEW_VALUE, true, null, dataTypeMap)) + .thenReturn(Either.left(NEW_VALUE)); + when(toscaOperationFacadeMock.updateInputOfComponent(service, oldInputDef)) + .thenReturn(Either.left(inputDef)); + + Either<List<InputDefinition>, ResponseFormat> result = + testInstance.updateInputsValue(service.getComponentType(), COMPONENT_ID, newInputDefs, USER_ID, true, false); + assertTrue(result.isLeft()); + // check if values are updated + assertEquals(service.getInputs().get(0).getDefaultValue(), NEW_VALUE); + assertEquals(service.getInputs().get(0).isRequired(), Boolean.TRUE); + } + } |