summaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-02-15 19:36:59 +0000
committerVasyl Razinkov <vasyl.razinkov@est.tech>2021-02-26 15:21:47 +0000
commit5d760031d3aeecff297c6141adfe5d7490cdcbb9 (patch)
tree321e3b04b1013d483ddc85c0620653ab3c621bce /catalog-model/src
parent72e2d333317dfc49ad9ec19abc336053ffb68159 (diff)
Implement Attributes/Outputs BE (part 3)
This commit includes unit test for new/changed code Change-Id: I619039f99c4a09484df098375067bdceee4636b0 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3448
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/AttributeDefinitionTest.java50
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstOutputsMapTest.java70
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceAttribOutputTest.java55
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceOutputTest.java42
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java284
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java26
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java237
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java56
8 files changed, 717 insertions, 103 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/AttributeDefinitionTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/AttributeDefinitionTest.java
new file mode 100644
index 0000000000..a6d87df05e
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/AttributeDefinitionTest.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021, Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.model;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
+
+class AttributeDefinitionTest {
+
+ private static final String VALUE = "mock";
+ private final AttributeDefinition testSubject = new AttributeDefinition();
+
+ @Test
+ void testCtor() throws Exception {
+ assertNotNull(new AttributeDefinition());
+ assertNotNull(new AttributeDefinition(new AttributeDefinition()));
+ assertNotNull(new AttributeDefinition(new AttributeDataDefinition()));
+ }
+
+ @Test
+ void test_DefaultValue() {
+ testSubject.setDefaultValue(VALUE);
+ final String result = testSubject.getDefaultValue();
+ assertEquals(VALUE, result);
+ }
+
+ @Test
+ void test_isDefinition() {
+ assertFalse(testSubject.isDefinition());
+ }
+} \ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstOutputsMapTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstOutputsMapTest.java
new file mode 100644
index 0000000000..79a69df62f
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstOutputsMapTest.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021, Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.model;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class ComponentInstOutputsMapTest {
+
+ private final ComponentInstOutputsMap testInstance = new ComponentInstOutputsMap();
+
+ @Test
+ void test_resolveAttributesToDeclare_isEmpty() {
+ Assertions.assertThrows(IllegalStateException.class, () -> {
+ final Pair<String, List<ComponentInstanceAttribOutput>> result = testInstance.resolveAttributesToDeclare();
+ });
+ }
+
+ @Test
+ void test_resolveAttributesToDeclare_success() {
+ Map<String, List<ComponentInstanceAttribOutput>> map = new HashMap<>();
+ map.put("mock", Arrays.asList(new ComponentInstanceAttribOutput()));
+ testInstance.setComponentInstanceOutputsMap(map);
+ testInstance.setComponentInstanceAttributes(null);
+ Pair<String, List<ComponentInstanceAttribOutput>> result = testInstance.resolveAttributesToDeclare();
+ Assertions.assertNotNull(result);
+
+ testInstance.setComponentInstanceOutputsMap(null);
+ testInstance.setComponentInstanceAttributes(map);
+ result = testInstance.resolveAttributesToDeclare();
+ Assertions.assertNotNull(result);
+ }
+
+ @Test
+ void test_getComponentInstanceOutputsMap() {
+ final Map<String, List<ComponentInstanceAttribOutput>> result = testInstance.getComponentInstanceOutputsMap();
+ Assertions.assertNotNull(result);
+ }
+
+ @Test
+ void test_getComponentInstanceAttributes() {
+ final Map<String, List<ComponentInstanceAttribOutput>> result = testInstance.getComponentInstanceAttributes();
+ Assertions.assertNotNull(result);
+ }
+
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceAttribOutputTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceAttribOutputTest.java
new file mode 100644
index 0000000000..27be652b7a
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceAttribOutputTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021, Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.model;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class ComponentInstanceAttribOutputTest {
+
+ private final ComponentInstanceAttribOutput testSubject = new ComponentInstanceAttribOutput();
+
+ @Test
+ void testCtor() throws Exception {
+ Assertions.assertThat(testSubject).isNotNull().isInstanceOf(ComponentInstanceAttribOutput.class);
+ Assertions.assertThat(new ComponentInstanceAttribOutput(testSubject)).isNotNull().isInstanceOf(ComponentInstanceAttribOutput.class);
+ }
+
+ @Test
+ void test_getParsedAttribNames() {
+ String[] result;
+
+ testSubject.setAttributesName("");
+ result = testSubject.getParsedAttribNames();
+ assertNull(result);
+
+ testSubject.setAttributesName("ZZZ");
+ result = testSubject.getParsedAttribNames();
+ assertNotNull(result);
+ assertEquals(1, result.length);
+
+ testSubject.setAttributesName("AAA#BBB#CCC");
+ result = testSubject.getParsedAttribNames();
+ assertNotNull(result);
+ assertEquals(3, result.length);
+ }
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceOutputTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceOutputTest.java
new file mode 100644
index 0000000000..29b2dc4659
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceOutputTest.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021, Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.model;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.util.List;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
+
+class ComponentInstanceOutputTest {
+
+ private static final String MOCK = "mock";
+
+ @Test
+ void testCtor() throws Exception {
+ Assertions.assertNotNull(new ComponentInstanceOutput(new AttributeDataDefinition()));
+ Assertions.assertNotNull(new ComponentInstanceOutput(new OutputDefinition(), MOCK, MOCK));
+ Assertions.assertNotNull(new ComponentInstanceOutput(new AttributeDataDefinition(), MOCK, MOCK, MOCK));
+ }
+
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java
index aea07799b2..cf4d6b22bf 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java
@@ -36,22 +36,28 @@ import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraphVertex;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestInstance.Lifecycle;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.elements.*;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
@@ -64,27 +70,34 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.codehaus.groovy.runtime.DefaultGroovyMethods.any;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
-public class NodeTemplateOperationTest extends ModelTestBase {
-
- private final static String COMPONENT_ID = "componentId";
- private final static String TO_INSTANCE_ID = "toInstanceId";
- private final static String FROM_INSTANCE_ID = "fromInstanceId";
- private final static String RELATION_ID = "relationId";
- private final static String CAPABILITY_OWNER_ID = "capabilityOwnerId";
- private final static String CAPABILITY_UID = "capabilityUid";
- private final static String CAPABILITY_NAME = "capabilityName";
- private final static String REQUIREMENT_OWNER_ID = "requirementOwnerId";
- private final static String REQUIREMENT_UID = "requirementUid";
- private final static String REQUIREMENT_NAME = "requirementName";
- private final static String RELATIONSHIP_TYPE = "relationshipType";
+@ExtendWith(MockitoExtension.class)
+@TestInstance(Lifecycle.PER_CLASS)
+class NodeTemplateOperationTest extends ModelTestBase {
+
+ private static final String COMPONENT_ID = "componentId";
+ private static final String TO_INSTANCE_ID = "toInstanceId";
+ private static final String FROM_INSTANCE_ID = "fromInstanceId";
+ private static final String RELATION_ID = "relationId";
+ private static final String CAPABILITY_OWNER_ID = "capabilityOwnerId";
+ private static final String CAPABILITY_UID = "capabilityUid";
+ private static final String CAPABILITY_NAME = "capabilityName";
+ private static final String REQUIREMENT_OWNER_ID = "requirementOwnerId";
+ private static final String REQUIREMENT_UID = "requirementUid";
+ private static final String REQUIREMENT_NAME = "requirementName";
+ private static final String RELATIONSHIP_TYPE = "relationshipType";
private static Map<String, MapListCapabilityDataDefinition> fulfilledCapability;
private static Map<String, MapListRequirementDataDefinition> fulfilledRequirement;
@@ -92,19 +105,15 @@ public class NodeTemplateOperationTest extends ModelTestBase {
private static RequirementDataDefinition requirement;
private static RequirementCapabilityRelDef relation;
- @InjectMocks
- private static NodeTemplateOperation operation;
-
- @Mock
- private static JanusGraphDao janusGraphDao;
+ private final JanusGraphDao janusGraphDao = Mockito.mock(JanusGraphDao.class);
+ private final TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
- @Mock
- private static TopologyTemplateOperation topologyTemplateOperation;
+ @InjectMocks
+ private NodeTemplateOperation operation;
- @BeforeClass
- public static void setup() {
+ @BeforeAll
+ public void setup() {
init();
- janusGraphDao = Mockito.mock(JanusGraphDao.class);
operation = new NodeTemplateOperation();
operation.setJanusGraphDao(janusGraphDao);
buildDataDefinition();
@@ -117,7 +126,7 @@ public class NodeTemplateOperationTest extends ModelTestBase {
}
@Test
- public void testGetFulfilledCapabilityByRelationSuccess(){
+ void testGetFulfilledCapabilityByRelationSuccess() {
GraphVertex vertex = Mockito.mock(GraphVertex.class);
Either<GraphVertex, JanusGraphOperationStatus> vertexRes = Either.left(vertex);
when(janusGraphDao.getVertexById(eq(COMPONENT_ID), eq(JsonParseFlagEnum.ParseAll))).thenReturn(vertexRes);
@@ -132,7 +141,7 @@ public class NodeTemplateOperationTest extends ModelTestBase {
}
@Test
- public void testGetFulfilledRequirementByRelationSuccess(){
+ void testGetFulfilledRequirementByRelationSuccess() {
GraphVertex vertex = Mockito.mock(GraphVertex.class);
Either<GraphVertex, JanusGraphOperationStatus> vertexRes = Either.left(vertex);
when(janusGraphDao.getVertexById(eq(COMPONENT_ID), eq(JsonParseFlagEnum.ParseAll))).thenReturn(vertexRes);
@@ -147,7 +156,7 @@ public class NodeTemplateOperationTest extends ModelTestBase {
}
@Test
- public void testGetFulfilledCapabilityByRelationNotFoundFailure(){
+ void testGetFulfilledCapabilityByRelationNotFoundFailure() {
GraphVertex vertex = Mockito.mock(GraphVertex.class);
Either<GraphVertex, JanusGraphOperationStatus> vertexRes = Either.left(vertex);
when(janusGraphDao.getVertexById(eq(COMPONENT_ID), eq(JsonParseFlagEnum.ParseAll))).thenReturn(vertexRes);
@@ -157,11 +166,11 @@ public class NodeTemplateOperationTest extends ModelTestBase {
when(janusGraphDao.getChildVertex(eq(vertex), eq(EdgeLabelEnum.FULLFILLED_CAPABILITIES), eq(JsonParseFlagEnum.ParseJson))).thenReturn(childVertexRes);
Either<CapabilityDataDefinition, StorageOperationStatus> result = operation.getFulfilledCapabilityByRelation(COMPONENT_ID, TO_INSTANCE_ID, relation, this::isBelongingCapability);
assertTrue(result.isRight());
- assertSame(result.right().value(), StorageOperationStatus.NOT_FOUND);
+ assertSame(StorageOperationStatus.NOT_FOUND, result.right().value());
}
@Test
- public void testGetFulfilledRequirementByRelationNotFoundFailure(){
+ void testGetFulfilledRequirementByRelationNotFoundFailure() {
GraphVertex vertex = Mockito.mock(GraphVertex.class);
Either<GraphVertex, JanusGraphOperationStatus> vertexRes = Either.left(vertex);
when(janusGraphDao.getVertexById(eq(COMPONENT_ID), eq(JsonParseFlagEnum.ParseAll))).thenReturn(vertexRes);
@@ -171,11 +180,11 @@ public class NodeTemplateOperationTest extends ModelTestBase {
when(janusGraphDao.getChildVertex(eq(vertex), eq(EdgeLabelEnum.FULLFILLED_REQUIREMENTS), eq(JsonParseFlagEnum.ParseJson))).thenReturn(childVertexRes);
Either<RequirementDataDefinition, StorageOperationStatus> result = operation.getFulfilledRequirementByRelation(COMPONENT_ID, FROM_INSTANCE_ID, relation, this::isBelongingRequirement);
assertTrue(result.isRight());
- assertSame(result.right().value(), StorageOperationStatus.NOT_FOUND);
+ assertSame(StorageOperationStatus.NOT_FOUND, result.right().value());
}
@Test
- public void testUpdateCIMetadataOfTopologyTemplate() {
+ void testUpdateCIMetadataOfTopologyTemplate() {
Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> result;
String id = "id";
TopologyTemplate container = new TopologyTemplate();
@@ -194,16 +203,16 @@ public class NodeTemplateOperationTest extends ModelTestBase {
assertTrue(result.isLeft());
}
- @Test
- public void testGetDefaultHeatTimeout() {
- Integer result;
+ @Test
+ void testGetDefaultHeatTimeout() {
+ Integer result;
- // default test
- result = NodeTemplateOperation.getDefaultHeatTimeout();
+ // default test
+ result = NodeTemplateOperation.getDefaultHeatTimeout();
}
- @Test
- public void testPrepareInstDeploymentArtifactPerInstance() {
+ @Test
+ void testPrepareInstDeploymentArtifactPerInstance() {
Map<String, Object> deploymentResourceArtifacts = new HashMap<>();
Map<String, ArtifactDataDefinition> deploymentArtifacts = new HashMap<>();
ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
@@ -220,22 +229,22 @@ public class NodeTemplateOperationTest extends ModelTestBase {
MapArtifactDataDefinition result;
result = operation.prepareInstDeploymentArtifactPerInstance(deploymentArtifacts, componentInstanceId, user,
- envType);
- Assert.assertEquals(2, result.getMapToscaDataDefinition().size());
+ envType);
+ assertEquals(2, result.getMapToscaDataDefinition().size());
}
- @Test
- public void testCreateCapPropertyKey() throws Exception {
- String key = "";
- String instanceId = "";
- String result;
+ @Test
+ void testCreateCapPropertyKey() throws Exception {
+ String key = "";
+ String instanceId = "";
+ String result;
- // default test
- result = NodeTemplateOperation.createCapPropertyKey(key, instanceId);
- }
+ // default test
+ result = NodeTemplateOperation.createCapPropertyKey(key, instanceId);
+ }
- @Test
- public void testPrepareCalculatedCapabiltyForNodeType() {
+ @Test
+ void testPrepareCalculatedCapabiltyForNodeType() {
Map<String, ListCapabilityDataDefinition> capabilities = new HashMap<>();
ListCapabilityDataDefinition listCapDataDefinition = new ListCapabilityDataDefinition();
List<CapabilityDataDefinition> listToscaDataDefinition = new ArrayList<>();
@@ -248,11 +257,11 @@ public class NodeTemplateOperationTest extends ModelTestBase {
MapListCapabilityDataDefinition result;
result = operation.prepareCalculatedCapabiltyForNodeType(capabilities, componentInstance);
- Assert.assertEquals(1, result.getMapToscaDataDefinition().size());
+ assertEquals(1, result.getMapToscaDataDefinition().size());
}
@Test
- public void testPrepareCalculatedReqForNodeType() {
+ void testPrepareCalculatedReqForNodeType() {
Map<String, ListRequirementDataDefinition> requirements = new HashMap<>();
ListRequirementDataDefinition listReqDataDef = new ListRequirementDataDefinition();
List<RequirementDataDefinition> listToscaDataDefinition = new ArrayList<>();
@@ -265,43 +274,43 @@ public class NodeTemplateOperationTest extends ModelTestBase {
MapListRequirementDataDefinition result;
result = operation.prepareCalculatedRequirementForNodeType(requirements, componentInstance);
- Assert.assertEquals(1, result.getMapToscaDataDefinition().size());
+ assertEquals(1, result.getMapToscaDataDefinition().size());
}
- @Test
- public void testAddGroupInstancesToComponentInstance() throws Exception {
- Component containerComponent = null;
- ComponentInstanceDataDefinition componentInstance = null;
- List<GroupDefinition> groups = null;
- Map<String, List<ArtifactDefinition>> groupInstancesArtifacts = null;
- StorageOperationStatus result;
-
- result = operation.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groups,
- groupInstancesArtifacts);
- Assert.assertEquals(StorageOperationStatus.OK, result);
- }
+ @Test
+ void testAddGroupInstancesToComponentInstance() throws Exception {
+ Component containerComponent = null;
+ ComponentInstanceDataDefinition componentInstance = null;
+ List<GroupDefinition> groups = null;
+ Map<String, List<ArtifactDefinition>> groupInstancesArtifacts = null;
+ StorageOperationStatus result;
+
+ result = operation.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groups,
+ groupInstancesArtifacts);
+ assertEquals(StorageOperationStatus.OK, result);
+ }
- @Test
- public void testGenerateCustomizationUUIDOnInstanceGroup() throws Exception {
- String componentId = "";
- String instanceId = "";
- List<String> groupInstances = null;
- StorageOperationStatus result;
+ @Test
+ void testGenerateCustomizationUUIDOnInstanceGroup() throws Exception {
+ String componentId = "";
+ String instanceId = "";
+ List<String> groupInstances = null;
+ StorageOperationStatus result;
- result = operation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances);
- Assert.assertEquals(StorageOperationStatus.OK, result);
- }
-
- @Test
- public void testUpdateComponentInstanceRequirement() {
+ result = operation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances);
+ assertEquals(StorageOperationStatus.OK, result);
+ }
+
+ @Test
+ void testUpdateComponentInstanceRequirement() {
String componentId = "";
String componentInstanceId = "requirementOwnerId";
-
+
GraphVertex graphVertex = new GraphVertex();
graphVertex.setUniqueId("uniqueId");
when(janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(graphVertex));
when(janusGraphDao.updateVertex(graphVertex)).thenReturn(Either.left(graphVertex));
-
+
MapListRequirementDataDefinition mapListRequirementDataDefinition = new MapListRequirementDataDefinition();
mapListRequirementDataDefinition.add(requirement.getCapability(), requirement);
Map<String, MapListRequirementDataDefinition> mapOfRequirements = new HashMap<>();
@@ -326,16 +335,108 @@ public class NodeTemplateOperationTest extends ModelTestBase {
}
};
String outId = (String) janusGraphDao
- .getProperty((JanusGraphVertex) outVertex, GraphPropertyEnum.UNIQUE_ID.getProperty());
+ .getProperty((JanusGraphVertex) outVertex, GraphPropertyEnum.UNIQUE_ID.getProperty());
when(janusGraphDao.getProperty(outVertex, GraphPropertyEnum.UNIQUE_ID.getProperty())).thenReturn("uniqueId");
when(janusGraphDao.updateVertex(childVertex)).thenReturn(Either.left(childVertex));
JanusGraphVertex janusGraphVertex = Mockito.mock(JanusGraphVertex.class);
childVertex.setVertex(janusGraphVertex);
when(janusGraphVertex.edges(Direction.IN, EdgeLabelEnum.CALCULATED_REQUIREMENTS.name())).thenReturn(edgeIterator);
-
- StorageOperationStatus result = operation.updateComponentInstanceRequirement(componentId, componentInstanceId, requirement);
- assertEquals(StorageOperationStatus.OK, result);
- }
+
+ StorageOperationStatus result = operation.updateComponentInstanceRequirement(componentId, componentInstanceId, requirement);
+ assertEquals(StorageOperationStatus.OK, result);
+ }
+
+ @Test
+ void test_addComponentInstanceOutput() {
+ final NodeTemplateOperation testInstance = Mockito.spy(new NodeTemplateOperation());
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+
+ final String componentInstanceId = "requirementOwnerId";
+
+ final ComponentInstanceOutput instanceOutput = new ComponentInstanceOutput();
+
+ doReturn(StorageOperationStatus.OK).when((BaseOperation) testInstance)
+ .addToscaDataDeepElementToToscaElement(eq(COMPONENT_ID), eq(EdgeLabelEnum.INST_OUTPUTS), eq(VertexTypeEnum.INST_OUTPUTS),
+ ArgumentMatchers.any(ComponentInstanceOutput.class), ArgumentMatchers.anyList(), eq(JsonPresentationFields.NAME));
+
+ final StorageOperationStatus result = testInstance.addComponentInstanceOutput(component, componentInstanceId, instanceOutput);
+ assertNotNull(result);
+ assertEquals(StorageOperationStatus.OK, result);
+ verify((BaseOperation) testInstance, times(1))
+ .addToscaDataDeepElementToToscaElement(eq(COMPONENT_ID), eq(EdgeLabelEnum.INST_OUTPUTS), eq(VertexTypeEnum.INST_OUTPUTS),
+ ArgumentMatchers.any(ComponentInstanceOutput.class), ArgumentMatchers.anyList(), eq(JsonPresentationFields.NAME));
+ }
+
+ @Test
+ void test_updateComponentInstanceAttributes() {
+ final NodeTemplateOperation testInstance = Mockito.spy(new NodeTemplateOperation());
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+
+ final String componentInstanceId = "requirementOwnerId";
+
+ final ComponentInstanceAttribute instanceAttribute = new ComponentInstanceAttribute();
+ final List<ComponentInstanceAttribute> attributes = new ArrayList<>();
+ attributes.add(instanceAttribute);
+
+ doReturn(StorageOperationStatus.OK).when((BaseOperation) testInstance)
+ .updateToscaDataDeepElementsOfToscaElement(eq(COMPONENT_ID), eq(EdgeLabelEnum.INST_ATTRIBUTES), eq(VertexTypeEnum.INST_ATTRIBUTES),
+ eq(attributes), ArgumentMatchers.anyList(), eq(JsonPresentationFields.NAME));
+
+ final StorageOperationStatus result = testInstance.updateComponentInstanceAttributes(component, componentInstanceId, attributes);
+ assertNotNull(result);
+ assertEquals(StorageOperationStatus.OK, result);
+ verify((BaseOperation) testInstance, times(1))
+ .updateToscaDataDeepElementsOfToscaElement(eq(COMPONENT_ID), eq(EdgeLabelEnum.INST_ATTRIBUTES), eq(VertexTypeEnum.INST_ATTRIBUTES),
+ eq(attributes), ArgumentMatchers.anyList(), eq(JsonPresentationFields.NAME));
+ }
+
+ @Test
+ void test_updateComponentInstanceAttribute() {
+ final NodeTemplateOperation testInstance = Mockito.spy(new NodeTemplateOperation());
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+
+ final String componentInstanceId = "requirementOwnerId";
+
+ final ComponentInstanceAttribute instanceAttribute = new ComponentInstanceAttribute();
+
+ doReturn(StorageOperationStatus.OK).when((BaseOperation) testInstance)
+ .updateToscaDataDeepElementOfToscaElement(eq(COMPONENT_ID), eq(EdgeLabelEnum.INST_ATTRIBUTES), eq(VertexTypeEnum.INST_ATTRIBUTES),
+ eq(instanceAttribute), ArgumentMatchers.anyList(), eq(JsonPresentationFields.NAME));
+
+ final StorageOperationStatus result = testInstance.updateComponentInstanceAttribute(component, componentInstanceId, instanceAttribute);
+ assertNotNull(result);
+ assertEquals(StorageOperationStatus.OK, result);
+ verify((BaseOperation) testInstance, times(1))
+ .updateToscaDataDeepElementOfToscaElement(eq(COMPONENT_ID), eq(EdgeLabelEnum.INST_ATTRIBUTES), eq(VertexTypeEnum.INST_ATTRIBUTES),
+ eq(instanceAttribute), ArgumentMatchers.anyList(), eq(JsonPresentationFields.NAME));
+ }
+
+ @Test
+ void test_updateComponentInstanceOutputs() {
+ final NodeTemplateOperation testInstance = Mockito.spy(new NodeTemplateOperation());
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+
+ final String componentInstanceId = "requirementOwnerId";
+
+ List<ComponentInstanceOutput> componentInstanceOutputList = new ArrayList<>();
+ ComponentInstanceOutput instanceOutput = new ComponentInstanceOutput();
+ componentInstanceOutputList.add(instanceOutput);
+
+ doReturn(StorageOperationStatus.OK).when((BaseOperation) testInstance)
+ .updateToscaDataDeepElementsOfToscaElement(eq(COMPONENT_ID), eq(EdgeLabelEnum.INST_OUTPUTS), eq(VertexTypeEnum.INST_OUTPUTS),
+ eq(componentInstanceOutputList), ArgumentMatchers.anyList(), eq(JsonPresentationFields.NAME));
+
+ final StorageOperationStatus result = testInstance.updateComponentInstanceOutputs(component, componentInstanceId, componentInstanceOutputList);
+ assertNotNull(result);
+ assertEquals(StorageOperationStatus.OK, result);
+ verify((BaseOperation) testInstance, times(1))
+ .updateToscaDataDeepElementsOfToscaElement(eq(COMPONENT_ID), eq(EdgeLabelEnum.INST_OUTPUTS), eq(VertexTypeEnum.INST_OUTPUTS),
+ eq(componentInstanceOutputList), ArgumentMatchers.anyList(), eq(JsonPresentationFields.NAME));
+ }
private ComponentInstance createCompInstance() {
ComponentInstance componentInstance = new ComponentInstance();
@@ -345,6 +446,7 @@ public class NodeTemplateOperationTest extends ModelTestBase {
componentInstance.setName(id);
return componentInstance;
}
+
private static void buildRequirementDataDefinition() {
buildRequirement();
fulfilledRequirement = new HashMap<>();
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java
index 436af94c1c..dc5e2fd5ea 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java
@@ -55,6 +55,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -148,6 +151,25 @@ public class TopologyTemplateOperationTest {
}
@Test
+ public void testSetOutputsFromGraph() {
+ final GraphVertex containerVertex = new GraphVertex();
+ final ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreOutputs(false);
+ final String componentName = "componentName";
+ final String componentId = UniqueIdBuilder.buildResourceUniqueId();
+ containerVertex.setVertex(Mockito.mock(JanusGraphVertex.class));
+ containerVertex.setJsonMetadataField(JsonPresentationFields.NAME, componentName);
+ containerVertex.setUniqueId(componentId);
+ containerVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ doReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR)).when(janusGraphDao)
+ .getChildVertex(any(GraphVertex.class), any(EdgeLabelEnum.class), any(JsonParseFlagEnum.class));
+ final Either<ToscaElement, StorageOperationStatus> storageOperationStatus
+ = topologyTemplateOperation.getToscaElement(containerVertex, filter);
+ assertThat(storageOperationStatus).isEqualTo(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ verify(janusGraphDao, times(1)).getChildVertex(any(GraphVertex.class), any(EdgeLabelEnum.class), any(JsonParseFlagEnum.class));
+ }
+
+ @Test
public void testUpdateDistributionStatus() {
Either<GraphVertex, StorageOperationStatus> result;
String uniqueId = "uniqueId";
@@ -176,7 +198,7 @@ public class TopologyTemplateOperationTest {
JanusGraphOperationStatus.OK);
when(janusGraphDao.updateVertex(graphVertex)).thenReturn(Either.left(graphVertex));
result = topologyTemplateOperation.updateDistributionStatus(uniqueId, user, DistributionStatusEnum.DISTRIBUTED);
- assertThat(result.isLeft());
+ assertThat(result.isLeft()).isTrue();
}
@SuppressWarnings("unchecked")
@@ -195,7 +217,7 @@ public class TopologyTemplateOperationTest {
int counter = 0;
Either<GraphVertex, JanusGraphOperationStatus> toscaDataVertexRes = Either.right(
JanusGraphOperationStatus.NOT_FOUND);
- when(janusGraphDao.getChildVertex(eq(componentV), eq(EdgeLabelEnum.POLICIES), eq(JsonParseFlagEnum.ParseJson))).thenReturn(toscaDataVertexRes);
+ when(janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.POLICIES, JsonParseFlagEnum.ParseJson)).thenReturn(toscaDataVertexRes);
Either<GraphVertex, JanusGraphOperationStatus> createVertex = Either.left(dataV);
when(janusGraphDao.createVertex(any(GraphVertex.class))).thenReturn(createVertex);
when(janusGraphDao.createEdge(any(JanusGraphVertex.class), any(JanusGraphVertex.class), any(EdgeLabelEnum.class), any(HashMap.class))).thenReturn(status);
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
index 971f4f79ab..621b275a67 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
@@ -48,6 +48,7 @@ import org.openecomp.sdc.be.dao.jsongraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -56,9 +57,13 @@ import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
+import org.openecomp.sdc.be.model.ComponentInstanceOutput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.ComponentParametersView;
@@ -90,8 +95,12 @@ import java.util.Collections;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -122,7 +131,7 @@ public class ToscaOperationFacadeTest {
private TopologyTemplateOperation topologyTemplateOperationMock;
@Mock
- private NodeTypeOperation nodeTypeOperation;
+ private NodeTypeOperation nodeTypeOperationMock;
@Mock
private NodeTemplateOperation nodeTemplateOperationMock;
@@ -369,7 +378,7 @@ public class ToscaOperationFacadeTest {
when(janusGraphDaoMock.getVertexById(id, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(graphVertex));
when(janusGraphDaoMock.getParentVertex(graphVertex, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(graphVertex));
when(topologyTemplateOperationMock.deleteToscaElement(graphVertex)).thenReturn(Either.left(toscaElement));
- when(nodeTypeOperation.createToscaElement(any(ToscaElement.class))).thenReturn(Either.left(nodeType));
+ when(nodeTypeOperationMock.createToscaElement(any(ToscaElement.class))).thenReturn(Either.left(nodeType));
when(janusGraphDaoMock.getVertexById(null, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(graphVertex));
when(janusGraphDaoMock.createEdge(graphVertex, graphVertex, EdgeLabelEnum.VERSION, null)).thenReturn(
JanusGraphOperationStatus.OK);
@@ -397,7 +406,7 @@ public class ToscaOperationFacadeTest {
component.setUniqueId(id);
GraphVertex graphVertex = getTopologyTemplateVertex();
when(janusGraphDaoMock.getVertexById(id, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(graphVertex));
- when(nodeTypeOperation.markComponentToDelete(graphVertex)).thenReturn(Either.left(graphVertex));
+ when(nodeTypeOperationMock.markComponentToDelete(graphVertex)).thenReturn(Either.left(graphVertex));
result = testInstance.markComponentToDelete(component);
assertEquals(result, StorageOperationStatus.OK);
}
@@ -484,7 +493,8 @@ public class ToscaOperationFacadeTest {
List<ToscaElement> toscaEleList = new ArrayList<>();
ToscaElement toscaElement = getToscaElementForTest();
toscaEleList.add(toscaElement);
- when(nodeTypeOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType)).thenReturn(Either.left(toscaEleList));
+ when(nodeTypeOperationMock.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType))
+ .thenReturn(Either.left(toscaEleList));
result = testInstance.getFollowed(userId, lifecycleStates, lastStateStates, componentType);
assertTrue(result.isLeft());
assertEquals(1, result.left().value().size());
@@ -806,11 +816,226 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void associateRequirementsToServiceSuccessTest(){
+ public void associateRequirementsToServiceSuccessTest() {
StorageOperationStatus result = associateRequirementsToServiceWithStatus(StorageOperationStatus.OK);
assertTrue(result == StorageOperationStatus.OK);
}
+ @Test
+ public void test_addOutputsToComponent() {
+ final GraphVertex graphVertex = getTopologyTemplateVertex();
+ final String componentId = "componentId";
+
+ doReturn(Either.left(graphVertex)).when(janusGraphDaoMock).getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ doReturn(StorageOperationStatus.OK).when(topologyTemplateOperationMock)
+ .addToscaDataToToscaElement(
+ any(GraphVertex.class), eq(EdgeLabelEnum.OUTPUTS), eq(VertexTypeEnum.OUTPUTS), anyMap(), eq(JsonPresentationFields.NAME));
+
+ final Map<String, OutputDefinition> outputs = new HashMap<>();
+ final OutputDefinition outputDefinition = new OutputDefinition();
+ outputs.put("mock", outputDefinition);
+ final Either<List<OutputDefinition>, StorageOperationStatus> result = testInstance.addOutputsToComponent(outputs, componentId);
+ assertNotNull(result);
+ assertTrue(result.isLeft());
+ assertFalse(result.left().value().isEmpty());
+ assertThat(result.left().value().get(0)).isInstanceOf(OutputDefinition.class);
+ verify(janusGraphDaoMock, times(1)).getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ verify(topologyTemplateOperationMock, times(1)).addToscaDataToToscaElement(
+ any(GraphVertex.class), eq(EdgeLabelEnum.OUTPUTS), eq(VertexTypeEnum.OUTPUTS), anyMap(), eq(JsonPresentationFields.NAME));
+ }
+
+ @Test
+ public void test_addComponentInstanceOutputsToComponent_updateComponentInstanceOutput() {
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+ final Map<String, List<ComponentInstanceOutput>> map = new HashMap<>();
+ final List<ComponentInstanceOutput> componentInstanceOutputList = new ArrayList<>();
+ final ComponentInstanceOutput componentInstanceOutput = new ComponentInstanceOutput();
+ componentInstanceOutput.setComponentInstanceId(COMPONENT_ID);
+ componentInstanceOutput.setComponentInstanceName(COMPONENT_ID);
+ componentInstanceOutput.setName(COMPONENT_ID);
+ componentInstanceOutputList.add(componentInstanceOutput);
+ map.put("mock", componentInstanceOutputList);
+ component.setComponentInstancesOutputs(map);
+
+ doReturn(StorageOperationStatus.OK).when(nodeTemplateOperationMock)
+ .updateComponentInstanceOutput(any(Component.class), anyString(), any(ComponentInstanceOutput.class));
+
+ final Either<Map<String, List<ComponentInstanceOutput>>, StorageOperationStatus> result
+ = testInstance.addComponentInstanceOutputsToComponent(component, map);
+ assertNotNull(result);
+ assertTrue(result.isLeft());
+ assertFalse(result.left().value().isEmpty());
+ assertSame(result.left().value(), map);
+ verify(nodeTemplateOperationMock, times(1))
+ .updateComponentInstanceOutput(any(Component.class), anyString(), any(ComponentInstanceOutput.class));
+
+ }
+
+ @Test
+ public void test_addComponentInstanceOutputsToComponent_addComponentInstanceOutput() {
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+ Map<String, List<ComponentInstanceOutput>> map = new HashMap<>();
+ List<ComponentInstanceOutput> componentInstanceOutputList = new ArrayList<>();
+ ComponentInstanceOutput componentInstanceOutput = new ComponentInstanceOutput();
+ componentInstanceOutput.setComponentInstanceId(COMPONENT_ID);
+ componentInstanceOutput.setComponentInstanceName(COMPONENT_ID);
+ componentInstanceOutput.setName(COMPONENT_ID);
+ componentInstanceOutputList.add(componentInstanceOutput);
+ map.put("mock", componentInstanceOutputList);
+ component.setComponentInstancesOutputs(map);
+
+ map = new HashMap<>();
+ componentInstanceOutputList = new ArrayList<>();
+ componentInstanceOutput = new ComponentInstanceOutput();
+ componentInstanceOutput.setComponentInstanceId("mock");
+ componentInstanceOutput.setComponentInstanceName("mock");
+ componentInstanceOutput.setName("mock");
+ componentInstanceOutputList.add(componentInstanceOutput);
+ map.put("mock", componentInstanceOutputList);
+
+ final Either<Map<String, List<ComponentInstanceOutput>>, StorageOperationStatus> result = testInstance
+ .addComponentInstanceOutputsToComponent(component, map);
+ assertNotNull(result);
+ assertTrue(result.isRight());
+ }
+
+ @Test
+ public void test_addComponentInstanceAttributesToComponent() {
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+ Map<String, List<ComponentInstanceAttribute>> map = new HashMap<>();
+ List<ComponentInstanceAttribute> componentInstanceOutputList = new ArrayList<>();
+ ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute();
+ componentInstanceAttribute.setComponentInstanceId(COMPONENT_ID);
+ componentInstanceAttribute.setUniqueId(COMPONENT_ID);
+ componentInstanceOutputList.add(componentInstanceAttribute);
+ map.put("mock", componentInstanceOutputList);
+ component.setComponentInstancesAttributes(map);
+
+ doReturn(StorageOperationStatus.OK).when(nodeTemplateOperationMock)
+ .updateComponentInstanceAttribute(any(Component.class), anyString(), any(ComponentInstanceAttribute.class));
+
+ final Either<Map<String, List<ComponentInstanceAttribute>>, StorageOperationStatus> result
+ = testInstance.addComponentInstanceAttributesToComponent(component, map);
+
+ assertNotNull(result);
+ assertTrue(result.isLeft());
+ assertFalse(result.left().value().isEmpty());
+ assertSame(result.left().value(), map);
+ verify(nodeTemplateOperationMock, times(1))
+ .updateComponentInstanceAttribute(any(Component.class), anyString(), any(ComponentInstanceAttribute.class));
+ }
+
+ @Test
+ public void test_updateAttributeOfComponent_success() {
+ final GraphVertex graphVertex = getTopologyTemplateVertex();
+ final String componentId = "componentId";
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+ doReturn(StorageOperationStatus.OK).when(nodeTypeOperationMock).updateToscaDataOfToscaElement(
+ anyString(), eq(EdgeLabelEnum.ATTRIBUTES), eq(VertexTypeEnum.ATTRIBUTES), any(AttributeDefinition.class),
+ eq(JsonPresentationFields.NAME));
+ doReturn(Either.left(graphVertex)).when(janusGraphDaoMock).getVertexById(eq(componentId), any(JsonParseFlagEnum.class));
+
+ final ToscaElement toscaElement = getToscaElementForTest();
+ final Map<String, AttributeDataDefinition> attributes = new HashMap<>();
+ final AttributeDefinition attributeDefinition = new AttributeDefinition();
+ attributeDefinition.setName("mock");
+ attributes.put("mock", attributeDefinition);
+ toscaElement.setAttributes(attributes);
+ doReturn(Either.left(toscaElement)).when(topologyTemplateOperationMock)
+ .getToscaElement(ArgumentMatchers.eq(graphVertex), any(ComponentParametersView.class));
+
+ final Either<AttributeDefinition, StorageOperationStatus> result
+ = testInstance.updateAttributeOfComponent(component, attributeDefinition);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void test_updateAttributeOfComponent_isNotPresent() {
+ final GraphVertex graphVertex = getTopologyTemplateVertex();
+ final String componentId = "componentId";
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+ doReturn(StorageOperationStatus.OK).when(nodeTypeOperationMock).updateToscaDataOfToscaElement(
+ anyString(), eq(EdgeLabelEnum.ATTRIBUTES), eq(VertexTypeEnum.ATTRIBUTES), any(AttributeDefinition.class),
+ eq(JsonPresentationFields.NAME));
+ doReturn(Either.left(graphVertex)).when(janusGraphDaoMock).getVertexById(eq(componentId), any(JsonParseFlagEnum.class));
+
+ final ToscaElement toscaElement = getToscaElementForTest();
+ final Map<String, AttributeDataDefinition> attributes = new HashMap<>();
+ final AttributeDefinition attributeDefinition = new AttributeDefinition();
+ attributeDefinition.setName("mock");
+ attributes.put("mock", attributeDefinition);
+ toscaElement.setAttributes(attributes);
+ doReturn(Either.left(toscaElement)).when(topologyTemplateOperationMock)
+ .getToscaElement(ArgumentMatchers.eq(graphVertex), any(ComponentParametersView.class));
+
+ final AttributeDefinition attributeDefinitionOneMore = new AttributeDefinition();
+ attributeDefinitionOneMore.setName("Anothermock");
+
+ final Either<AttributeDefinition, StorageOperationStatus> result
+ = testInstance.updateAttributeOfComponent(component, attributeDefinitionOneMore);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void test_updateComponentInstanceAttributes() {
+ final GraphVertex graphVertex = getTopologyTemplateVertex();
+ final String componentId = "componentId";
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+
+ final List<ComponentInstanceAttribute> attributes = new ArrayList<>();
+ final ComponentInstanceAttribute attributeDefinition = new ComponentInstanceAttribute();
+ attributeDefinition.setName("mock");
+ attributes.add(attributeDefinition);
+
+ doReturn(StorageOperationStatus.OK).when(nodeTemplateOperationMock).updateComponentInstanceAttributes(component, componentId, attributes);
+
+ final StorageOperationStatus result = testInstance.updateComponentInstanceAttributes(component, componentId, attributes);
+ assertNotNull(result);
+ assertEquals(StorageOperationStatus.OK, result);
+ verify(nodeTemplateOperationMock, times(1)).updateComponentInstanceAttributes(component, componentId, attributes);
+ }
+
+ @Test
+ public void test_updateComponentInstanceOutputs() {
+ final GraphVertex graphVertex = getTopologyTemplateVertex();
+ final String componentId = "componentId";
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+
+ final List<ComponentInstanceOutput> list = new ArrayList<>();
+ final ComponentInstanceOutput output = new ComponentInstanceOutput();
+ output.setName("mock");
+ list.add(output);
+
+ doReturn(StorageOperationStatus.OK).when(nodeTemplateOperationMock).updateComponentInstanceOutputs(component, componentId, list);
+
+ final StorageOperationStatus result = testInstance.updateComponentInstanceOutputs(component, componentId, list);
+ assertNotNull(result);
+ assertEquals(StorageOperationStatus.OK, result);
+ verify(nodeTemplateOperationMock, times(1)).updateComponentInstanceOutputs(component, componentId, list);
+ }
+
+ @Test
+ public void test_deleteOutputOfResource() {
+ final Component component = new Resource();
+ component.setUniqueId(COMPONENT_ID);
+
+ doReturn(StorageOperationStatus.OK).when(nodeTypeOperationMock)
+ .deleteToscaDataElement(anyString(), eq(EdgeLabelEnum.OUTPUTS), eq(VertexTypeEnum.OUTPUTS), anyString(), eq(JsonPresentationFields.NAME));
+
+ final StorageOperationStatus result = testInstance.deleteOutputOfResource(component, "mock");
+ assertNotNull(result);
+ assertEquals(StorageOperationStatus.OK, result);
+ verify(nodeTypeOperationMock, times(1))
+ .deleteToscaDataElement(anyString(), eq(EdgeLabelEnum.OUTPUTS), eq(VertexTypeEnum.OUTPUTS), anyString(), eq(JsonPresentationFields.NAME));
+ }
+
private StorageOperationStatus associateRequirementsToServiceWithStatus(StorageOperationStatus status) {
Map<String, ListRequirementDataDefinition> requirementsMap = new HashedMap();
String componentId = "componentid";
@@ -819,7 +1044,7 @@ public class ToscaOperationFacadeTest {
requirementsMap.put("requirements1", listRequirementDataDefinition1);
GraphVertex vertex;
- if(status == StorageOperationStatus.OK){
+ if (status == StorageOperationStatus.OK) {
vertex = getTopologyTemplateVertex();
} else {
vertex = getNodeTypeVertex();
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java
index 740d148a79..81635e20e0 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java
@@ -29,14 +29,25 @@
*/
package org.openecomp.sdc.be.model.jsonjanusgraph.utils;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.AttributeDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceOutput;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.Component;
@@ -47,6 +58,8 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -107,8 +120,7 @@ public class ModelConverterTest {
}
@Test
- public void testConvertFromToscaElementResourceType()
- {
+ public void testConvertFromToscaElementResourceType() {
TopologyTemplate topologyTemplate = new TopologyTemplate();
topologyTemplate.setComponentType(ComponentTypeEnum.RESOURCE);
topologyTemplate.setResourceType(ResourceTypeEnum.PNF);
@@ -117,8 +129,44 @@ public class ModelConverterTest {
}
@Test
- public void testIsAtomicComponent()
- {
+ public void testConvertFromToscaElementResourceOutputs() {
+ final TopologyTemplate topologyTemplate = new TopologyTemplate();
+ topologyTemplate.setComponentType(ComponentTypeEnum.RESOURCE);
+ final OutputDefinition outputDefinition = new OutputDefinition();
+ final Map<String, AttributeDataDefinition> map = new HashMap<>();
+ map.put("mock", outputDefinition);
+ topologyTemplate.setOutputs(map);
+ final Resource resource = test.convertFromToscaElement(topologyTemplate);
+ assertNotNull(resource.getOutputs());
+ assertFalse(resource.getOutputs().isEmpty());
+ }
+
+ @Test
+ public void testConvertFromToscaElementResourceComponentInstancesOutputs() {
+ final TopologyTemplate topologyTemplate = new TopologyTemplate();
+ topologyTemplate.setComponentType(ComponentTypeEnum.RESOURCE);
+
+ final Map<String, MapAttributesDataDefinition> instOutputs = new HashMap<>();
+ final MapAttributesDataDefinition mapAttributesDataDefinition = new MapAttributesDataDefinition();
+ final AttributeDefinition attributeDefinition = new AttributeDefinition();
+ final Map<String, AttributeDataDefinition> mapToscaDataDefinition = new HashMap<>();
+ mapToscaDataDefinition.put("mock", attributeDefinition);
+ mapAttributesDataDefinition.setMapToscaDataDefinition(mapToscaDataDefinition);
+ instOutputs.put("mock", mapAttributesDataDefinition);
+ topologyTemplate.setInstOutputs(instOutputs);
+
+ final Map<String, ComponentInstanceDataDefinition> componentInstanceDataDefinitionMap = new HashMap<>();
+ componentInstanceDataDefinitionMap.put("mock", new ComponentInstance());
+ topologyTemplate.setComponentInstances(componentInstanceDataDefinitionMap);
+
+ final Resource resource = test.convertFromToscaElement(topologyTemplate);
+ assertNotNull(resource);
+ assertNotNull(resource.getComponentInstancesOutputs());
+ assertFalse(resource.getComponentInstancesOutputs().isEmpty());
+ }
+
+ @Test
+ public void testIsAtomicComponent() {
Resource component = new Resource();
component.setComponentType(ComponentTypeEnum.RESOURCE);
boolean result = test.isAtomicComponent(component);