From 407bbefe5b0b932f6c6bed65193815c78b4d41b5 Mon Sep 17 00:00:00 2001 From: Satoshi Fujii Date: Wed, 26 Feb 2020 15:39:38 +0900 Subject: Add 'required in runtime' for service inputs User may want to set required to true for some inputs so that make sure those input values are given at service instantiation time. By this change 'required in runtime' column is introduced into service inputs table in Properties Assignment screen and user can select required true/false for each input. Change-Id: I0d676d2d20e02c975d51c7f4d2bb63c699743d66 Issue-ID: SDC-2659 Signed-off-by: Satoshi Fujii --- .../components/impl/InputsBusinessLogicTest.java | 50 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'catalog-be/src/test') 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 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 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 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, 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); + } + } -- cgit 1.2.3-korg