Maintain VFC instance attribute outputs on instance version change
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / utils / ComponentBuilder.java
index 7275814..b9e181f 100644 (file)
@@ -1,13 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. 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.utils;
 
 import org.openecomp.sdc.be.dao.utils.MapUtil;
 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.model.*;
+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;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.OutputDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+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>> {
 
@@ -104,6 +136,22 @@ public abstract class ComponentBuilder<T extends Component, B extends ComponentB
         return self();
     }
 
+    public ComponentBuilder<T, B> addOutput(final OutputDefinition output) {
+        if (component.getOutputs() == null) {
+            component.setOutputs(new ArrayList<>());
+        }
+        component.getOutputs().add(output);
+        return self();
+    }
+
+    public ComponentBuilder<T, B> addOutput(final String outputName) {
+        final OutputDefinition outputDefinition = new OutputDefinition();
+        outputDefinition.setName(outputName);
+        outputDefinition.setUniqueId(outputName);
+        this.addOutput(outputDefinition);
+        return self();
+    }
+
     public ComponentBuilder<T, B> addInstanceProperty(String instanceId, ComponentInstanceProperty prop) {
         if (component.getComponentInstancesProperties() == null) {
             component.setComponentInstancesProperties(new HashMap<>());
@@ -145,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<>());