From c0b223d4fa51947c1aad771cae210678554aff3e Mon Sep 17 00:00:00 2001 From: Satoshi Fujii Date: Mon, 20 May 2019 16:00:56 +0900 Subject: Fixed declared properties are not updated properly Change-Id: I3712f9656d7cdeb8fa9c4212b2dd1496043c1006 Issue-ID: SDC-2314 Signed-off-by: Satoshi Fujii --- .../operations/ToscaOperationFacadeTest.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'catalog-model/src/test/java') diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java index 0eb0b3c6d2..b43b632ad1 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java @@ -51,6 +51,7 @@ import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.ComponentParametersView; @@ -82,6 +83,8 @@ import java.util.Arrays; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyMap; @@ -91,6 +94,12 @@ import static org.mockito.ArgumentMatchers.eq; @RunWith(MockitoJUnitRunner.class) public class ToscaOperationFacadeTest { + private static final String COMPONENT_ID = "componentId"; + private static final String PROPERTY1_NAME = "prop1"; + private static final String PROPERTY1_TYPE = "string"; + private static final String PROPERTY2_NAME = "prop2"; + private static final String PROPERTY2_TYPE = "integer"; + @InjectMocks private ToscaOperationFacade testInstance; @@ -103,6 +112,9 @@ public class ToscaOperationFacadeTest { @Mock private NodeTypeOperation nodeTypeOperation; + @Mock + private NodeTemplateOperation nodeTemplateOperationMock; + @Before public void setUp() throws Exception { testInstance = new ToscaOperationFacade(); @@ -584,6 +596,36 @@ public class ToscaOperationFacadeTest { assertEquals(datatype, result); } + @Test + public void testAddComponentInstancePropertiesToComponent() { + // set up component object + Component component = new Resource(); + component.setUniqueId(COMPONENT_ID); + List instanceProps = new ArrayList<>(); + ComponentInstanceProperty instanceProp = new ComponentInstanceProperty(); + instanceProp.setName(PROPERTY1_NAME); + instanceProp.setType(PROPERTY1_TYPE); + instanceProps.add(instanceProp); + instanceProp = new ComponentInstanceProperty(); + instanceProp.setName(PROPERTY2_NAME); + instanceProp.setType(PROPERTY2_TYPE); + instanceProps.add(instanceProp); + Map> instancePropsMap = + Collections.singletonMap(COMPONENT_ID, instanceProps); + component.setComponentInstancesProperties(Collections.singletonMap(COMPONENT_ID, new ArrayList<>())); + + when(nodeTemplateOperationMock.addComponentInstanceProperty(any(), any(), any())) + .thenReturn(StorageOperationStatus.OK); + + Either>, StorageOperationStatus> result = + testInstance.addComponentInstancePropertiesToComponent(component, instancePropsMap); + assertTrue(result.isLeft()); + verify(nodeTemplateOperationMock, times(2)).addComponentInstanceProperty(any(), any(), any()); + List resultProps = result.left().value().get(COMPONENT_ID); + assertTrue(resultProps.stream().anyMatch(e -> e.getName().equals(PROPERTY1_NAME))); + assertTrue(resultProps.stream().anyMatch(e -> e.getName().equals(PROPERTY2_NAME))); + } + private Either associatePolicyToComponentWithStatus(StorageOperationStatus status) { PolicyDefinition policy = new PolicyDefinition(); String componentId = "componentId"; -- cgit 1.2.3-korg