summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/components/merge')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalInputsFilteringBusinessLogicTest.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalTypesMergeBusinessLogicTest.java73
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/RelationsComparatorTest.java12
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/TopologyComparatorTest.java9
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolverTest.java15
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/group/ComponentGroupMergeCommandTest.java215
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/group/GroupPropertiesMergeCommandTest.java157
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/heat/HeatEnvArtifactsMergeBusinessLogicTest.java14
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/BaseComponentInputsMerge.java61
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBLTest.java134
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/DeclaredInputsResolverTest.java101
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/GlobalInputsMergeCommandTest.java68
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogicTest.java49
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMergeTest.java24
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesMergeBLTest.java36
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesPropertiesMergeTest.java (renamed from catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabiliteisPropertiesMergeTest.java)24
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMergeTest.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInputsRedeclareHandlerTest.java132
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogicTest.java28
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMergeTest.java49
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMergeTest.java354
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ContainerRelationsMergeInfoTest.java34
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolderTest.java17
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBLTest.java97
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/RelationMergeInfoTest.java46
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/VfRelationsMergeInfoTest.java52
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/path/ComponentInstanceForwardingPathMergeTest.java59
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/policy/PoliciesMergeCommandTest.java225
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComplexPropertyValueMergerTest.java35
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java15
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstancePropertiesMergeBLTest.java65
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/DataDefinitionsValuesMergingBusinessLogicTest.java12
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/MergePropertyDataTest.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogicTest.java399
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java38
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ScalarPropertyValueMergerTest.java33
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java35
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtilsTest.java381
38 files changed, 2172 insertions, 972 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalInputsFilteringBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalInputsFilteringBusinessLogicTest.java
index ab2e865ae0..89b82b91d2 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalInputsFilteringBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalInputsFilteringBusinessLogicTest.java
@@ -1,14 +1,7 @@
package org.openecomp.sdc.be.components.merge;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
+import com.google.common.collect.Sets;
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -24,9 +17,14 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import com.google.common.collect.Sets;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
-import fj.data.Either;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class GlobalInputsFilteringBusinessLogicTest {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalTypesMergeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalTypesMergeBusinessLogicTest.java
deleted file mode 100644
index d39db5a500..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalTypesMergeBusinessLogicTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.openecomp.sdc.be.components.merge;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-import static org.openecomp.sdc.be.components.utils.ObjectGenerator.buildResourceWithInputs;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.components.merge.input.ComponentInputsMergeBL;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.Resource;
-
-import fj.data.Either;
-
-public class GlobalTypesMergeBusinessLogicTest {
-
- @InjectMocks
- private GlobalTypesMergeBusinessLogic testInstance;
-
- @Mock
- private ComponentInputsMergeBL resourceInputsMergeBLMock;
-
- @Mock
- private GlobalInputsFilteringBusinessLogic globalInputsFilteringBusinessLogic;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void mergeInstancePropsAndInputs_mergeOnlyNewResourceGenericGlobalTypes() {
- Resource oldResource = buildResourceWithInputs("input1", "input2");
- Resource newResource = buildResourceWithInputs("input1", "input2", "global1", "global2");
- List<InputDefinition> globalInputs = Arrays.asList(newResource.getInputs().get(2), newResource.getInputs().get(3));
- when(globalInputsFilteringBusinessLogic.filterGlobalInputs(newResource)).thenReturn(Either.left(globalInputs));
- when(resourceInputsMergeBLMock.mergeComponentInputs(oldResource, newResource, globalInputs)).thenReturn(ActionStatus.OK);
- ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
- assertEquals(ActionStatus.OK, actionStatus);
-
- }
-
- @Test
- public void mergeInstancePropsAndInputs_mergeOldResourceNull() {
- Resource oldResource = null;
- Resource newResource = buildResourceWithInputs("input1", "input2", "global1", "global2");
- List<InputDefinition> globalInputs = Arrays.asList(newResource.getInputs().get(2), newResource.getInputs().get(3));
- when(globalInputsFilteringBusinessLogic.filterGlobalInputs(newResource)).thenReturn(Either.left(globalInputs));
- ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
- assertEquals(ActionStatus.OK, actionStatus);
-
- }
-
- @Test
- public void mergeInstancePropsAndInputs_failedToFilterGlobalInputs() throws Exception {
- Resource oldResource = buildResourceWithInputs("input1", "input2");
- Resource newResource = buildResourceWithInputs("input1", "input2", "global1", "global2");
- when(globalInputsFilteringBusinessLogic.filterGlobalInputs(newResource)).thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
- ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
- assertEquals(actionStatus, ActionStatus.GENERAL_ERROR);
- verifyZeroInteractions(resourceInputsMergeBLMock);
- }
-
-
-} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/RelationsComparatorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/RelationsComparatorTest.java
index eed98b1752..98d7d7b991 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/RelationsComparatorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/RelationsComparatorTest.java
@@ -1,11 +1,5 @@
package org.openecomp.sdc.be.components.merge;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.LinkedList;
-
import org.junit.Before;
import org.junit.Test;
import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
@@ -15,6 +9,12 @@ import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.Resource;
+import java.util.Arrays;
+import java.util.LinkedList;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
public class RelationsComparatorTest {
public static final String INSTANCE1 = "instance1";
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/TopologyComparatorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/TopologyComparatorTest.java
index aa5962eccf..ed554d20f5 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/TopologyComparatorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/TopologyComparatorTest.java
@@ -1,10 +1,6 @@
package org.openecomp.sdc.be.components.merge;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -20,7 +16,8 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import fj.data.Either;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
public class TopologyComparatorTest {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolverTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolverTest.java
index 8071749fdf..be9f426c2c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolverTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolverTest.java
@@ -1,12 +1,6 @@
package org.openecomp.sdc.be.components.merge.capability;
-import static java.util.Arrays.asList;
-import static java.util.Collections.emptyMap;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.when;
-
-import java.util.Map;
-
+import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -21,7 +15,12 @@ import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.Resource;
-import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyMap;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class SimpleCapabilityResolverTest {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/group/ComponentGroupMergeCommandTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/group/ComponentGroupMergeCommandTest.java
new file mode 100644
index 0000000000..26b0034704
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/group/ComponentGroupMergeCommandTest.java
@@ -0,0 +1,215 @@
+package org.openecomp.sdc.be.components.merge.group;
+
+import fj.data.Either;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
+import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.jsontitan.operations.GroupsOperation;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.*;
+import static java.util.stream.Collectors.toMap;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ComponentGroupMergeCommandTest {
+
+ private static final Resource DONT_CARE = new Resource();
+ private ComponentGroupMergeCommand testInstance;
+ @Mock
+ private GroupsOperation groupsOperation;
+
+ @Captor
+ private ArgumentCaptor<List<GroupDefinition>> groupsToAddCaptor;
+
+ @Before
+ public void setUp() throws Exception {
+ testInstance = new ComponentGroupMergeCommand(groupsOperation, new ComponentsUtils(Mockito.mock(AuditingManager.class)));
+ }
+
+ @Test
+ public void whenPrevComponentHasNoGroups_returnOk() {
+ ActionStatus actionStatus = testInstance.mergeComponents(new Resource(), DONT_CARE);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+
+ Resource prevResource = new Resource();
+ prevResource.setGroups(emptyList());
+
+ actionStatus = testInstance.mergeComponents(prevResource, DONT_CARE);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(groupsOperation);
+ }
+
+ @Test
+ public void whenAllPrevGroupsCreatedFromCsar_returnOk() {
+ GroupDefinition group1 = createCsarGroup("group1");
+ GroupDefinition group2 = createCsarGroup("group2");
+ Resource prevResource = createResourceWithGroups(group1, group2);
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, DONT_CARE);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(groupsOperation);
+ }
+
+ @Test
+ public void whenAllPrevGroupsAlreadyExistInNewComponent_returnOk() {
+ GroupDefinition group1 = createCsarGroup("group1");
+ GroupDefinition group2 = createUserDefinedGroup("group2");
+ GroupDefinition group3 = createUserDefinedGroup("group3");
+ Resource prevResource = createResourceWithGroups(group1, group2, group3);
+ Resource currResource = createResourceWithGroups(group1, group2, group3);
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, currResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(groupsOperation);
+ }
+
+ @Test
+ public void addAllPrevUserDefinedGroupsToComponent() {
+ GroupDefinition group1 = createCsarGroup("group1");
+ GroupDefinition group2 = createUserDefinedGroup("group2");
+ GroupDefinition group3 = createUserDefinedGroup("group3");
+ Resource prevResource = createResourceWithGroups(group1, group2, group3);
+ Resource currResource = createResourceWithGroups(group1, group2);
+ when(groupsOperation.addGroups(eq(currResource), groupsToAddCaptor.capture())).thenReturn(Either.left(null));
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, currResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ assertThat(groupsToAddCaptor.getValue())
+ .containsExactlyInAnyOrder(group3);
+ assertThat(currResource.getGroups())
+ .containsExactlyInAnyOrder(group1, group2, group3);
+ }
+
+ @Test
+ public void whenPrevUserDefinedGroupHasNoMembers_itShouldHaveNoMembersInNewComponent() {
+ GroupDefinition group1 = createUserDefinedGroup("group1");
+ Resource prevResource = createResourceWithGroups(group1);
+ Resource currResource = new Resource();
+ when(groupsOperation.addGroups(eq(currResource), groupsToAddCaptor.capture())).thenReturn(Either.left(null));
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, currResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ List<GroupDefinition> groupsAdded = groupsToAddCaptor.getValue();
+ assertThat(groupsAdded)
+ .extracting("members")
+ .containsNull();
+ }
+
+ @Test
+ public void whenPrevUserDefinedGroupHasInstanceMembersThatNotExistInNewComponent_removeMembersFromGroup() {
+ GroupDefinition group1 = createUserDefinedGroup("group1", "inst1Id", "inst2Id", "inst3Id");
+ GroupDefinition group2 = createUserDefinedGroup("group2", "inst1Id");
+
+ ComponentInstance inst1 = createInstance("inst1", "inst1Id");
+ ComponentInstance inst2 = createInstance("inst2", "inst2Id");
+ ComponentInstance inst3 = createInstance("inst3", "inst3Id");
+
+ Resource prevResource = createResourceWithGroupsAndInstances(asList(group1, group2), asList(inst1, inst2, inst3));
+ Resource currResource = createResourceWithInstances(inst3);
+
+ when(groupsOperation.addGroups(eq(currResource), groupsToAddCaptor.capture())).thenReturn(Either.left(null));
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, currResource);
+
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ List<GroupDefinition> groupsAdded = groupsToAddCaptor.getValue();
+ Map<String, String> group1ExpectedMembers = cmptInstancesToGroups(inst3);
+ Map<String, String> group2ExpectedMembers = emptyMap();
+ assertThat(groupsAdded)
+ .extracting("members")
+ .containsExactlyInAnyOrder(group1ExpectedMembers, group2ExpectedMembers);
+ }
+
+ @Test
+ public void groupsMembersShouldBeUpdatedAccordingToNewInstancesIds() {
+ String prevInstance1Id = "inst1Id";
+ String prevInstance2Id = "inst2Id";
+
+ String currInstance1Id = "newInst1Id";
+ String currInstance2Id = "newInst2Id";
+
+ GroupDefinition group1 = createUserDefinedGroup("group1", prevInstance1Id, prevInstance2Id);
+ ComponentInstance prevInst1 = createInstance("inst1", prevInstance1Id);
+ ComponentInstance prevInst2 = createInstance("inst2", prevInstance2Id);
+ Resource prevResource = createResourceWithGroupsAndInstances(singletonList(group1), asList(prevInst1, prevInst2));
+
+ ComponentInstance currInst1 = createInstance("inst1", currInstance1Id);
+ ComponentInstance currInst2 = createInstance("inst2", currInstance2Id);
+ Resource currResource = createResourceWithInstances(currInst1, currInst2);
+
+ when(groupsOperation.addGroups(eq(currResource), groupsToAddCaptor.capture())).thenReturn(Either.left(null));
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, currResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ List<GroupDefinition> groupsAdded = groupsToAddCaptor.getValue();
+ assertThat(groupsAdded)
+ .extracting("members")
+ .containsExactly(cmptInstancesToGroups(currInst1, currInst2));
+ }
+
+ private ComponentInstance createInstance(String name, String instId) {
+ return new ComponentInstanceBuilder()
+ .setName(name)
+ .setUniqueId(instId)
+ .build();
+ }
+
+ private GroupDefinition createCsarGroup(String id) {
+ return createGroup(id, CreatedFrom.CSAR);
+ }
+
+ private GroupDefinition createUserDefinedGroup(String id, String ... members) {
+ return createGroup(id, CreatedFrom.UI, members);
+ }
+
+ private GroupDefinition createGroup(String id, CreatedFrom createdFrom, String ... members) {
+ GroupDefinitionBuilder groupDefinitionBuilder = GroupDefinitionBuilder.create()
+ .setUniqueId(id)
+ .setCreatedFrom(createdFrom)
+ .setName("name" + id)
+ .setInvariantName("invName" + id);
+ Stream.of(members).forEach(groupDefinitionBuilder::addMember);
+ return groupDefinitionBuilder.build();
+ }
+
+ private Resource createResourceWithGroups(GroupDefinition ... groups) {
+ return createResourceWithGroupsAndInstances(asList(groups), null);
+ }
+
+ private Resource createResourceWithInstances(ComponentInstance ... instances) {
+ return createResourceWithGroupsAndInstances(null, asList(instances));
+ }
+
+ private Resource createResourceWithGroupsAndInstances(List<GroupDefinition> groups, List<ComponentInstance> instances) {
+ ResourceBuilder resourceBuilder = new ResourceBuilder();
+ if (groups != null) {
+ groups.forEach(resourceBuilder::addGroup);
+ }
+ if (instances != null) {
+ instances.forEach(resourceBuilder::addComponentInstance);
+ }
+ return resourceBuilder.build();
+ }
+
+ private Map<String, String> cmptInstancesToGroups(ComponentInstance ... instances) {
+ return Stream.of(instances).collect(toMap(ComponentInstance::getName, ComponentInstance::getUniqueId));
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/group/GroupPropertiesMergeCommandTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/group/GroupPropertiesMergeCommandTest.java
new file mode 100644
index 0000000000..b815251ea1
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/group/GroupPropertiesMergeCommandTest.java
@@ -0,0 +1,157 @@
+package org.openecomp.sdc.be.components.merge.group;
+
+
+import fj.data.Either;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.merge.property.DataDefinitionsValuesMergingBusinessLogic;
+import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.jsontitan.operations.GroupsOperation;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
+
+@RunWith(MockitoJUnitRunner.class)
+public class GroupPropertiesMergeCommandTest {
+
+ private GroupPropertiesMergeCommand testInstance;
+ @Mock
+ private DataDefinitionsValuesMergingBusinessLogic mergeBusinessLogic;
+ @Mock
+ private GroupsOperation groupsOperation;
+ @Captor
+ private ArgumentCaptor<List<GroupDefinition>> updatedGroupsCaptor;
+
+ private GroupDefinition newGroup1, newGroup2, newGroup3;
+ private GroupDefinition prevGroup1, prevGroup2, prevGroup3;
+ private Resource prevResource, newResource;
+
+
+ @Before
+ public void setUp() throws Exception {
+ testInstance = new GroupPropertiesMergeCommand(groupsOperation, new ComponentsUtils(mock(AuditingManager.class)), mergeBusinessLogic);
+ newGroup1 = createVspGroupWithProperties("group1Id", "group1New", "prop1", "prop2");
+ newGroup2 = createUserGroupWithProperties("group2Id", "group2New", "prop3", "prop4");
+ newGroup3 = createVspGroupWithProperties("group3Id", "group3New");
+ prevGroup1 = createVspGroupWithProperties("group1Id", "group1Old", "prop1", "prop2");
+ prevGroup2 = createUserGroupWithProperties("group2Id", "group2Old", "prop3", "prop4");
+ prevGroup3 = createVspGroupWithProperties("group3Id", "group3Old");
+
+ prevResource = new ResourceBuilder()
+ .addGroup(prevGroup1)
+ .addGroup(prevGroup2)
+ .addGroup(prevGroup3)
+ .addInput("input1")
+ .addInput("input2")
+ .build();
+
+ newResource = new ResourceBuilder()
+ .addGroup(newGroup1)
+ .addGroup(newGroup2)
+ .addGroup(newGroup3)
+ .addInput("input1")
+ .build();
+ }
+
+ @Test
+ public void whenNewComponentHasNoGroups_returnOk() {
+ ActionStatus mergeStatus = testInstance.mergeComponents(prevResource, new Resource());
+ assertThat(mergeStatus).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(mergeBusinessLogic, groupsOperation);
+ }
+
+ @Test
+ public void whenOldComponentHasNoGroups_returnOk() {
+ ActionStatus mergeStatus = testInstance.mergeComponents(new Resource(), newResource);
+ assertThat(mergeStatus).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(mergeBusinessLogic, groupsOperation);
+ }
+
+ @Test
+ public void whenOldOrNewGroupHasNoProperties_noNeedToMergeItsProperties() {
+ GroupDefinition oldGrpNoProps = createVspGroupWithProperties("grp1", "grp1");
+ GroupDefinition newGrpWithProps = createVspGroupWithProperties("grp1", "grp1", "prop1", "prop2");
+
+ GroupDefinition oldGrpWithProps = createVspGroupWithProperties("grp2", "grp2", "prop3");
+ GroupDefinition newGrpNoProps = createVspGroupWithProperties("grp2", "grp2");
+
+ Resource prevResource = createResourceWithGroups(oldGrpNoProps, oldGrpWithProps);
+ Resource newResource = createResourceWithGroups(newGrpWithProps, newGrpNoProps);
+ ActionStatus mergeStatus = testInstance.mergeComponents(prevResource, newResource);
+ assertThat(mergeStatus).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(mergeBusinessLogic, groupsOperation);
+ }
+
+ @Test
+ public void whenNewGroupIsUserDefined_itWasAlreadyMergedInEarlierCommand_noNeedToMerge() {
+ GroupDefinition oldUserDefinedGrp = createUserGroupWithProperties("grp1", "grp1", "prop1");
+ GroupDefinition newUserDefinedGrp = createVspGroupWithProperties("grp1", "grp1", "prop1");
+ Resource prevResource = createResourceWithGroups(oldUserDefinedGrp);
+ Resource newResource = createResourceWithGroups(newUserDefinedGrp);
+ ActionStatus mergeStatus = testInstance.mergeComponents(prevResource, newResource);
+ assertThat(mergeStatus).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(mergeBusinessLogic, groupsOperation);
+ }
+
+ @Test
+ public void whenNewGroupWasntExistInPrevVersion_noMergeRequired_matchByInvariantName() {
+ GroupDefinition oldGrp = createUserGroupWithProperties("grp1", "grp1", "prop1");
+ GroupDefinition newGrp = createVspGroupWithProperties("newGrp1", "grp1", "prop1");
+ Resource prevResource = createResourceWithGroups(oldGrp);
+ Resource newResource = createResourceWithGroups(newGrp);
+ ActionStatus mergeStatus = testInstance.mergeComponents(prevResource, newResource);
+ assertThat(mergeStatus).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(mergeBusinessLogic, groupsOperation);
+ }
+
+ @Test
+ public void mergeGroupProperties_updateGroupsAfterMerge_mergeOnlyGroups() {
+ when(groupsOperation.updateGroups(eq(newResource), updatedGroupsCaptor.capture(), eq(false))).thenReturn(Either.left(null));
+ ActionStatus mergeStatus = testInstance.mergeComponents(prevResource, newResource);
+ assertThat(mergeStatus).isEqualTo(ActionStatus.OK);
+ verify(mergeBusinessLogic).mergeInstanceDataDefinitions(prevGroup1.getProperties(), prevResource.getInputs(), newGroup1.getProperties(), newResource.getInputs());
+ assertThat(updatedGroupsCaptor.getValue())
+ .containsExactly(newGroup1);
+
+ }
+
+ private GroupDefinition createUserGroupWithProperties(String invariantName, String groupName, String ... propsNames) {
+ return createGroupWithProperties(invariantName, groupName, CreatedFrom.UI, propsNames);
+ }
+
+ private GroupDefinition createVspGroupWithProperties(String invariantName, String groupName, String ... propsNames) {
+ return createGroupWithProperties(invariantName, groupName, CreatedFrom.CSAR, propsNames);
+ }
+
+ private GroupDefinition createGroupWithProperties(String invariantName, String groupName, CreatedFrom createdFrom, String ... propsNames) {
+ GroupDefinitionBuilder groupDefinitionBuilder = GroupDefinitionBuilder.create()
+ .setUniqueId(invariantName)
+ .setName(groupName)
+ .setCreatedFrom(createdFrom)
+ .setInvariantName(invariantName);
+ Stream.of(propsNames).forEach(groupDefinitionBuilder::addProperty);
+ return groupDefinitionBuilder.build();
+ }
+
+ private Resource createResourceWithGroups(GroupDefinition ... groups) {
+ ResourceBuilder resourceBuilder = new ResourceBuilder();
+ Stream.of(groups).forEach(resourceBuilder::addGroup);
+ return resourceBuilder.build();
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/heat/HeatEnvArtifactsMergeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/heat/HeatEnvArtifactsMergeBusinessLogicTest.java
index bcdd08e95b..c75a6ccd5d 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/heat/HeatEnvArtifactsMergeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/heat/HeatEnvArtifactsMergeBusinessLogicTest.java
@@ -1,12 +1,5 @@
package org.openecomp.sdc.be.components.merge.heat;
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Stream;
-
import org.junit.Before;
import org.junit.Test;
import org.openecomp.sdc.be.components.utils.ArtifactBuilder;
@@ -15,6 +8,13 @@ import org.openecomp.sdc.be.datatypes.elements.HeatParameterDataDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertEquals;
+
public class HeatEnvArtifactsMergeBusinessLogicTest {
private HeatEnvArtifactsMergeBusinessLogic testInstance;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/BaseComponentInputsMerge.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/BaseComponentInputsMerge.java
new file mode 100644
index 0000000000..e1d4d39e52
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/BaseComponentInputsMerge.java
@@ -0,0 +1,61 @@
+package org.openecomp.sdc.be.components.merge.input;
+
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public abstract class BaseComponentInputsMerge {
+
+ @Mock
+ protected ToscaOperationFacade toscaOperationFacade;
+
+ @Mock
+ InputsValuesMergingBusinessLogic inputsValuesMergingBusinessLogic;
+
+ @Mock
+ DeclaredInputsResolver declaredInputsResolver;
+
+ @Captor
+ ArgumentCaptor<Map<String, List<PropertyDataDefinition>>> getInputPropertiesCaptor;
+
+ Resource prevResource, currResource;
+ protected static final String RESOURCE_ID = "newResourceId";
+
+ public void setUp() throws Exception {
+ prevResource = new ResourceBuilder()
+ .addInput("input1")
+ .addInput("input2")
+ .build();
+
+ currResource = new ResourceBuilder()
+ .addInstanceProperty("inst1", "prop1")
+ .addInstanceProperty("inst1", "prop2")
+ .addInstanceInput("inst2", "prop3")
+ .addGroupProperty("group1", "prop1")
+ .addPolicyProperty("policy1", "prop2")
+ .addInput("input1")
+ .setUniqueId(RESOURCE_ID)
+ .build();
+ }
+
+ void verifyCallToMergeComponentInputs(Resource oldResource, List<InputDefinition> inputsToMerge) {
+ Map<String, InputDefinition> oldInputsByName = oldResource.getInputs().stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
+ Map<String, InputDefinition> inputsToMergeByName = inputsToMerge.stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
+ verify(inputsValuesMergingBusinessLogic).mergeComponentInputs(oldInputsByName, inputsToMergeByName);
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBLTest.java
index 26b6782918..31e9ce710f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBLTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBLTest.java
@@ -1,94 +1,102 @@
package org.openecomp.sdc.be.components.merge.input;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
-import org.apache.commons.collections.ListUtils;
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
import org.openecomp.sdc.be.components.utils.ObjectGenerator;
import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-
-import fj.data.Either;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-public class ComponentInputsMergeBLTest {
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
- @InjectMocks
- private ComponentInputsMergeBL testInstance;
+import static java.util.Collections.emptyList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.components.utils.Conditions.hasPropertiesWithNames;
+import static org.openecomp.sdc.be.dao.utils.CollectionUtils.union;
- @Mock
- private InputsValuesMergingBusinessLogic inputsValuesMergingBusinessLogicMock;
+public class ComponentInputsMergeBLTest extends BaseComponentInputsMerge {
- @Mock
- private ToscaOperationFacade toscaOperationFacade;
+ private ComponentInputsMergeBL testInstance;
@Before
+ @Override
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
+ super.setUp();
+ testInstance = new ComponentInputsMergeBL(inputsValuesMergingBusinessLogic, declaredInputsResolver, toscaOperationFacade, new ComponentsUtils(mock(AuditingManager.class)));
}
@Test
- public void mergeComponentInputs() {
- Resource oldResource = new ResourceBuilder()
- .addInput("input1")
- .addInput("input2")
- .build();
-
- Resource newResource = new Resource();
-
- List<InputDefinition> inputsToMerge = ObjectGenerator.buildInputs("input1", "input2", "input3");
-
- when(toscaOperationFacade.updateInputsToComponent(inputsToMerge, newResource.getUniqueId())).thenReturn(Either.left(inputsToMerge));
- ActionStatus actionStatus = testInstance.mergeComponentInputs(oldResource, newResource, inputsToMerge);
- assertEquals(ActionStatus.OK, actionStatus);
- verifyCallToMergeComponentInputs(oldResource, inputsToMerge);
+ public void whenOldComponentHasNoInputs_returnOk() {
+ ActionStatus actionStatus = testInstance.mergeComponents(new Resource(), new Resource());
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(toscaOperationFacade, inputsValuesMergingBusinessLogic, declaredInputsResolver);
}
- @SuppressWarnings("unchecked")
@Test
- public void mergeAndRedeclareComponentInputs() throws Exception {
- Resource oldResource = new ResourceBuilder()
- .addInput("input1")
- .addInput("input2")
- .build();
+ public void whenCurrResourceHasNoProperties_noRedeclarationOFInputsRequired() {
+ Resource newResource = new ResourceBuilder().setUniqueId(RESOURCE_ID).build();
+ when(toscaOperationFacade.updateInputsToComponent(emptyList(), RESOURCE_ID)).thenReturn(Either.left(null));
+ doCallRealMethod().when(inputsValuesMergingBusinessLogic).mergeComponentInputs(Mockito.anyList(), Mockito.anyList());
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, newResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ verifyCallToMergeComponentInputs(prevResource, emptyList());
+ }
- Resource newResource = ObjectGenerator.buildBasicResource();
- List<InputDefinition> inputsToMerge = ObjectGenerator.buildInputs("input1", "input2", "input3");
- List<InputDefinition> inputsToRedeclare = ObjectGenerator.buildInputs("input4");
- List<InputDefinition> expectedInputsToUpdate = ListUtils.union(inputsToMerge, inputsToRedeclare);
- when(inputsValuesMergingBusinessLogicMock.getPreviouslyDeclaredInputsToMerge(oldResource, newResource)).thenReturn(inputsToRedeclare);
- when(toscaOperationFacade.updateInputsToComponent(expectedInputsToUpdate, newResource.getUniqueId())).thenReturn(Either.left(inputsToMerge));
- ActionStatus actionStatus = testInstance.mergeAndRedeclareComponentInputs(oldResource, newResource, inputsToMerge);
- assertEquals(ActionStatus.OK, actionStatus);
+ @Test
+ public void whenCurrResourceHasNoInputs_noMergeRequired_updateResourceWithInputsDeclaredInPrevVersion() {
+ List<InputDefinition> prevDeclaredInputs = ObjectGenerator.buildInputs("declared1", "declared2");
+ currResource.setInputs(null);
+ when(declaredInputsResolver.getPreviouslyDeclaredInputsToMerge(eq(prevResource), eq(currResource), getInputPropertiesCaptor.capture())).thenReturn(prevDeclaredInputs);
+ when(toscaOperationFacade.updateInputsToComponent(prevDeclaredInputs, RESOURCE_ID)).thenReturn(Either.left(null));
+ doCallRealMethod().when(inputsValuesMergingBusinessLogic).mergeComponentInputs(Mockito.anyList(), Mockito.anyList());
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, currResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ verifyCallToMergeComponentInputs(prevResource, emptyList());
+ verifyPropertiesPassedToDeclaredInputsResolver();
}
@Test
- public void redeclareResourceInputsForInstance() throws Exception {
- List<InputDefinition> oldInputs = ObjectGenerator.buildInputs("input1", "input2");
- Resource newResource = ObjectGenerator.buildBasicResource();
- List<InputDefinition> inputsToRedeclare = ObjectGenerator.buildInputs("input1");
- when(inputsValuesMergingBusinessLogicMock.getPreviouslyDeclaredInputsToMerge(oldInputs, newResource, "inst1")).thenReturn(inputsToRedeclare);
- when(toscaOperationFacade.updateInputsToComponent(inputsToRedeclare, newResource.getUniqueId())).thenReturn(Either.left(inputsToRedeclare));
- ActionStatus actionStatus = testInstance.redeclareComponentInputsForInstance(oldInputs, newResource, "inst1");
+ public void findInputsDeclaredFromPropertiesAndMergeThemIntoNewComponent() {
+ List<InputDefinition> prevDeclaredInputs = ObjectGenerator.buildInputs("declared1", "declared2");
+ List<InputDefinition> currInputsPreMerge = new ArrayList<>(currResource.getInputs());
+ when(declaredInputsResolver.getPreviouslyDeclaredInputsToMerge(eq(prevResource), eq(currResource), getInputPropertiesCaptor.capture())).thenReturn(prevDeclaredInputs);
+ List<InputDefinition> expectedInputsToUpdate = union(currInputsPreMerge, prevDeclaredInputs);
+ when(toscaOperationFacade.updateInputsToComponent(expectedInputsToUpdate, RESOURCE_ID)).thenReturn(Either.left(null));
+ doCallRealMethod().when(inputsValuesMergingBusinessLogic).mergeComponentInputs(Mockito.anyList(), Mockito.anyList());
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, currResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ verifyCallToMergeComponentInputs(prevResource, currInputsPreMerge);
+ verifyPropertiesPassedToDeclaredInputsResolver();
}
- private void verifyCallToMergeComponentInputs(Resource oldResource, List<InputDefinition> inputsToMerge) {
- Map<String, InputDefinition> oldInputsByName = oldResource.getInputs().stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
- Map<String, InputDefinition> inputsToMergeByName = inputsToMerge.stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
- verify(inputsValuesMergingBusinessLogicMock).mergeComponentInputs(oldInputsByName, inputsToMergeByName);
+ @Test
+ public void whenFailingToUpdateInputs_propagateTheError() {
+ Resource newResource = new ResourceBuilder().setUniqueId(RESOURCE_ID).build();
+ when(toscaOperationFacade.updateInputsToComponent(emptyList(), RESOURCE_ID)).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, newResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
}
+ private void verifyPropertiesPassedToDeclaredInputsResolver() {
+ Map<String, List<PropertyDataDefinition>> allResourceProps = getInputPropertiesCaptor.getValue();
+ assertThat(allResourceProps)
+ .hasEntrySatisfying("inst1", hasPropertiesWithNames("prop1", "prop2"))
+ .hasEntrySatisfying("inst2", hasPropertiesWithNames("prop3"))
+ .hasEntrySatisfying("group1", hasPropertiesWithNames("prop1"))
+ .hasEntrySatisfying("policy1", hasPropertiesWithNames("prop2"));
+ }
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/DeclaredInputsResolverTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/DeclaredInputsResolverTest.java
new file mode 100644
index 0000000000..5dedbb39d6
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/DeclaredInputsResolverTest.java
@@ -0,0 +1,101 @@
+package org.openecomp.sdc.be.components.merge.input;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.Resource;
+
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyMap;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class DeclaredInputsResolverTest {
+
+ private DeclaredInputsResolver testInstance;
+ private Resource prevResource, currResource;
+
+ @Before
+ public void setUp() throws Exception {
+ testInstance = new DeclaredInputsResolver();
+ prevResource = new ResourceBuilder()
+ .addInput("input1")
+ .addInput("input2")
+ .addInput("input3")
+ .addInput("input4")
+ .build();
+
+ currResource = new ResourceBuilder()
+ .addInput("input1")
+ .addInput("input3")
+ .build();
+ }
+
+ @Test
+ public void whenPropertiesMapIsEmpty_returnEmptyList() {
+ List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(prevResource, currResource, emptyMap());
+ assertThat(previouslyDeclaredInputsToMerge).isEmpty();
+ }
+
+ @Test
+ public void whenPrevResourceHasNoInputs_returnEmptyList() {
+ List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(new Resource(), currResource, emptyMap());
+ assertThat(previouslyDeclaredInputsToMerge).isEmpty();
+ }
+
+ @Test
+ public void whenAllPropertiesNotReferencingInput_returnEmptyList() {
+ PropertyDataDefinition prop1 = createProperty("prop1");
+ PropertyDataDefinition prop2 = createProperty("prop2");
+ Map<String, List<PropertyDataDefinition>> props = ImmutableMap.of("inst1", singletonList(prop1), "inst2", singletonList(prop2));
+ List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(prevResource, currResource, props);
+ assertThat(previouslyDeclaredInputsToMerge).isEmpty();
+ }
+
+ @Test
+ public void doNotReturnReferencedInputIfAlreadyExistInNewResource() {
+ PropertyDataDefinition prop1 = createPropertyReferencingInput("prop1", "input1");
+ PropertyDataDefinition prop2 = createPropertyReferencingInput("prop2", "input3");
+ Map<String, List<PropertyDataDefinition>> props = ImmutableMap.of("inst1", singletonList(prop1), "inst2", singletonList(prop2));
+ List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(prevResource, currResource, props);
+ assertThat(previouslyDeclaredInputsToMerge).isEmpty();
+ }
+
+ @Test
+ public void returnAllInputsReferencedByPropertyAndNotExistInNewResource() {
+ PropertyDataDefinition prop1 = createPropertyReferencingInput("prop1", "input1");
+ PropertyDataDefinition prop2 = createPropertyReferencingInput("prop2", "input2");
+ PropertyDataDefinition prop3 = createPropertyReferencingInput("prop3", "input3");
+ PropertyDataDefinition prop4 = createPropertyReferencingInput("prop4", "input4");
+ PropertyDataDefinition prop5 = createProperty("prop5");
+ Map<String, List<PropertyDataDefinition>> props = ImmutableMap.of("inst1", asList(prop1, prop3), "inst2", singletonList(prop2), "group1", asList(prop4, prop5));
+ List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(prevResource, currResource, props);
+ assertThat(previouslyDeclaredInputsToMerge)
+ .extracting("name")
+ .containsExactlyInAnyOrder("input2", "input4");
+ }
+
+ private PropertyDataDefinition createPropertyReferencingInput(String propName, String referencingInputName) {
+ return new PropertyDataDefinitionBuilder()
+ .setName(propName)
+ .addGetInputValue(referencingInputName)
+ .build();
+ }
+
+ private PropertyDataDefinition createProperty(String propName) {
+ return new PropertyDataDefinitionBuilder()
+ .setName(propName)
+ .build();
+ }
+
+
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/GlobalInputsMergeCommandTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/GlobalInputsMergeCommandTest.java
new file mode 100644
index 0000000000..e25df75f0d
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/GlobalInputsMergeCommandTest.java
@@ -0,0 +1,68 @@
+package org.openecomp.sdc.be.components.merge.input;
+
+import fj.data.Either;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
+import org.openecomp.sdc.be.components.merge.GlobalInputsFilteringBusinessLogic;
+import org.openecomp.sdc.be.components.utils.ObjectGenerator;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.InputDefinition;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.components.utils.Conditions.hasPropertiesWithNames;
+import static org.openecomp.sdc.be.dao.utils.CollectionUtils.union;
+
+public class GlobalInputsMergeCommandTest extends BaseComponentInputsMerge {
+
+ private GlobalInputsMergeCommand testInstance;
+ @Mock
+ private GlobalInputsFilteringBusinessLogic globalInputsFilteringBusinessLogic;
+ @Mock
+ private ExceptionUtils exceptionUtils;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ new ComponentInputsMergeBL(inputsValuesMergingBusinessLogic, declaredInputsResolver, toscaOperationFacade, new ComponentsUtils(mock(AuditingManager.class)));
+ testInstance = new GlobalInputsMergeCommand(inputsValuesMergingBusinessLogic, declaredInputsResolver, toscaOperationFacade, new ComponentsUtils(mock(AuditingManager.class)), globalInputsFilteringBusinessLogic, exceptionUtils);
+ }
+
+ @Test
+ public void mergeOnlyGlobalInputs_redeclareOnlyGroupAndPolicyProperties() {
+ List<InputDefinition> globalInputs = ObjectGenerator.buildInputs("input1");
+ List<InputDefinition> prevDeclaredInputs = ObjectGenerator.buildInputs("input2", "input3");
+ List<InputDefinition> expectedInputsToMerge = new ArrayList<>(globalInputs);
+ List<InputDefinition> expectedInputsToUpdate = union(globalInputs, prevDeclaredInputs);
+
+ when(globalInputsFilteringBusinessLogic.filterGlobalInputs(currResource)).thenReturn(Either.left(globalInputs));
+ when(declaredInputsResolver.getPreviouslyDeclaredInputsToMerge(eq(prevResource), eq(currResource), getInputPropertiesCaptor.capture())).thenReturn(prevDeclaredInputs);
+ when(toscaOperationFacade.updateInputsToComponent(expectedInputsToUpdate, RESOURCE_ID)).thenReturn(Either.left(null));
+ doCallRealMethod().when(inputsValuesMergingBusinessLogic).mergeComponentInputs(Mockito.anyList(), Mockito.anyList());
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, currResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ verifyCallToMergeComponentInputs(prevResource, expectedInputsToMerge);
+ verifyGroupsAndPolicyPropertiesPassedToDeclaredInputsResolver();
+ }
+
+ private void verifyGroupsAndPolicyPropertiesPassedToDeclaredInputsResolver() {
+ Map<String, List<PropertyDataDefinition>> allResourceProps = getInputPropertiesCaptor.getValue();
+ assertThat(allResourceProps)
+ .hasEntrySatisfying("group1", hasPropertiesWithNames("prop1"))
+ .hasEntrySatisfying("policy1", hasPropertiesWithNames("prop2"));
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogicTest.java
index d593e6ffd0..f918f41c79 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogicTest.java
@@ -10,22 +10,15 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
-import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
-import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.dao.utils.MapUtil;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.model.ComponentInstanceInput;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.Resource;
-
public class InputsValuesMergingBusinessLogicTest {
- public static final String INPUT_DEFUALT_TYPE = "string";
- public static final String INPUT1_ID = "input1";
- public static final String INPUT2_ID = "input2";
- public static final String INPUT3_ID = "input3";
- public static final String INPUT4_ID = "input4";
+ private static final String INPUT_DEFUALT_TYPE = "string";
+ private static final String INPUT1_ID = "input1";
+ private static final String INPUT2_ID = "input2";
+ private static final String INPUT3_ID = "input3";
+ private static final String INPUT4_ID = "input4";
private InputsValuesMergingBusinessLogic testInstance;
@Before
@@ -34,7 +27,7 @@ public class InputsValuesMergingBusinessLogicTest {
}
@Test
- public void testMergeInputs_inputsOfDifferentType_dontCopyOldValue() throws Exception {
+ public void testMergeInputs_inputsOfDifferentType_dontCopyOldValue() {
InputDefinition oldInput = createUserDefinedInputDefinition(INPUT1_ID, "oldVal1");
InputDefinition newInput = createInputDefinition(INPUT1_ID, null);
@@ -49,7 +42,7 @@ public class InputsValuesMergingBusinessLogicTest {
}
@Test
- public void testMergeInputs_newInputsHaveNoValue_copyOldValues() throws Exception {
+ public void testMergeInputs_newInputsHaveNoValue_copyOldValues() {
InputDefinition oldInputWithCsarDefaultValue = createInputDefinition(INPUT1_ID, "oldVal1");
InputDefinition oldInputWithUserDefinedValue = createUserDefinedInputDefinition(INPUT2_ID, "oldVal2");
InputDefinition oldInputNotExistOnNew = createUserDefinedInputDefinition(INPUT3_ID, null);
@@ -67,7 +60,7 @@ public class InputsValuesMergingBusinessLogicTest {
}
@Test
- public void testMergeInputs_newInputsHaveValue_dontOverrideNewValue() throws Exception {
+ public void testMergeInputs_newInputsHaveValue_dontOverrideNewValue() {
InputDefinition oldInputWithCsarDefaultValue = createInputDefinition(INPUT1_ID, "oldVal1");
InputDefinition oldInputWithUserDefinedValue = createUserDefinedInputDefinition(INPUT2_ID, "oldVal2");
InputDefinition oldInputWithNoValue = createUserDefinedInputDefinition(INPUT3_ID, null);
@@ -87,32 +80,6 @@ public class InputsValuesMergingBusinessLogicTest {
assertEquals(updatedInputs.get(INPUT4_ID).getDefaultValue(), newInput4.getDefaultValue());
}
- @Test
- public void getPrevoislyDeclaredInputsToMerge() throws Exception {
- PropertyDataDefinition declaredInputProp1 = new PropertyDataDefinitionBuilder().addGetInputValue(INPUT1_ID).addGetInputValue(INPUT3_ID).setUniqueId("prevDeclaredPropId").build();
- PropertyDataDefinition declaredInputProp2 = new PropertyDataDefinitionBuilder().addGetInputValue(INPUT4_ID).setUniqueId("prevDeclaredPropId2").build();
-
- Resource prevResource = new ResourceBuilder().addInput(INPUT1_ID).addInput(INPUT2_ID).addInput(INPUT3_ID).addInput(INPUT4_ID).build();
-
- Resource currentResource = new ResourceBuilder()
- .addInput(INPUT2_ID)
- .addInstanceProperty("inst1", new ComponentInstanceProperty(declaredInputProp1))
- .addInstanceInput("inst2", new ComponentInstanceInput(declaredInputProp2))
- .build();
-
- List<InputDefinition> previouslyDeclaredInputs = testInstance.getPreviouslyDeclaredInputsToMerge(prevResource, currentResource);
- assertEquals(3, previouslyDeclaredInputs.size());
-
- assertInput(previouslyDeclaredInputs.get(0), INPUT1_ID, declaredInputProp1.getUniqueId(), "inst1");
- assertInput(previouslyDeclaredInputs.get(1), INPUT3_ID, declaredInputProp1.getUniqueId(), "inst1");
- assertInput(previouslyDeclaredInputs.get(2), INPUT4_ID, declaredInputProp2.getUniqueId(), "inst2");
- }
-
- private void assertInput(InputDefinition inputDefinition, String expectedInputId, String expectedPropertyId, String expectedInstanceUniqueId) {
- assertEquals(expectedInputId, inputDefinition.getUniqueId());
- assertEquals(expectedPropertyId, inputDefinition.getPropertyId());
- assertEquals(inputDefinition.getInstanceUniqueId(), expectedInstanceUniqueId);
- }
private Map<String, InputDefinition> mapInputsByName(List<InputDefinition> inputs) {
return MapUtil.toMap(inputs, InputDefinition::getName);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMergeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMergeTest.java
index 3f3fc26558..d4d79b94ce 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMergeTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMergeTest.java
@@ -1,13 +1,6 @@
package org.openecomp.sdc.be.components.merge.instance;
-import static junit.framework.TestCase.assertEquals;
-import static org.mockito.Mockito.when;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -16,17 +9,18 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.exception.ResponseFormat;
-import fj.data.Either;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.mockito.Mockito.when;
public class ComponentInstanceArtifactsMergeTest {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesMergeBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesMergeBLTest.java
index adf19011db..af6b72ef5d 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesMergeBLTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesMergeBLTest.java
@@ -1,21 +1,7 @@
package org.openecomp.sdc.be.components.merge.instance;
-import static java.util.Collections.emptyMap;
-import static java.util.Collections.singletonList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyList;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
+import com.google.common.collect.ImmutableMap;
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,20 +20,24 @@ 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.CapabilityDefinition;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.ComponentParametersView;
-import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
-import com.google.common.collect.ImmutableMap;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
-import fj.data.Either;
+import static java.util.Collections.emptyMap;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class ComponentInstanceCapabilitiesMergeBLTest {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabiliteisPropertiesMergeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesPropertiesMergeTest.java
index 9b88ecb157..4c803a6148 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabiliteisPropertiesMergeTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesPropertiesMergeTest.java
@@ -1,11 +1,6 @@
package org.openecomp.sdc.be.components.merge.instance;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-import java.util.Collections;
-import java.util.List;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -14,21 +9,20 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-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.*;
import org.openecomp.sdc.exception.ResponseFormat;
-import fj.data.Either;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
-public class ComponentInstanceCapabiliteisPropertiesMergeTest {
+public class ComponentInstanceCapabilitiesPropertiesMergeTest {
@InjectMocks
- private ComponentInstanceCapabiliteisPropertiesMerge testInstance;
+ private ComponentInstanceCapabilitiesPropertiesMerge testInstance;
@Mock
private ComponentCapabilitiesPropertiesMergeBL capabilitiesPropertiesMergeBL;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMergeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMergeTest.java
index f5cd924957..89843420d3 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMergeTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMergeTest.java
@@ -1,13 +1,6 @@
package org.openecomp.sdc.be.components.merge.instance;
-import static org.mockito.Mockito.when;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -26,7 +19,14 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import fj.data.Either;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.when;
public class ComponentInstanceHeatEnvMergeTest {
@@ -71,7 +71,7 @@ public class ComponentInstanceHeatEnvMergeTest {
when(artifactsBusinessLogicMock.updateResourceInstanceArtifactNoContent(Mockito.eq(instanceId), Mockito.eq(resource),
Mockito.eq(USER), Mockito.eq(json),
Mockito.refEq(artifactUpdateOperation),
- Mockito.isNull(ArtifactDefinition.class)))
+ isNull()))
.thenReturn(Either.left(Either.left(new ArtifactDefinition())));
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInputsRedeclareHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInputsRedeclareHandlerTest.java
new file mode 100644
index 0000000000..2e5128c180
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInputsRedeclareHandlerTest.java
@@ -0,0 +1,132 @@
+package org.openecomp.sdc.be.components.merge.instance;
+
+import fj.data.Either;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.merge.input.DeclaredInputsResolver;
+import org.openecomp.sdc.be.components.merge.input.InputsValuesMergingBusinessLogic;
+import org.openecomp.sdc.be.components.utils.AnnotationBuilder;
+import org.openecomp.sdc.be.components.utils.InputsBuilder;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.Annotation;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.components.utils.Conditions.hasPropertiesWithNames;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ComponentInstanceInputsRedeclareHandlerTest {
+
+ private static final String RESOURCE_ID = "resourceID";
+ private ComponentInstanceInputsRedeclareHandler testInstance;
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private DeclaredInputsResolver declaredInputsResolver;
+ @Mock
+ private InputsValuesMergingBusinessLogic inputsValuesMergingBusinessLogic;
+ @Captor
+ private ArgumentCaptor<Map<String, List<PropertyDataDefinition>>> getInputPropertiesCaptor;
+ private Resource currContainer;
+ private List<InputDefinition> prevDeclaredInputs;
+ private Annotation annotation1, annotation2, annotation3;
+
+ @Before
+ public void setUp() throws Exception {
+ testInstance = new ComponentInstanceInputsRedeclareHandler(declaredInputsResolver, toscaOperationFacade, new ComponentsUtils(mock(AuditingManager.class)), inputsValuesMergingBusinessLogic);
+ currContainer = new ResourceBuilder()
+ .addInstanceProperty("inst1", "prop1")
+ .addInstanceProperty("inst1", "prop2")
+ .addInstanceInput("inst2", "prop3")
+ .setUniqueId(RESOURCE_ID)
+ .build();
+
+ annotation1 = AnnotationBuilder.create()
+ .setName("annotation1")
+ .build();
+
+ annotation2 = AnnotationBuilder.create()
+ .setName("annotation2")
+ .build();
+
+ annotation3 = AnnotationBuilder.create()
+ .setName("annotation3")
+ .build();
+
+ InputDefinition declaredInput1 = InputsBuilder.create()
+ .setPropertyId("prop1")
+ .setName("input1")
+ .addAnnotation(annotation1)
+ .addAnnotation(annotation2)
+ .build();
+
+ InputDefinition declaredInput2 = InputsBuilder.create()
+ .setPropertyId("prop2")
+ .setName("input2")
+ .addAnnotation(annotation3)
+ .build();
+
+ prevDeclaredInputs = asList(declaredInput1, declaredInput2);
+ }
+
+ @Test
+ public void redeclareOnlyPropertiesForGivenInstance() {
+ Resource originInstanceType = new Resource();
+ when(declaredInputsResolver.getPreviouslyDeclaredInputsToMerge(anyList(), eq(currContainer), getInputPropertiesCaptor.capture())).thenReturn(prevDeclaredInputs);
+ when(toscaOperationFacade.updateInputsToComponent(prevDeclaredInputs, RESOURCE_ID)).thenReturn(Either.left(null));
+ ActionStatus actionStatus = testInstance.redeclareComponentInputsForInstance(currContainer, "inst1", originInstanceType, Collections.emptyList());
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ verifyInstanceSpecificPropertiesPassedToDeclaredInputsResolver();
+ }
+
+ @Test
+ public void updateInputsWithAnnotationsFromOriginInstanceType() {
+ InputDefinition input1 = InputsBuilder.create()
+ .addAnnotation(annotation2)
+ .addAnnotation(annotation3)
+ .setName("prop1")
+ .build();
+
+ InputDefinition input2 = InputsBuilder.create()
+ .setName("prop2")
+ .build();
+ Resource originInstanceType = new ResourceBuilder()
+ .addInput(input1)
+ .addInput(input2)
+ .build();
+
+ when(declaredInputsResolver.getPreviouslyDeclaredInputsToMerge(anyList(), eq(currContainer), getInputPropertiesCaptor.capture())).thenReturn(prevDeclaredInputs);
+ when(toscaOperationFacade.updateInputsToComponent(prevDeclaredInputs, RESOURCE_ID)).thenReturn(Either.left(null));
+ ActionStatus actionStatus = testInstance.redeclareComponentInputsForInstance(currContainer, "inst1", originInstanceType, Collections.emptyList());
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ assertThat(prevDeclaredInputs)
+ .extracting("annotations")
+ .containsExactlyInAnyOrder(asList(annotation1, annotation3, annotation2), asList(annotation3));
+ }
+
+ private void verifyInstanceSpecificPropertiesPassedToDeclaredInputsResolver() {
+ Map<String, List<PropertyDataDefinition>> allResourceProps = getInputPropertiesCaptor.getValue();
+ assertThat(allResourceProps)
+ .hasEntrySatisfying("inst1", hasPropertiesWithNames("prop1", "prop2"));
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogicTest.java
index 79064bce50..345e93051e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogicTest.java
@@ -1,35 +1,23 @@
package org.openecomp.sdc.be.components.merge.instance;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.*;
import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentParametersView;
-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.*;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.exception.ResponseFormat;
-import fj.data.Either;
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.*;
public class ComponentInstanceMergeDataBusinessLogicTest {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMergeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMergeTest.java
index 0efbf5fc5b..c6e5bed950 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMergeTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMergeTest.java
@@ -1,42 +1,25 @@
package org.openecomp.sdc.be.components.merge.instance;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyList;
-import static org.mockito.ArgumentMatchers.anyListOf;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-import java.util.List;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.components.merge.input.ComponentInputsMergeBL;
+import org.mockito.*;
import org.openecomp.sdc.be.components.utils.ObjectGenerator;
import org.openecomp.sdc.be.components.utils.ResourceBuilder;
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.ComponentInstanceInput;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.ComponentParametersView;
-import org.openecomp.sdc.be.model.InputDefinition;
-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.*;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.exception.ResponseFormat;
-import fj.data.Either;
+import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class ComponentInstancePropsAndInputsMergeTest {
private static final String INSTANCE_ID1 = "inst1";
@@ -58,7 +41,7 @@ public class ComponentInstancePropsAndInputsMergeTest {
private ComponentInstanceInputsMergeBL componentInstanceInputsMergeBL;
@Mock
- private ComponentInputsMergeBL componentInputsMergeBL;
+ private ComponentInstanceInputsRedeclareHandler componentInstanceInputsRedeclareHandler;
private Resource resourceToUpdate;
@@ -95,13 +78,15 @@ public class ComponentInstancePropsAndInputsMergeTest {
dataForMergeHolder.setOrigComponentInputs(oldInputs);
dataForMergeHolder.setOrigComponentInstanceProperties(oldInstProps);
dataForMergeHolder.setOrigComponentInstanceInputs(oldInstInputs);
+ Resource currInstanceOriginType = new Resource();
+ dataForMergeHolder.setCurrInstanceNode(currInstanceOriginType);
ArgumentCaptor<ComponentParametersView> parametersViewCaptor = ArgumentCaptor.forClass(ComponentParametersView.class);
when(toscaOperationFacade.getToscaElement(Mockito.eq("resourceId"), parametersViewCaptor.capture())).thenReturn(Either.left(resourceToUpdate));
when(componentInstanceInputsMergeBL.mergeComponentInstanceInputs(oldInstInputs, oldInputs, resourceToUpdate, INSTANCE_ID1)).thenReturn(ActionStatus.OK);
when(componentInstancePropertiesMergeBL.mergeComponentInstanceProperties(oldInstProps, oldInputs, resourceToUpdate, INSTANCE_ID1)).thenReturn(ActionStatus.OK);
- when(componentInputsMergeBL.redeclareComponentInputsForInstance(oldInputs, resourceToUpdate, INSTANCE_ID1)).thenReturn(ActionStatus.OK);
+ when(componentInstanceInputsRedeclareHandler.redeclareComponentInputsForInstance(resourceToUpdate, INSTANCE_ID1, currInstanceOriginType, oldInputs)).thenReturn(ActionStatus.OK);
Either<Component, ResponseFormat> mergeResult = testInstance.mergeDataAfterCreate(USER, dataForMergeHolder, resourceToUpdate, INSTANCE_ID1);
assertEquals(mergeResult.left().value(), resourceToUpdate);
assertComponentFilter(parametersViewCaptor.getValue());
@@ -111,10 +96,10 @@ public class ComponentInstancePropsAndInputsMergeTest {
public void mergeDataAfterCreate_failedToMergeComponentInstanceInputs() throws Exception {
ResponseFormat errorResponse = new ResponseFormat();
when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(errorResponse);
- when(componentInstanceInputsMergeBL.mergeComponentInstanceInputs(anyListOf(ComponentInstanceInput.class), anyListOf(InputDefinition.class), any(Component.class), anyString())).thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentInstanceInputsMergeBL.mergeComponentInstanceInputs(anyList(), anyList(), any(Component.class), anyString())).thenReturn(ActionStatus.GENERAL_ERROR);
Either<Component, ResponseFormat> mergeResult = testInstance.mergeDataAfterCreate(USER, new DataForMergeHolder(), new Service(), "inst1");
assertEquals(errorResponse, mergeResult.right().value());
- verifyZeroInteractions(componentInputsMergeBL, componentInstancePropertiesMergeBL, toscaOperationFacade);
+ verifyZeroInteractions(componentInstanceInputsRedeclareHandler, componentInstancePropertiesMergeBL, toscaOperationFacade);
}
@Test
@@ -125,7 +110,7 @@ public class ComponentInstancePropsAndInputsMergeTest {
when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(errorResponse);
Either<Component, ResponseFormat> mergeResult = testInstance.mergeDataAfterCreate(USER, new DataForMergeHolder(), new Service(), "inst1");
assertEquals(errorResponse, mergeResult.right().value());
- verifyZeroInteractions(componentInputsMergeBL, toscaOperationFacade);
+ verifyZeroInteractions(componentInstanceInputsRedeclareHandler, toscaOperationFacade);
}
@Test
@@ -140,7 +125,7 @@ public class ComponentInstancePropsAndInputsMergeTest {
dataHolder.setOrigComponentInputs(ObjectGenerator.buildInputs("input1", "input2"));
Either<Component, ResponseFormat> mergeResult = testInstance.mergeDataAfterCreate(USER, dataHolder, new Service(), "inst1");
assertEquals(errorResponse, mergeResult.right().value());
- verifyZeroInteractions(componentInputsMergeBL);
+ verifyZeroInteractions(componentInstanceInputsRedeclareHandler);
}
private void assertComponentFilter(ComponentParametersView value) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMergeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMergeTest.java
index b341052d9e..1b6aa00c69 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMergeTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMergeTest.java
@@ -1,18 +1,6 @@
package org.openecomp.sdc.be.components.merge.instance;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.IntStream;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -21,24 +9,27 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
+import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.RelationshipImpl;
-import org.openecomp.sdc.be.model.RelationshipInfo;
-import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
-import org.openecomp.sdc.be.model.RequirementDefinition;
-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.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.exception.ResponseFormat;
-import fj.data.Either;
+import java.util.*;
+import java.util.stream.IntStream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ComponentInstanceRelationMergeTest {
@@ -53,26 +44,29 @@ public class ComponentInstanceRelationMergeTest {
private RequirementCapabilityRelDef requirementDef2;
private RequirementCapabilityRelDef capabilityDef1;
private RequirementCapabilityRelDef capabilityDef2;
-
+ private RequirementCapabilityRelDef capabilityDef3;
+
+ @Mock
+ private ComponentsUtils componentsUtils;
+
@Mock
private ToscaOperationFacade toscaOperationFacade;
@Mock
private User user;
+ @Mock
+ private ExceptionUtils exceptionUtils;
+
@Captor
- ArgumentCaptor<VfRelationsMergeInfo> argumentCaptor;
-
-
+ private ArgumentCaptor<ContainerRelationsMergeInfo> argumentCaptor;
+
+
@Before
public void startUp() {
- compInstanceRelationMerge = new ComponentInstanceRelationMerge();
- compInstanceRelationMerge.setToscaOperationFacade(toscaOperationFacade);
-
- MergeInstanceUtils mergeInstanceUtils = new MergeInstanceUtils();
- mergeInstanceUtils.setToscaOperationFacade(toscaOperationFacade);
- compInstanceRelationMerge.setMergeInstanceUtils(mergeInstanceUtils);
-
+ MergeInstanceUtils mergeInstanceUtils = new MergeInstanceUtils(toscaOperationFacade, exceptionUtils);
+ compInstanceRelationMerge = new ComponentInstanceRelationMerge(componentsUtils, mergeInstanceUtils, toscaOperationFacade);
+
containerComponent = new Service();
List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
@@ -80,26 +74,56 @@ public class ComponentInstanceRelationMergeTest {
resourceInstancesRelations.add(requirementDef1);
requirementDef2 = createRequirementDef("SRV1.VF1.VFI_1", "SRV1.VF3.VFI_1", "SRV1.VF1.VFC_2.VFCI_2", "Requirement2");
resourceInstancesRelations.add(requirementDef2);
-
-
+
+
capabilityDef1 = createCapabilityDef("SRV1.VF4.VFI_1", "SRV1.VF1.VFI_1", "SRV1.VF1.VFC_3.VFCI_3", "Capability3");
resourceInstancesRelations.add(capabilityDef1);
capabilityDef2 = createCapabilityDef("SRV1.VF5.VFI_1", "SRV1.VF1.VFI_1", "SRV1.VF1.VFC_4.VFCI_1", "Capability4");
resourceInstancesRelations.add(capabilityDef2);
- containerComponent.setComponentInstancesRelations(resourceInstancesRelations );
+ capabilityDef3 = createCapabilityDef("SRV1.VF5.VFI_1", "SRV1.VF1.VFI_1", "grp1Id", "Capability5");
+ resourceInstancesRelations.add(capabilityDef3);
+
+ containerComponent.setComponentInstancesRelations(resourceInstancesRelations );
+
currentResourceInstance = new ComponentInstance();
currentResourceInstance.setUniqueId("SRV1.VF1.VFI_1");
currentResourceInstance.setComponentUid("SRV1.VF1");
currentResourceInstance.setIsProxy(false);
-
+
updatedContainerComponent = new Service();
updatedContainerComponent.setUniqueId("123123123123123123");
}
-
+
@Test
public void testSaveDataBeforeMerge() {
+ Resource vf = new ResourceBuilder()
+ .setResourceType(ResourceTypeEnum.VF)
+ .setComponentType(ComponentTypeEnum.RESOURCE)
+ .addComponentInstance(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true))
+ .addComponentInstance(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true))
+ .addComponentInstance(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false))
+ .addComponentInstance(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true))
+ .addGroup(createGroup("grp1", "grp1Id"))
+ .build();
+
+ compInstanceRelationMerge.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, vf);
+
+ verify(dataHolder).setVfRelationsInfo(argumentCaptor.capture());
+ ContainerRelationsMergeInfo relationsMergeInfo = argumentCaptor.getValue();
+ List<RelationMergeInfo> fromRelationsMergeInfo = relationsMergeInfo.getFromRelationsInfo();
+ List<RelationMergeInfo> toRelationsMergeInfo = relationsMergeInfo.getToRelationsInfo();
+
+ assertNotNull("Expected not null list of relations merge info", fromRelationsMergeInfo);
+ assertNotNull("Expected not null list of relations merge info", toRelationsMergeInfo);
+
+ assertEquals("Expected 2 elements", 2, fromRelationsMergeInfo.size());
+ assertEquals("Expected 2 elements", 2, toRelationsMergeInfo.size());
+ }
+
+ @Test
+ public void testSaveDataBeforeMerge_RelationsNull() {
Resource vf = new Resource();
List<ComponentInstance> vfcInstances = new ArrayList<>();
@@ -110,32 +134,91 @@ public class ComponentInstanceRelationMergeTest {
vf.setComponentInstances(vfcInstances);
vf.setComponentType(ComponentTypeEnum.RESOURCE);
vf.setResourceType(ResourceTypeEnum.VF);
-
+
+ containerComponent.setComponentInstancesRelations(null);
compInstanceRelationMerge.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, vf);
-
- verify(dataHolder).setVfRelationsInfo(argumentCaptor.capture());
- VfRelationsMergeInfo relationsMergeInfo = argumentCaptor.getValue();
- List<RelationMergeInfo> fromRelationsMergeInfo = relationsMergeInfo.getFromRelationsInfo();
- List<RelationMergeInfo> toRelationsMergeInfo = relationsMergeInfo.getToRelationsInfo();
-
- assertNotNull("Expected not null list of relations merge info", fromRelationsMergeInfo);
- assertNotNull("Expected not null list of relations merge info", toRelationsMergeInfo);
-
- assertEquals("Expected 2 elements", 2, fromRelationsMergeInfo.size());
- assertEquals("Expected 1 elements", 1, toRelationsMergeInfo.size());
+
+ verify(dataHolder, Mockito.never()).setVfRelationsInfo(Mockito.any());
}
+
+ @Test
+ public void testSaveDataBeforeMerge_RelationsEmptyList() {
+ Resource vf = new Resource();
+ List<ComponentInstance> vfcInstances = new ArrayList<>();
+ vfcInstances.add(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true));
+ vfcInstances.add(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true));
+ vfcInstances.add(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false));
+ vfcInstances.add(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true));
+ vf.setComponentInstances(vfcInstances);
+ vf.setComponentType(ComponentTypeEnum.RESOURCE);
+ vf.setResourceType(ResourceTypeEnum.VF);
+
+ containerComponent.setComponentInstancesRelations(Collections.emptyList());
+ compInstanceRelationMerge.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, vf);
+
+ verify(dataHolder, Mockito.never()).setVfRelationsInfo(Mockito.any());
+ }
+
@Test
public void testMergeDataAfterCreate_NoSavedData() {
+ when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(null);
compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
-
- verify(dataHolder).getVfRelationsMergeInfo();
List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
assertNull("Expected no relations", relations);
}
@Test
public void testMergeDataAfterCreate() {
+ Resource newInstanceOriginVf = new ResourceBuilder()
+ .setResourceType(ResourceTypeEnum.VF)
+ .setComponentType(ComponentTypeEnum.RESOURCE)
+ .addComponentInstance(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true))
+ .addComponentInstance(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true))
+ .addComponentInstance(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false))
+ .addComponentInstance(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true))
+ .addGroup(createGroup("grp1", "grp1Id"))
+ .build();
+
+
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ componentInstances.add(createVfi("SRV1.VF1", "SRV1.VF1.VFI_2"));
+ updatedContainerComponent.setComponentInstances(componentInstances);
+
+ List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
+ updatedContainerComponent.setComponentInstancesRelations(resourceInstancesRelations);
+
+ List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
+ List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
+
+ RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
+ fromRelationsMergeInfo.add(relationMergeInfo1);
+ RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
+ toRelationsMergeInfo.add(relationMergeInfo2);
+
+ RelationMergeInfo relationMergeInfo3 = new RelationMergeInfo("CapabilityType5", "capabilityE", "grp1", capabilityDef3);
+ toRelationsMergeInfo.add(relationMergeInfo3);
+
+ ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
+
+ when(toscaOperationFacade.getToscaElement("SRV1.VF1")).thenReturn(Either.left(newInstanceOriginVf));
+ when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
+ when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.OK);
+ Either<Component, ResponseFormat> mergeResult = compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
+ assertTrue(mergeResult.isLeft());
+ List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
+ assertThat(relations)
+ .containsExactlyInAnyOrder(requirementDef1, capabilityDef2, capabilityDef3)
+ .extracting(relation -> relation.resolveSingleRelationship().getRelation().getCapabilityOwnerId(),
+ relation -> relation.resolveSingleRelationship().getRelation().getRequirementOwnerId())
+ .containsExactlyInAnyOrder(tuple("SRV1.VF1.VFC_4.VFCI_1", null),
+ tuple("grp1Id", null),
+ tuple(null, "SRV1.VF1.VFC_1.VFCI_1"));
+ }
+
+
+ @Test
+ public void testMergeDataAfterCreate_FailedToAssociateResourceInstances() {
Resource vf = new Resource();
List<ComponentInstance> vfcInstances = new ArrayList<>();
@@ -146,23 +229,23 @@ public class ComponentInstanceRelationMergeTest {
vf.setComponentInstances(vfcInstances);
vf.setComponentType(ComponentTypeEnum.RESOURCE);
vf.setResourceType(ResourceTypeEnum.VF);
-
+
Either<Component, StorageOperationStatus> eitherVF = Either.left(vf);
when(toscaOperationFacade.getToscaElement("SRV1.VF1")).thenReturn(eitherVF);
-
-
+
+
List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
-
+
RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
fromRelationsMergeInfo.add(relationMergeInfo1);
RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
toRelationsMergeInfo.add(relationMergeInfo2);
-
- VfRelationsMergeInfo relationsMergeInfo = new VfRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
-
- when(dataHolder.getVfRelationsMergeInfo()).thenReturn(relationsMergeInfo);
-
+
+ ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
+
+ when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
+
List<ComponentInstance> componentInstances = new ArrayList<>();
componentInstances.add(createVfi("SRV1.VF1", "SRV1.VF1.VFI_2"));
componentInstances.add(createVfi("SRV1.VF2", "SRV1.VF2.VFI_1"));
@@ -170,34 +253,40 @@ public class ComponentInstanceRelationMergeTest {
componentInstances.add(createVfi("SRV1.VF4", "SRV1.VF4.VFI_1"));
componentInstances.add(createVfi("SRV1.VF5", "SRV1.VF5.VFI_1"));
updatedContainerComponent.setComponentInstances(componentInstances);
-
+
List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
updatedContainerComponent.setComponentInstancesRelations(resourceInstancesRelations);
-
- when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.OK);
-
- compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
-
- verify(dataHolder).getVfRelationsMergeInfo();
- verify(toscaOperationFacade).associateResourceInstances(Mockito.anyString(), Mockito.anyList());
-
- List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
- assertEquals("Expected 2 relations", 2, relations.size());
-
-
- RequirementCapabilityRelDef capabilityRelDef = relations.get(0);
- assertEquals("SRV1.VF1.VFC_4.VFCI_1", capabilityRelDef.resolveSingleRelationship().getRelation().getCapabilityOwnerId());
- assertEquals("SRV1.VF5.VFI_1", capabilityRelDef.getFromNode());
- assertEquals("SRV1.VF1.VFI_2", capabilityRelDef.getToNode());
-
- RequirementCapabilityRelDef requirementRelDef = relations.get(1);
- assertEquals("SRV1.VF1.VFC_1.VFCI_1", requirementRelDef.resolveSingleRelationship().getRelation().getRequirementOwnerId());
- assertEquals("SRV1.VF1.VFI_2", requirementRelDef.getFromNode());
- assertEquals("SRV1.VF2.VFI_1", requirementRelDef.getToNode());
+
+ when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.GENERAL_ERROR);
+ when(componentsUtils.convertFromStorageResponse(Mockito.any())).thenReturn(ActionStatus.GENERAL_ERROR);
+
+ ResponseFormat expectedRresponseFormat = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, updatedContainerComponent.getUniqueId())).thenReturn(expectedRresponseFormat );
+
+ Either<Component, ResponseFormat> result = compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
+ assertTrue(result.isRight());
+ assertEquals(expectedRresponseFormat, result.right().value());
}
-
-
-
+
+ @Test
+ public void testMergeDataAfterCreate_UpdatedContainerEmpty() {
+ List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
+ List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
+
+ RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
+ fromRelationsMergeInfo.add(relationMergeInfo1);
+ RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
+ toRelationsMergeInfo.add(relationMergeInfo2);
+
+ ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
+
+ when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
+
+ Either<Component, ResponseFormat> result = compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
+ assertTrue(result.isLeft());
+ assertEquals(updatedContainerComponent, result.left().value());
+ }
+
@Test
public void testMergeDataAfterCreate_OwnerChanged() {
Resource vf = new Resource();
@@ -210,23 +299,23 @@ public class ComponentInstanceRelationMergeTest {
vf.setComponentInstances(vfcInstances);
vf.setComponentType(ComponentTypeEnum.RESOURCE);
vf.setResourceType(ResourceTypeEnum.VF);
-
+
Either<Component, StorageOperationStatus> eitherVF = Either.left(vf);
when(toscaOperationFacade.getToscaElement("SRV1.VF1")).thenReturn(eitherVF);
-
-
+
+
List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
-
+
RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
fromRelationsMergeInfo.add(relationMergeInfo1);
RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
toRelationsMergeInfo.add(relationMergeInfo2);
-
- VfRelationsMergeInfo relationsMergeInfo = new VfRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
-
- when(dataHolder.getVfRelationsMergeInfo()).thenReturn(relationsMergeInfo);
-
+
+ ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
+
+ when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
+
List<ComponentInstance> componentInstances = new ArrayList<>();
componentInstances.add(createVfi("SRV1.VF1", "SRV1.VF1.VFI_2"));
componentInstances.add(createVfi("SRV1.VF2", "SRV1.VF2.VFI_1"));
@@ -234,26 +323,26 @@ public class ComponentInstanceRelationMergeTest {
componentInstances.add(createVfi("SRV1.VF4", "SRV1.VF4.VFI_1"));
componentInstances.add(createVfi("SRV1.VF5", "SRV1.VF5.VFI_1"));
updatedContainerComponent.setComponentInstances(componentInstances);
-
+
List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
updatedContainerComponent.setComponentInstancesRelations(resourceInstancesRelations);
-
+
when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.OK);
-
+
compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
-
- verify(dataHolder).getVfRelationsMergeInfo();
+
+ verify(dataHolder).getContainerRelationsMergeInfo();
verify(toscaOperationFacade).associateResourceInstances(Mockito.anyString(), Mockito.anyList());
-
+
List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
assertEquals("Expected 2 relations", 2, relations.size());
-
-
+
+
RequirementCapabilityRelDef capabilityRelDef = relations.get(0);
assertEquals("SRV1.VF1.VFC_4.VFCI_2", capabilityRelDef.resolveSingleRelationship().getRelation().getCapabilityOwnerId());
assertEquals("SRV1.VF5.VFI_1", capabilityRelDef.getFromNode());
assertEquals("SRV1.VF1.VFI_2", capabilityRelDef.getToNode());
-
+
RequirementCapabilityRelDef requirementRelDef = relations.get(1);
assertEquals("SRV1.VF1.VFC_1.VFCI_2", requirementRelDef.resolveSingleRelationship().getRelation().getRequirementOwnerId());
assertEquals("SRV1.VF1.VFI_2", requirementRelDef.getFromNode());
@@ -270,18 +359,18 @@ public class ComponentInstanceRelationMergeTest {
ComponentInstance vfi = new ComponentInstance();
vfi.setUniqueId(vfiUniqueId);
vfi.setComponentUid(vfId);
-
+
Resource vf = new Resource();
vf.setUniqueId(vfId);
return vfi;
}
-
+
private ComponentInstance createVfci(String name, String uniqueId, String componentUid, boolean foundVfc) {
ComponentInstance compInst = new ComponentInstance();
compInst.setName(name);
compInst.setUniqueId(uniqueId);
compInst.setComponentUid(componentUid);
-
+
if(foundVfc) {
createVfc(componentUid);
}
@@ -291,6 +380,14 @@ public class ComponentInstanceRelationMergeTest {
return compInst;
}
+ public GroupDefinition createGroup(String name, String id) {
+ return GroupDefinitionBuilder.create()
+ .setUniqueId(id)
+ .setInvariantName(name)
+ .build();
+
+ }
+
private void failLoadVfc(String uid) {
Either<Component, StorageOperationStatus> eitherVFC = Either.right(StorageOperationStatus.NOT_FOUND);
when(toscaOperationFacade.getToscaElement(uid)).thenReturn(eitherVFC);
@@ -298,12 +395,13 @@ public class ComponentInstanceRelationMergeTest {
private Component createVfc(String uid) {
Resource vfc = new Resource();
+ vfc.setComponentType(ComponentTypeEnum.RESOURCE);
vfc.setUniqueId(uid);
-
+
Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
Map<String, List<RequirementDefinition>> requirements = new HashMap<>();;
IntStream.range(0, 5).forEach(i -> {
-
+
List<CapabilityDefinition> capList = new LinkedList<>();
capList.add(null);
CapabilityDefinition capDef = new CapabilityDefinition();
@@ -312,7 +410,7 @@ public class ComponentInstanceRelationMergeTest {
capDef.setType("CapabilityType" + i);
capList.add(capDef);
capabilities.put("Key" + i, capList);
-
+
List<RequirementDefinition> reqList = new LinkedList<>();
reqList.add(null);
RequirementDefinition reqDef = new RequirementDefinition();
@@ -321,59 +419,59 @@ public class ComponentInstanceRelationMergeTest {
reqDef.setCapability("CapabilityType" + i);
reqList.add(reqDef);
requirements.put("Key" + i, reqList);
-
+
});
vfc.setCapabilities(capabilities );
vfc.setRequirements(requirements);
-
+
Either<Component, StorageOperationStatus> eitherVFC = Either.left(vfc);
when(toscaOperationFacade.getToscaElement(uid)).thenReturn(eitherVFC);
-
+
return vfc;
}
-
+
private RequirementCapabilityRelDef createRequirementCapabilityDef(String fromNode, String toNode) {
RequirementCapabilityRelDef reqCapDef = new RequirementCapabilityRelDef();
-
+
reqCapDef.setFromNode(fromNode);
reqCapDef.setToNode(toNode);
-
+
List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
CapabilityRequirementRelationship capabilityRequirementRelationship = new CapabilityRequirementRelationship();
relationships.add(capabilityRequirementRelationship);
reqCapDef.setRelationships(relationships);
-
+
return reqCapDef;
}
private RequirementCapabilityRelDef createRequirementDef(String fromNode, String toNode, String ownerId, String requirementUid) {
RequirementCapabilityRelDef reqCapDef = createRequirementCapabilityDef(fromNode, toNode);
CapabilityRequirementRelationship capabilityRequirementRelationship = reqCapDef.resolveSingleRelationship();
-
+
RelationshipInfo relationshipInfo = new RelationshipInfo();
relationshipInfo.setRequirementOwnerId(ownerId);
relationshipInfo.setRequirementUid(requirementUid);
relationshipInfo.setRelationships(new RelationshipImpl());
capabilityRequirementRelationship.setRelation(relationshipInfo );
-
-
-
+
+
+
return reqCapDef;
}
-
+
private RequirementCapabilityRelDef createCapabilityDef(String fromNode, String toNode, String ownerId, String capabilityUid) {
RequirementCapabilityRelDef reqCapDef = createRequirementCapabilityDef(fromNode, toNode);
CapabilityRequirementRelationship capabilityRequirementRelationship = reqCapDef.resolveSingleRelationship();
-
+
RelationshipInfo relationshipInfo = new RelationshipInfo();
relationshipInfo.setCapabilityOwnerId(ownerId);
relationshipInfo.setCapabilityUid(capabilityUid);
relationshipInfo.setRelationships(new RelationshipImpl());
capabilityRequirementRelationship.setRelation(relationshipInfo );
-
+
return reqCapDef;
}
-
+
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ContainerRelationsMergeInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ContainerRelationsMergeInfoTest.java
new file mode 100644
index 0000000000..ba207c83de
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ContainerRelationsMergeInfoTest.java
@@ -0,0 +1,34 @@
+package org.openecomp.sdc.be.components.merge.instance;
+
+import org.junit.Test;
+
+import java.util.List;
+
+public class ContainerRelationsMergeInfoTest {
+
+ private ContainerRelationsMergeInfo createTestSubject() {
+ return new ContainerRelationsMergeInfo(null, null);
+ }
+
+ @Test
+ public void testGetFromRelationsInfo() throws Exception {
+ ContainerRelationsMergeInfo testSubject;
+ List<RelationMergeInfo> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getFromRelationsInfo();
+ }
+
+
+ @Test
+ public void testGetToRelationsInfo() throws Exception {
+ ContainerRelationsMergeInfo testSubject;
+ List<RelationMergeInfo> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getToRelationsInfo();
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolderTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolderTest.java
index 8c265a6be3..1b09e629b2 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolderTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolderTest.java
@@ -1,17 +1,12 @@
package org.openecomp.sdc.be.components.merge.instance;
+import org.junit.Test;
+import org.openecomp.sdc.be.model.*;
+
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import org.junit.Test;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstanceInput;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.InputDefinition;
-
public class DataForMergeHolderTest {
private DataForMergeHolder createTestSubject() {
@@ -144,7 +139,7 @@ public class DataForMergeHolderTest {
@Test
public void testSetVfRelationsInfo() throws Exception {
DataForMergeHolder testSubject;
- VfRelationsMergeInfo vfRelationsMergeInfo = null;
+ ContainerRelationsMergeInfo vfRelationsMergeInfo = null;
// default test
testSubject = createTestSubject();
@@ -154,11 +149,11 @@ public class DataForMergeHolderTest {
@Test
public void testGetVfRelationsMergeInfo() throws Exception {
DataForMergeHolder testSubject;
- VfRelationsMergeInfo result;
+ ContainerRelationsMergeInfo result;
// default test
testSubject = createTestSubject();
- result = testSubject.getVfRelationsMergeInfo();
+ result = testSubject.getContainerRelationsMergeInfo();
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBLTest.java
new file mode 100644
index 0000000000..65f88358a5
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBLTest.java
@@ -0,0 +1,97 @@
+package org.openecomp.sdc.be.components.merge.instance;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsontitan.operations.ExternalReferencesOperation;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ExternalRefsMergeBLTest {
+
+ private static final String NEW_INSTANCE_ID = "NEW_INSTANCE_ID";
+ @Resource
+ private ExternalRefsMergeBL externalRefsMergeBL;
+ @Mock
+ private ExternalReferencesOperation externalReferencesOperation;
+
+ private final Map<String, List<String>> externalRefs = new HashMap<>();
+
+ @Before
+ public void setUp() throws Exception {
+ externalRefsMergeBL = new ExternalRefsMergeBL(externalReferencesOperation);
+ externalRefs.put("a", Arrays.asList("1", "2"));
+ }
+
+ @Test
+ public void testExternalArtifactsSaveData_noArtifactsExist() {
+ Component containerComponent = new org.openecomp.sdc.be.model.Resource();
+ ComponentInstance componentInstance = new ComponentInstance();
+ when(externalReferencesOperation.getAllExternalReferences(any(), any()))
+ .thenReturn(new HashMap<>());
+
+ DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
+ externalRefsMergeBL.saveDataBeforeMerge(dataForMergeHolder, containerComponent, componentInstance, containerComponent);
+ Map<String, List<String>> originalComponentDeploymentArtifactsCreatedOnTheInstance = dataForMergeHolder.getOrigCompInstExternalRefs();
+
+ assertThat(originalComponentDeploymentArtifactsCreatedOnTheInstance.size()).isZero();
+ }
+
+ @Test
+ public void testExternalArtifactsSaveData_artifactsExist() {
+ Component containerComponent = new org.openecomp.sdc.be.model.Resource();
+ ComponentInstance componentInstance = new ComponentInstance();
+ when(externalReferencesOperation.getAllExternalReferences(any(), any()))
+ .thenReturn(externalRefs);
+
+ DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
+ externalRefsMergeBL.saveDataBeforeMerge(dataForMergeHolder, containerComponent, componentInstance, containerComponent);
+ Map<String, List<String>> origCompInstExternalRefs = dataForMergeHolder.getOrigCompInstExternalRefs();
+
+ assertThat(origCompInstExternalRefs.size()).isEqualTo(1);
+ assertThat(origCompInstExternalRefs.containsKey("a")).isTrue();
+ }
+
+ @Test
+ public void testExternalArtifactsRestoreData_noArtifacts() {
+ Component containerComponent = new org.openecomp.sdc.be.model.Resource();
+ ComponentInstance ci = new ComponentInstance();
+ ci.setUniqueId(NEW_INSTANCE_ID);
+ containerComponent.setComponentInstances(Collections.singletonList(ci));
+ DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
+ externalRefsMergeBL.mergeDataAfterCreate(new User(), dataForMergeHolder, containerComponent, NEW_INSTANCE_ID);
+ verifyZeroInteractions(externalReferencesOperation);
+ }
+
+ @Test
+ public void testExternalArtifactsRestoreData_hasArtifacts() {
+ Component containerComponent = new org.openecomp.sdc.be.model.Resource();
+ ComponentInstance ci = new ComponentInstance();
+ ci.setUniqueId(NEW_INSTANCE_ID);
+ containerComponent.setComponentInstances(Collections.singletonList(ci));
+ DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
+ dataForMergeHolder.setOrigComponentInstanceExternalRefs(externalRefs);
+ externalRefsMergeBL.mergeDataAfterCreate(new User(), dataForMergeHolder, containerComponent, NEW_INSTANCE_ID);
+ verify(externalReferencesOperation, times(1)).addAllExternalReferences(any(), eq(NEW_INSTANCE_ID), eq(externalRefs));
+ }
+
+ @Test(expected=ComponentException.class)
+ public void testExternalArtifactsRestoreData_noCI() {
+ Component containerComponent = new org.openecomp.sdc.be.model.Resource();
+ DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
+ externalRefsMergeBL.mergeDataAfterCreate(new User(), dataForMergeHolder, containerComponent, NEW_INSTANCE_ID);
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/RelationMergeInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/RelationMergeInfoTest.java
index 7173af3d4c..27aec7191a 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/RelationMergeInfoTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/RelationMergeInfoTest.java
@@ -19,35 +19,6 @@ public class RelationMergeInfoTest {
result = testSubject.getCapReqType();
}
- @Test
- public void testSetCapReqType() throws Exception {
- RelationMergeInfo testSubject;
- String type = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCapReqType(type);
- }
-
- @Test
- public void testGetVfcInstanceName() throws Exception {
- RelationMergeInfo testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getVfcInstanceName();
- }
-
- @Test
- public void testSetVfcInstanceName() throws Exception {
- RelationMergeInfo testSubject;
- String vfcInstanceName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setVfcInstanceName(vfcInstanceName);
- }
@Test
public void testGetRelDef() throws Exception {
@@ -59,15 +30,7 @@ public class RelationMergeInfoTest {
result = testSubject.getRelDef();
}
- @Test
- public void testSetRelDef() throws Exception {
- RelationMergeInfo testSubject;
- RequirementCapabilityRelDef relDef = null;
- // default test
- testSubject = createTestSubject();
- testSubject.setRelDef(relDef);
- }
@Test
public void testGetCapReqName() throws Exception {
@@ -79,13 +42,4 @@ public class RelationMergeInfoTest {
result = testSubject.getCapReqName();
}
- @Test
- public void testSetCapReqName() throws Exception {
- RelationMergeInfo testSubject;
- String capReqName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCapReqName(capReqName);
- }
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/VfRelationsMergeInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/VfRelationsMergeInfoTest.java
deleted file mode 100644
index 40a5ea5ee3..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/VfRelationsMergeInfoTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.openecomp.sdc.be.components.merge.instance;
-
-import java.util.List;
-
-import org.junit.Test;
-
-public class VfRelationsMergeInfoTest {
-
- private VfRelationsMergeInfo createTestSubject() {
- return new VfRelationsMergeInfo(null, null);
- }
-
- @Test
- public void testGetFromRelationsInfo() throws Exception {
- VfRelationsMergeInfo testSubject;
- List<RelationMergeInfo> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getFromRelationsInfo();
- }
-
- @Test
- public void testSetFromRelationsInfo() throws Exception {
- VfRelationsMergeInfo testSubject;
- List<RelationMergeInfo> fromRelationsInfo = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setFromRelationsInfo(fromRelationsInfo);
- }
-
- @Test
- public void testGetToRelationsInfo() throws Exception {
- VfRelationsMergeInfo testSubject;
- List<RelationMergeInfo> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getToRelationsInfo();
- }
-
- @Test
- public void testSetToRelationsInfo() throws Exception {
- VfRelationsMergeInfo testSubject;
- List<RelationMergeInfo> toRelationsInfo = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setToRelationsInfo(toRelationsInfo);
- }
-} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/path/ComponentInstanceForwardingPathMergeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/path/ComponentInstanceForwardingPathMergeTest.java
index 972ea4e620..04b62dd941 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/path/ComponentInstanceForwardingPathMergeTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/path/ComponentInstanceForwardingPathMergeTest.java
@@ -1,15 +1,6 @@
package org.openecomp.sdc.be.components.merge.path;
-import static groovy.util.GroovyTestCase.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.Mockito.when;
-
-import java.util.Set;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -26,7 +17,14 @@ import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.common.api.UserRoleEnum;
import org.openecomp.sdc.exception.ResponseFormat;
-import fj.data.Either;
+import java.util.Set;
+
+import static groovy.util.GroovyTestCase.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.TestCase.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.when;
public class ComponentInstanceForwardingPathMergeTest extends BaseForwardingPathVersionChangeTest {
@@ -52,7 +50,7 @@ public class ComponentInstanceForwardingPathMergeTest extends BaseForwardingPath
public void testIgnoreMergeSinceItIsNotService() {
testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
- assertEquals(nodeACI.getUniqueId(), dataHolder.getOrigComponentInstId());
+ assertEquals(nodeACI.getName(), dataHolder.getOrigComponentInstId());
Either<Component, ResponseFormat> componentResponseFormatEither = testInstance
.mergeDataAfterCreate(user, dataHolder, newNodeAC, "3344");
assertNotNull(componentResponseFormatEither);
@@ -66,8 +64,9 @@ public class ComponentInstanceForwardingPathMergeTest extends BaseForwardingPath
.findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeACI.getUniqueId());
nodeACI.getCapabilities().clear();
newNodeAC.getCapabilities().clear();
+ Either<Set<String>, ResponseFormat> returnValue = Either.left(forwardingPathNamesToDeleteOnComponentInstanceDeletion);
when(serviceBusinessLogic.deleteForwardingPaths(any(), any(), any(), anyBoolean()))
- .thenReturn(Either.left(forwardingPathNamesToDeleteOnComponentInstanceDeletion));
+ .thenReturn(returnValue);
when(toscaOperationFacade.getToscaFullElement(any())).thenReturn(Either.left(newNodeAC));
// Change internal ci, just like change version do
@@ -75,7 +74,7 @@ public class ComponentInstanceForwardingPathMergeTest extends BaseForwardingPath
service.getComponentInstances().add(newNodeACI);
testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
- assertEquals(nodeACI.getUniqueId(), dataHolder.getOrigComponentInstId());
+ assertEquals(nodeACI.getName(), dataHolder.getOrigComponentInstId());
Either<Component, ResponseFormat> componentResponseFormatEither = testInstance
.mergeDataAfterCreate(user, dataHolder, service, newNodeA);
assertNotNull(componentResponseFormatEither);
@@ -85,19 +84,25 @@ public class ComponentInstanceForwardingPathMergeTest extends BaseForwardingPath
@Test
public void mergeShouldUpdate() {
- when(serviceBusinessLogic.updateForwardingPath(any(), any(), any(), anyBoolean()))
- .thenReturn(Either.left(service));
- when(toscaOperationFacade.getToscaFullElement(any())).thenReturn(Either.left(newNodeAC));
- testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
- assertEquals(nodeACI.getUniqueId(), dataHolder.getOrigComponentInstId());
-
- // Change internal ci, just like change version do
- service.getComponentInstances().remove(nodeACI);
- service.getComponentInstances().add(newNodeACI);
+ when(serviceBusinessLogic.updateForwardingPath(any(), any(), any(), anyBoolean()))
+ .then(invocationOnMock -> Either.left(service));
+ when(toscaOperationFacade.getToscaFullElement(any())).thenReturn(Either.left(newNodeAC));
+ testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
+ assertEquals(nodeACI.getName(), dataHolder.getOrigComponentInstId());
+
+ // Change internal ci, just like change version do
+ service.getComponentInstances().remove(nodeACI);
+ service.getComponentInstances().add(newNodeACI);
+
+ Either<Component, ResponseFormat> componentResponseFormatEither = testInstance
+ .mergeDataAfterCreate(user, dataHolder, service, newNodeA);
+ assertNotNull(componentResponseFormatEither);
+ assertTrue(componentResponseFormatEither.isLeft());
+ }
- Either<Component, ResponseFormat> componentResponseFormatEither = testInstance
- .mergeDataAfterCreate(user, dataHolder, service, newNodeA);
- assertNotNull(componentResponseFormatEither);
- assertTrue(componentResponseFormatEither.isLeft());
+ @Test
+ public void handleNullCapailities() {
+ nodeACI.setCapabilities(null);
+ testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
}
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/policy/PoliciesMergeCommandTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/policy/PoliciesMergeCommandTest.java
new file mode 100644
index 0000000000..5d5ccb0551
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/policy/PoliciesMergeCommandTest.java
@@ -0,0 +1,225 @@
+package org.openecomp.sdc.be.components.merge.policy;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
+import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
+import org.openecomp.sdc.be.components.utils.PolicyDefinitionBuilder;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PoliciesMergeCommandTest {
+
+ private static final String CONTAINER_ID = "containerId";
+ private static final String GROUP1 = "group1";
+ private static final String GROUP1_ORIG_ID = GROUP1 + "Id";
+ private static final String GROUP1_UPDATED_ID = GROUP1 +"NewId";
+ private static final String GROUP2_ORIG_ID = "group2Id";
+ private static final String INSTANCE1 = "instance1";
+ private static final String INSTANCE1_ORIG_ID = INSTANCE1 + "Id";
+ private static final String INSTANCE1_UPDATED_ID = INSTANCE1+ "NewId";
+ private static final String INSTANCE2_ORIG_ID = "instance2Id";
+ private static final Resource DONT_CARE = new Resource();
+ @InjectMocks
+ private PoliciesMergeCommand testInstance;
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private ComponentsUtils componentsUtils;
+ @Captor
+ private ArgumentCaptor<List<PolicyDefinition>> policiesToMerge;
+
+ private PolicyDefinition noTargetsPolicy;
+ private ComponentInstance instance1;
+ private GroupDefinition group1;
+ private Resource prevResource, newResource;
+ private PolicyDefinition policy1;
+
+ @Before
+ public void setUp() throws Exception {
+ instance1 = new ComponentInstanceBuilder()
+ .setName(INSTANCE1)
+ .setId(INSTANCE1_UPDATED_ID)
+ .build();
+ group1 = GroupDefinitionBuilder.create()
+ .setName(GROUP1 + "newName")
+ .setInvariantName(GROUP1)
+ .setUniqueId(GROUP1_UPDATED_ID)
+ .build();
+ newResource = new ResourceBuilder()
+ .addGroup(group1)
+ .addComponentInstance(instance1)
+ .setUniqueId(CONTAINER_ID)
+ .build();
+
+ ComponentInstance prevInstance1 = new ComponentInstanceBuilder()
+ .setName(INSTANCE1)
+ .setId(INSTANCE1_ORIG_ID)
+ .build();
+
+ ComponentInstance prevInstance2 = new ComponentInstanceBuilder()
+ .setName(INSTANCE2_ORIG_ID)
+ .setId(INSTANCE2_ORIG_ID)
+ .build();
+
+ GroupDefinition prevGroup1 = GroupDefinitionBuilder.create()
+ .setName(GROUP1)
+ .setInvariantName(GROUP1)
+ .setUniqueId(GROUP1_ORIG_ID)
+ .build();
+
+ GroupDefinition prevGroup2 = GroupDefinitionBuilder.create()
+ .setName(GROUP2_ORIG_ID)
+ .setInvariantName(GROUP2_ORIG_ID)
+ .setUniqueId(GROUP2_ORIG_ID)
+ .build();
+
+ policy1 = PolicyDefinitionBuilder.create()
+ .addComponentInstanceTarget(prevInstance1.getUniqueId())
+ .addComponentInstanceTarget(prevInstance2.getUniqueId())
+ .addGroupTarget(prevGroup1.getUniqueId())
+ .addGroupTarget(prevGroup2.getUniqueId())
+ .setName("policy1")
+ .setUniqueId("policy1")
+ .build();
+
+ noTargetsPolicy = PolicyDefinitionBuilder.create()
+ .setUniqueId("policy2")
+ .setName("policy2")
+ .build();
+
+
+ prevResource = new ResourceBuilder()
+ .addGroup(prevGroup1)
+ .addGroup(prevGroup2)
+ .addComponentInstance(prevInstance1)
+ .addComponentInstance(prevInstance2)
+ .build();
+ }
+
+ @Test
+ public void whenPreviousComponentHasNoPolicies_returnOk() {
+ ActionStatus mergeResult = testInstance.mergeComponents(new Resource(), DONT_CARE);
+ assertThat(mergeResult).isEqualTo(ActionStatus.OK);
+ verifyZeroInteractions(toscaOperationFacade, componentsUtils);
+ }
+
+ @Test
+ public void associatePrevPoliciesToNewComponent() {
+ prevResource = new ResourceBuilder()
+ .addPolicy(policy1)
+ .addPolicy(noTargetsPolicy)
+ .build();
+ when(toscaOperationFacade.associatePoliciesToComponent(eq(CONTAINER_ID), policiesToMerge.capture())).thenReturn(StorageOperationStatus.OK);
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.OK)).thenReturn(ActionStatus.OK);
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, newResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ List<PolicyDefinition> mergedPolicies = policiesToMerge.getValue();
+ assertThat(mergedPolicies)
+ .containsExactlyInAnyOrder(policy1, noTargetsPolicy);
+ }
+
+ @Test
+ public void whenFailingToAssociatePolicies_propagateTheError() {
+ prevResource = new ResourceBuilder()
+ .addPolicy(policy1)
+ .build();
+ when(toscaOperationFacade.associatePoliciesToComponent(eq(CONTAINER_ID), anyList())).thenReturn(StorageOperationStatus.GENERAL_ERROR);
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR)).thenReturn(ActionStatus.GENERAL_ERROR);
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, newResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
+ }
+
+ @Test
+ public void whenPreviousPolicyTargetsDoesNotExistInNewVersion_ignoreTargets() {
+ Map<PolicyTargetType, List<String>> expectedTargetsMap = createTargetsMap(singletonList(instance1.getUniqueId()), singletonList(group1.getUniqueId()));
+ mergePolicies_verifyPoliciesTargets(policy1, expectedTargetsMap);
+ }
+
+ @Test
+ public void whenPrevPolicyGroupTargetNotExistInNewVersion_returnEmptyListInTargetMap() {
+ PolicyDefinition policy = PolicyDefinitionBuilder.create()
+ .setName("policy")
+ .setUniqueId("policy")
+ .addGroupTarget(GROUP2_ORIG_ID)
+ .addComponentInstanceTarget(INSTANCE1_ORIG_ID)
+ .build();
+ Map<PolicyTargetType, List<String>> expectedTargetsMap = createTargetsMap(singletonList(INSTANCE1_UPDATED_ID), emptyList());
+ mergePolicies_verifyPoliciesTargets(policy, expectedTargetsMap);
+ }
+
+ @Test
+ public void whenPrevCapabilityInstanceTargetNotExistInNewVersion_returnEmptyListInTargetMap() {
+ PolicyDefinition policy = PolicyDefinitionBuilder.create()
+ .setName("policy")
+ .setUniqueId("policy")
+ .addGroupTarget(GROUP1_ORIG_ID)
+ .addComponentInstanceTarget(INSTANCE2_ORIG_ID)
+ .build();
+ Map<PolicyTargetType, List<String>> expectedTargetsMap = createTargetsMap(emptyList(), singletonList(GROUP1_UPDATED_ID));
+ mergePolicies_verifyPoliciesTargets(policy, expectedTargetsMap);
+ }
+
+ @Test
+ public void whenPrevCapabilityInstanceAndGroupTargetsNotExistInNewVersion_returnTargetMapWithEmptyListsOfIds() {
+ PolicyDefinition policy = PolicyDefinitionBuilder.create()
+ .setName("policy")
+ .setUniqueId("policy")
+ .addGroupTarget(GROUP2_ORIG_ID)
+ .addComponentInstanceTarget(INSTANCE2_ORIG_ID)
+ .build();
+ Map<PolicyTargetType, List<String>> expectedTargetsMap = createTargetsMap(emptyList(), emptyList());
+ mergePolicies_verifyPoliciesTargets(policy, expectedTargetsMap);
+ }
+
+ @Test
+ public void whenPrevCapabilityHasNoTargets_returnNullTargetsMap() {
+ mergePolicies_verifyPoliciesTargets(noTargetsPolicy, null);
+ }
+
+ private void mergePolicies_verifyPoliciesTargets(PolicyDefinition prevPolicy, Map<PolicyTargetType, List<String>> expectedTargetsMap) {
+ prevResource.setPolicies(new HashMap<>());
+ prevResource.getPolicies().put(prevPolicy.getUniqueId(), prevPolicy);
+ when(toscaOperationFacade.associatePoliciesToComponent(eq(CONTAINER_ID), policiesToMerge.capture())).thenReturn(StorageOperationStatus.OK);
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.OK)).thenReturn(ActionStatus.OK);
+ ActionStatus actionStatus = testInstance.mergeComponents(prevResource, newResource);
+ assertThat(actionStatus).isEqualTo(ActionStatus.OK);
+ List<PolicyDefinition> mergedPolicies = policiesToMerge.getValue();
+ assertThat(mergedPolicies)
+ .extracting("targets")
+ .containsExactlyInAnyOrder(expectedTargetsMap);
+ }
+
+ private Map<PolicyTargetType, List<String>> createTargetsMap(List<String> cmptInstanceTargets, List<String> groupTargets) {
+ return ImmutableMap.of(PolicyTargetType.COMPONENT_INSTANCES, cmptInstanceTargets, PolicyTargetType.GROUPS, groupTargets);
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComplexPropertyValueMergerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComplexPropertyValueMergerTest.java
deleted file mode 100644
index 4e4a77fadd..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComplexPropertyValueMergerTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.openecomp.sdc.be.components.merge.property;
-
-import java.util.List;
-
-import org.junit.Test;
-
-import mockit.Deencapsulation;
-
-public class ComplexPropertyValueMergerTest {
-
- private ComplexPropertyValueMerger createTestSubject() {
- return new ComplexPropertyValueMerger();
- }
-
- @Test
- public void testGetInstance() throws Exception {
- PropertyValueMerger result;
-
- // default test
- result = ComplexPropertyValueMerger.getInstance();
- }
-
- @Test
- public void testMerge() throws Exception {
- ComplexPropertyValueMerger testSubject;
- Object oldVal = null;
- Object newVal = null;
- List<String> someStrings = null;
- Object result;
-
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "merge", new Object[] { Object.class, Object.class, List.class });
- }
-} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java
index bb1ea68cbd..32edf3e631 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java
@@ -1,13 +1,6 @@
package org.openecomp.sdc.be.components.merge.property;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-import java.util.Collections;
-import java.util.List;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -24,7 +17,11 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import fj.data.Either;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
public class ComponentInstanceInputsMergeBLTest {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstancePropertiesMergeBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstancePropertiesMergeBLTest.java
index e5ca990b7e..98cd89c9a9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstancePropertiesMergeBLTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstancePropertiesMergeBLTest.java
@@ -1,13 +1,6 @@
package org.openecomp.sdc.be.components.merge.property;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-import java.util.Collections;
-import java.util.List;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -22,12 +15,20 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import fj.data.Either;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
public class ComponentInstancePropertiesMergeBLTest {
private static final String INSTANCE1 = "instance1";
private static final String INSTANCE2 = "instance2";
+ private static final String OLD_INSTANCE1 = "old.instance1";
+ private static final String OLD_INSTANCE2 = "old.instance2";
+ private static final String NEW_INSTANCE1 = "new.instance1";
+ private static final String NEW_INSTANCE2 = "new.instance2";
@InjectMocks
private ComponentInstancePropertiesMergeBL testInstance;
@@ -48,16 +49,20 @@ public class ComponentInstancePropertiesMergeBLTest {
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
oldResource = new ResourceBuilder()
- .addInstanceProperty(INSTANCE1, "property1")
- .addInstanceProperty(INSTANCE1, "property2")
- .addInstanceProperty(INSTANCE2, "property3")
+ .addComponentInstance(INSTANCE1, OLD_INSTANCE1)
+ .addComponentInstance(INSTANCE2, OLD_INSTANCE2)
+ .addInstanceProperty(OLD_INSTANCE1, "property1")
+ .addInstanceProperty(OLD_INSTANCE1, "property2")
+ .addInstanceProperty(OLD_INSTANCE2, "property3")
.addInput("input1")
.addInput("input2").build();
newResource = new ResourceBuilder()
- .addInstanceProperty(INSTANCE1, "property11")
- .addInstanceProperty(INSTANCE1, "property12")
- .addInstanceProperty(INSTANCE2, "property13")
+ .addComponentInstance(INSTANCE1, NEW_INSTANCE1)
+ .addComponentInstance(INSTANCE2, NEW_INSTANCE2)
+ .addInstanceProperty(NEW_INSTANCE1, "property11")
+ .addInstanceProperty(NEW_INSTANCE1, "property12")
+ .addInstanceProperty(NEW_INSTANCE2, "property13")
.addInput("input11")
.addInput("input12").build();
}
@@ -67,7 +72,7 @@ public class ComponentInstancePropertiesMergeBLTest {
when(toscaOperationFacade.updateComponentInstancePropsToComponent(newResource.getComponentInstancesProperties(), newResource.getUniqueId()))
.thenReturn(Either.left(Collections.emptyMap()));
ActionStatus actionStatus = testInstance.mergeComponents(oldResource, newResource);
- assertEquals(actionStatus, ActionStatus.OK);
+ assertEquals(ActionStatus.OK, actionStatus);
verifyMergeBLCalled(oldResource, newResource);
}
@@ -83,32 +88,32 @@ public class ComponentInstancePropertiesMergeBLTest {
@Test
public void mergeInstanceProps() throws Exception {
- List<ComponentInstanceProperty> newInstanceProps = newResource.safeGetComponentInstanceProperties(INSTANCE1);
- List<ComponentInstanceProperty> oldInstProps = oldResource.safeGetComponentInstanceProperties(INSTANCE1);
- when(toscaOperationFacade.updateComponentInstanceProperties(newResource, INSTANCE1, newInstanceProps))
+ List<ComponentInstanceProperty> newInstanceProps = newResource.safeGetComponentInstanceProperties(NEW_INSTANCE1);
+ List<ComponentInstanceProperty> oldInstProps = oldResource.safeGetComponentInstanceProperties(OLD_INSTANCE1);
+ when(toscaOperationFacade.updateComponentInstanceProperties(newResource, NEW_INSTANCE1, newInstanceProps))
.thenReturn(StorageOperationStatus.OK);
- ActionStatus actionStatus = testInstance.mergeComponentInstanceProperties(oldInstProps, oldResource.getInputs(), newResource, INSTANCE1);
- assertEquals(actionStatus, ActionStatus.OK);
+ ActionStatus actionStatus = testInstance.mergeComponentInstanceProperties(oldInstProps, oldResource.getInputs(), newResource, NEW_INSTANCE1);
+ assertEquals(ActionStatus.OK, actionStatus);
verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(oldInstProps, oldResource.getInputs(), newInstanceProps, newResource.getInputs());
}
@Test
public void mergeInstanceProps_failure() throws Exception {
- List<ComponentInstanceProperty> newInstanceProps = newResource.safeGetComponentInstanceProperties(INSTANCE1);
- List<ComponentInstanceProperty> oldInstProps = oldResource.safeGetComponentInstanceProperties(INSTANCE1);
- when(toscaOperationFacade.updateComponentInstanceProperties(newResource, INSTANCE1, newInstanceProps))
+ List<ComponentInstanceProperty> newInstanceProps = newResource.safeGetComponentInstanceProperties(NEW_INSTANCE1);
+ List<ComponentInstanceProperty> oldInstProps = oldResource.safeGetComponentInstanceProperties(OLD_INSTANCE1);
+ when(toscaOperationFacade.updateComponentInstanceProperties(newResource, NEW_INSTANCE1, newInstanceProps))
.thenReturn(StorageOperationStatus.GENERAL_ERROR);
when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR)).thenReturn(ActionStatus.GENERAL_ERROR);
- ActionStatus actionStatus = testInstance.mergeComponentInstanceProperties(oldInstProps, oldResource.getInputs(), newResource, INSTANCE1);
- assertEquals(actionStatus, ActionStatus.GENERAL_ERROR);
+ ActionStatus actionStatus = testInstance.mergeComponentInstanceProperties(oldInstProps, oldResource.getInputs(), newResource, NEW_INSTANCE1);
+ assertEquals(ActionStatus.GENERAL_ERROR, actionStatus);
verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(oldInstProps, oldResource.getInputs(), newInstanceProps, newResource.getInputs());
}
private void verifyMergeBLCalled(Resource oldResource, Resource newResource) {
- List<ComponentInstanceProperty> instance1oldProps = oldResource.getComponentInstancesProperties().get(INSTANCE1);
- List<ComponentInstanceProperty> instance1newProps = newResource.getComponentInstancesProperties().get(INSTANCE1);
- List<ComponentInstanceProperty> instance2oldProps = oldResource.getComponentInstancesProperties().get(INSTANCE2);
- List<ComponentInstanceProperty> instance2newProps = newResource.getComponentInstancesProperties().get(INSTANCE2);
+ List<ComponentInstanceProperty> instance1oldProps = oldResource.getComponentInstancesProperties().get(OLD_INSTANCE1);
+ List<ComponentInstanceProperty> instance1newProps = newResource.getComponentInstancesProperties().get(NEW_INSTANCE1);
+ List<ComponentInstanceProperty> instance2oldProps = oldResource.getComponentInstancesProperties().get(OLD_INSTANCE2);
+ List<ComponentInstanceProperty> instance2newProps = newResource.getComponentInstancesProperties().get(NEW_INSTANCE2);
verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(instance1oldProps, oldResource.getInputs(), instance1newProps, newResource.getInputs());
verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(instance2oldProps, oldResource.getInputs(), instance2newProps, newResource.getInputs());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/DataDefinitionsValuesMergingBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/DataDefinitionsValuesMergingBusinessLogicTest.java
index e310cad300..3b079d30d5 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/DataDefinitionsValuesMergingBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/DataDefinitionsValuesMergingBusinessLogicTest.java
@@ -1,11 +1,5 @@
package org.openecomp.sdc.be.components.merge.property;
-import static org.mockito.Mockito.verify;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -17,6 +11,12 @@ import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.mockito.Mockito.verify;
+
public class DataDefinitionsValuesMergingBusinessLogicTest {
private static final String DEFAULT_PROP_TYPE = "string";
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/MergePropertyDataTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/MergePropertyDataTest.java
index cbc040010e..ded46d9d4c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/MergePropertyDataTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/MergePropertyDataTest.java
@@ -1,11 +1,11 @@
package org.openecomp.sdc.be.components.merge.property;
-import java.util.LinkedList;
-import java.util.List;
-
import org.junit.Test;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import java.util.LinkedList;
+import java.util.List;
+
public class MergePropertyDataTest {
private MergePropertyData createTestSubject() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogicTest.java
index 6faee487f4..79012ae74b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogicTest.java
@@ -1,35 +1,39 @@
package org.openecomp.sdc.be.components.merge.property;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Maps;
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.InjectMocks;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
-import fj.data.Either;
+import java.io.IOException;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.class)
public class PropertyDataValueMergeBusinessLogicTest {
- @InjectMocks
+ private ObjectMapper mapper = new ObjectMapper();
+
private PropertyDataValueMergeBusinessLogic testInstance;
@Mock
@@ -37,7 +41,9 @@ public class PropertyDataValueMergeBusinessLogicTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
+ PropertyValueMerger propertyValueMerger = new PropertyValueMerger();
+
+ testInstance = new PropertyDataValueMergeBusinessLogic(propertyValueMerger, applicationDataTypeCache);
}
@Test
@@ -71,14 +77,14 @@ public class PropertyDataValueMergeBusinessLogicTest {
@Test
public void mergeSimpleIntType_copyOldValueIfNoNewValue() throws Exception {
PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.INTEGER.getType(), null, "44");
- PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, null);
+ PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.INTEGER.getType(), null, null);
testMergeProps(oldProp, newProp, "44");
}
@Test
public void mergeSimpleIntType_dontCopyOldValIfHasNewVal() throws Exception {
PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.INTEGER.getType(), null, "44");
- PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, "45");
+ PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.INTEGER.getType(), null, "45");
testMergeProps(oldProp, newProp, "45");
}
@@ -98,27 +104,136 @@ public class PropertyDataValueMergeBusinessLogicTest {
@Test
public void mergeSimpleListType_copyOldValuesByIndex() throws Exception {
+ PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "string", "[\"a\", \"b\"]");
+ PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "string", "[\"x\", \"\"]");
+ testMergeProps(oldProp, newProp, "[\"x\",\"b\"]");
+ }
+
+ @Test
+ public void mergeSimpleListType_differentSize() throws Exception {
PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "string", "[\"a\", \"b\", \"c\"]");
PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "string", "[\"x\", \"\"]");
- testMergeProps(oldProp, newProp, "[\"x\",\"b\",\"c\"]");
+ testMergeProps(oldProp, newProp, "[\"x\",\"\"]");
}
@Test
public void mergeSimpleListType_jsonList() throws Exception {
PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "json", "[[\"a\", \"b\"], \"c\"]");
- PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "json", "[[\"a\"], \"\"]");
- testMergeProps(oldProp, newProp, "[[\"a\"],\"c\"]");
+ PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "json", "[[\"a\"], \"d\"]");
+ testMergeProps(oldProp, newProp, "[[\"a\"],\"d\"]");
}
+ /**
+ * Old property: New property: Expected:
+ * { { {
+ * "mac_range_plan": "y", "mac_range_plan": "", "mac_range_plan": "y",
+ * "mac_count_required": { "mac_count_required": { "mac_count_required": {
+ * "is_required": true, "is_required": false, "is_required": false,
+ * "count": 44 "mac_address": "myAddress" "mac_address": "myAddress"
+ * } } }
+ * } } }
+ *
+ */
@Test
public void mergeComplexType() throws Exception {
PropertyDataDefinition oldProp = createProp("prop1", "myType", null, "{\"mac_range_plan\":\"y\", \"mac_count_required\":{\"is_required\":true,\"count\":44}}");
- PropertyDataDefinition newProp = createProp("prop1", "myType", null, "{\"mac_count_required\":{\"is_required\":false, \"mac_address\":\"myAddress\"}}");
- testMergeProps(oldProp, newProp, "{\"mac_range_plan\":\"y\",\"mac_count_required\":{\"is_required\":false,\"mac_address\":\"myAddress\",\"count\":44}}");
+ PropertyDataDefinition newProp = createProp("prop1", "myType", null, "{\"mac_range_plan\":\"\", \"mac_count_required\":{\"is_required\":false, \"mac_address\":\"myAddress\"}}");
+
+ DataTypeDefinition myType = new DataTypeDefinition();
+ myType.setName("myType");
+
+ PropertyDefinition mac_range_plan = new PropertyDefinition();
+ mac_range_plan.setName("mac_range_plan");
+ mac_range_plan.setType("string");
+
+ PropertyDefinition mac_count_required = new PropertyDefinition();
+ mac_count_required.setName("mac_count_required");
+ mac_count_required.setType("map");
+
+ myType.setProperties(Arrays.asList(mac_range_plan, mac_count_required));
+ Map<String, DataTypeDefinition> dataTypes = Collections.singletonMap(myType.getName(), myType);
+
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
+
+ testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
+
+ assertEquals("myType", "{\"mac_range_plan\":\"y\",\"mac_count_required\":{\"is_required\":false,\"mac_address\":\"myAddress\"}}", newProp.getValue());
}
+
+
+
+
+ /** Expected property:
+ * Old property: New property: {
+ * { { "mac_range_plan": "n",
+ * "mac_range_plan": "y", " "mac_range_plan": "n", "mymap": {
+ * "mymap": { "mymap": { "mac_count_required": {
+ * "mac_count_required": { "mac_count_required": { "is_required": false,
+ * "is_required": true, "is_required": false "count": 44
+ * "count": 44 }, },
+ * }, "host":"localhost", "host":"localhost",
+ * "backup-mode":"daily", "ip":"127.0.0.1" "ip":"127.0.0.1"
+ * "ip":"0.0.0.0" } }
+ * } } }
+ * }
+ *
+ */
+ @Test
+ public void mergeComplexType_containingMapWithComplexType() throws Exception {
+ PropertyDataDefinition oldProp = createProp("prop1", "myType", null, "{\"mac_range_plan\":\"y\",\"mymap\": {\"mac_count_required\": {\"is_required\":true,\"count\":44},\"backup-mode\":\"daily\",\"ip\":\"0.0.0.0\"}}");
+ PropertyDataDefinition newProp = createProp("prop1", "myType", null, "{\"mac_range_plan\":\"n\",\"mymap\": {\"mac_count_required\": {\"is_required\":false},\"host\":\"localhost\",\"ip\":\"127.0.0.1\"}}");
+
+ DataTypeDefinition myType = new DataTypeDefinition();
+ myType.setName("myType");
+
+ PropertyDefinition mac_range_plan = new PropertyDefinition();
+ mac_range_plan.setName("mac_range_plan");
+ mac_range_plan.setType("string");
+
+ PropertyDefinition mymap = new PropertyDefinition();
+ mymap.setName("mymap");
+ mymap.setType("map");
+
+ PropertyDefinition mac_count_required = new PropertyDefinition();
+ mac_count_required.setName("mac_count_required");
+ mac_count_required.setType("MacType");
+
+ SchemaDefinition entrySchema = new SchemaDefinition();
+ entrySchema.setProperty(mac_count_required);
+ mymap.setSchema(entrySchema);
+
+ myType.setProperties(Arrays.asList(mac_range_plan, mymap, mac_count_required));
+ Map<String, DataTypeDefinition> dataTypes = Collections.singletonMap(myType.getName(), myType);
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
+
+ testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
+
+ assertEquals("myType", "{\"mac_range_plan\":\"n\",\"mymap\":{\"ip\":\"127.0.0.1\",\"mac_count_required\":{\"is_required\":false,\"count\":44},\"host\":\"localhost\"}}", newProp.getValue());
+ }
+
+
+ /*
+ * Old Property: New Property: Expected:
+ * [ [ [
+ * { { {
+ * "prop1": "val1", "prop2": { "prop2": {
+ * "prop2": { "prop3": false "prop3": false
+ * "prop3": true, } }
+ * "prop4": 44 } }
+ * } ] ]
+ * },
+ * {
+ * "prop1": "val2",
+ * "prop2": {
+ * "prop3": true
+ * }
+ * }
+ * ]
+ *
+ */
@Test
- public void mergeListOfComplexType() throws Exception {
+ public void mergeListOfComplexType_differentSize() throws Exception {
PropertyDataDefinition oldProp = createProp("prop1", "list", "myType", "[{\"prop1\":\"val1\", \"prop2\":{\"prop3\":true,\"prop4\":44}}, " +
"{\"prop1\":\"val2\", \"prop2\":{\"prop3\":true}}]");
PropertyDataDefinition newProp = createProp("prop1", "list", "myType", "[{\"prop2\":{\"prop3\":false}}]");
@@ -126,40 +241,215 @@ public class PropertyDataValueMergeBusinessLogicTest {
Map<String, DataTypeDefinition> dataTypes = buildDataTypes();
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
- String expectedValue = "[{\"prop2\":{\"prop4\":44,\"prop3\":false},\"prop1\":\"\\\"val1\\\"\"}," +
- "{\"prop2\":{\"prop3\":true},\"prop1\":\"\\\"val2\\\"\"}]";
+ assertEquals("myType", "[{\"prop2\":{\"prop3\":false}}]", newProp.getValue());
+ }
+
+
+ /*
+ * Old Property: New Property: Expected:
+ * [ [ [
+ * { { {
+ * "prop1": "val1", "prop1": "", "prop1": "val1",
+ * "prop2": { "prop2": { "prop2": {
+ * "prop3": true, "prop4": 45 "prop3": true
+ * "prop4": 44 } "prop4": 45
+ * } }, }
+ * }, { },
+ * { {
+ * "prop1": "val2", "prop2": { "prop1": "val2",
+ * "prop2": { "prop3": false "prop2": {
+ * "prop3": true } "prop3": false
+ * } } }
+ * } ] }
+ * ] ]
+ *
+ */
+ @Test
+ public void mergeListOfComplexType() throws Exception {
+ PropertyDataDefinition oldProp = createProp("lprop", "list", "myType", "[{\"prop1\":\"val1\", \"prop2\":{\"prop3\":true,\"prop4\":44}}, " +
+ "{\"prop1\":\"val2\", \"prop2\":{\"prop3\":true}}]");
+ PropertyDataDefinition newProp = createProp("lprop", "list", "myType", "[{\"prop1\":\"\", \"prop2\":{\"prop4\":45}}, {\"prop2\":{\"prop3\":false}}]");
- assertEquals(expectedValue, newProp.getValue());
+
+ DataTypeDefinition myType = new DataTypeDefinition();
+ myType.setName("myType");
+
+ Map<String, DataTypeDefinition> dataTypes = buildDataTypes();
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
+ testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
+ assertEquals("lprop", "[{\"prop2\":{\"prop4\":45,\"prop3\":true},\"prop1\":\"val1\"},{\"prop2\":{\"prop3\":false},\"prop1\":\"val2\"}]", newProp.getValue());
}
+
+
+
+ /*
+ * Old Property: New Property: Expected:
+ * { { {
+ * "lprop": [ "lprop": [ "lprop": [
+ * { { {
+ * "prop1": "val1", "prop2": [ "prop1": "val1",
+ * "prop2": [ { "prop2": [
+ * { "prop3": true {
+ * "prop3": true, }, "prop3": true,
+ * "prop4": 44 { "prop4": 44
+ * }, "prop4":69 },
+ * { } {
+ * "prop3": false, ] "prop3": false,
+ * "prop4": 96 }, "prop4": 69
+ * } { }
+ * ] "prop1": "val1", ]
+ * }, "prop2": [ },
+ * { { {
+ * "prop1": "val2", "prop3": false "prop1": "val1",
+ * "prop2": [ } "prop2": [
+ * { ] {
+ * "prop3": true } "prop3": false
+ * } ], }
+ * ] "prop5": "value05" ]
+ * } } }
+ * ], ],
+ * "prop5": "value5" "prop5": "value05"
+ * } }
+ *
+ *
+ */
+ @Test
+ public void mergeComplexType_containsListOfComplexType() throws Exception {
+ PropertyDataDefinition oldProp = createProp("complexProp", "complexType", null,
+ "{\"lprop\":[{\"prop1\":\"val1\",\"prop2\":[{\"prop3\":true,\"prop4\":44},{\"prop3\":false,\"prop4\":96}]}," +
+ "{\"prop1\":\"val2\",\"prop2\":[{\"prop3\":true}]}],\"prop5\":\"value5\"} ");
+ PropertyDataDefinition newProp = createProp("complexProp", "complexType", null,
+ "{\"lprop\":[{\"prop2\":[{\"prop3\":true},{\"prop4\":69}]},{\"prop1\":\"val1\",\"prop2\":[{\"prop3\":false}]}],\"prop5\":\"value05\"}");
+
+ DataTypeDefinition complexType = new DataTypeDefinition();
+ complexType.setName("complexType");
+
+ PropertyDefinition lprop = new PropertyDefinition(createProp("lprop", "list", "myType", null));
+
+ PropertyDefinition prop5 = new PropertyDefinition();
+ prop5.setName("prop5");
+ prop5.setType("string");
+
+ DataTypeDefinition complexProp = new DataTypeDefinition();
+ complexProp.setName("complexType");
+ complexType.setProperties(Arrays.asList(lprop, prop5));
+
+ DataTypeDefinition myType = new DataTypeDefinition();
+ myType.setName("myType");
+
+ PropertyDefinition prop1 = new PropertyDefinition();
+ prop1.setName("prop1");
+ prop1.setType("string");
+
+ DataTypeDefinition myInnerType = new DataTypeDefinition();
+ myInnerType.setName("myInnerType");
+
+ PropertyDefinition prop2 = new PropertyDefinition(createProp("prop2", "list", "myInnerType", null));
+ PropertyDefinition prop3 = new PropertyDefinition();
+ prop3.setName("prop3");
+ prop3.setType("boolean");
+
+ PropertyDefinition prop4 = new PropertyDefinition();
+ prop4.setName("prop4");
+ prop4.setType("integer");
+
+ complexType.setProperties(Arrays.asList(lprop, prop5));
+ myType.setProperties(Arrays.asList(prop1, prop2));
+ myInnerType.setProperties(Arrays.asList(prop3, prop4));
+
+ Map<String, DataTypeDefinition> dataTypes = Stream.of(complexType, myType, myInnerType)
+ .collect(Collectors.toMap(DataTypeDefinition::getName, Function.identity()));
+
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
+
+ testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
+
+ assertEquals("complexProp",
+ "{\"lprop\":[{\"prop2\":[{\"prop4\":44,\"prop3\":true},{\"prop4\":69,\"prop3\":false}],\"prop1\":\"val1\"},{\"prop2\":[{\"prop3\":false}],\"prop1\":\"val1\"}],\"prop5\":\"value05\"}",
+ newProp.getValue());
+ }
+
+
+ @Test
+ public void mergeMapType_differentSize() throws Exception {
+ PropertyDataDefinition oldProp = createProp("prop1", "map", "string", "{\"prop1\":\"val1\", \"prop2\":\"val2\", \"prop3\":\"val3\"}");
+ PropertyDataDefinition newProp = createProp("prop1", "map", "string", "{\"prop1\":\"valY\", \"prop2\":\"\"}");
+
+ HashMap<String, String> expected = Maps.newHashMap();
+ expected.put("prop1", "valY");
+ expected.put("prop2", "val2");
+ verifyMapMerge(getMergedMapProp(oldProp, newProp, Collections.emptyList()), expected);
+ }
+
+
@Test
public void mergeMapType() throws Exception {
+ PropertyDataDefinition oldProp = createProp("prop1", "map", "string", "{\"prop1\":\"val1\", \"prop2\":\"val2\", \"prop3\":\"\", \"prop4\":\"val4\"}");
+ PropertyDataDefinition newProp = createProp("prop1", "map", "string", "{\"prop1\":\"valY\", \"prop2\":\"\", \"prop3\":\"val3\", \"prop5\":\"val5\"}");
+
+
+ HashMap<String, String> expected = Maps.newHashMap();
+ expected.put("prop1", "valY");
+ expected.put("prop2", "val2");
+ expected.put("prop3", "val3");
+ expected.put("prop5", "val5");
+ verifyMapMerge(getMergedMapProp(oldProp, newProp, Collections.emptyList()), expected);
+ }
+
+ @Test
+ public void mergeMapTypeWhenNewValueIsEmpty() throws Exception {
PropertyDataDefinition oldProp = createProp("prop1", "map", "string", "{\"prop1\":\"val1\", \"prop2\":\"val2\", \"prop3\":\"val3\"}");
- PropertyDataDefinition newProp = createProp("prop1", "map", "string", "{\"prop1\":\"newVal1\", \"prop2\":\"\"}");
- testMergeProps(oldProp, newProp, "{\"prop2\":\"val2\",\"prop1\":\"newVal1\",\"prop3\":\"val3\"}");
+ PropertyDataDefinition newProp = createProp("prop1", "map", "string", null);
+ HashMap<String, String> expected = Maps.newHashMap();
+ expected.put("prop1", "val1");
+ expected.put("prop2", "val2");
+ expected.put("prop3", "val3");
+ verifyMapMerge(getMergedMapProp(oldProp, newProp, Collections.singletonList("input1")), expected);
}
@Test
public void mergeGetInputValue() throws Exception {
PropertyDataDefinition oldProp = createGetInputProp("prop1", "string", null, "input1");
- PropertyDataDefinition newProp = createProp("prop1", "string", null, null);
+ PropertyDataDefinition newProp = createProp("prop1", "string", null, "");
testMergeProps(oldProp, newProp, oldProp.getValue(), Collections.singletonList("input1"));
- assertGetInputValues(newProp, "input1");
+ assertEquals(oldProp.getGetInputValues(), newProp.getGetInputValues());
}
@Test
- public void mergeGetInputValue_inputNotForMerging() throws Exception {
+ public void mergeGetInputValue_valueIsNull_InNewProp() throws Exception {
PropertyDataDefinition oldProp = createGetInputProp("prop1", "string", null, "input1");
PropertyDataDefinition newProp = createProp("prop1", "string", null, null);
- testMergeProps(oldProp, newProp,null, Collections.singletonList("input2"));
- assertTrue(newProp.getGetInputValues().isEmpty());
+ testMergeProps(oldProp, newProp,"{\"get_input\":\"input1\"}", Collections.singletonList("input1"));
+ assertGetInputValues(newProp, "input1");
}
+ /*
+ * Old property: New property: Expected:
+ * [ [ [
+ * { { {
+ * "mac_range_plan": { "mac_count_required": { "mac_range_plan": {
+ * "get_input": "input1" "is_required": true "get_input": "input1"
+ * }, } },
+ * "mac_count_required": { } "mac_count_required": {
+ * "is_required": true, "is_required": true
+ * "count": { inputs: intput1, input2 }
+ * "get_input": "input2" ] }
+ * }
+ * } inputs: input2
+ * } ]
+ *
+ * inputs: intput1, input2
+ * ]
+ *
+ *
+ *
+ */
@Test
- public void mergeComplexGetInputValue_moreThanOneGetInput_copyOnlyInputsForMerging() throws Exception {
+ public void mergeComplexGetInputValue() throws Exception {
PropertyDataDefinition oldProp = new PropertyDataDefinitionBuilder().addGetInputValue("input1").addGetInputValue("input2").setName("prop1").setType("myType").setValue("{\"mac_range_plan\":{\"get_input\": \"input1\"}, \"mac_count_required\":{\"is_required\":true,\"count\":{\"get_input\": \"input2\"}}}").build();
- PropertyDataDefinition newProp = createProp("prop1", "myType", null, "{\"mac_count_required\":{\"is_required\":true}}");
- testMergeProps(oldProp, newProp,"{\"mac_range_plan\":{},\"mac_count_required\":{\"is_required\":true,\"count\":{\"get_input\":\"input2\"}}}", Collections.singletonList("input2"));
+ PropertyDataDefinition newProp = new PropertyDataDefinitionBuilder().addGetInputValue("input2").setName("prop1").setType("myType").setValue("{\"mac_count_required\":{\"is_required\":true}}").build();
+ testMergeProps(oldProp, newProp,"{\"mac_range_plan\":{},\"mac_count_required\":{\"is_required\":true}}", Collections.singletonList("input2"));
assertGetInputValues(newProp, "input2");
}
@@ -174,13 +464,14 @@ public class PropertyDataValueMergeBusinessLogicTest {
PropertyDataDefinition newProp = new PropertyDataDefinitionBuilder()
.addGetInputValue("input3")
+ .addGetInputValue("input5")
.setName("prop1")
.setType("list").setSchemaType("string")
- .setValue("[\"\", {\"get_input\": \"input3\"}]")
+ .setValue("[{\"get_input\": \"input5\"}, {\"get_input\": \"input3\"}]")
.build();
- testMergeProps(oldProp, newProp,"[{},{\"get_input\":\"input3\"},{\"get_input\":\"input1\"}]", Arrays.asList("input3", "input1"));
- assertGetInputValues(newProp, "input3", "input1");
+ testMergeProps(oldProp, newProp,"[{\"get_input\":\"input5\"},{\"get_input\":\"input3\"}]");
+ assertGetInputValues(newProp, "input3", "input5");
}
private void assertGetInputValues(PropertyDataDefinition newProp, String ... expectedInputNames) {
@@ -192,17 +483,30 @@ public class PropertyDataValueMergeBusinessLogicTest {
assertEquals(getInputValueDataDefinition.getInputName(), expectedInputName);
}
}
-
+
private void testMergeProps(PropertyDataDefinition oldProp, PropertyDataDefinition newProp, String expectedValue) {
testMergeProps(oldProp, newProp, expectedValue, Collections.emptyList());
}
- private void testMergeProps(PropertyDataDefinition oldProp, PropertyDataDefinition newProp, String expectedValue, List<String> getInputsToMerge) {
+ private void testMergeProps(PropertyDataDefinition oldProp, PropertyDataDefinition newProp, String expectedValue, List<String> getInputsToMerge) {
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(Collections.emptyMap()));
testInstance.mergePropertyValue(oldProp, newProp, getInputsToMerge);
assertEquals(expectedValue, newProp.getValue());
}
+
+ private String getMergedMapProp(PropertyDataDefinition oldProp, PropertyDataDefinition newProp, List<String> getInputsToMerge) {
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(Collections.emptyMap()));
+ testInstance.mergePropertyValue(oldProp, newProp, getInputsToMerge);
+ return newProp.getValue();
+ }
+
+ private void verifyMapMerge(String newValue, Map<String, String> expectedValues) {
+ Map<String, String> values = convertJsonToMap(newValue);
+ assertThat(values).isNotNull();
+ assertThat(values).containsAllEntriesOf(expectedValues);
+ }
+
private PropertyDataDefinition createProp(String name, String type, String innerType, String val) {
return new PropertyDataDefinitionBuilder()
.setType(type)
@@ -224,6 +528,14 @@ public class PropertyDataValueMergeBusinessLogicTest {
}
+ private Map<String, String> convertJsonToMap(String jsonString) {
+ try {
+ return mapper.readValue(jsonString, new TypeReference<Map<String, String>>(){});
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
private Map<String, DataTypeDefinition> buildDataTypes() {
DataTypeDefinition myType = new DataTypeDefinition();
myType.setName("myType");
@@ -232,6 +544,7 @@ public class PropertyDataValueMergeBusinessLogicTest {
PropertyDefinition prop1 = new PropertyDefinition();
prop1.setName("prop1");
+ prop1.setType("string");
PropertyDefinition prop2 = new PropertyDefinition();
prop2.setName("prop2");
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java
index 581782c2ba..119828936a 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilderTest.java
@@ -1,31 +1,20 @@
package org.openecomp.sdc.be.components.merge.property;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
+import mockit.Deencapsulation;
import org.apache.tinkerpop.gremlin.structure.T;
import org.junit.Test;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
-import mockit.Deencapsulation;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
public class PropertyInstanceMergeDataBuilderTest {
- private PropertyInstanceMergeDataBuilder createTestSubject() {
- return PropertyInstanceMergeDataBuilder.getInstance();
- }
- @Test
- public void testGetInstance() throws Exception {
- PropertyInstanceMergeDataBuilder result;
-
- // default test
- result = PropertyInstanceMergeDataBuilder.getInstance();
- }
@Test
public void testBuildDataForMerging() throws Exception {
@@ -37,8 +26,8 @@ public class PropertyInstanceMergeDataBuilderTest {
List<MergePropertyData> result;
// default test
- testSubject = createTestSubject();
- result = testSubject.buildDataForMerging(oldProps, oldInputs, newProps, newInputs);
+
+ result = PropertyInstanceMergeDataBuilder.buildDataForMerging(oldProps, oldInputs, newProps, newInputs);
}
@Test
@@ -51,8 +40,8 @@ public class PropertyInstanceMergeDataBuilderTest {
List<MergePropertyData> result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "buildMergeData", new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>());
+
+ result = Deencapsulation.invoke(PropertyInstanceMergeDataBuilder.class, "buildMergeData", new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>());
}
@Test
@@ -65,8 +54,7 @@ public class PropertyInstanceMergeDataBuilderTest {
MergePropertyData result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "buildMergePropertyData", new PropertyDataDefinition(), new HashMap<>(),
+ result = Deencapsulation.invoke(PropertyInstanceMergeDataBuilder.class, "buildMergePropertyData", new PropertyDataDefinition(), new HashMap<>(),
new PropertyDataDefinition(), new HashMap<>());
}
@@ -78,8 +66,7 @@ public class PropertyInstanceMergeDataBuilderTest {
List<String> result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "getOldGetInputNamesWhichExistInNewVersion", new LinkedList<>(), new HashMap<>());
+ result = Deencapsulation.invoke(PropertyInstanceMergeDataBuilder.class, "getOldGetInputNamesWhichExistInNewVersion", new LinkedList<>(), new HashMap<>());
}
@Test
@@ -90,7 +77,6 @@ public class PropertyInstanceMergeDataBuilderTest {
List<String> result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "getOldDeclaredInputsByUser", new LinkedList<>(), new HashMap<>());
+ result = Deencapsulation.invoke(PropertyInstanceMergeDataBuilder.class, "getOldDeclaredInputsByUser", new LinkedList<>(), new HashMap<>());
}
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ScalarPropertyValueMergerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ScalarPropertyValueMergerTest.java
deleted file mode 100644
index 2c8fa0a320..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ScalarPropertyValueMergerTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.openecomp.sdc.be.components.merge.property;
-
-import java.util.List;
-
-import org.junit.Test;
-
-import mockit.Deencapsulation;
-
-public class ScalarPropertyValueMergerTest {
-
- private ScalarPropertyValueMerger createTestSubject() {
- return new ScalarPropertyValueMerger();
- }
-
- @Test
- public void testGetInstance() throws Exception {
- PropertyValueMerger result;
-
- // default test
- result = ScalarPropertyValueMerger.getInstance();
- }
-
- @Test
- public void testMerge() throws Exception {
- ScalarPropertyValueMerger testSubject;Object oldVal = null;
- Object newVal = null;
- List<String> getInputNamesToMerge = null;
- Object result;
-
- // default test
- testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "merge", new Object[]{Object.class, Object.class, List.class});
- }
-} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java
index a43e1e68ca..90784a4cbe 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java
@@ -1,23 +1,21 @@
package org.openecomp.sdc.be.components.merge.resource;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.sdc.be.components.merge.instance.ComponentsMergeCommand;
+import org.openecomp.sdc.be.components.merge.ComponentsMergeCommand;
import org.openecomp.sdc.be.components.utils.ObjectGenerator;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.Resource;
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
+
@RunWith(MockitoJUnitRunner.class)
public class ResourceDataMergeBusinessLogicTest {
@@ -25,6 +23,9 @@ public class ResourceDataMergeBusinessLogicTest {
private ResourceDataMergeBusinessLogic testInstance;
@Mock
+ private MergeCommandsFactory mergeCommandsFactory;
+
+ @Mock
private ComponentsMergeCommand commandA;
@Mock
@@ -33,15 +34,25 @@ public class ResourceDataMergeBusinessLogicTest {
@Mock
private ComponentsMergeCommand commandC;
+ private Resource oldResource, newResource;
+
@Before
public void setUp() throws Exception {
- testInstance = new ResourceDataMergeBusinessLogic(Arrays.asList(commandA, commandB, commandC));
+ oldResource = ObjectGenerator.buildBasicResource();
+ newResource = ObjectGenerator.buildBasicResource();
+ when(mergeCommandsFactory.getMergeCommands(oldResource, newResource)).thenReturn(Either.left(asList(commandA, commandB, commandC)));
+ }
+
+ @Test
+ public void whenCommandsFactoryFails_propagateTheFailure() {
+ when(mergeCommandsFactory.getMergeCommands(oldResource, newResource)).thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
+ ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
+ assertEquals(ActionStatus.GENERAL_ERROR, actionStatus);
+ verifyZeroInteractions(commandA, commandB, commandC);
}
@Test
public void mergeResources_allMergeClassesAreCalled() {
- Resource oldResource = ObjectGenerator.buildBasicResource();
- Resource newResource = ObjectGenerator.buildBasicResource();
when(commandA.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.OK);
when(commandB.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.OK);
when(commandC.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.OK);
@@ -51,8 +62,6 @@ public class ResourceDataMergeBusinessLogicTest {
@Test
public void mergeResources_mergeCommandFailed_dontCallOtherMergeMethods() {
- Resource oldResource = ObjectGenerator.buildBasicResource();
- Resource newResource = ObjectGenerator.buildBasicResource();
when(commandA.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.GENERAL_ERROR);
ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
assertEquals(ActionStatus.GENERAL_ERROR, actionStatus);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtilsTest.java
index 9d07be276b..ef87dba483 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtilsTest.java
@@ -1,70 +1,71 @@
package org.openecomp.sdc.be.components.merge.utils;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
+import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
+import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
+import org.openecomp.sdc.be.components.utils.ServiceBuilder;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import fj.data.Either;
+import java.util.Map;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class MergeInstanceUtilsTest {
- private MergeInstanceUtils mergeInstanceUtils = new MergeInstanceUtils();
+
+ private MergeInstanceUtils mergeInstanceUtils;
@Mock
private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private TitanDao titanDao;
+
@Before
public void startUp() {
- mergeInstanceUtils.setToscaOperationFacade(toscaOperationFacade);
+ ExceptionUtils exceptionUtils = new ExceptionUtils(titanDao);
+ mergeInstanceUtils = new MergeInstanceUtils(toscaOperationFacade, exceptionUtils);
}
@Test
public void testMapOldToNewCapabilitiesOwnerIdsComponentComponent() {
Component container = new Service();
- Resource vfOld = new Resource();
- vfOld.setComponentType(ComponentTypeEnum.RESOURCE);
- vfOld.setResourceType(ResourceTypeEnum.VF);
-
- ComponentInstance vfci1 = createComponentInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1" ,"SRV1.VF1.VFI_1.VFC1", false);
- createVfc(vfci1);
- List<ComponentInstance> vfciList = Arrays.asList(vfci1);
- vfOld.setComponentInstances(vfciList);
-
+ ComponentInstance vfciOld = createVfcInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1", "SRV1.VF1.VFI_1.VFC1");
+ GroupDefinition oldGrp = createGroup("group1", "grp1Id");
+ Component vfOld = createVf("prevVfId", vfciOld, oldGrp);
ComponentInstance vfi1 = createComponentInstance("SRV1.VF2.VFI_1" ,"SRV1.VF2", false);
- container.setComponentInstances(Arrays.asList(vfi1));
-
- Resource vfNew = new Resource();
- vfNew.setComponentType(ComponentTypeEnum.RESOURCE);
- vfNew.setResourceType(ResourceTypeEnum.VF);
-
- List<ComponentInstance> vfciList2 = Arrays.asList(vfci1);
- vfNew.setComponentInstances(vfciList2);
+ container.setComponentInstances(singletonList(vfi1));
- Either<Component, StorageOperationStatus> eitherComponent = Either.left(vfNew);
- when(toscaOperationFacade.getToscaElement(vfi1.getComponentUid())).thenReturn(eitherComponent);
+ ComponentInstance vfciNew = createComponentInstance("SRV1.VF1.VFI_1.VFC1.VFCI_2", "SRV1.VF1.VFI_1.VFC1", false);
+ GroupDefinition newGrp = createGroup("group1", "newGrp1Id");
+ Component vfNew = createVf("newVfId", vfciNew, newGrp);
+ when(toscaOperationFacade.getToscaElement(vfi1.getComponentUid())).thenReturn(Either.left(vfNew));
-
- Map<String, String> mapResult = mergeInstanceUtils.mapOldToNewCapabilitiesOwnerIds(container, vfOld, "SRV1.VF2.VFI_1", Arrays.asList("SRV1.VF1.VFI_1.VFC1.VFCI_1"));
- assertEquals("SRV1.VF1.VFI_1.VFC1.VFCI_1", mapResult.get("SRV1.VF1.VFI_1.VFC1.VFCI_1"));
+ Map<String, String> mapResult = mergeInstanceUtils.mapOldToNewCapabilitiesOwnerIds(container, vfOld, "SRV1.VF2.VFI_1", asList("SRV1.VF1.VFI_1.VFC1.VFCI_1", oldGrp.getUniqueId()));
+ assertThat(mapResult)
+ .containsEntry("SRV1.VF1.VFI_1.VFC1.VFCI_1", "SRV1.VF1.VFI_1.VFC1.VFCI_2")
+ .containsEntry(oldGrp.getUniqueId(), newGrp.getUniqueId());
}
@Test
@@ -73,40 +74,21 @@ public class MergeInstanceUtilsTest {
container.setComponentType(ComponentTypeEnum.RESOURCE);
container.setResourceType(ResourceTypeEnum.VF);
-
Component serviceOld = new Service();
serviceOld.setComponentType(ComponentTypeEnum.SERVICE);
- Resource vfOld = new Resource();
- vfOld.setComponentType(ComponentTypeEnum.RESOURCE);
- vfOld.setResourceType(ResourceTypeEnum.VF);
-
- ComponentInstance vfciOld = createComponentInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1" ,"SRV1.VF1.VFI_1.VFC1", false);
- createVfc(vfciOld);
- List<ComponentInstance> vfciList = Arrays.asList(vfciOld);
- vfOld.setComponentInstances(vfciList);
-
- ComponentInstance vfiOld = createComponentInstance("SRV1.VF1.VFI_1" ,"SRV1.VF1", false);
- serviceOld.setComponentInstances(Arrays.asList(vfiOld));
- Either<Component, StorageOperationStatus> eitherComponent = Either.left(vfOld);
- when(toscaOperationFacade.getToscaElement(vfiOld.getComponentUid())).thenReturn(eitherComponent);
+ ComponentInstance vfciOld = createVfcInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1", "SRV1.VF1.VFI_1.VFC1");
+ GroupDefinition prevGroup = createGroup("grp1", "grp1Old");
+ ComponentInstance vfiOld = createVfInstance("SRV1.VF1.VFI_1", vfciOld, prevGroup);
+ serviceOld.setComponentInstances(singletonList(vfiOld));
Component serviceNew = new Service();
serviceNew.setComponentType(ComponentTypeEnum.SERVICE);
- Resource vfNew = new Resource();
- vfNew.setComponentType(ComponentTypeEnum.RESOURCE);
- vfNew.setResourceType(ResourceTypeEnum.VF);
-
- ComponentInstance vfciNew = createComponentInstance("SRV1.VF2.VFI_1.VFC2.VFCI_1" ,"SRV1.VF2.VFI_1.VFC2", false);
- createVfc(vfciNew);
- List<ComponentInstance> vfciList2 = Arrays.asList(vfciNew);
- vfNew.setComponentInstances(vfciList2);
-
- ComponentInstance vfiNew = createComponentInstance("SRV1.VF2.VFI_1" ,"SRV1.VF2", false);
- serviceNew.setComponentInstances(Arrays.asList(vfiNew));
- Either<Component, StorageOperationStatus> eitherComponent3 = Either.left(vfNew);
- when(toscaOperationFacade.getToscaElement(vfiNew.getComponentUid())).thenReturn(eitherComponent3);
+ ComponentInstance vfciNew = createVfcInstance("SRV1.VF2.VFI_1.VFC2.VFCI_1", "SRV1.VF2.VFI_1.VFC2");
+ GroupDefinition grpNew = createGroup("grp1", "newGrp1");
+ ComponentInstance vfiNew = createVfInstance("SRV1.VF2.VFI_1" ,vfciNew, grpNew);
+ serviceNew.setComponentInstances(singletonList(vfiNew));
ComponentInstance proxyVfciNew = createComponentInstance("SRV1.PROXY_VFC_NEW.VFCI1", "SRV1.PROXY_VFC_NEW", true);
proxyVfciNew.setSourceModelUid("SRV_PROXY_NEW");
@@ -117,44 +99,66 @@ public class MergeInstanceUtilsTest {
Either<Component, StorageOperationStatus> eitherComponent4 = Either.left(serviceNew);
when(toscaOperationFacade.getToscaElement(proxyVfciNew.getSourceModelUid())).thenReturn(eitherComponent4);
- container.setComponentInstances(Arrays.asList(proxyVfciNew));
+ container.setComponentInstances(singletonList(proxyVfciNew));
- Map<String, String> mapResult = mergeInstanceUtils.mapOldToNewCapabilitiesOwnerIds(container, serviceOld, "SRV1.PROXY_VFC_NEW.VFCI1", Arrays.asList("SRV1.VF1.VFI_1.VFC1.VFCI_1"));
+ Map<String, String> mapResult = mergeInstanceUtils.mapOldToNewCapabilitiesOwnerIds(container, serviceOld, "SRV1.PROXY_VFC_NEW.VFCI1", asList("SRV1.VF1.VFI_1.VFC1.VFCI_1", prevGroup.getUniqueId()));
+ assertThat(mapResult)
+ .containsEntry("SRV1.VF1.VFI_1.VFC1.VFCI_1", "SRV1.VF2.VFI_1.VFC2.VFCI_1")
+ .containsEntry(prevGroup.getUniqueId(), grpNew.getUniqueId());
+ }
- assertEquals("SRV1.VF2.VFI_1.VFC2.VFCI_1", mapResult.get("SRV1.VF1.VFI_1.VFC1.VFCI_1"));
+ @Test
+ public void whenFailingToGetInstanceOriginNodeType_throwExceptionAndRollBack() {
+ Resource oldVf = new ResourceBuilder()
+ .setResourceType(ResourceTypeEnum.VF)
+ .setComponentType(ComponentTypeEnum.RESOURCE)
+ .build();
+
+ ComponentInstance newVfInstance = createComponentInstance("inst1", "inst1Uid", false);
+ Resource container = new ResourceBuilder()
+ .addComponentInstance(newVfInstance)
+ .build();
+ when(toscaOperationFacade.getToscaElement("inst1Uid")).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ assertThatExceptionOfType(StorageException.class)
+ .isThrownBy(() -> mergeInstanceUtils.mapOldToNewCapabilitiesOwnerIds(container, oldVf, "inst1", emptyList()));
+ verify(titanDao).rollback();
}
@Test
public void testMapOldToNewCapabilitiesOwnerIdsComponentInstanceComponentInstance() {
- ComponentInstance oldInstance = createComponentInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1" ,"SRV1.VF1.VFI_1.VFC1", false);
- createVfc(oldInstance);
-
- ComponentInstance newInstance = createComponentInstance("SRV1.VF1.VFI_1.VFC2.VFCI_1" ,"SRV1.VF1.VFI_1.VFC2", false);
- createVfc(newInstance);
-
+ ComponentInstance oldInstance = createVfcInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1", "SRV1.VF1.VFI_1.VFC1");
+ ComponentInstance newInstance = createVfcInstance("SRV1.VF1.VFI_1.VFC2.VFCI_1", "SRV1.VF1.VFI_1.VFC2");
Map<String, String> mapResult = mergeInstanceUtils.mapOldToNewCapabilitiesOwnerIds(oldInstance, newInstance);
assertEquals("SRV1.VF1.VFI_1.VFC2.VFCI_1", mapResult.get("SRV1.VF1.VFI_1.VFC1.VFCI_1"));
}
@Test
- public void testMapOldToNewCapabilitiesOwnerIdsComponentInstComponentInst_Proxy() {
+ public void testMapOldToNewCapabilitiesOwnerIdsInstToInstWithGroups() {
+ ComponentInstance prevInstance = createVfcInstance("prevInst1", "prevInst1Uid");
+ GroupDefinition prevGroup = createGroup("grp1", "prevGrp1");
+ ComponentInstance prevInstanceRoot = createVfInstance("prevId", prevInstance, prevGroup);
+
+ ComponentInstance currInstance = createVfcInstance("newInst1", "newInst1Uid");
+ GroupDefinition currGroup = createGroup("grp1", "currGrp1");
+ ComponentInstance newInstanceRoot = createVfInstance("currId", currInstance, currGroup);
+
+ Map<String, String> mapResult = mergeInstanceUtils.mapOldToNewCapabilitiesOwnerIds(prevInstanceRoot, newInstanceRoot);
+ assertThat(mapResult)
+ .containsEntry(prevInstance.getUniqueId(), currInstance.getUniqueId())
+ .containsEntry(prevGroup.getUniqueId(), currGroup.getUniqueId());
+ }
- Component serviceOld = new Service();
- serviceOld.setComponentType(ComponentTypeEnum.SERVICE);
- Resource vfOld = new Resource();
- vfOld.setComponentType(ComponentTypeEnum.RESOURCE);
- vfOld.setResourceType(ResourceTypeEnum.VF);
+ @Test
+ public void testMapOldToNewCapabilitiesOwnerIdsComponentInstComponentInst_Proxy() {
- ComponentInstance vfciOld = createComponentInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1" ,"SRV1.VF1.VFI_1.VFC1", false);
- createVfc(vfciOld);
- List<ComponentInstance> vfciList = Arrays.asList(vfciOld);
- vfOld.setComponentInstances(vfciList);
+ ComponentInstance vfciOld = createVfcInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1", "SRV1.VF1.VFI_1.VFC1");
+ GroupDefinition oldGrp = createGroup("grp1", "grp1Old");
+ ComponentInstance vfiOld = createVfInstance("SRV1.VF1.VFI_1", vfciOld, oldGrp);
- ComponentInstance vfiOld = createComponentInstance("SRV1.VF1.VFI_1" ,"SRV1.VF1", false);
- serviceOld.setComponentInstances(Arrays.asList(vfiOld));
- Either<Component, StorageOperationStatus> eitherComponent = Either.left(vfOld);
- when(toscaOperationFacade.getToscaElement(vfiOld.getComponentUid())).thenReturn(eitherComponent);
+ Component serviceOld = new Service();
+ serviceOld.setComponentType(ComponentTypeEnum.SERVICE);
+ serviceOld.setComponentInstances(singletonList(vfiOld));
ComponentInstance proxyVfciOld = createComponentInstance("SRV1.PROXY_VFC.VFCI1", "SRV1.PROXY_VFC", true);
proxyVfciOld.setSourceModelUid("SRV_PROXY");
@@ -165,23 +169,13 @@ public class MergeInstanceUtilsTest {
Either<Component, StorageOperationStatus> eitherComponent2 = Either.left(serviceOld);
when(toscaOperationFacade.getToscaElement(proxyVfciOld.getSourceModelUid())).thenReturn(eitherComponent2);
+ ComponentInstance vfciNew = createVfcInstance("SRV1.VF2.VFI_1.VFC2.VFCI_1", "SRV1.VF2.VFI_1.VFC2");
+ GroupDefinition newGrp = createGroup("grp1", "grp1New");
+ ComponentInstance vfiNew = createVfInstance("SRV1.VF2.VFI_1" ,vfciNew, newGrp);
Component serviceNew = new Service();
serviceNew.setComponentType(ComponentTypeEnum.SERVICE);
-
- Resource vfNew = new Resource();
- vfNew.setComponentType(ComponentTypeEnum.RESOURCE);
- vfNew.setResourceType(ResourceTypeEnum.VF);
-
- ComponentInstance vfciNew = createComponentInstance("SRV1.VF2.VFI_1.VFC2.VFCI_1" ,"SRV1.VF2.VFI_1.VFC2", false);
- createVfc(vfciNew);
- List<ComponentInstance> vfciList2 = Arrays.asList(vfciNew);
- vfNew.setComponentInstances(vfciList2);
-
- ComponentInstance vfiNew = createComponentInstance("SRV1.VF2.VFI_1" ,"SRV1.VF2", false);
- serviceNew.setComponentInstances(Arrays.asList(vfiNew));
- Either<Component, StorageOperationStatus> eitherComponent3 = Either.left(vfNew);
- when(toscaOperationFacade.getToscaElement(vfiNew.getComponentUid())).thenReturn(eitherComponent3);
+ serviceNew.setComponentInstances(singletonList(vfiNew));
ComponentInstance proxyVfciNew = createComponentInstance("SRV1.PROXY_VFC_NEW.VFCI1", "SRV1.PROXY_VFC_NEW", true);
proxyVfciNew.setSourceModelUid("SRV_PROXY_NEW");
@@ -193,132 +187,150 @@ public class MergeInstanceUtilsTest {
when(toscaOperationFacade.getToscaElement(proxyVfciNew.getSourceModelUid())).thenReturn(eitherComponent4);
Map<String, String> mapResult = mergeInstanceUtils.mapOldToNewCapabilitiesOwnerIds(proxyVfciOld, proxyVfciNew);
- assertEquals("SRV1.VF2.VFI_1.VFC2.VFCI_1", mapResult.get("SRV1.VF1.VFI_1.VFC1.VFCI_1"));
+ assertThat(mapResult)
+ .containsEntry("SRV1.VF1.VFI_1.VFC1.VFCI_1", "SRV1.VF2.VFI_1.VFC2.VFCI_1")
+ .containsEntry(oldGrp.getUniqueId(), newGrp.getUniqueId());
}
@Test
- public void testConvertToVfciNameMap() {
- ComponentInstance componentInstance1 = new ComponentInstance();
- componentInstance1.setName("ComponentInstance1");
-
- ComponentInstance componentInstance2 = new ComponentInstance();
- componentInstance2.setName("ComponentInstance2");
-
- List<ComponentInstance> componentInstances = Arrays.asList(componentInstance1, componentInstance2);
- Map<String, ComponentInstance> mapResult = mergeInstanceUtils.convertToVfciNameMap(componentInstances);
-
- assertEquals(2, mapResult.size());
- assertEquals(componentInstance1, mapResult.get("ComponentInstance1"));
- assertEquals(componentInstance2, mapResult.get("ComponentInstance2"));
- }
-
- @Test
- public void testGetVfcInstances_NullComponentInstance() {
- List<ComponentInstance> vfcInstances = mergeInstanceUtils.getVfcInstances(null);
-
- assertTrue(vfcInstances.isEmpty());
+ public void testGetInstanceAtomicBuildingBlocks_NullComponentInstance() {
+ assertEmpty(mergeInstanceUtils.getInstanceAtomicBuildingBlocks(null));
}
@Test
- public void testGetVfcInstances_ComponentInstanceFailedLoadComponent() {
+ public void testgetInstanceAtomicBuildingBlocks_ComponentInstanceFailedLoadComponent() {
ComponentInstance componentInstance = createComponentInstance("SRV1.VF1.VFI_1", "SRV1.VF1", false);
-
Either<Component, StorageOperationStatus> eitherComponent = Either.right(StorageOperationStatus.NOT_FOUND);
when(toscaOperationFacade.getToscaElement(componentInstance.getComponentUid())).thenReturn(eitherComponent);
-
- List<ComponentInstance> vfcInstances = mergeInstanceUtils.getVfcInstances(componentInstance);
-
- assertTrue(vfcInstances.isEmpty());
+ assertThatExceptionOfType(StorageException.class).isThrownBy(() -> mergeInstanceUtils.getInstanceAtomicBuildingBlocks(componentInstance));
}
@Test
- public void testGetVfcInstances_ComponentInstanceFailedLoadActualComponent() {
+ public void testGetInstanceAtomicBuildingBlocks_ComponentInstanceFailedLoadActualComponent() {
ComponentInstance componentInstance = createComponentInstance("SRV1.PROXY_VFC.VFCI1", "SRV1.PROXY_VFC", true);
componentInstance.setSourceModelUid("SRV_PROXY");
-
Either<Component, StorageOperationStatus> eitherComponent = Either.right(StorageOperationStatus.NOT_FOUND);
when(toscaOperationFacade.getToscaElement(componentInstance.getSourceModelUid())).thenReturn(eitherComponent);
-
- List<ComponentInstance> vfcInstances = mergeInstanceUtils.getVfcInstances(componentInstance);
-
- assertTrue(vfcInstances.isEmpty());
+ assertThatExceptionOfType(StorageException.class).isThrownBy(() -> mergeInstanceUtils.getInstanceAtomicBuildingBlocks(componentInstance));
}
@Test
- public void testGetVfcInstancesAtomicComponentInstance() {
- ComponentInstance componentInstance = createComponentInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1" ,"SRV1.VF1.VFI_1.VFC1", false);
-
- createVfc(componentInstance);
-
- List<ComponentInstance> vfcInstances = mergeInstanceUtils.getVfcInstances(componentInstance);
-
- assertEquals(1, vfcInstances.size());
- assertEquals(componentInstance, vfcInstances.get(0));
+ public void testGetAtomicBuildingBlocks() {
+ ComponentInstance componentInstance = createVfcInstance("inst1", "inst1Uid");
+ GroupDefinition group = createGroup("grp1", "grp1Id");
+ ComponentInstance vfi = createVfInstance("vfi", componentInstance, group);
+ ComponentInstanceBuildingBlocks instanceBuildingBlocks = mergeInstanceUtils.getInstanceAtomicBuildingBlocks(vfi);
+ assertThat(instanceBuildingBlocks)
+ .extracting("vfcInstances", "groups")
+ .containsExactlyInAnyOrder(singletonList(componentInstance), singletonList(group));
}
-
@Test
- public void testGetVfcInstancesNonAtomicComponentInstance() {
- ComponentInstance componentInstance = createComponentInstance("SRV1.VF1.VFI_1", "SRV1.VF1", false);
-
- Resource vf = new Resource();
- Either<Component, StorageOperationStatus> eitherComponent = Either.left(vf);
- vf.setComponentType(ComponentTypeEnum.RESOURCE);
- vf.setResourceType(ResourceTypeEnum.VF);
-
- ComponentInstance vfci = createComponentInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1" ,"SRV1.VF1.VFI_1.VFC1", false);
- createVfc(vfci);
- List<ComponentInstance> vfciList = Arrays.asList(vfci);
-
- vf.setComponentInstances(vfciList);
- when(toscaOperationFacade.getToscaElement(componentInstance.getComponentUid())).thenReturn(eitherComponent);
+ public void testGetAtomicBuildingBlocksComponentInstance_noGroups() {
+ ComponentInstance componentInstance = createVfcInstance("SRV1.VF1.VFI_1.VFC1.VFCI_1", "SRV1.VF1.VFI_1.VFC1");
+ ComponentInstanceBuildingBlocks instanceBuildingBlocks = mergeInstanceUtils.getInstanceAtomicBuildingBlocks(componentInstance);
+ assertThat(instanceBuildingBlocks)
+ .extracting("vfcInstances", "groups")
+ .containsExactly(singletonList(componentInstance), emptyList());
+ }
- List<ComponentInstance> vfcInstances = mergeInstanceUtils.getVfcInstances(componentInstance);
+ @Test
+ public void testGetAtomicBuildingBlocks_noInstances() {
+ GroupDefinition group = createGroup("grp1", "grp1Id");
+ ComponentInstance vfi = createVfInstance("vfi", null, group);
+ ComponentInstanceBuildingBlocks instanceBuildingBlocks = mergeInstanceUtils.getInstanceAtomicBuildingBlocks(vfi);
+ assertThat(instanceBuildingBlocks)
+ .extracting("groups", "vfcInstances")
+ .containsExactlyInAnyOrder(singletonList(group), emptyList());
+ }
- assertEquals(vfciList, vfcInstances);
+ @Test
+ public void testGetAtomicBuildingBlocks_noDuplication() {
+ GroupDefinition group1FirstCopy = createGroup("grp1", "grp1Id");
+ GroupDefinition group1SecondCopy = createGroup("grp1", "grp1Id");
+
+ ComponentInstance cmtInst1FirstCopy = createVfcInstance("inst1", "inst1Uid");
+ ComponentInstance cmtInst1SecondCopy = createVfcInstance("inst1", "inst1Uid");
+
+ ComponentInstance vfi = createVfInstance("vfi", cmtInst1FirstCopy, group1FirstCopy);
+ ComponentInstance vfi2 = createVfInstance("vfi2", cmtInst1SecondCopy, group1SecondCopy);
+
+ Service service = new ServiceBuilder()
+ .addComponentInstance(vfi)
+ .addComponentInstance(vfi2)
+ .setUniqueId("service1")
+ .build();
+
+ ComponentInstance proxy = createServiceProxy("serviceProxy", service);
+ ComponentInstanceBuildingBlocks instanceAtomicBuildingBlocks = mergeInstanceUtils.getInstanceAtomicBuildingBlocks(proxy);
+ assertThat(instanceAtomicBuildingBlocks)
+ .extracting("groups", "vfcInstances")
+ .containsExactlyInAnyOrder(singletonList(group1FirstCopy), singletonList(cmtInst1FirstCopy));
}
@Test
- public void testGetVfcInstances_ComponentNullI_nstanceComponent() {
- List<ComponentInstance> vfcInstances = mergeInstanceUtils.getVfcInstances(null, new Resource());
+ public void testGetAtomicBuildingBlocks_ComponentNull_InstanceComponent() {
+ assertEmpty(mergeInstanceUtils.getInstanceAtomicBuildingBlocks(null, new Resource()));
+ }
- assertTrue(vfcInstances.isEmpty());
+ @Test
+ public void testGetInstanceAtomicBuildingBlocks_ComponentInstance_NullComponent() {
+ assertEmpty(mergeInstanceUtils.getInstanceAtomicBuildingBlocks(new ComponentInstance(), null));
}
@Test
- public void testGetVfcInstances_ComponentInstance_NullComponent() {
- List<ComponentInstance> vfcInstances = mergeInstanceUtils.getVfcInstances(new ComponentInstance(), null);
+ public void testGetInstanceAtomicBuildingBlocks_NullComponentInstance_NullComponent() {
+ assertEmpty(mergeInstanceUtils.getInstanceAtomicBuildingBlocks(null, null));
+ }
- assertTrue(vfcInstances.isEmpty());
+ private void assertEmpty(ComponentInstanceBuildingBlocks componentInstanceBuildingBlocks) {
+ assertThat(componentInstanceBuildingBlocks)
+ .extracting("vfcInstances", "groups")
+ .containsExactly(emptyList(), emptyList());
}
- @Test
- public void testGetVfcInstances_NullComponentInstance_NullComponent() {
- List<ComponentInstance> vfcInstances = mergeInstanceUtils.getVfcInstances(null, null);
+ private ComponentInstance createVfcInstance(String instId, String instUid) {
+ ComponentInstance vfci = createComponentInstance(instId, instUid, false);
+ createVfc(vfci);
+ return vfci;
+ }
- assertTrue(vfcInstances.isEmpty());
+ private ComponentInstance createVfInstance(String id, ComponentInstance withInstance, GroupDefinition withGroup) {
+ Component vf = createVf(id, withInstance, withGroup);
+ ComponentInstance vfInstance = new ComponentInstanceBuilder().setComponentUid(vf.getUniqueId()).build();
+ when(toscaOperationFacade.getToscaElement(id)).thenReturn(Either.left(vf));
+ return vfInstance;
}
+ private ComponentInstance createServiceProxy(String id, Service fromService) {
+ when(toscaOperationFacade.getToscaElement(fromService.getUniqueId())).thenReturn(Either.left(fromService));
+ return createComponentInstance(id, fromService.getUniqueId(), true);
+ }
+
+ private Component createVf(String id, ComponentInstance instance, GroupDefinition group) {
+ return new ResourceBuilder()
+ .setResourceType(ResourceTypeEnum.VF)
+ .setComponentType(ComponentTypeEnum.RESOURCE)
+ .addGroup(group)
+ .addComponentInstance(instance)
+ .setUniqueId(id)
+ .build();
+ }
- /**
- * @param uniqueId
- * @param componentUid
- * @param isProxy
- * @return
- */
private ComponentInstance createComponentInstance(String uniqueId, String componentUid, boolean isProxy) {
ComponentInstance componentInstance = new ComponentInstance();
componentInstance.setUniqueId(uniqueId);
- componentInstance.setComponentUid(componentUid);
componentInstance.setIsProxy(isProxy);
+ if (isProxy) {
+ componentInstance.setSourceModelUid(componentUid);
+ } else {
+ componentInstance.setComponentUid(componentUid);
+ }
return componentInstance;
}
- /**
- * @param componentInstance
- */
private void createVfc(ComponentInstance componentInstance) {
Resource vfc = new Resource();
Either<Component, StorageOperationStatus> eitherComponent = Either.left(vfc);
@@ -326,4 +338,13 @@ public class MergeInstanceUtilsTest {
vfc.setResourceType(ResourceTypeEnum.VFC);
when(toscaOperationFacade.getToscaElement(componentInstance.getComponentUid())).thenReturn(eitherComponent);
}
+
+ private GroupDefinition createGroup(String invariantName, String id) {
+ return GroupDefinitionBuilder.create()
+ .setInvariantName(invariantName)
+ .setUniqueId(id)
+ .setName(id + "name")
+ .build();
+
+ }
}