aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test/java
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2018-03-04 14:53:33 +0200
committerMichael Lando <ml636r@att.com>2018-03-07 13:19:05 +0000
commita5445100050e49e83f73424198d73cd72d672a4d (patch)
treecacf4df817df31be23e4e790d1dda857bdae061e /catalog-model/src/test/java
parent51157f92c21976cba4914c378aaa3cba49826931 (diff)
Sync Integ to Master
Change-Id: I71e3acc26fa612127756ac04073a522b9cc6cd74 Issue-ID: SDC-977 Signed-off-by: Gitelman, Tal (tg851x) <tg851x@intl.att.com>
Diffstat (limited to 'catalog-model/src/test/java')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java9
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ExternalReferencesOperationTest.java178
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java1
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperationIntegrationTest.java133
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperationTest.java93
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationCapabilityIntegrationTest.java199
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationIntegrationTest.java199
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java125
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperationTest.java6
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadePoliciesTest.java144
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java118
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/GraphTestUtils.java7
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java346
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperationTest.java12
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java291
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java25
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java460
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java16
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverterTest.java73
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/MapValidatorTest.java16
20 files changed, 2182 insertions, 269 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java
new file mode 100644
index 0000000000..1215b5fc6f
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java
@@ -0,0 +1,9 @@
+package org.openecomp.sdc.be.model.config;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ComponentScan({"org.openecomp.sdc.be.model.jsontitan.operations","org.openecomp.sdc.be.model.jsontitan.utils"})
+public class ModelOperationsSpringConfig {
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ExternalReferencesOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ExternalReferencesOperationTest.java
new file mode 100644
index 0000000000..c0ba256957
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ExternalReferencesOperationTest.java
@@ -0,0 +1,178 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+import fj.data.Either;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.MapComponentInstanceExternalRefs;
+import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.jsontitan.utils.GraphTestUtils;
+import org.openecomp.sdc.be.model.jsontitan.utils.IdMapper;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by yavivi on 26/01/2018.
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:application-context-test.xml")
+public class ExternalReferencesOperationTest extends ModelTestBase {
+
+ @Resource
+ private ExternalReferencesOperation externalReferenceOperation;
+
+ @Resource
+ private TitanDao titanDao;
+
+ private boolean isInitialized;
+
+ private GraphVertex serviceVertex;
+
+ private String serviceVertexUuid;
+ private static final String COMPONENT_ID = "ci-MyComponentName";
+
+ private static final String MONITORING_OBJECT_TYPE = "monitoring";
+ private static final String WORKFLOW_OBJECT_TYPE = "workflow";
+ private static final String REF_1 = "ref1";
+ private static final String REF_2 = "ref2";
+ private static final String REF_3 = "ref3";
+ private static final String REF_4 = "ref4";
+ private static final String REF_5 = "ref5";
+
+ //workflow
+ private static final String REF_6 = "ref6";
+
+ private IdMapper idMapper;
+
+ @BeforeClass
+ public static void initTest(){
+ ModelTestBase.init();
+ }
+
+ @Before
+ public void beforeTest() {
+ idMapper = Mockito.mock(IdMapper.class);
+ this.externalReferenceOperation.setIdMapper(idMapper);
+ when(idMapper.mapComponentNameToUniqueId(Mockito.anyString(), Mockito.any(GraphVertex.class))).thenReturn(COMPONENT_ID);
+ if (!isInitialized) {
+ GraphTestUtils.clearGraph(titanDao);
+ initGraphForTest();
+ isInitialized = true;
+ }
+ }
+
+ @Test
+ public void testAddComponentInstanceExternalRef(){
+ Either<String, ActionStatus> addResult = externalReferenceOperation.addExternalReference(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_4);
+ assertThat(addResult.isLeft()).isEqualTo(true);
+
+ //commit changes to titan
+ final TitanOperationStatus commit = this.titanDao.commit();
+ assertThat(commit).isEqualTo(TitanOperationStatus.OK);
+
+ assertThat(getServiceExternalRefs()).contains(REF_1, REF_2, REF_3, REF_4);
+ }
+
+ @Test
+ public void testGetComponentInstanceExternalRef(){
+ assertThat(externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE).left().value()).contains(REF_1, REF_2, REF_3, REF_5);
+ assertThat(externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, WORKFLOW_OBJECT_TYPE).left().value()).containsExactly(REF_6);
+ }
+
+ @Test
+ public void testGetComponentInstanceExternalRefForNonExistingObjectId(){
+ assertThat(externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE).left().value()).contains(REF_1, REF_2, REF_3, REF_5);
+ Either<List<String>, ActionStatus> getResult = externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, "FAKE_OBJECT_TYPE");
+ assertThat(getResult.left().value()).isEmpty();
+ }
+
+ @Test
+ public void testDeleteComponentInstanceExternalRef(){
+ //Test the precondition
+ assertThat(getServiceExternalRefs()).contains(REF_5);
+
+ //Remove REF 5
+ Either<String, ActionStatus> deleteStatus = externalReferenceOperation.deleteExternalReference(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_5);
+ assertThat(deleteStatus.isLeft()).isEqualTo(true);
+
+ //commit changes to titan
+ final TitanOperationStatus commit = this.titanDao.commit();
+ assertThat(commit).isEqualTo(TitanOperationStatus.OK);
+
+ //Check that ref does not exist anymore
+ assertThat(getServiceExternalRefs()).doesNotContain(REF_5).contains(REF_1, REF_2, REF_3);
+ }
+
+ @Test
+ public void testUpdateComponentInstanceExternalRef(){
+ //Test the precondition
+ assertThat(getServiceExternalRefs()).contains(REF_5).doesNotContain(REF_4);
+
+ //Update REF 5 with REF_4
+ Either<String, ActionStatus> updateResult = externalReferenceOperation.updateExternalReference(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_5, REF_4);
+
+ assertThat(updateResult.isLeft()).isEqualTo(true);
+
+ //commit changes to titan
+ final TitanOperationStatus commit = this.titanDao.commit();
+ assertThat(commit).isEqualTo(TitanOperationStatus.OK);
+
+ //Check that ref does not exist anymore
+ assertThat(getServiceExternalRefs()).doesNotContain(REF_5).contains(REF_1, REF_2, REF_3, REF_4);
+ }
+
+ private List<String> getServiceExternalRefs(){
+ //Get service vertex
+ final Either<GraphVertex, TitanOperationStatus> externalRefsVertexResult = this.titanDao.getChildVertex(this.serviceVertex, EdgeLabelEnum.EXTERNAL_REFS, JsonParseFlagEnum.ParseJson);
+ assertThat(externalRefsVertexResult.isLeft()).isEqualTo(true);
+
+ GraphVertex externalRefVertex = externalRefsVertexResult.left().value();
+
+ //Get the full map
+ Map<String, MapComponentInstanceExternalRefs> componentInstancesMap = (Map<String, MapComponentInstanceExternalRefs>) externalRefVertex.getJson();
+ assertThat(componentInstancesMap).isNotNull();
+
+ //Get Map of external refs by object type
+ final MapComponentInstanceExternalRefs mapComponentInstanceExternalRefs = componentInstancesMap.get(COMPONENT_ID);
+
+ //Get List of references
+ //final List<String> externalRefsByObjectType = mapComponentInstanceExternalRefs.externalRefsByObjectType(objectType);
+ final List<String> externalRefsByObjectType = mapComponentInstanceExternalRefs.getExternalRefsByObjectType(MONITORING_OBJECT_TYPE);
+
+ return externalRefsByObjectType;
+ }
+
+ private void initGraphForTest() {
+ //create a service and add 1 ref
+ this.serviceVertex = GraphTestUtils.createServiceVertex(titanDao, new HashMap<>());
+ this.serviceVertexUuid = this.serviceVertex.getUniqueId();
+
+ //monitoring references
+ externalReferenceOperation.addExternalReference(serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_1);
+ externalReferenceOperation.addExternalReference(serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_2);
+ externalReferenceOperation.addExternalReference(serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_3);
+ externalReferenceOperation.addExternalReference(serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_5);
+
+ //workflow references
+ externalReferenceOperation.addExternalReference(serviceVertexUuid, COMPONENT_ID, WORKFLOW_OBJECT_TYPE, REF_6);
+
+ final TitanOperationStatus commit = this.titanDao.commit();
+ assertThat(commit).isEqualTo(TitanOperationStatus.OK);
+ }
+} \ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java
index a1a257b893..71d54bca73 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java
@@ -25,7 +25,6 @@ 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.operations.api.StorageOperationStatus;
-
import com.google.common.collect.Lists;
import fj.data.Either;
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperationIntegrationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperationIntegrationTest.java
new file mode 100644
index 0000000000..d4188744d8
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperationIntegrationTest.java
@@ -0,0 +1,133 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+import fj.data.Either;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.sdc.be.dao.config.TitanSpringConfig;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.config.ModelOperationsSpringConfig;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.commons.collections.ListUtils.union;
+import static org.assertj.core.api.Assertions.assertThat;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {TitanSpringConfig.class, ModelOperationsSpringConfig.class})
+public class PolicyOperationIntegrationTest extends ModelTestBase {
+
+ private static final String CONTAINER_ID = "container";
+ public static final String POLICY_ID = "policy";
+ @Resource
+ private TopologyTemplateOperation topologyTemplateOperation;
+ @Resource
+ private TitanDao titanDao;
+ @Resource
+ private PolicyOperation policyOperation;
+ private PropertyDataDefinition prop1, prop2;
+ private PolicyDefinition policy;
+
+ @BeforeClass
+ public static void setupBeforeClass() {
+
+ ModelTestBase.init();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ prop1 = new PropertyDataDefinition();
+ prop1.setUniqueId("prop1");
+ prop1.setName("prop1");
+ prop1.setValue("prop1");
+
+ prop2 = new PropertyDataDefinition();
+ prop2.setUniqueId("prop2");
+ prop2.setName("prop2");
+ prop2.setValue("prop2");
+
+ policy = new PolicyDefinition();
+ policy.setUniqueId(POLICY_ID);
+
+ policy.setProperties(Arrays.asList(prop1, prop2));
+
+ GraphVertex resource = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID);
+ titanDao.createVertex(resource);
+ GraphVertex loadedResource = titanDao.getVertexById(CONTAINER_ID).left().value();
+ topologyTemplateOperation.addToscaDataToToscaElement(loadedResource, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policy, JsonPresentationFields.UNIQUE_ID);
+ titanDao.commit();
+ }
+
+ @After
+ public void tearDown() {
+ titanDao.rollback();
+ }
+
+ @Test
+ public void testUpdatePolicyProperties_singleProperty() {
+ PropertyDataDefinition prop1Copy = new PropertyDataDefinition(prop1);
+ prop1Copy.setValue("prop1NewValue");
+ testUpdatePolicyProperties(Collections.singletonList(prop1Copy), Collections.singletonList(prop2));
+ }
+
+ @Test
+ public void testUpdatePolicyProperties_multipleProperties() {
+ PropertyDataDefinition prop1Copy = new PropertyDataDefinition(prop1);
+ prop1Copy.setValue("prop1NewValue");
+
+ PropertyDataDefinition prop2Copy = new PropertyDataDefinition(prop2);
+ prop2Copy.setValue("prop2NewValue");
+
+ testUpdatePolicyProperties(Arrays.asList(prop1Copy, prop2Copy), Collections.emptyList());
+ }
+
+ private void testUpdatePolicyProperties(List<PropertyDataDefinition> updatedProperties, List<PropertyDataDefinition> nonUpdatedPropeties) {
+ Component cmpt = new org.openecomp.sdc.be.model.Resource();
+ cmpt.setUniqueId(CONTAINER_ID);
+ cmpt.setPolicies(Collections.singletonMap(POLICY_ID, policy));
+ StorageOperationStatus storageOperationStatus = policyOperation.updatePolicyProperties(cmpt, POLICY_ID, updatedProperties);
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnorePolicies(false);
+ Either<ToscaElement, StorageOperationStatus> loadedCmptEither = topologyTemplateOperation.getToscaElement(CONTAINER_ID, componentParametersView);
+
+ assertThat(loadedCmptEither.isLeft());
+ ToscaElement loadedCmpt = loadedCmptEither.left().value();
+ assertThat(loadedCmpt).isInstanceOf(TopologyTemplate.class);
+ @SuppressWarnings("unchecked") List<PropertyDataDefinition> allProperties = union(updatedProperties, nonUpdatedPropeties);
+ verifyPolicyPropertiesValuesUpdated((TopologyTemplate) loadedCmpt, allProperties);
+ }
+
+ private void verifyPolicyPropertiesValuesUpdated(TopologyTemplate toscaElement, List<PropertyDataDefinition> expectedUpdatedProperties) {
+ Map<String, PolicyDataDefinition> policies = toscaElement.getPolicies();
+ PolicyDataDefinition policy = policies.get(POLICY_ID);
+ List<PropertyDataDefinition> policyProperties = policy.getProperties();
+ assertThat(policyProperties).usingElementComparatorOnFields("value")
+ .containsAll(expectedUpdatedProperties);
+ }
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperationTest.java
new file mode 100644
index 0000000000..136f95b987
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperationTest.java
@@ -0,0 +1,93 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+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.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+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 PolicyOperationTest {
+
+ private static final String CONTAINER_ID = "containerId";
+ private static final String POLICY_ID = "policyId";
+ @InjectMocks
+ private PolicyOperation testInstance;
+ @Mock
+ private TitanDao titanDao;
+ @Mock
+ private TopologyTemplateOperation topologyTemplateOperation;
+ @Captor
+ private ArgumentCaptor<PolicyDefinition> policyDefCaptor;
+ private Component component;
+ private PolicyDefinition policyDefinition;
+ private PropertyDataDefinition prop1, prop2;
+
+ @Before
+ public void setUp() throws Exception {
+ component = new Resource();
+ component.setUniqueId(CONTAINER_ID);
+ policyDefinition = new PolicyDefinition();
+ policyDefinition.setUniqueId(POLICY_ID);
+ prop1 = new PropertyDataDefinition();
+ prop1.setName("prop1");
+ prop1.setValue("prop1");
+
+ prop2 = new PropertyDataDefinition();
+ prop2.setName("prop2");
+ prop2.setValue("prop2");
+ policyDefinition.setProperties(Arrays.asList(prop1, prop2));
+ component.setPolicies(Collections.singletonMap(POLICY_ID, policyDefinition));
+ }
+
+ @Test
+ public void updatePolicyProperties_failedToFetchContainer() {
+ when(titanDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ StorageOperationStatus storageOperationStatus = testInstance.updatePolicyProperties(component, POLICY_ID, Collections.emptyList());
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.NOT_FOUND);
+ verifyZeroInteractions(topologyTemplateOperation);
+ }
+
+ @Test
+ public void updatePolicyProperties_updateFailed() {
+ GraphVertex cmptVertex = new GraphVertex();
+ when(titanDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(cmptVertex));
+ when(topologyTemplateOperation.updatePolicyOfToscaElement(cmptVertex, policyDefinition)).thenReturn(StorageOperationStatus.GENERAL_ERROR);
+ StorageOperationStatus storageOperationStatus = testInstance.updatePolicyProperties(component, POLICY_ID, Collections.emptyList());
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.GENERAL_ERROR);
+ }
+
+ @Test
+ public void updatePolicyProperties() {
+ GraphVertex cmptVertex = new GraphVertex();
+ when(titanDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(cmptVertex));
+ when(topologyTemplateOperation.updatePolicyOfToscaElement(eq(cmptVertex), policyDefCaptor.capture())).thenReturn(StorageOperationStatus.OK);
+ PropertyDataDefinition prop1Copy = new PropertyDataDefinition(prop1);
+ prop1Copy.setValue("prop1Copy");
+ StorageOperationStatus storageOperationStatus = testInstance.updatePolicyProperties(component, POLICY_ID, Collections.singletonList(prop1Copy));
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ assertThat(policyDefCaptor.getValue().getProperties()).usingElementComparatorOnFields("value")
+ .containsExactlyInAnyOrder(prop1Copy, prop2);
+ }
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationCapabilityIntegrationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationCapabilityIntegrationTest.java
new file mode 100644
index 0000000000..103b27d3e6
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationCapabilityIntegrationTest.java
@@ -0,0 +1,199 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.sdc.be.dao.config.TitanSpringConfig;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty;
+import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.config.ModelOperationsSpringConfig;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {TitanSpringConfig.class, ModelOperationsSpringConfig.class})
+public class TopologyTemplateOperationCapabilityIntegrationTest extends ModelTestBase {
+
+ private static final String CONTAINER_ID = "id";
+ private Map<String, MapCapabiltyProperty> capabilitiesPropsMap;
+ private List<CapabilityPropertyDataObject> capabilitiesProperties;
+
+ @Resource
+ private TopologyTemplateOperation topologyTemplateOperation;
+
+ @Resource
+ private TitanDao titanDao;
+ private CapabilityPropertyDataObject capabilityProperty1;
+ private CapabilityPropertyDataObject capabilityProperty2;
+ private CapabilityPropertyDataObject capabilityProperty3;
+
+ @BeforeClass
+ public static void setupBeforeClass() {
+
+ ModelTestBase.init();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+
+ capabilitiesPropsMap = new HashMap<>();
+ capabilityProperty1 = new CapabilityPropertyDataObject("instance1", "capability1", "prop1", "val1");
+ capabilityProperty2 = new CapabilityPropertyDataObject("instance1", "capability2", "prop2", "val2");
+ capabilityProperty3 = new CapabilityPropertyDataObject("instance2", "capability3", "prop3", "val3");
+ capabilitiesProperties = Arrays.asList(capabilityProperty1, capabilityProperty2, capabilityProperty3);
+
+
+ //capablities props == Map<instance id, Map<capability id, Map<prop id, property>>>
+ capabilitiesProperties.forEach(capabilitiesProperty -> {
+ capabilitiesPropsMap.computeIfAbsent(capabilitiesProperty.getInstanceId(), k -> new MapCapabiltyProperty(new HashMap<>()))
+ .getMapToscaDataDefinition().computeIfAbsent(capabilitiesProperty.getCapabilityId(), k -> new MapPropertiesDataDefinition(new HashMap<>()))
+ .getMapToscaDataDefinition().computeIfAbsent(capabilitiesProperty.getPropName(), k -> new PropertyDefinition(createPropWithValue(capabilitiesProperty.getPropValue())));
+ });
+
+ GraphVertex resource = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID);
+ titanDao.createVertex(resource);
+ GraphVertex loadedResource = titanDao.getVertexById(CONTAINER_ID).left().value();
+ topologyTemplateOperation.assosiateElementToData(loadedResource, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, capabilitiesPropsMap).left().value();
+ titanDao.commit();
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanDao.rollback();
+ }
+
+ @Test
+ public void overrideCalculatedCapabilityProperties() {
+ Map<String, MapCapabiltyProperty> loadedCapPropsMap = fetchCapabilitiesProps(CONTAINER_ID);
+ compareCapabilitiesProperties(capabilitiesProperties, loadedCapPropsMap);
+ capabilityProperty1.setPropValue("newVal1");
+ capabilityProperty3.setPropValue("newVal3");
+ setPropertyValue(capabilitiesPropsMap, capabilityProperty1);
+ setPropertyValue(capabilitiesPropsMap, capabilityProperty3);
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, capabilitiesPropsMap);
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ Map<String, MapCapabiltyProperty> updatedCapPropsMap = fetchCapabilitiesProps(CONTAINER_ID);
+ compareCapabilitiesProperties(capabilitiesProperties, updatedCapPropsMap);
+ }
+
+ @Test
+ public void updateToscaDataDeepElementsBlockToToscaElement() {
+ assertCapabilityPropValue(capabilityProperty1, "val1");
+ assertCapabilityPropValue(capabilityProperty2, "val2");
+ assertCapabilityPropValue(capabilityProperty3, "val3");
+
+ MapCapabiltyProperty instance1Props = capabilitiesPropsMap.get("instance1");
+ capabilityProperty1.setPropValue("newVal1");
+ setPropertyValue(capabilitiesPropsMap, capabilityProperty1);
+
+ capabilityProperty3.setPropValue("newVal3");
+ setPropertyValue(capabilitiesPropsMap, capabilityProperty3);
+
+ Component component = new org.openecomp.sdc.be.model.Resource();
+ component.setUniqueId(CONTAINER_ID);
+ StorageOperationStatus updateStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instance1Props, "instance1");
+
+ assertThat(updateStatus).isEqualTo(StorageOperationStatus.OK);
+ assertCapabilityPropValue(capabilityProperty1, "newVal1");
+ assertCapabilityPropValue(capabilityProperty2, "val2");
+ assertCapabilityPropValue(capabilityProperty3, "val3");//only instance1 props should be updated
+ }
+
+ private Map<String, MapCapabiltyProperty> fetchCapabilitiesProps(String containerId) {
+ ComponentParametersView capabilityPropsFilter = new ComponentParametersView(true);
+ capabilityPropsFilter.setIgnoreCapabiltyProperties(false);
+ return ((TopologyTemplate) topologyTemplateOperation.getToscaElement(containerId, capabilityPropsFilter).left().value()).getCalculatedCapabilitiesProperties();
+ }
+
+ private void compareCapabilitiesProperties(List<CapabilityPropertyDataObject> expected, Map<String, MapCapabiltyProperty> actual) {
+ expected.forEach(expectedCapabilityProp -> {
+ assertThat(getPropertyValue(actual, expectedCapabilityProp.instanceId, expectedCapabilityProp.capabilityId, expectedCapabilityProp.propName))
+ .isEqualTo(expectedCapabilityProp.propValue);
+ });
+ }
+
+ private String getPropertyValue(Map<String, MapCapabiltyProperty> capabilityPropertyMap, String instance, String capability, String prop) {
+ return capabilityPropertyMap.get(instance).getMapToscaDataDefinition().get(capability).getMapToscaDataDefinition().get(prop).getValue();
+ }
+
+ private void setPropertyValue(Map<String, MapCapabiltyProperty> capabilityPropertyMap, CapabilityPropertyDataObject capabilityProperty) {
+ setPropertyValue(capabilityPropertyMap.get(capabilityProperty.getInstanceId()), capabilityProperty);
+
+ }
+
+ private void setPropertyValue(MapCapabiltyProperty capabilitiesInstanceProperties, CapabilityPropertyDataObject capabilityProperty) {
+ capabilitiesInstanceProperties.getMapToscaDataDefinition().get(capabilityProperty.getCapabilityId())
+ .getMapToscaDataDefinition().get(capabilityProperty.getPropName())
+ .setValue(capabilityProperty.getPropValue());
+ }
+
+ private void assertCapabilityPropValue(CapabilityPropertyDataObject prop, String expectedValue) {
+ Map<String, MapCapabiltyProperty> loadedCapPropsMap = fetchCapabilitiesProps(CONTAINER_ID);
+ String propertyValue = getPropertyValue(loadedCapPropsMap, prop.getInstanceId(), prop.getCapabilityId(), prop.getPropName());
+ assertThat(propertyValue).isEqualTo(expectedValue);
+ }
+
+
+ private PropertyDefinition createPropWithValue(String val) {
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setValue(val);
+ return propertyDefinition;
+ }
+
+ private static class CapabilityPropertyDataObject {
+ private String instanceId;
+ private String capabilityId;
+ private String propName;
+ private String propValue;
+
+ CapabilityPropertyDataObject(String instanceId, String capabilityId, String propName, String propValue) {
+ this.instanceId = instanceId;
+ this.capabilityId = capabilityId;
+ this.propName = propName;
+ this.propValue = propValue;
+ }
+
+ String getInstanceId() {
+ return instanceId;
+ }
+
+ String getCapabilityId() {
+ return capabilityId;
+ }
+
+ String getPropName() {
+ return propName;
+ }
+
+ String getPropValue() {
+ return propValue;
+ }
+
+ void setPropValue(String propValue) {
+ this.propValue = propValue;
+ }
+ }
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationIntegrationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationIntegrationTest.java
new file mode 100644
index 0000000000..d104cd3d42
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationIntegrationTest.java
@@ -0,0 +1,199 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.sdc.be.dao.config.TitanSpringConfig;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty;
+import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.config.ModelOperationsSpringConfig;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {TitanSpringConfig.class, ModelOperationsSpringConfig.class})
+public class TopologyTemplateOperationIntegrationTest extends ModelTestBase {
+
+ private static final String CONTAINER_ID = "id";
+ private Map<String, MapCapabiltyProperty> capabilitiesPropsMap;
+ private List<CapabilityPropertyDataObject> capabilitiesProperties;
+
+ @Resource
+ private TopologyTemplateOperation topologyTemplateOperation;
+
+ @Resource
+ private TitanDao titanDao;
+ private CapabilityPropertyDataObject capabilityProperty1;
+ private CapabilityPropertyDataObject capabilityProperty2;
+ private CapabilityPropertyDataObject capabilityProperty3;
+
+ @BeforeClass
+ public static void setupBeforeClass() {
+
+ ModelTestBase.init();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+
+ capabilitiesPropsMap = new HashMap<>();
+ capabilityProperty1 = new CapabilityPropertyDataObject("instance1", "capability1", "prop1", "val1");
+ capabilityProperty2 = new CapabilityPropertyDataObject("instance1", "capability2", "prop2", "val2");
+ capabilityProperty3 = new CapabilityPropertyDataObject("instance2", "capability3", "prop3", "val3");
+ capabilitiesProperties = Arrays.asList(capabilityProperty1, capabilityProperty2, capabilityProperty3);
+
+
+ //capablities props == Map<instance id, Map<capability id, Map<prop id, property>>>
+ capabilitiesProperties.forEach(capabilitiesProperty -> {
+ capabilitiesPropsMap.computeIfAbsent(capabilitiesProperty.getInstanceId(), k -> new MapCapabiltyProperty(new HashMap<>()))
+ .getMapToscaDataDefinition().computeIfAbsent(capabilitiesProperty.getCapabilityId(), k -> new MapPropertiesDataDefinition(new HashMap<>()))
+ .getMapToscaDataDefinition().computeIfAbsent(capabilitiesProperty.getPropName(), k -> new PropertyDefinition(createPropWithValue(capabilitiesProperty.getPropValue())));
+ });
+
+ GraphVertex resource = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID);
+ titanDao.createVertex(resource);
+ GraphVertex loadedResource = titanDao.getVertexById(CONTAINER_ID).left().value();
+ topologyTemplateOperation.assosiateElementToData(loadedResource, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, capabilitiesPropsMap).left().value();
+ titanDao.commit();
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanDao.rollback();
+ }
+
+ @Test
+ public void overrideCalculatedCapabilityProperties() {
+ Map<String, MapCapabiltyProperty> loadedCapPropsMap = fetchCapabilitiesProps(CONTAINER_ID);
+ compareCapabilitiesProperties(capabilitiesProperties, loadedCapPropsMap);
+ capabilityProperty1.setPropValue("newVal1");
+ capabilityProperty3.setPropValue("newVal3");
+ setPropertyValue(capabilitiesPropsMap, capabilityProperty1);
+ setPropertyValue(capabilitiesPropsMap, capabilityProperty3);
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, capabilitiesPropsMap);
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ Map<String, MapCapabiltyProperty> updatedCapPropsMap = fetchCapabilitiesProps(CONTAINER_ID);
+ compareCapabilitiesProperties(capabilitiesProperties, updatedCapPropsMap);
+ }
+
+ @Test
+ public void updateToscaDataDeepElementsBlockToToscaElement() {
+ assertCapabilityPropValue(capabilityProperty1, "val1");
+ assertCapabilityPropValue(capabilityProperty2, "val2");
+ assertCapabilityPropValue(capabilityProperty3, "val3");
+
+ MapCapabiltyProperty instance1Props = capabilitiesPropsMap.get("instance1");
+ capabilityProperty1.setPropValue("newVal1");
+ setPropertyValue(capabilitiesPropsMap, capabilityProperty1);
+
+ capabilityProperty3.setPropValue("newVal3");
+ setPropertyValue(capabilitiesPropsMap, capabilityProperty3);
+
+ Component component = new org.openecomp.sdc.be.model.Resource();
+ component.setUniqueId(CONTAINER_ID);
+ StorageOperationStatus updateStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instance1Props, "instance1");
+
+ assertThat(updateStatus).isEqualTo(StorageOperationStatus.OK);
+ assertCapabilityPropValue(capabilityProperty1, "newVal1");
+ assertCapabilityPropValue(capabilityProperty2, "val2");
+ assertCapabilityPropValue(capabilityProperty3, "val3");//only instance1 props should be updated
+ }
+
+ private Map<String, MapCapabiltyProperty> fetchCapabilitiesProps(String containerId) {
+ ComponentParametersView capabilityPropsFilter = new ComponentParametersView(true);
+ capabilityPropsFilter.setIgnoreCapabiltyProperties(false);
+ return ((TopologyTemplate) topologyTemplateOperation.getToscaElement(containerId, capabilityPropsFilter).left().value()).getCalculatedCapabilitiesProperties();
+ }
+
+ private void compareCapabilitiesProperties(List<CapabilityPropertyDataObject> expected, Map<String, MapCapabiltyProperty> actual) {
+ expected.forEach(expectedCapabilityProp -> {
+ assertThat(getPropertyValue(actual, expectedCapabilityProp.instanceId, expectedCapabilityProp.capabilityId, expectedCapabilityProp.propName))
+ .isEqualTo(expectedCapabilityProp.propValue);
+ });
+ }
+
+ private String getPropertyValue(Map<String, MapCapabiltyProperty> capabilityPropertyMap, String instance, String capability, String prop) {
+ return capabilityPropertyMap.get(instance).getMapToscaDataDefinition().get(capability).getMapToscaDataDefinition().get(prop).getValue();
+ }
+
+ private void setPropertyValue(Map<String, MapCapabiltyProperty> capabilityPropertyMap, CapabilityPropertyDataObject capabilityProperty) {
+ setPropertyValue(capabilityPropertyMap.get(capabilityProperty.getInstanceId()), capabilityProperty);
+
+ }
+
+ private void setPropertyValue(MapCapabiltyProperty capabilitiesInstanceProperties, CapabilityPropertyDataObject capabilityProperty) {
+ capabilitiesInstanceProperties.getMapToscaDataDefinition().get(capabilityProperty.getCapabilityId())
+ .getMapToscaDataDefinition().get(capabilityProperty.getPropName())
+ .setValue(capabilityProperty.getPropValue());
+ }
+
+ private void assertCapabilityPropValue(CapabilityPropertyDataObject prop, String expectedValue) {
+ Map<String, MapCapabiltyProperty> loadedCapPropsMap = fetchCapabilitiesProps(CONTAINER_ID);
+ String propertyValue = getPropertyValue(loadedCapPropsMap, prop.getInstanceId(), prop.getCapabilityId(), prop.getPropName());
+ assertThat(propertyValue).isEqualTo(expectedValue);
+ }
+
+
+ private PropertyDefinition createPropWithValue(String val) {
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setValue(val);
+ return propertyDefinition;
+ }
+
+ private static class CapabilityPropertyDataObject {
+ private String instanceId;
+ private String capabilityId;
+ private String propName;
+ private String propValue;
+
+ CapabilityPropertyDataObject(String instanceId, String capabilityId, String propName, String propValue) {
+ this.instanceId = instanceId;
+ this.capabilityId = capabilityId;
+ this.propName = propName;
+ this.propValue = propValue;
+ }
+
+ String getInstanceId() {
+ return instanceId;
+ }
+
+ String getCapabilityId() {
+ return capabilityId;
+ }
+
+ String getPropName() {
+ return propName;
+ }
+
+ String getPropValue() {
+ return propValue;
+ }
+
+ void setPropValue(String propValue) {
+ this.propValue = propValue;
+ }
+ }
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java
new file mode 100644
index 0000000000..7756a08cc1
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java
@@ -0,0 +1,125 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+import fj.data.Either;
+
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty;
+import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+
+import com.thinkaurelius.titan.core.PropertyKey;
+import com.thinkaurelius.titan.core.TitanEdge;
+import com.thinkaurelius.titan.core.TitanTransaction;
+import com.thinkaurelius.titan.core.TitanVertex;
+import com.thinkaurelius.titan.core.TitanVertexProperty;
+import com.thinkaurelius.titan.core.TitanVertexQuery;
+import com.thinkaurelius.titan.core.VertexLabel;
+import com.thinkaurelius.titan.diskstorage.EntryMetaData.Map;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+
+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.when;
+
+@RunWith(MockitoJUnitRunner.class)
+//error scenarios
+public class TopologyTemplateOperationTest {
+
+ private static final String CONTAINER_ID = "containerId";
+ @InjectMocks
+ private TopologyTemplateOperation topologyTemplateOperation;
+ @Mock
+ private TitanDao titanDao;
+
+ @Test
+ public void overrideToscaDataOfToscaElement_failedToFetchContainerVertex() {
+ when(titanDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(TitanOperationStatus.INVALID_ID));
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, Collections.emptyMap());
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.INVALID_ID);
+ }
+
+ @Test
+ public void overrideToscaDataOfToscaElement_failedToFetchDataVertex() {
+ GraphVertex containerVertex = new GraphVertex();
+ when(titanDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(containerVertex));
+ when(titanDao.getChildVertex(containerVertex, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, JsonParseFlagEnum.ParseJson)).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, Collections.emptyMap());
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.NOT_FOUND);
+ }
+
+ @Test
+ public void updateToscaDataDeepElements_failedToFetchContainerVertex() {
+ when(titanDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(TitanOperationStatus.INVALID_ID));
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, new MapCapabiltyProperty(), "");
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.INVALID_ID);
+ }
+
+ @Test
+ public void updateToscaDataDeepElements_failedToFetchDataVertex() {
+ GraphVertex containerVertex = new GraphVertex();
+ when(titanDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(containerVertex));
+ when(titanDao.getChildVertex(containerVertex, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, JsonParseFlagEnum.ParseJson)).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, new MapCapabiltyProperty(), "");
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.NOT_FOUND);
+ }
+
+ @Test
+ public void addPolicyToToscaElementSuccessTest(){
+ TitanOperationStatus status = TitanOperationStatus.OK;
+ StorageOperationStatus result = addPolicyToToscaElementWithStatus(status);
+ assertThat(result).isEqualTo(StorageOperationStatus.OK);
+ }
+
+ @Test
+ public void addPolicyToToscaElementFailureTest(){
+ TitanOperationStatus status = TitanOperationStatus.ALREADY_EXIST;
+ StorageOperationStatus result = addPolicyToToscaElementWithStatus(status);
+ assertThat(result).isEqualTo(StorageOperationStatus.ENTITY_ALREADY_EXISTS);
+ }
+
+ @SuppressWarnings("unchecked")
+ private StorageOperationStatus addPolicyToToscaElementWithStatus(TitanOperationStatus status) {
+ GraphVertex componentV = new GraphVertex();
+ componentV.setVertex(Mockito.mock(TitanVertex.class));
+ GraphVertex dataV = new GraphVertex();
+ dataV.setVertex(Mockito.mock(TitanVertex.class));
+ String componentName = "componentName";
+ String componentId = UniqueIdBuilder.buildResourceUniqueId();
+ String policyTypeName = "org.openecomp.policies.placement.valet.Affinity";
+ componentV.setJsonMetadataField(JsonPresentationFields.NAME, componentName);
+ componentV.setUniqueId(componentId);
+ PolicyDefinition policy = new PolicyDefinition();
+ policy.setPolicyTypeName(policyTypeName);
+ int counter = 0;
+ Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = Either.right(TitanOperationStatus.NOT_FOUND);
+ when(titanDao.getChildVertex(eq(componentV), eq(EdgeLabelEnum.POLICIES), eq(JsonParseFlagEnum.ParseJson))).thenReturn(toscaDataVertexRes);
+ Either<GraphVertex, TitanOperationStatus> createVertex = Either.left(dataV);
+ when(titanDao.createVertex(any(GraphVertex.class))).thenReturn(createVertex);
+ when(titanDao.createEdge(any(TitanVertex.class), any(TitanVertex.class), any(EdgeLabelEnum.class), any(HashMap.class))).thenReturn(status);
+ return topologyTemplateOperation.addPolicyToToscaElement(componentV, policy, counter);
+ }
+
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperationTest.java
index 806c22a8fb..d9148a18e1 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperationTest.java
@@ -22,6 +22,7 @@ import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.catalog.CatalogComponent;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsontitan.utils.GraphTestUtils;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -81,6 +82,9 @@ public class ToscaElementOperationTest extends ModelTestBase{
}, null);
assertEquals(highestResources.stream().count(), highestResourcesExpectedCount);
}
+
+
+
@Test
public void testGetAllResourcesCertifiedNoFilter() {
@@ -268,6 +272,8 @@ public class ToscaElementOperationTest extends ModelTestBase{
}
private void initGraphForTest() {
+ GraphTestUtils.createRootCatalogVertex(titanDao);
+
Map<GraphPropertyEnum, Object> highstVerticesProps = new HashMap<GraphPropertyEnum, Object>() {
{
put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadePoliciesTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadePoliciesTest.java
new file mode 100644
index 0000000000..6a4a117360
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadePoliciesTest.java
@@ -0,0 +1,144 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+import fj.data.Either;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.sdc.be.dao.config.TitanSpringConfig;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.config.ModelOperationsSpringConfig;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {TitanSpringConfig.class, ModelOperationsSpringConfig.class})
+public class ToscaOperationFacadePoliciesTest extends ModelTestBase {
+
+ private static final String CONTAINER_ID = "containerId";
+ private static final String CONTAINER_NAME = "containerName";
+ @Autowired
+ private ToscaOperationFacade toscaOperationFacade;
+ @Autowired
+ private TitanDao titanDao;
+
+ private PolicyDefinition policy1, policy2;
+
+ @BeforeClass
+ public static void setupBeforeClass() {
+ ModelTestBase.init();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ policy1 = createPolicyDefinition("type1");
+ policy2 = createPolicyDefinition("type2");
+ createContainerVertexInDB();
+ createPoliciesOnGraph(policy1, policy2);
+ }
+
+ private void createPoliciesOnGraph(PolicyDefinition ... policies) {
+ for (int i = 0; i < policies.length; i++) {
+ PolicyDefinition policy = policies[i];
+ Either<PolicyDefinition, StorageOperationStatus> createdPolicy = toscaOperationFacade.associatePolicyToComponent(CONTAINER_ID, policy, i);
+ assertTrue(createdPolicy.isLeft());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ titanDao.rollback();
+ }
+
+ @Test
+ public void updatePoliciesTargetsOfComponent_updateSinglePolicy() {
+ List<String> updatedTargetIds = asList("instance1new", "instance2");
+ PolicyDefinition originalPolicy2 = clonePolicyWithTargets(policy2);
+ updatePolicyTypeTargetsIds(policy1, PolicyTargetType.COMPONENT_INSTANCES, updatedTargetIds);
+ updatePolicyTypeTargetsIds(policy2, PolicyTargetType.COMPONENT_INSTANCES, updatedTargetIds);
+
+ StorageOperationStatus storageOperationStatus = toscaOperationFacade.updatePoliciesOfComponent(CONTAINER_ID, singletonList(policy1));
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ Component updatedComponent = fetchComponentFromDB();
+ verifyPolicyTargets(updatedComponent.getPolicyById(policy1.getUniqueId()), policy1);
+ verifyPolicyTargets(updatedComponent.getPolicyById(policy2.getUniqueId()), originalPolicy2);
+ }
+
+ @Test
+ public void updatePoliciesTargetsOfComponent_updateMultiplePolicies() {
+ List<String> updatedTargetIds = asList("instance1new", "instance2");
+ updatePolicyTypeTargetsIds(policy1, PolicyTargetType.COMPONENT_INSTANCES, updatedTargetIds);
+ updatePolicyTypeTargetsIds(policy2, PolicyTargetType.COMPONENT_INSTANCES, updatedTargetIds);
+ StorageOperationStatus storageOperationStatus = toscaOperationFacade.updatePoliciesOfComponent(CONTAINER_ID, asList(policy1, policy2));
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ Component updatedComponent = fetchComponentFromDB();
+ verifyPolicyTargets(updatedComponent.getPolicyById(policy1.getUniqueId()), policy1);
+ verifyPolicyTargets(updatedComponent.getPolicyById(policy2.getUniqueId()), policy2);
+ }
+
+ private PolicyDefinition clonePolicyWithTargets(PolicyDefinition policy) {
+ PolicyDefinition originalPolicy = new PolicyDefinition(policy);
+ Map<PolicyTargetType, List<String>> clonedTargetMap = policy.getTargets().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> new ArrayList<>(entry.getValue())));
+ originalPolicy.setTargets(clonedTargetMap);
+ return originalPolicy;
+ }
+
+ private void verifyPolicyTargets(PolicyDefinition updatedPolicy, PolicyDefinition expectedPolicy) {
+ assertThat(updatedPolicy.getTargets())
+ .isEqualTo(expectedPolicy.getTargets());
+ }
+
+ private void updatePolicyTypeTargetsIds(PolicyDefinition policy, PolicyTargetType targetType, List<String> updatedTargetIds) {
+ policy.getTargets().put(targetType, updatedTargetIds);
+ }
+
+ private Component fetchComponentFromDB() {
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnorePolicies(false);
+ return toscaOperationFacade.getToscaElement(CONTAINER_ID, componentParametersView).left().value();
+ }
+
+ private void createContainerVertexInDB() {
+ GraphVertex resource = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID);
+ resource.addMetadataProperty(GraphPropertyEnum.NAME, CONTAINER_NAME);
+ resource.setJsonMetadataField(JsonPresentationFields.NAME, CONTAINER_NAME);
+ resource.setJsonMetadataField(JsonPresentationFields.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ Either<GraphVertex, TitanOperationStatus> container = titanDao.createVertex(resource);
+ assertTrue(container.isLeft());
+ }
+
+ private PolicyDefinition createPolicyDefinition(String type) {
+ PolicyDefinition policy = new PolicyDefinition();
+ policy.setPolicyTypeName(type);
+ policy.setTargets(new HashMap<>());
+ policy.getTargets().put(PolicyTargetType.COMPONENT_INSTANCES, asList("instance1", "instance2"));
+ return policy;
+ }
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java
index 4a7d27812d..37d466c648 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java
@@ -1,15 +1,6 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-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.IntStream;
-
+import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,11 +20,24 @@ import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-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.IntStream;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ToscaOperationFacadeTest {
@@ -58,16 +62,18 @@ public class ToscaOperationFacadeTest {
@Test
public void fetchMetaDataByResourceType() throws Exception {
ArgumentCaptor<Map> criteriaCapture = ArgumentCaptor.forClass(Map.class);
+ ArgumentCaptor<Map> criteriaNotCapture = ArgumentCaptor.forClass(Map.class);
ComponentParametersView dataFilter = new ComponentParametersView();
List<GraphVertex> mockVertices = getMockVertices(2);
Either<List<GraphVertex>, TitanOperationStatus> returnedVertices = Either.left(mockVertices);
- when(titanDaoMock.getByCriteria(Mockito.eq(null), criteriaCapture.capture(), Mockito.eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(returnedVertices);
+ when(titanDaoMock.getByCriteria(eq(null), criteriaCapture.capture(), criteriaNotCapture.capture(), eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(returnedVertices);
when(topologyTemplateOperationMock.getToscaElement(mockVertices.get(0), dataFilter)).thenReturn(Either.left(getResourceToscaElement("0")));
when(topologyTemplateOperationMock.getToscaElement(mockVertices.get(1), dataFilter)).thenReturn(Either.left(getResourceToscaElement("1")));
Either<List<Component>, StorageOperationStatus> fetchedComponents = testInstance.fetchMetaDataByResourceType(ResourceTypeEnum.VF.getValue(), dataFilter);
verifyCriteriaForHighestVersionAndVfResourceType(criteriaCapture);
+ verifyCriteriaNotIsDeleted(criteriaNotCapture);
assertTrue(fetchedComponents.isLeft());
List<Component> cmpts = fetchedComponents.left().value();
@@ -83,17 +89,93 @@ public class ToscaOperationFacadeTest {
assertEquals(criteria.get(GraphPropertyEnum.IS_HIGHEST_VERSION), true);
}
+ private void verifyCriteriaNotIsDeleted(ArgumentCaptor<Map> criteriaNotCapture) {
+ Map<GraphPropertyEnum, Object> notCriteria = (Map<GraphPropertyEnum, Object>)criteriaNotCapture.getValue();
+ assertEquals(1, notCriteria.size());
+ assertEquals(notCriteria.get(GraphPropertyEnum.IS_DELETED), true);
+ }
+
@SuppressWarnings("unchecked")
@Test
public void fetchMetaDataByResourceType_failedToGetData() throws Exception {
- when(titanDaoMock.getByCriteria(Mockito.eq(null), Mockito.anyMap(), Mockito.eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(Either.right(TitanOperationStatus.GENERAL_ERROR));
+ when(titanDaoMock.getByCriteria(eq(null), anyMap(), anyMap(), eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(Either.right(TitanOperationStatus.GENERAL_ERROR));
Either<List<Component>, StorageOperationStatus> fetchedComponents = testInstance.fetchMetaDataByResourceType(ResourceTypeEnum.VF.getValue(), new ComponentParametersView());
assertTrue(fetchedComponents.isRight());
assertEquals(StorageOperationStatus.GENERAL_ERROR, fetchedComponents.right().value());
}
+
+ @Test
+ public void associatePolicyToComponentSuccessTest(){
+ Either<PolicyDefinition, StorageOperationStatus> result = associatePolicyToComponentWithStatus(StorageOperationStatus.OK);
+ assertTrue(result.isLeft());
+ }
+
+ @Test
+ public void associatePolicyToComponentFailureTest(){
+ Either<PolicyDefinition, StorageOperationStatus> result = associatePolicyToComponentWithStatus(StorageOperationStatus.BAD_REQUEST);
+ assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.BAD_REQUEST);
+ }
+
+ @Test
+ public void updatePolicyOfComponentSuccessTest(){
+ Either<PolicyDefinition, StorageOperationStatus> result = updatePolicyOfComponentWithStatus(StorageOperationStatus.OK);
+ assertTrue(result.isLeft());
+ }
+
+ @Test
+ public void updatePolicyOfComponentFailureTest(){
+ Either<PolicyDefinition, StorageOperationStatus> result = updatePolicyOfComponentWithStatus(StorageOperationStatus.NOT_FOUND);
+ assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.NOT_FOUND);
+ }
+
+ @Test
+ public void removePolicyFromComponentSuccessTest(){
+ removePolicyFromComponentWithStatus(StorageOperationStatus.OK);
+ }
+
+ @Test
+ public void removePolicyFromComponentFailureTest(){
+ removePolicyFromComponentWithStatus(StorageOperationStatus.NOT_FOUND);
+ }
+
+ private Either<PolicyDefinition, StorageOperationStatus> associatePolicyToComponentWithStatus(StorageOperationStatus status) {
+ PolicyDefinition policy = new PolicyDefinition();
+ String componentId = "componentId";
+ int counter = 0;
+ GraphVertex vertex;
+ if(status == StorageOperationStatus.OK){
+ vertex = getTopologyTemplateVertex();
+ } else {
+ vertex = getNodeTypeVertex();
+ }
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = Either.left(vertex);
+ when(titanDaoMock.getVertexById(eq(componentId), eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(getVertexEither);
+ when(topologyTemplateOperationMock.addPolicyToToscaElement(eq(vertex), any(PolicyDefinition.class), anyInt())).thenReturn(status);
+ return testInstance.associatePolicyToComponent(componentId, policy, counter);
+ }
+
+ private Either<PolicyDefinition, StorageOperationStatus> updatePolicyOfComponentWithStatus(StorageOperationStatus status) {
+ PolicyDefinition policy = new PolicyDefinition();
+ String componentId = "componentId";
+ GraphVertex vertex = getTopologyTemplateVertex();
+ when(titanDaoMock.getVertexById(eq(componentId), eq(JsonParseFlagEnum.NoParse))).thenReturn(Either.left(vertex));
+ when(topologyTemplateOperationMock.updatePolicyOfToscaElement(eq(vertex), any(PolicyDefinition.class))).thenReturn(status);
+ return testInstance.updatePolicyOfComponent(componentId, policy);
+ }
+ private void removePolicyFromComponentWithStatus(StorageOperationStatus status) {
+ String componentId = "componentId";
+ String policyId = "policyId";
+ GraphVertex vertex = getTopologyTemplateVertex();
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = Either.left(vertex);
+ when(titanDaoMock.getVertexById(eq(componentId), eq(JsonParseFlagEnum.NoParse))).thenReturn(getVertexEither);
+ when(topologyTemplateOperationMock.removePolicyFromToscaElement(eq(vertex), eq(policyId))).thenReturn(status);
+ StorageOperationStatus result = testInstance.removePolicyFromComponent(componentId, policyId);
+ assertTrue(result == status);
+ }
+
private List<GraphVertex> getMockVertices(int numOfVertices) {
- return IntStream.range(0, numOfVertices).mapToObj(i -> getMockVertex()).collect(Collectors.toList());
+ return IntStream.range(0, numOfVertices).mapToObj(i -> getTopologyTemplateVertex()).collect(Collectors.toList());
}
private ToscaElement getResourceToscaElement(String id) {
@@ -104,9 +186,15 @@ public class ToscaOperationFacadeTest {
return toscaElement;
}
- private GraphVertex getMockVertex() {
+ private GraphVertex getTopologyTemplateVertex() {
GraphVertex graphVertex = new GraphVertex();
graphVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
return graphVertex;
}
+
+ private GraphVertex getNodeTypeVertex() {
+ GraphVertex graphVertex = new GraphVertex();
+ graphVertex.setLabel(VertexTypeEnum.NODE_TYPE);
+ return graphVertex;
+ }
} \ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/GraphTestUtils.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/GraphTestUtils.java
index 862515c58e..72919b6136 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/GraphTestUtils.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/GraphTestUtils.java
@@ -32,6 +32,7 @@ import org.apache.tinkerpop.gremlin.structure.io.IoCore;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.jsongraph.utils.IdBuilderUtils;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
@@ -44,6 +45,12 @@ import fj.data.Either;
public final class GraphTestUtils {
+ public static void createRootCatalogVertex(TitanDao titanDao) {
+ GraphVertex catalogRootVertex = new GraphVertex(VertexTypeEnum.CATALOG_ROOT);
+ catalogRootVertex.setUniqueId(IdBuilderUtils.generateUniqueId());
+ titanDao.createVertex(catalogRootVertex);
+ }
+
public static GraphVertex createResourceVertex(TitanDao titanDao, Map<GraphPropertyEnum,Object> metadataProps, ResourceTypeEnum type) {
GraphVertex vertex = new GraphVertex();
if (type == ResourceTypeEnum.VF) {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java
new file mode 100644
index 0000000000..809134ecb6
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java
@@ -0,0 +1,346 @@
+package org.openecomp.sdc.be.model.operations.impl;
+
+import fj.data.Either;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.tosca.ToscaType;
+import org.openecomp.sdc.be.resources.data.CapabilityTypeData;
+import org.openecomp.sdc.be.resources.data.GroupTypeData;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static com.google.common.collect.Sets.newHashSet;
+import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.*;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:application-context-test.xml")
+public class GroupTypeOperationTest extends ModelTestBase {
+ private static final String TOSCA_GROUPS_ROOT = "tosca.groups.Root";
+
+ @Resource(name = "titan-generic-dao")
+ private TitanGenericDao titanDao;
+
+ @Resource(name = "capability-type-operation")
+ private CapabilityTypeOperation capabilityTypeOperation;
+
+ @Resource(name = "group-type-operation")
+ private GroupTypeOperation groupTypeOperation;
+
+ @BeforeClass
+ public static void setupBeforeClass() {
+ ModelTestBase.init();
+ }
+
+ @After
+ public void tearDown() {
+ titanDao.rollback();
+ }
+
+ @Test
+ public void getAllGroupTypes() {
+ GroupTypeDefinition rootGroupDefinition = createRootGroupDefinition();
+ GroupTypeDefinition type1 = createGroupType("type1");
+ GroupTypeDefinition type2 = createGroupType("type2");
+ groupTypeOperation.addGroupType(rootGroupDefinition);
+ groupTypeOperation.addGroupType(type1);
+ groupTypeOperation.addGroupType(type2);
+
+ List<GroupTypeDefinition> allGroupTypesNoExclusion = groupTypeOperation.getAllGroupTypes(null);
+ assertThat(allGroupTypesNoExclusion)
+ .usingElementComparatorOnFields("type")
+ .containsExactlyInAnyOrder(rootGroupDefinition, type1, type2);
+ }
+
+ @Test
+ public void getAllGroupTypes_whenPassingExclusionList_doNotReturnExcludedTypes() {
+ GroupTypeDefinition rootGroupDefinition = createRootGroupDefinition();
+ GroupTypeDefinition type1 = createGroupType("type1");
+ GroupTypeDefinition type2 = createGroupType("type2");
+ groupTypeOperation.addGroupType(rootGroupDefinition);
+ groupTypeOperation.addGroupType(type1);
+ groupTypeOperation.addGroupType(type2);
+
+ List<GroupTypeDefinition> allGroupTypes = groupTypeOperation.getAllGroupTypes(newHashSet("type1", "type2"));
+ assertThat(allGroupTypes)
+ .usingElementComparatorOnFields("type")
+ .containsExactly(rootGroupDefinition);
+ }
+
+ @Test
+ public void groupTypeWithoutCapabilityTypeCreated() {
+ GroupTypeData rootNode = getOrCreateRootGroupTypeNode();
+
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ groupTypeDefinition.setDerivedFrom(TOSCA_GROUPS_ROOT);
+ groupTypeDefinition.setDescription("groups l3-networks in network collection");
+ groupTypeDefinition.setType("org.openecomp.groups.NetworkCollection");
+ groupTypeDefinition.setVersion("1.0");
+
+ List<PropertyDefinition> properties = asList(
+ buildProperty("network_collection_type", "l3-network", "network collection type, defined with default value"),
+ buildProperty("network_collection_subtype", "sub-interface", "network collection subtype, defined with default value"),
+ buildProperty("network_collection_role", null, "network collection role"),
+ buildProperty("network_collection_description", null, "network collection description, free format text"));
+
+ groupTypeDefinition.setProperties(properties );
+
+ Either<GroupTypeDefinition, StorageOperationStatus> addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, false);
+ assertEquals("check group type added", true, addGroupTypeResult.isLeft());
+ compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
+
+ addGroupTypeResult = groupTypeOperation.getGroupTypeByTypeAndVersion("org.openecomp.groups.NetworkCollection", "1.0");
+ assertEquals("check group type added", true, addGroupTypeResult.isLeft());
+ compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
+
+ Either<GroupTypeData, TitanOperationStatus> groupTypeResult = titanDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), groupTypeDefinition.getType(), GroupTypeData.class);
+ GroupTypeData groupTypeNode = extractVal(groupTypeResult);
+
+ Either<Edge, TitanOperationStatus> edgeResult = titanDao.getEdgeByNodes(groupTypeNode, rootNode, GraphEdgeLabels.DERIVED_FROM);
+ validate(edgeResult);
+ }
+
+ @Test
+ public void groupTypeWithCapabilityTypeAndEdgeCreated() {
+ GroupTypeData rootNode = getOrCreateRootGroupTypeNode();
+
+ CapabilityTypeDefinition capabilityTypeDef = createCapabilityType();
+ Either<CapabilityTypeData, TitanOperationStatus> capabilityTypeResult = titanDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), capabilityTypeDef.getType(), CapabilityTypeData.class);
+ CapabilityTypeData capabilityTypeNode = extractVal(capabilityTypeResult);
+
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ groupTypeDefinition.setDerivedFrom(TOSCA_GROUPS_ROOT);
+ groupTypeDefinition.setDescription("groups l3-networks in network collection");
+ groupTypeDefinition.setType("org.openecomp.groups.NetworkCollection");
+ groupTypeDefinition.setCapabilityTypes(asList(capabilityTypeDef));
+
+ List<PropertyDefinition> properties = asList(
+ buildProperty("vfc_instance_group_role", null, "role of this VFC group"),
+ buildProperty("vfc_parent_port_role", null, "common role of parent ports of VFCs in this group"),
+ buildProperty("network_collection_role", null, "network collection role assigned to this group"),
+ buildProperty("subinterface_role", null, "common role of subinterfaces of VFCs in this group, criteria the group is created"));
+
+ groupTypeDefinition.setProperties(properties );
+
+ Either<GroupTypeDefinition, StorageOperationStatus> addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true);
+ assertEquals("check group type added", true, addGroupTypeResult.isLeft());
+ compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
+
+ Either<GroupTypeData, TitanOperationStatus> groupTypeResult = titanDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), groupTypeDefinition.getType(), GroupTypeData.class);
+ GroupTypeData groupTypeNode = extractVal(groupTypeResult);
+
+ Either<Edge, TitanOperationStatus> edgeCapTypeResult = titanDao.getEdgeByNodes(groupTypeNode, capabilityTypeNode, GraphEdgeLabels.GROUP_TYPE_CAPABILITY_TYPE);
+ validate(edgeCapTypeResult);
+
+ Either<Edge, TitanOperationStatus> edgeDerivedFromResult = titanDao.getEdgeByNodes(groupTypeNode, rootNode, GraphEdgeLabels.DERIVED_FROM);
+ validate(edgeDerivedFromResult);
+ }
+
+ @Test
+ public void testUpgradeGroupTypeWithDerrivedFromEdge() {
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ groupTypeDefinition.setDerivedFrom(TOSCA_GROUPS_ROOT);
+ groupTypeDefinition.setDescription("groups l2-networks in network collection");
+ groupTypeDefinition.setType("org.openecomp.groups.PrivateCollection");
+ groupTypeDefinition.setVersion("1.0");
+
+ List<PropertyDefinition> properties = singletonList(
+ buildProperty("network_collection_type", "l2-network", "network collection type, defined with default value"));
+
+ groupTypeDefinition.setProperties(properties );
+
+ Either<GroupTypeDefinition, StorageOperationStatus> addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true);
+ assertEquals("check group type added", true, addGroupTypeResult.isLeft());
+ compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
+
+ addGroupTypeResult = groupTypeOperation.getGroupTypeByTypeAndVersion("org.openecomp.groups.PrivateCollection", "1.0");
+ assertEquals("check group type added", true, addGroupTypeResult.isLeft());
+ compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
+
+ Either<GroupTypeDefinition, StorageOperationStatus> upgradeResult = groupTypeOperation.upgradeGroupType(groupTypeDefinition, groupTypeDefinition, true);
+ assertNotNull(upgradeResult);
+ assertTrue(upgradeResult.isLeft());
+ }
+
+ @Test
+ public void testUpgradeNonExistingGroupType() {
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ groupTypeDefinition.setDerivedFrom(TOSCA_GROUPS_ROOT);
+ groupTypeDefinition.setDescription("groups l2-networks in network collection");
+ groupTypeDefinition.setType("org.openecomp.groups.MyCollection");
+ groupTypeDefinition.setVersion("1.0");
+
+ Either<GroupTypeDefinition, StorageOperationStatus> upgradeResult = groupTypeOperation.upgradeGroupType(groupTypeDefinition, groupTypeDefinition, true);
+ assertNotNull(upgradeResult);
+ assertTrue(upgradeResult.isRight());
+ }
+
+ @Test
+ public void testUpgradeNotDerivedGroupType() {
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ groupTypeDefinition.setDescription("groups social-networks in school");
+ groupTypeDefinition.setType("org.openecomp.groups.Teachers");
+ groupTypeDefinition.setVersion("1.0");
+
+ Either<GroupTypeDefinition, StorageOperationStatus> addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true);
+ assertEquals("check group type added", true, addGroupTypeResult.isLeft());
+ compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
+
+ Either<GroupTypeDefinition, StorageOperationStatus> upgradeResult = groupTypeOperation.upgradeGroupType(groupTypeDefinition, groupTypeDefinition, true);
+ assertNotNull(upgradeResult);
+ assertTrue(upgradeResult.isLeft());
+ assertEquals(groupTypeDefinition, upgradeResult.left().value());
+ }
+
+ @Test
+ public void testUpgradeGroupTypeWithNonExistingParent() {
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ groupTypeDefinition.setDescription("groups social-networks in work");
+ groupTypeDefinition.setType("org.openecomp.groups.Cowokers");
+ groupTypeDefinition.setVersion("1.0");
+
+ Either<GroupTypeDefinition, StorageOperationStatus> addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true);
+ assertEquals("check group type added", true, addGroupTypeResult.isLeft());
+ compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
+
+ groupTypeDefinition.setDerivedFrom("Non.existing.parent");
+ Either<GroupTypeDefinition, StorageOperationStatus> upgradeResult = groupTypeOperation.upgradeGroupType(groupTypeDefinition, groupTypeDefinition, true);
+ assertNotNull(upgradeResult);
+ assertTrue(upgradeResult.isRight());
+ }
+
+ @Test
+ public void testUpgradeGroupType() {
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ groupTypeDefinition.setDescription("groups social-networks in university");
+ groupTypeDefinition.setType("org.openecomp.groups.Students");
+ groupTypeDefinition.setVersion("1.0");
+
+ Either<GroupTypeDefinition, StorageOperationStatus> addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true);
+ assertEquals("check group type added", true, addGroupTypeResult.isLeft());
+ compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
+
+ GroupTypeDefinition parentGroupTypeDefinition = new GroupTypeDefinition();
+ parentGroupTypeDefinition.setDescription("groups social-networks in university");
+ parentGroupTypeDefinition.setType("org.openecomp.groups.Parents");
+ parentGroupTypeDefinition.setVersion("1.0");
+
+ Either<GroupTypeDefinition, StorageOperationStatus> addParentGroupTypeResult = groupTypeOperation.addGroupType(parentGroupTypeDefinition, true);
+ assertEquals("check group type added", true, addParentGroupTypeResult.isLeft());
+ compareBetweenCreatedToSent(parentGroupTypeDefinition, addParentGroupTypeResult.left().value());
+
+ groupTypeDefinition.setDerivedFrom("org.openecomp.groups.Parents");
+ Either<GroupTypeDefinition, StorageOperationStatus> upgradeResult = groupTypeOperation.upgradeGroupType(groupTypeDefinition, groupTypeDefinition, true);
+ assertNotNull(upgradeResult);
+ assertTrue(upgradeResult.isLeft());
+ assertEquals(groupTypeDefinition, upgradeResult.left().value());
+ }
+
+
+ private GroupTypeData getOrCreateRootGroupTypeNode() {
+ Either<GroupTypeData, TitanOperationStatus> groupTypeResult = titanDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), TOSCA_GROUPS_ROOT, GroupTypeData.class);
+ if(groupTypeResult.isLeft()) {
+ return groupTypeResult.left().value();
+ }
+
+ return createRootGroupTypeNode();
+ }
+
+ private GroupTypeData createRootGroupTypeNode() {
+ GroupTypeDefinition rootGroupDefinition = createRootGroupDefinition();
+ Either<GroupTypeDefinition, StorageOperationStatus> addGroupTypeResult = groupTypeOperation.addGroupType(rootGroupDefinition, true);
+ assertEquals("check group type added", true, addGroupTypeResult.isLeft());
+
+ Either<GroupTypeData, TitanOperationStatus> groupTypeResult = titanDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), rootGroupDefinition.getType(), GroupTypeData.class);
+ return extractVal(groupTypeResult);
+ }
+
+ private GroupTypeDefinition createRootGroupDefinition() {
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ groupTypeDefinition.setDescription("The TOSCA Group Type all other TOSCA Group Types derive from");
+ groupTypeDefinition.setType(TOSCA_GROUPS_ROOT);
+ return groupTypeDefinition;
+ }
+
+ private GroupTypeDefinition createGroupType(String type) {
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ groupTypeDefinition.setDescription("description for type " + type);
+ groupTypeDefinition.setType(type);
+ return groupTypeDefinition;
+ }
+
+ private CapabilityTypeDefinition createCapabilityType() {
+ CapabilityTypeDefinition capabilityTypeDefinition = new CapabilityTypeDefinition();
+ capabilityTypeDefinition.setDescription("ability to expose routing information of the internal network");
+ capabilityTypeDefinition.setType("org.openecomp.capabilities.VLANAssignment");
+ capabilityTypeDefinition.setVersion("1.0");
+
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+ properties.put("vfc_instance_group_reference",
+ buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance"));
+
+ capabilityTypeDefinition.setProperties(properties);
+
+ Either<CapabilityTypeDefinition, StorageOperationStatus> addCapabilityTypeResult = capabilityTypeOperation.addCapabilityType(capabilityTypeDefinition, true);
+ assertEquals("check capability type added", true, addCapabilityTypeResult.isLeft());
+
+ CapabilityTypeDefinition capabilityTypeAdded = addCapabilityTypeResult.left().value();
+ compareBetweenCreatedToSent(capabilityTypeDefinition, capabilityTypeAdded);
+
+ return capabilityTypeDefinition;
+ }
+
+ private PropertyDefinition buildProperty(String name, String defaultValue, String description) {
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName(name);
+ property.setDefaultValue(defaultValue);
+ property.setRequired(true);
+ property.setDescription(description);
+ property.setType(ToscaType.STRING.name().toLowerCase());
+
+ return property;
+ }
+
+ private void compareBetweenCreatedToSent(CapabilityTypeDefinition expected, CapabilityTypeDefinition actual) {
+ assertEquals(expected.getDerivedFrom(), actual.getDerivedFrom());
+ assertEquals(expected.getType(), actual.getType());
+ assertEquals(expected.getDescription(), actual.getDescription());
+ }
+
+ private void compareBetweenCreatedToSent(GroupTypeDefinition expected, GroupTypeDefinition actual) {
+ assertEquals(expected.getType(), actual.getType());
+ assertEquals(expected.getDescription(), actual.getDescription());
+ }
+
+ private <T> void validate(Either<T, TitanOperationStatus> result) {
+ extractVal(result);
+ }
+
+ private <T> T extractVal(Either<T, TitanOperationStatus> result) {
+ assertTrue(result.isLeft());
+ T t = result.left().value();
+ assertNotNull(t);
+
+ return t;
+ }
+
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperationTest.java
index 8b4ebbdaf8..05b9ec1b89 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperationTest.java
@@ -20,13 +20,12 @@
package org.openecomp.sdc.be.model.operations.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Matchers.anyMap;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
@@ -45,6 +44,7 @@ import org.openecomp.sdc.be.model.HeatParameterDefinition;
import org.openecomp.sdc.be.model.ModelTestBase;
import org.openecomp.sdc.be.model.heat.HeatParameterType;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.HeatParametersOperation;
import org.openecomp.sdc.be.resources.data.HeatParameterData;
import org.openecomp.sdc.be.resources.data.HeatParameterValueData;
@@ -103,7 +103,7 @@ public class HeatParametersOperationTest extends ModelTestBase {
Either<GraphRelation, TitanOperationStatus> relationResult = Either.left(graphRelation);
when(titanGenericDao.createNode(any(HeatParameterData.class), eq(HeatParameterData.class))).thenReturn(either);
- when(titanGenericDao.createRelation(any(GraphNode.class), any(GraphNode.class), eq(GraphEdgeLabels.HEAT_PARAMETER), anyMap())).thenReturn(relationResult);
+ when(titanGenericDao.createRelation(any(GraphNode.class), (GraphNode) any(GraphNode.class), eq(GraphEdgeLabels.HEAT_PARAMETER), anyMap())).thenReturn(relationResult);
StorageOperationStatus result = heatParametersOperation.addPropertiesToGraph(parameters, "resourceId.artifactId", NodeTypeEnum.ArtifactRef);
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java
index 516ee51bab..c7e59006cf 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java
@@ -20,40 +20,51 @@
package org.openecomp.sdc.be.model.operations.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Iterator;
-
-import javax.annotation.Resource;
-
+import com.thinkaurelius.titan.core.TitanGraph;
+import com.thinkaurelius.titan.core.TitanVertex;
+import fj.data.Either;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
+import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.ModelTestBase;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.PolicyTypeData;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.core.TitanVertex;
+import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Stream;
-import fj.data.Either;
+import static com.google.common.collect.Sets.newHashSet;
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
-
public class PolicyTypeOperationTest extends ModelTestBase {
- @Resource(name = "policy-type-operation")
+ private static final String NULL_STRING = null;
+ @Autowired
private PolicyTypeOperation policyTypeOperation;
+ @Autowired
+ private TitanGenericDao titanGenericDao;
+
@BeforeClass
public static void setupBeforeClass() {
ModelTestBase.init();
@@ -99,17 +110,269 @@ public class PolicyTypeOperationTest extends ModelTestBase {
assertTrue(eitherPolicyTypeFetched.isLeft());
PolicyTypeDefinition policyTypeFetched = eitherPolicyTypeFetched.left().value();
assertEquals(policyTypeFetched.toString(), policyTypeCreated.toString());
+ }
+
+ @Test
+ public void testGetLatestPolicyTypeByType_derivedFromFetchedCorrectly() {
+ PolicyTypeDefinition rootPolicyType = createRootPolicyTypeOnGraph();
+ String derivedFromRootType = rootPolicyType.getType();
+ PolicyTypeDefinition policyType1 = createPolicyTypeDef("tosca.policies.type1", "desc1", derivedFromRootType);
+ policyTypeOperation.addPolicyType(policyType1);
+ Either<PolicyTypeDefinition, StorageOperationStatus> eitherPolicyTypeFetched = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ assertThat(eitherPolicyTypeFetched.left().value().getDerivedFrom()).isEqualTo(rootPolicyType.getType());
+ }
+
+ @Test
+ public void testGetLatestPolicyTypeByType_whenGettingTypeGetPropertiesFromAllDerivedFromChain_policyTypeHasNoDirectProps() {
+ PropertyDefinition prop1 = createSimpleProperty("val1", "prop1", "string");
+ PropertyDefinition prop2 = createSimpleProperty("val2", "prop2", "string");
+ PolicyTypeDefinition policyType1 = createPolicyTypeDef("tosca.policies.type1", null, prop1, prop2);
+ PolicyTypeDefinition policyType2 = createPolicyTypeDef("tosca.policies.type2", "desc3", policyType1.getType(), null);
+ addPolicyTypesToDB(policyType1, policyType2);
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType2 = policyTypeOperation.getLatestPolicyTypeByType(policyType2.getType());
+ assertThat(latestPolicyType2.isLeft());
+ assertThat(latestPolicyType2.left().value().getProperties())
+ .usingElementComparatorOnFields("defaultValue", "name", "type")
+ .containsExactlyInAnyOrder(prop1, prop2);
+ }
+
+ @Test
+ public void testGetLatestPolicyTypeByType_whenGettingTypeGetPropertiesFromAllDerivedFromChain() {
+ PropertyDefinition prop1 = createSimpleProperty("val1", "prop1", "string");
+ PropertyDefinition prop2 = createSimpleProperty("val2", "prop2", "string");
+ PropertyDefinition prop3 = createSimpleProperty("val3", "prop3", "string");
+
+ PolicyTypeDefinition rootPolicyType = createPolicyTypeDef(prop1);
+ PolicyTypeDefinition policyType1 = createPolicyTypeDef("tosca.policies.type1", "desc1", rootPolicyType.getType(), null);
+ PolicyTypeDefinition policyType2 = createPolicyTypeDef("tosca.policies.type2", "desc2", policyType1.getType(), prop2);
+ PolicyTypeDefinition policyType3 = createPolicyTypeDef("tosca.policies.type3", "desc3", policyType2.getType(), null);
+ PolicyTypeDefinition policyType4 = createPolicyTypeDef("tosca.policies.type4", "desc4", policyType3.getType(), prop3);
+
+ addPolicyTypesToDB(rootPolicyType, policyType1, policyType2, policyType3, policyType4);
+
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType3 = policyTypeOperation.getLatestPolicyTypeByType(policyType4.getType());
+ assertThat(latestPolicyType3.isLeft());
+ assertThat(latestPolicyType3.left().value().getProperties())
+ .usingElementComparatorOnFields("defaultValue", "name", "type")
+ .containsExactlyInAnyOrder(prop1, prop2, prop3);
+ }
+
+ @Test
+ public void getAllPolicyTypes_noPolicies() {
+ Either<List<PolicyTypeDefinition>, StorageOperationStatus> allPolicyTypes = policyTypeOperation.getAllPolicyTypes(null);
+ assertThat(allPolicyTypes.isRight());
+ assertThat(allPolicyTypes.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND);
+ }
+
+ @Test
+ public void getAllPolicyTypes() {
+ PolicyTypeDefinition policyType1 = createPolicyTypeDef();
+ PolicyTypeDefinition policyType2 = createPolicyTypeDef("tosca.policies.test1", "desc1", "tosca.policies.Root");
+ addPolicyTypesToDB(policyType1, policyType2);
+ Either<List<PolicyTypeDefinition>, StorageOperationStatus> allPolicyTypesWithNoExcluded = policyTypeOperation.getAllPolicyTypes(null);
+ assertThat(allPolicyTypesWithNoExcluded.left().value()).hasSize(2);
+ assertThat(allPolicyTypesWithNoExcluded.left().value()).usingElementComparatorOnFields("uniqueId", "description", "version", "type")
+ .containsExactlyInAnyOrder(policyType1, policyType2);
+ }
+
+ @Test
+ public void getAllPolicyTypes_whenPassingExcludedTypeList_dontReturnExcludedTypes() {
+ PolicyTypeDefinition policyType1 = createPolicyTypeDef();
+ PolicyTypeDefinition policyType2 = createPolicyTypeDef("tosca.policies.test1", "desc1", "tosca.policies.Root");
+ PolicyTypeDefinition policyType3 = createPolicyTypeDef("tosca.policies.test2", "desc2", "tosca.policies.Root");
+ policyTypeOperation.addPolicyType(policyType1);
+ policyTypeOperation.addPolicyType(policyType2);
+ policyTypeOperation.addPolicyType(policyType3);
+ Either<List<PolicyTypeDefinition>, StorageOperationStatus> allPolicyTypes = policyTypeOperation.getAllPolicyTypes(newHashSet("tosca.policies.test1", "tosca.policies.test2"));
+ assertThat(allPolicyTypes.left().value()).hasSize(1);
+ assertThat(allPolicyTypes.left().value()).usingElementComparatorOnFields("type")
+ .containsExactly(policyType1);
+ }
+
+ @Test
+ public void addPolicyType_whenDerivedFromNodeNotExist_returnNotFound() {
+ PolicyTypeDefinition type1 = createPolicyTypeDef("tosca.policies.type1", "desc1", "derivedFrom");
+ Either<PolicyTypeDefinition, StorageOperationStatus> addedPolicyTypeResult = policyTypeOperation.addPolicyType(type1);
+ assertThat(addedPolicyTypeResult.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND);
+ }
+
+ @Test//bug379696
+ public void addPolicyType_derivedFromAddedCorrectly() {
+ PolicyTypeDefinition rootPolicyType = createRootPolicyTypeOnGraph();
+ String derivedFromRootType = rootPolicyType.getType();
+ PolicyTypeDefinition policyType1 = createPolicyTypeDef("tosca.policies.type1", "desc1", derivedFromRootType);
+ Either<PolicyTypeDefinition, StorageOperationStatus> addedPolicyTypeResult = policyTypeOperation.addPolicyType(policyType1);
+ assertThat(addedPolicyTypeResult.isLeft()).isTrue();
+
+ Either<PolicyTypeDefinition, StorageOperationStatus> fetchedPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ PolicyTypeDefinition fetchedPolicyTypeVal = fetchedPolicyType.left().value();
+ assertThat(fetchedPolicyTypeVal.getDerivedFrom()).isEqualTo(derivedFromRootType);
+ verifyDerivedFromNodeEqualsToRootPolicyType(rootPolicyType, fetchedPolicyTypeVal.getUniqueId());
+
+ }
+
+ @Test
+ public void updatePolicyType_returnNotFoundErrorIfTryingToUpdateANonExistingType() {
+ PolicyTypeDefinition currType = createPolicyTypeDef();
+ PolicyTypeDefinition updatedType = createPolicyTypeDef();
+ Either<PolicyTypeDefinition, StorageOperationStatus> updatePolicyTypeRes = policyTypeOperation.updatePolicyType(updatedType, currType);
+ assertThat(updatePolicyTypeRes.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND);
+ }
+ @Test
+ public void updatePolicyType_basicFields() {
+ PolicyTypeDefinition createdType = createPolicyTypeDef("type1", "description1", NULL_STRING);
+ Either<PolicyTypeDefinition, StorageOperationStatus> currPolicyType = policyTypeOperation.addPolicyType(createdType);
+
+ PolicyTypeDefinition updatedType = createPolicyTypeDef("type1", "description2", NULL_STRING);
+ policyTypeOperation.updatePolicyType(updatedType, currPolicyType.left().value());
+
+ Either<PolicyTypeDefinition, StorageOperationStatus> fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(createdType.getType());
+ PolicyTypeDefinition fetchedPolicyType = fetchedUpdatedType.left().value();
+ assertThat(fetchedPolicyType.getProperties()).isEmpty();
+ assertThat(fetchedPolicyType)
+ .isEqualToIgnoringGivenFields(updatedType, "properties");
+
+ }
+
+ @Test
+ public void updatePolicyType_updateProperties() {
+ PropertyDefinition prop1 = createSimpleProperty("val1", "prop1", "string");
+ PolicyTypeDefinition policyType = createPolicyTypeDef(prop1);
+ Either<PolicyTypeDefinition, StorageOperationStatus> currPolicyType = policyTypeOperation.addPolicyType(policyType);
+
+ PropertyDefinition updatedProp1 = duplicateProperty(prop1, "newVal1", "int");
+ PropertyDefinition prop2 = createSimpleProperty("val2", "prop2", "string");
+ PolicyTypeDefinition updatedPolicyType = createPolicyTypeDef(updatedProp1, prop2);
+
+ policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value());
+
+ Either<PolicyTypeDefinition, StorageOperationStatus> fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(policyType.getType());
+ assertThat(fetchedUpdatedType.left().value().getProperties())
+ .usingElementComparatorOnFields("name", "defaultValue", "type")
+ .containsExactlyInAnyOrder(updatedProp1, prop2);
+
+ }
+
+ @Test
+ public void updatePolicyType_derivedFrom_whenNoPrevDerivedFrom_updateToNewDerivedFrom() {
+ PolicyTypeDefinition rootPolicyType = createPolicyTypeDef();
+ PolicyTypeDefinition policyType1 = createPolicyTypeDef("type1", "descr", NULL_STRING);
+ PolicyTypeDefinition updatedPolicyType = createPolicyTypeDef("type1", "descr", rootPolicyType.getType());
+ policyTypeOperation.addPolicyType(rootPolicyType);
+ Either<PolicyTypeDefinition, StorageOperationStatus> currPolicyType = policyTypeOperation.addPolicyType(policyType1);
+ policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value());
+
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ assertThat(latestPolicyType.left().value().getDerivedFrom()).isEqualTo(rootPolicyType.getType());
+ verifyDerivedFromNodeEqualsToRootPolicyType(rootPolicyType, latestPolicyType.left().value().getUniqueId());
+ }
+
+ @Test
+ public void updatePolicyType_derivedFrom_updateToNullDerivedFrom_derivedFromDeleted() {
+ PolicyTypeDefinition rootPolicyType = createPolicyTypeDef();
+ PolicyTypeDefinition policyType1 = createPolicyTypeDef("type1", "descr", rootPolicyType.getType());
+ PolicyTypeDefinition updatedPolicyType = createPolicyTypeDef("type1", "descr", null, new PropertyDefinition[]{});
+ policyTypeOperation.addPolicyType(rootPolicyType);
+ Either<PolicyTypeDefinition, StorageOperationStatus> currPolicyType = policyTypeOperation.addPolicyType(policyType1);
+
+ policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value());
+
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ assertThat(latestPolicyType.left().value().getDerivedFrom()).isNull();
+ verifyDerivedFromRelationDoesntExist(latestPolicyType.left().value().getUniqueId());
+ }
+
+ @Test
+ public void updatePolicyType_updateDerivedFrom() {
+ PolicyTypeDefinition rootPolicyType = createPolicyTypeDef();
+ PolicyTypeDefinition derivedType1 = createPolicyTypeDef("derivedType1", "descr", NULL_STRING);
+ PolicyTypeDefinition policyType1 = createPolicyTypeDef("type1", "descr", derivedType1.getType());
+ PolicyTypeDefinition updatedPolicyType = createPolicyTypeDef("type1", "descr", rootPolicyType.getType());
+
+ policyTypeOperation.addPolicyType(rootPolicyType);
+ policyTypeOperation.addPolicyType(derivedType1);
+ Either<PolicyTypeDefinition, StorageOperationStatus> currPolicyType = policyTypeOperation.addPolicyType(policyType1);
+
+ policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value());
+
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ assertThat(latestPolicyType.left().value().getDerivedFrom()).isEqualTo(rootPolicyType.getType());
+ verifyDerivedFromNodeEqualsToRootPolicyType(rootPolicyType, latestPolicyType.left().value().getUniqueId());
+ }
+
+ private PropertyDefinition duplicateProperty(PropertyDefinition prop1, String updatedValue, String updatedType) {
+ PropertyDefinition updatedProp1 = new PropertyDefinition(prop1);
+ updatedProp1.setUniqueId(null);
+ updatedProp1.setDefaultValue(updatedValue);
+ updatedProp1.setType(updatedType);
+ return updatedProp1;
+ }
+
+ private PropertyDefinition createSimpleProperty(String defaultValue, String name, String type) {
+ PropertyDefinition prop1 = new PropertyDefinition();
+ prop1.setDefaultValue(defaultValue);
+ prop1.setName(name);
+ prop1.setType(type);
+ return prop1;
}
+ private void verifyDerivedFromNodeEqualsToRootPolicyType(PolicyTypeDefinition rootPolicyType, String parentPolicyId) {
+ Either<ImmutablePair<PolicyTypeData, GraphEdge>, TitanOperationStatus> derivedFromRelation = titanGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), parentPolicyId, GraphEdgeLabels.DERIVED_FROM,
+ NodeTypeEnum.PolicyType, PolicyTypeData.class);
+ assertThat(derivedFromRelation.left().value().getLeft().getPolicyTypeDataDefinition())
+ .isEqualToComparingFieldByField(rootPolicyType);
+ }
+
+ private void verifyDerivedFromRelationDoesntExist(String parentPolicyId) {
+ Either<ImmutablePair<PolicyTypeData, GraphEdge>, TitanOperationStatus> derivedFromRelation = titanGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), parentPolicyId, GraphEdgeLabels.DERIVED_FROM,
+ NodeTypeEnum.PolicyType, PolicyTypeData.class);
+ assertThat(derivedFromRelation.right().value())
+ .isEqualTo(TitanOperationStatus.NOT_FOUND);
+ }
+
+ private PolicyTypeDefinition createRootPolicyTypeOnGraph() {
+ PolicyTypeDefinition rootPolicyType = createPolicyTypeDef();
+ policyTypeOperation.addPolicyType(rootPolicyType);
+ return rootPolicyType;
+
+ }
+
private PolicyTypeDefinition createPolicyTypeDef() {
+ return createPolicyTypeDef("tosca.policies.Root", "description: The TOSCA Policy Type all other TOSCA Policy Types derive from", null, new PropertyDefinition[]{});
+ }
+
+ private PolicyTypeDefinition createPolicyTypeDef(PropertyDefinition ... props) {
+ return createPolicyTypeDef("tosca.policies.Root", null, props);
+ }
+
+ private PolicyTypeDefinition createPolicyTypeDef(String type, String derivedFrom, PropertyDefinition ... props) {
+ PolicyTypeDefinition policyType = createPolicyTypeDef(type, "description: The TOSCA Policy Type all other TOSCA Policy Types derive from", derivedFrom);
+ policyType.setProperties(asList(props));
+ return policyType;
+ }
+
+ private PolicyTypeDefinition createPolicyTypeDef(String type, String description, String derivedFrom) {
+ return createPolicyTypeDef(type, description, derivedFrom, null);
+ }
+
+ private PolicyTypeDefinition createPolicyTypeDef(String type, String description, String derivedFrom, PropertyDefinition ... props) {
PolicyTypeDataDefinition policyTypeDataDefinition = new PolicyTypeDataDefinition();
- policyTypeDataDefinition.setDescription("description: The TOSCA Policy Type all other TOSCA Policy Types derive from");
- policyTypeDataDefinition.setType("tosca.policies.Root");
+ policyTypeDataDefinition.setDescription(description);
+ policyTypeDataDefinition.setType(type);
+ policyTypeDataDefinition.setDerivedFrom(derivedFrom);
PolicyTypeDefinition policyTypeDefinition = new PolicyTypeDefinition(policyTypeDataDefinition);
policyTypeDefinition.setHighestVersion(true);
policyTypeDefinition.setVersion("1.0");
+ if (props != null) {
+ policyTypeDefinition.setProperties(asList(props));
+ }
return policyTypeDefinition;
}
+ private void addPolicyTypesToDB(PolicyTypeDefinition ... policyTypeDefinitions) {
+ Stream.of(policyTypeDefinitions).forEach(policyTypeOperation::addPolicyType);
+ }
+
+
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java
index d862c56790..88f3a24b5d 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java
@@ -20,19 +20,6 @@
package org.openecomp.sdc.be.model.operations.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -48,11 +35,21 @@ import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
public class PropertyOperationTest extends ModelTestBase {
TitanGenericDao titanGenericDao = Mockito.mock(TitanGenericDao.class);
- PropertyOperation propertyOperation = new PropertyOperation(titanGenericDao);
+ PropertyOperation propertyOperation = new PropertyOperation(titanGenericDao, null);
@Before
public void setup() {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java
index 53bd753fa3..6e9fdc2928 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java
@@ -45,6 +45,7 @@ import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.jsongraph.utils.IdBuilderUtils;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
@@ -57,6 +58,7 @@ import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.catalog.CatalogComponent;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
@@ -65,6 +67,7 @@ import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation;
+import org.openecomp.sdc.be.model.jsontitan.utils.GraphTestUtils;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.springframework.test.context.ContextConfiguration;
@@ -78,23 +81,23 @@ import fj.data.Either;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
public class ToscaElementLifecycleOperationTest extends ModelTestBase {
-
+
@javax.annotation.Resource
protected TitanDao titanDao;
@javax.annotation.Resource
private NodeTypeOperation nodeTypeOperation;
-
+
@javax.annotation.Resource
private TopologyTemplateOperation topologyTemplateOperation;
-
+
@javax.annotation.Resource
private ToscaElementLifecycleOperation lifecycleOperation;
-
+
String categoryName = "category";
String subcategory = "mycategory";
String outputDirectory = "C:\\Output";
-
+
@Rule
public TestName name = new TestName();
@@ -102,11 +105,12 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
public static void initLifecycleOperation() {
ModelTestBase.init();
}
-
+
private GraphVertex ownerVertex;
private GraphVertex modifierVertex;
private GraphVertex vfVertex;
private GraphVertex serviceVertex;
+ private GraphVertex rootVertex;
@Before
public void setupBefore() {
@@ -114,222 +118,271 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
createUsers();
createResourceCategory();
createServiceCategory();
- createRootNodeType();
+ GraphTestUtils.createRootCatalogVertex(titanDao);
+ rootVertex = createRootNodeType();
createNodeType("firstVf");
- createTopologyTemplate("firstService");
+ serviceVertex = createTopologyTemplate("firstService");
}
-
@Test
public void lifecycleTest() {
- Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation
- .checkinToscaELement(LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)),
- vfVertex.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+ Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(), modifierVertex.getUniqueId(),
+ ownerVertex.getUniqueId());
StorageOperationStatus status;
-
+
assertTrue(res.isLeft());
+ // 1-node type
+ // 2-vf
+ // 3- service
+ verifyInCatalogData(3, null);
+
String id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
+ verifyInCatalogData(3, null);
+
PropertyDataDefinition prop55 = new PropertyDataDefinition();
prop55.setName("prop55");
prop55.setDefaultValue("def55");
-
+
status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
assertTrue(status == StorageOperationStatus.OK);
-
+
CapabilityDataDefinition cap1 = new CapabilityDataDefinition();
cap1.setName("cap1");
cap1.setDescription("create");
cap1.setUniqueId(UniqueIdBuilder.buildCapabilityUid(id, "cap1"));
-
+
status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILTIES, cap1, JsonPresentationFields.NAME);
assertTrue(status == StorageOperationStatus.OK);
-
+
res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
prop55.setDefaultValue("AAAAAAAA");
status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
assertTrue(status == StorageOperationStatus.OK);
-
+
cap1.setDescription("update");
-
+
status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILTIES, cap1, JsonPresentationFields.NAME);
assertTrue(status == StorageOperationStatus.OK);
-
+
PropertyDataDefinition prop66 = new PropertyDataDefinition();
prop66.setName("prop66");
prop66.setDefaultValue("def66");
-
+
status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66, JsonPresentationFields.NAME);
assertTrue(status == StorageOperationStatus.OK);
-
+
res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
+
+ verifyInCatalogData(3, null);
res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
+
+ verifyInCatalogData(4, null);
PropertyDataDefinition prop77 = new PropertyDataDefinition();
prop77.setName("prop77");
prop77.setDefaultValue("def77");
-
+
status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop77, JsonPresentationFields.NAME);
assertTrue(status == StorageOperationStatus.OK);
-
+
res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
PropertyDataDefinition prop88 = new PropertyDataDefinition();
prop88.setName("prop88");
prop88.setDefaultValue("def88");
-
+
status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop88, JsonPresentationFields.NAME);
assertTrue(status == StorageOperationStatus.OK);
-
+
res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
+ verifyInCatalogData(3, null);
res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
+
+ verifyInCatalogData(4, null);
PropertyDataDefinition prop99 = new PropertyDataDefinition();
prop99.setName("prop99");
prop99.setDefaultValue("def99");
-
+
status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99, JsonPresentationFields.NAME);
assertTrue(status == StorageOperationStatus.OK);
-
+
res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99", JsonPresentationFields.NAME);
assertTrue(status == StorageOperationStatus.OK);
-
- //cancel certification
+
+ // cancel certification
res = lifecycleOperation.cancelOrFailCertification(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), LifecycleStateEnum.READY_FOR_CERTIFICATION);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
- //fail certification
+
+ // fail certification
res = lifecycleOperation.cancelOrFailCertification(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
-
- //exportGraphMl(titanDao.getGraph().left().value());
-
+ verifyInCatalogData(4, null);
+ // exportGraphMl(titanDao.getGraph().left().value());
+
}
@Test
public void serviceConformanceLevelTest() {
- Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation
- .checkinToscaELement(LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)),
- serviceVertex.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
-
+ Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(),
+ modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+
assertTrue(res.isLeft());
String id = res.left().value().getUniqueId();
-
+
res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
assertTrue(res.isLeft());
-
+
String conformanceLevel = res.left().value().getMetadataValue(JsonPresentationFields.CONFORMANCE_LEVEL).toString();
assertEquals(conformanceLevel, ModelTestBase.configurationManager.getConfiguration().getToscaConformanceLevel());
}
-
- private void createResourceCategory() {
+
+ @Test
+ public void catalogTest() {
+ // start position - 3 in catalog
+ List<String> expectedIds = new ArrayList<String>();
+ expectedIds.add(rootVertex.getUniqueId());
+ expectedIds.add(vfVertex.getUniqueId());
+ expectedIds.add(serviceVertex.getUniqueId());
+
+ verifyInCatalogData(3, expectedIds);
+ GraphVertex vertex4 = createTopologyTemplate("topTemp4");
+ expectedIds.add(vertex4.getUniqueId());
+ verifyInCatalogData(4, expectedIds);
+
+ Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.undoCheckout(vertex4.getUniqueId());
+ expectedIds.remove(vertex4.getUniqueId());
+ verifyInCatalogData(3, expectedIds);
+
+ vertex4 = createTopologyTemplate("topTemp4");
+ expectedIds.add(vertex4.getUniqueId());
+ verifyInCatalogData(4, expectedIds);
+
+ res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)), vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+ Either<ToscaElement, StorageOperationStatus> certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+ assertTrue(certifyToscaElement.isLeft());
+ expectedIds.remove(vertex4.getUniqueId());
+ String certifiedId = certifyToscaElement.left().value().getUniqueId();
+ expectedIds.add(certifiedId);
+ verifyInCatalogData(4, expectedIds);
+
+ res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+ assertTrue(certifyToscaElement.isLeft());
+ expectedIds.add(res.left().value().getUniqueId());
+ verifyInCatalogData(5, expectedIds);
+ }
+
+ private void createResourceCategory() {
+
GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY);
Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
cat.setUniqueId(catId);
- metadataProperties.put(GraphPropertyEnum.UNIQUE_ID,catId);
+ metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
- metadataProperties.put(GraphPropertyEnum.NAME,categoryName);
+ metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
cat.setMetadataProperties(metadataProperties);
cat.updateMetadataJsonWithCurrentMetadataProperties();
-
+
GraphVertex subCat = new GraphVertex(VertexTypeEnum.RESOURCE_SUBCATEGORY);
metadataProperties = new HashMap<>();
String subCatId = UniqueIdBuilder.buildSubCategoryUid(cat.getUniqueId(), subcategory);
subCat.setUniqueId(subCatId);
- metadataProperties.put(GraphPropertyEnum.UNIQUE_ID,subCatId);
+ metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
- metadataProperties.put(GraphPropertyEnum.NAME,subcategory);
+ metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
+ metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
subCat.setMetadataProperties(metadataProperties);
subCat.updateMetadataJsonWithCurrentMetadataProperties();
-
+
Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
-
+
Either<GraphVertex, TitanOperationStatus> subCatRes = titanDao.createVertex(subCat);
-
+
TitanOperationStatus status = titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
assertEquals(TitanOperationStatus.OK, status);
}
-
+
private void createServiceCategory() {
-
+
GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY);
Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
cat.setUniqueId(catId);
- metadataProperties.put(GraphPropertyEnum.UNIQUE_ID,catId);
+ metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
- metadataProperties.put(GraphPropertyEnum.NAME,categoryName);
+ metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
cat.setMetadataProperties(metadataProperties);
cat.updateMetadataJsonWithCurrentMetadataProperties();
-
+
Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
-
+
assertTrue(catRes.isLeft());
}
-
- private TopologyTemplate createTopologyTemplate(String name) {
-
+
+ private GraphVertex createTopologyTemplate(String name) {
+
TopologyTemplate service = new TopologyTemplate();
String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
service.setUniqueId(uniqueId);
@@ -337,28 +390,28 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
- service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(),ResourceTypeEnum.VF.name());
- service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(),ComponentTypeEnum.RESOURCE);
+ service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
+ service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
List<CategoryDefinition> categories = new ArrayList<>();
CategoryDefinition cat = new CategoryDefinition();
categories.add(cat);
cat.setName(categoryName);
service.setCategories(categories);
-
+
service.setComponentType(ComponentTypeEnum.SERVICE);
Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
assertTrue(createRes.isLeft());
-
- Either<GraphVertex, TitanOperationStatus> getNodeTyeRes= titanDao.getVertexById(createRes.left().value().getUniqueId());
+
+ Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createRes.left().value().getUniqueId());
assertTrue(getNodeTyeRes.isLeft());
-
- serviceVertex = getNodeTyeRes.left().value();
-
- return service;
+
+ // serviceVertex = getNodeTyeRes.left().value();
+
+ return getNodeTyeRes.left().value();
}
-
+
private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) {
-
+
NodeType vf = new NodeType();
String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
vf.setUniqueId(uniqueId);
@@ -366,8 +419,8 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName);
vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
- vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(),ResourceTypeEnum.VF.name());
- vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(),ComponentTypeEnum.RESOURCE);
+ vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
+ vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
List<CategoryDefinition> categories = new ArrayList<>();
CategoryDefinition cat = new CategoryDefinition();
categories.add(cat);
@@ -378,95 +431,90 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
subCategories.add(subCat);
cat.setSubcategories(subCategories);
vf.setCategories(categories);
-
-
+
List<String> derivedFrom = new ArrayList<>();
derivedFrom.add("root");
vf.setDerivedFrom(derivedFrom);
-
-// Map<String, PropertyDataDefinition> properties = new HashMap<>();
-// PropertyDataDefinition prop1 = new PropertyDataDefinition();
-// prop1.setName("prop1");
-// prop1.setDefaultValue("def1");
-//
-// properties.put("prop1", prop1);
-//
-// PropertyDataDefinition prop2 = new PropertyDataDefinition();
-// prop2.setName("prop2");
-// prop2.setDefaultValue("def2");
-// properties.put("prop2", prop2);
-//
-// PropertyDataDefinition prop3 = new PropertyDataDefinition();
-// prop3.setName("prop3");
-// prop3.setDefaultValue("def3");
-// properties.put("prop3", prop3);
-//
-// vf.setProperties(properties);
- vf.setComponentType(ComponentTypeEnum.RESOURCE);
+
+ // Map<String, PropertyDataDefinition> properties = new HashMap<>();
+ // PropertyDataDefinition prop1 = new PropertyDataDefinition();
+ // prop1.setName("prop1");
+ // prop1.setDefaultValue("def1");
+ //
+ // properties.put("prop1", prop1);
+ //
+ // PropertyDataDefinition prop2 = new PropertyDataDefinition();
+ // prop2.setName("prop2");
+ // prop2.setDefaultValue("def2");
+ // properties.put("prop2", prop2);
+ //
+ // PropertyDataDefinition prop3 = new PropertyDataDefinition();
+ // prop3.setName("prop3");
+ // prop3.setDefaultValue("def3");
+ // properties.put("prop3", prop3);
+ //
+ // vf.setProperties(properties);
+ vf.setComponentType(ComponentTypeEnum.RESOURCE);
Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
assertTrue(createVFRes.isLeft());
-
- Either<GraphVertex, TitanOperationStatus> getNodeTyeRes= titanDao.getVertexById(createVFRes.left().value().getUniqueId());
+
+ Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
assertTrue(getNodeTyeRes.isLeft());
-
+
vfVertex = getNodeTyeRes.left().value();
-
-
-
- List<PropertyDataDefinition> addProperties = new ArrayList<>();
- PropertyDataDefinition prop11 = new PropertyDataDefinition();
- prop11.setName("prop11");
- prop11.setDefaultValue("def11");
-
- addProperties.add(prop11);
-
- PropertyDataDefinition prop22 = new PropertyDataDefinition();
- prop22.setName("prop22");
- prop22.setDefaultValue("def22");
- addProperties.add(prop22);
-
- StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
- assertTrue(status == StorageOperationStatus.OK);
-
- PropertyDataDefinition prop33 = new PropertyDataDefinition();
- prop33.setName("prop33");
- prop33.setDefaultValue("def33");
-
- status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
- assertTrue(status == StorageOperationStatus.OK);
-
- PropertyDataDefinition prop44 = new PropertyDataDefinition();
- prop44.setName("prop44");
- prop44.setDefaultValue("def44");
-
- status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
- assertTrue(status == StorageOperationStatus.OK);
-
-
- PropertyDataDefinition capProp = new PropertyDataDefinition();
- capProp.setName( "capProp");
- capProp.setDefaultValue( "capPropDef");
-
- MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
- dataToCreate.put("capProp", capProp);
-
- Map<String, MapDataDefinition> capProps = new HashMap();
- capProps.put("capName", dataToCreate);
-
- Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.assosiateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
-
+
+ List<PropertyDataDefinition> addProperties = new ArrayList<>();
+ PropertyDataDefinition prop11 = new PropertyDataDefinition();
+ prop11.setName("prop11");
+ prop11.setDefaultValue("def11");
+
+ addProperties.add(prop11);
+
+ PropertyDataDefinition prop22 = new PropertyDataDefinition();
+ prop22.setName("prop22");
+ prop22.setDefaultValue("def22");
+ addProperties.add(prop22);
+
+ StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
+ assertTrue(status == StorageOperationStatus.OK);
+
+ PropertyDataDefinition prop33 = new PropertyDataDefinition();
+ prop33.setName("prop33");
+ prop33.setDefaultValue("def33");
+
+ status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
+ assertTrue(status == StorageOperationStatus.OK);
+
+ PropertyDataDefinition prop44 = new PropertyDataDefinition();
+ prop44.setName("prop44");
+ prop44.setDefaultValue("def44");
+
+ status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
+ assertTrue(status == StorageOperationStatus.OK);
+
+ PropertyDataDefinition capProp = new PropertyDataDefinition();
+ capProp.setName("capProp");
+ capProp.setDefaultValue("capPropDef");
+
+ MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
+ dataToCreate.put("capProp", capProp);
+
+ Map<String, MapDataDefinition> capProps = new HashMap();
+ capProps.put("capName", dataToCreate);
+
+ Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.assosiateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
+
// exportGraphMl(titanDao.getGraph().left().value());
-
- List<String> pathKeys = new ArrayList<>();
- pathKeys.add("capName");
- capProp.setDefaultValue( "BBBB");
- status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES,
- capProp, pathKeys, JsonPresentationFields.NAME);
+
+ List<String> pathKeys = new ArrayList<>();
+ pathKeys.add("capName");
+ capProp.setDefaultValue("BBBB");
+ status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
return vf;
}
-
- private void createRootNodeType() {
-
+
+ private GraphVertex createRootNodeType() {
+
NodeType vf = new NodeType();
String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
vf.setUniqueId(uniqueId);
@@ -475,11 +523,11 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
- vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(),ResourceTypeEnum.VFC.name());
+ vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
vf.getMetadata().put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
-
+
List<CategoryDefinition> categories = new ArrayList<>();
CategoryDefinition cat = new CategoryDefinition();
categories.add(cat);
@@ -490,42 +538,42 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
subCategories.add(subCat);
cat.setSubcategories(subCategories);
vf.setCategories(categories);
-
-
+
List<String> derivedFrom = new ArrayList<>();
vf.setDerivedFrom(derivedFrom);
-
- Map<String, PropertyDataDefinition> properties = new HashMap<>();
- PropertyDataDefinition prop1 = new PropertyDataDefinition();
- prop1.setName("derived1");
- prop1.setDefaultValue("deriveddef1");
-
- properties.put("derived1", prop1);
-
- PropertyDataDefinition prop2 = new PropertyDataDefinition();
- prop2.setUniqueId("derived2");
- prop2.setName("deriveddef2");
- properties.put("derived2", prop2);
-
- PropertyDataDefinition prop3 = new PropertyDataDefinition();
- prop3.setName("derived3");
- prop3.setDefaultValue("deriveddef3");
- properties.put("derived3", prop3);
-
- vf.setProperties(properties);
- vf.setComponentType(ComponentTypeEnum.RESOURCE);
+
+ Map<String, PropertyDataDefinition> properties = new HashMap<>();
+ PropertyDataDefinition prop1 = new PropertyDataDefinition();
+ prop1.setName("derived1");
+ prop1.setDefaultValue("deriveddef1");
+
+ properties.put("derived1", prop1);
+
+ PropertyDataDefinition prop2 = new PropertyDataDefinition();
+ prop2.setUniqueId("derived2");
+ prop2.setName("deriveddef2");
+ properties.put("derived2", prop2);
+
+ PropertyDataDefinition prop3 = new PropertyDataDefinition();
+ prop3.setName("derived3");
+ prop3.setDefaultValue("deriveddef3");
+ properties.put("derived3", prop3);
+
+ vf.setProperties(properties);
+ vf.setComponentType(ComponentTypeEnum.RESOURCE);
Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
assertTrue(createVFRes.isLeft());
-
- Either<GraphVertex, TitanOperationStatus> getNodeTyeRes= titanDao.getVertexById(createVFRes.left().value().getUniqueId());
+
+ Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
assertTrue(getNodeTyeRes.isLeft());
+ return getNodeTyeRes.left().value();
}
private void createUsers() {
-
+
GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
ownerV.setUniqueId("user1");
-
+
Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
@@ -535,12 +583,12 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
ownerV.setJson(new HashMap<>());
Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV);
assertTrue(createUserRes.isLeft());
-
+
ownerVertex = createUserRes.left().value();
-
+
GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
modifierV.setUniqueId("user2");
-
+
metadataProperties = new HashMap<>();
metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
@@ -550,12 +598,24 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
modifierV.setJson(new HashMap<>());
createUserRes = titanDao.createVertex(modifierV);
assertTrue(createUserRes.isLeft());
-
+
modifierVertex = createUserRes.left().value();
-
+
Either<GraphVertex, TitanOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId());
assertTrue(getOwnerRes.isLeft());
-
+
+ }
+
+ public void verifyInCatalogData(int expected, List<String> expectedIds) {
+
+ Either<List<CatalogComponent>, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData();
+ assertTrue(highestResourcesRes.isLeft());
+ List<CatalogComponent> highestResources = highestResourcesRes.left().value();
+ // calculate expected count value
+ assertEquals(expected, highestResources.stream().count());
+ if (expectedIds != null) {
+ highestResources.forEach(a -> assertTrue(expectedIds.contains(a.getUniqueId())));
+ }
}
@After
@@ -594,5 +654,5 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase {
return result;
}
-
+
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java
index d5425504e6..e15d784c7a 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java
@@ -1,19 +1,19 @@
package org.openecomp.sdc.be.model.tosca.converters;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import com.google.gson.JsonObject;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import javax.json.Json;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-
-import com.google.gson.JsonObject;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
public class DataTypePropertyConverterTest {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverterTest.java
index 5367dcb8a3..7e9388ee1b 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverterTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverterTest.java
@@ -2,22 +2,73 @@ package org.openecomp.sdc.be.model.tosca.converters;
import org.junit.Test;
+import java.util.Collections;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.junit.Assert.assertNull;
+
public class ToscaFloatConverterTest {
- private ToscaFloatConverter createTestSubject() {
- return ToscaFloatConverter.getInstance();
- }
+ @Test
+ public void convertEmptyString_returnNull() {
+ assertNull(executeFloatConversion(""));
+ }
+
+ @Test
+ public void convertNull_returnNull() {
+ assertNull(executeFloatConversion(null));
+ }
+
+ @Test
+ public void convertWholeNumber() {
+ assertThat(executeFloatConversion("1234"))
+ .isEqualTo("1234");
+ }
+
+ @Test
+ public void convertFloatNumber() {
+ assertThat(executeFloatConversion("3.141"))
+ .isEqualTo("3.141");
+ }
+
+ @Test
+ public void convertNotValidFloat() {
+ assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123.55.66"));
+ }
+
+ @Test
+ public void convertNumericWithSpecialChars() {
+ assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123,55"));
+ assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123&55"));
+ assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123$$55"));
+ assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123#55"));
+ }
+
+ @Test
+ public void convertNonNumeric() {
+ assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("1234ABC"));
+ }
-
- @Test
- public void testGetInstance() throws Exception {
- ToscaFloatConverter result;
+ @Test
+ public void convertNumericWithCapitalFloatSign() {
+ assertThat(executeFloatConversion("1234F"))
+ .isEqualTo("1234");
+ }
- // default test
- result = ToscaFloatConverter.getInstance();
- }
+ @Test
+ public void convertNumericWithSmallLetterFloatSign() {
+ assertThat(executeFloatConversion("1234f"))
+ .isEqualTo("1234");
+ }
-
+ @Test
+ public void convertNumericWithFloatSignNotAtTheEnd_ThrowsException() {
+ assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("12f34"));
+ }
+ private String executeFloatConversion(String s) {
+ return ToscaFloatConverter.getInstance().convert(s, null, Collections.emptyMap());
+ }
} \ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/MapValidatorTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/MapValidatorTest.java
new file mode 100644
index 0000000000..6f33b19de3
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/MapValidatorTest.java
@@ -0,0 +1,16 @@
+package org.openecomp.sdc.be.model.tosca.validators;
+
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.*;
+
+public class MapValidatorTest {
+
+ @Test
+ public void isValid_nonMapString() {
+ assertFalse(MapValidator.getInstance().isValid("abc", "string", Collections.emptyMap()));
+ assertFalse(MapValidator.getInstance().isValid("1", "string", Collections.emptyMap()));
+ }
+} \ No newline at end of file