summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2022-05-23 08:26:40 +0100
committerMichael Morris <michael.morris@est.tech>2022-06-03 12:20:16 +0000
commita80da69b9e95a6cbdbe50251c37c9dcc50650e4c (patch)
treef21a6acc25dab04f42b2891e5d1ec2b099c36dd6 /catalog-be/src/test
parentff317808f308af03321de0f0b0849cd9f6f8ccad (diff)
Maintain VFC instance attribute outputs on instance version change
Issue-ID: SDC-4025 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: Ia44a6ac73d9a52042caaacf0c5f790e1e2fc73f1
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceAttributesAndOutputsMergeTest.java183
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java30
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ObjectGenerator.java20
3 files changed, 233 insertions, 0 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceAttributesAndOutputsMergeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceAttributesAndOutputsMergeTest.java
new file mode 100644
index 0000000000..931469a2cf
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceAttributesAndOutputsMergeTest.java
@@ -0,0 +1,183 @@
+/*
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.merge.instance;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.List;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.utils.ObjectGenerator;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.OutputDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+class ComponentInstanceAttributesAndOutputsMergeTest {
+
+ private static final String INSTANCE_ID1 = "inst1";
+ private static final User USER = new User();
+
+ @InjectMocks
+ private ComponentInstanceAttributesAndOutputsMerge testInstance;
+
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+
+ @Mock
+ private ComponentsUtils componentsUtils;
+
+ @Mock
+ private ComponentInstanceAttributesMergeBL componentInstanceAttributesMergeBL;
+
+ @Mock
+ private ComponentInstanceOutputsRedeclareHandler componentInstanceOutputsRedeclareHandler;
+
+ private Resource resourceToUpdate;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ MockitoAnnotations.openMocks(this);
+ resourceToUpdate = new ResourceBuilder()
+ .addInstanceAttribute(INSTANCE_ID1, "instAttribute1")
+ .addInstanceAttribute(INSTANCE_ID1, "instAttribute2")
+ .addOutput("output1")
+ .addOutput("output2")
+ .setUniqueId("resourceId").build();
+
+ List<OutputDefinition> oldOutputs = ObjectGenerator.buildOutputs("output1");
+ List<ComponentInstanceAttribute> oldInstAttribute = ObjectGenerator.buildInstanceAttributes("instAttribute1", "instAttribute3");
+
+ DataForMergeHolder oldDataHolder = new DataForMergeHolder();
+ oldDataHolder.setOrigComponentOutputs(oldOutputs);
+ oldDataHolder.setOrigComponentInstanceAttributes(oldInstAttribute);
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ }
+
+ @Test
+ void mergeDataAfterCreate() {
+ List<OutputDefinition> oldOutputs = ObjectGenerator.buildOutputs("output1");
+ List<ComponentInstanceAttribute> oldInstAttributes = ObjectGenerator.buildInstanceAttributes("instAttribute1", "instAttribute3");
+
+ DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
+ dataForMergeHolder.setOrigComponentOutputs(oldOutputs);
+ dataForMergeHolder.setOrigComponentInstanceAttributes(oldInstAttributes);
+
+ ArgumentCaptor<ComponentParametersView> parametersViewCaptor = ArgumentCaptor.forClass(ComponentParametersView.class);
+
+ when(componentInstanceAttributesMergeBL.mergeComponentInstanceAttributes(anyList(), eq(resourceToUpdate), eq(INSTANCE_ID1)))
+ .thenReturn(ActionStatus.OK);
+ when(componentInstanceOutputsRedeclareHandler.redeclareComponentOutputsForInstance(any(), any(), anyList()))
+ .thenReturn(ActionStatus.OK);
+ when(toscaOperationFacade.getToscaElement(eq("resourceId"), parametersViewCaptor.capture()))
+ .thenReturn(Either.left(resourceToUpdate));
+ Component mergeResult = testInstance.mergeDataAfterCreate(USER, dataForMergeHolder, resourceToUpdate, INSTANCE_ID1);
+ assertEquals(mergeResult, resourceToUpdate);
+ assertComponentFilter(parametersViewCaptor.getValue());
+ }
+
+ @Test
+ void mergeDataAfterCreate_failedToMergeComponentInstanceOutputs() {
+ List<OutputDefinition> oldOutputs = ObjectGenerator.buildOutputs("output1");
+ List<ComponentInstanceAttribute> oldInstAttributes = ObjectGenerator.buildInstanceAttributes("instAttribute1", "instAttribute3");
+
+ DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
+ dataForMergeHolder.setOrigComponentOutputs(oldOutputs);
+ dataForMergeHolder.setOrigComponentInstanceAttributes(oldInstAttributes);
+
+ ArgumentCaptor<ComponentParametersView> parametersViewCaptor = ArgumentCaptor.forClass(ComponentParametersView.class);
+
+ when(componentInstanceAttributesMergeBL.mergeComponentInstanceAttributes(anyList(), eq(resourceToUpdate), eq(INSTANCE_ID1)))
+ .thenReturn(ActionStatus.OK);
+ when(toscaOperationFacade.getToscaElement(eq("resourceId"), parametersViewCaptor.capture()))
+ .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR)).thenReturn(ActionStatus.GENERAL_ERROR);
+ assertThrows(ComponentException.class, () -> {
+ testInstance.mergeDataAfterCreate(USER, dataForMergeHolder, resourceToUpdate, "inst1");
+ });
+ verifyNoInteractions(componentInstanceOutputsRedeclareHandler);
+ }
+
+ @Test
+ void mergeDataAfterCreate_failedToMergeComponentInstAttributes() {
+ final ResponseFormat errorResponse = new ResponseFormat();
+ when(componentInstanceAttributesMergeBL.mergeComponentInstanceAttributes(anyList(), any(Component.class), anyString()))
+ .thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(errorResponse);
+ final DataForMergeHolder dataHolder = new DataForMergeHolder();
+ final Service service = new Service();
+ assertThrows(ComponentException.class, () -> {
+ testInstance.mergeDataAfterCreate(USER, dataHolder, service, "inst1");
+ });
+ verifyNoInteractions(componentInstanceOutputsRedeclareHandler, toscaOperationFacade);
+ }
+
+ @Test
+ void mergeDataAfterCreate_mergeInputs_FailedToFetchResource() {
+ final ResponseFormat errorResponse = new ResponseFormat();
+ when(componentInstanceAttributesMergeBL.mergeComponentInstanceAttributes(anyList(), any(Component.class), anyString()))
+ .thenReturn(ActionStatus.OK);
+ when(toscaOperationFacade.getToscaElement(any(), any(ComponentParametersView.class)))
+ .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR)).thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(errorResponse);
+ final DataForMergeHolder dataHolder = new DataForMergeHolder();
+ dataHolder.setOrigComponentOutputs(ObjectGenerator.buildOutputs("output1", "output2"));
+ final Service service = new Service();
+ assertThrows(ComponentException.class, () -> {
+ testInstance.mergeDataAfterCreate(USER, dataHolder, service, "inst1");
+ });
+ verifyNoInteractions(componentInstanceOutputsRedeclareHandler);
+ }
+
+ private void assertComponentFilter(ComponentParametersView value) {
+ assertFalse(value.isIgnoreComponentInstances());
+ assertFalse(value.isIgnoreComponentInstancesAttributes());
+ assertFalse(value.isIgnoreOutputs());
+ assertFalse(value.isIgnoreArtifacts());
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java
index 0dad76ebfe..b9e181fcfe 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java
@@ -25,7 +25,9 @@ import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceOutput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
@@ -37,6 +39,7 @@ import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public abstract class ComponentBuilder<T extends Component, B extends ComponentBuilder<T, B>> {
@@ -190,6 +193,33 @@ public abstract class ComponentBuilder<T extends Component, B extends ComponentB
return self();
}
+ public void addInstanceAttribute(String instanceId, ComponentInstanceAttribute attribute) {
+ Map<String, List<ComponentInstanceAttribute>> compInstAttribute = component.safeGetComponentInstancesAttributes();
+ if (compInstAttribute == null || compInstAttribute.isEmpty()) {
+ component.setComponentInstancesAttributes(new HashMap<>());
+ }
+ Map<String, List<ComponentInstanceAttribute>> instAttribute = component.safeGetComponentInstancesAttributes();
+ instAttribute.computeIfAbsent(instanceId, key -> new ArrayList<>()).add(attribute);
+ self();
+ }
+
+ public ComponentBuilder<T, B> addInstanceAttribute(String instanceId, String AttributeName) {
+ ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute();
+ componentInstanceAttribute.setName(AttributeName);
+ componentInstanceAttribute.setUniqueId(AttributeName);
+ this.addInstanceAttribute(instanceId, componentInstanceAttribute);
+ return self();
+ }
+
+ public void addInstanceOutput(String instanceId, ComponentInstanceOutput attribute) {
+ if (component.getComponentInstancesOutputs() == null) {
+ component.setComponentInstancesOutputs(new HashMap<>());
+ }
+ component.getComponentInstancesOutputs().computeIfAbsent(instanceId, key -> new ArrayList<>()).add(attribute);
+ self();
+ }
+
+
public ComponentBuilder<T, B> addRelationship(RequirementCapabilityRelDef requirementCapabilityRelDef) {
if (component.getComponentInstancesRelations() == null) {
component.setComponentInstancesRelations(new ArrayList<>());
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ObjectGenerator.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ObjectGenerator.java
index c6a36971a8..8f194f1d0f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ObjectGenerator.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ObjectGenerator.java
@@ -21,10 +21,12 @@
package org.openecomp.sdc.be.components.utils;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.HeatParameterDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.Resource;
@@ -80,6 +82,24 @@ public class ObjectGenerator {
return inputs;
}
+ public static List<ComponentInstanceAttribute> buildInstanceAttributes(String ... attributesNames) {
+ return Stream.of(attributesNames).map(name -> {
+ ComponentInstanceAttribute instAttribute = new ComponentInstanceAttribute();
+ instAttribute.setName(name);
+ return instAttribute;
+ }).collect(Collectors.toList());
+ }
+
+ public static List<OutputDefinition> buildOutputs(String ... outputNames) {
+ List<OutputDefinition> outputs = new ArrayList<>();
+ for (String outputName : outputNames) {
+ OutputDefinition outputDefinition = new OutputDefinition();
+ outputDefinition.setName(outputName);
+ outputs.add(outputDefinition);
+ }
+ return outputs;
+ }
+
public static Resource buildResourceWithComponentInstance(String ... instanceNames) {
List<ComponentInstance> instances = new ArrayList<>();
for (String instanceName : instanceNames) {