From 51411acd1d4b06fc9bbc40338a27dd061dba425f Mon Sep 17 00:00:00 2001 From: Toshimichi Fukuda Date: Thu, 18 Apr 2019 21:38:46 +0900 Subject: Change to enable SDC list type input Change-Id: Ic3a9c6e714a5afd22b58bf2cb066932b1ec2a5c0 Issue-ID: SDC-2046 Signed-off-by: Toshimichi Fukuda Signed-off-by: Satoshi Fujii Signed-off-by: Ayumu Ueha --- .../sdc/be/model/ComponentParametersViewTest.java | 24 ++++- .../jsontitan/datamodel/TopologyTemplateTest.java | 20 ++++ .../operations/TopologyTemplateOperationTest.java | 24 ++++- .../operations/ToscaOperationFacadeTest.java | 104 ++++++++++++++++++++- 4 files changed, 166 insertions(+), 6 deletions(-) (limited to 'catalog-model/src/test/java/org') diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java index d84b821950..7f8ea5184c 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java @@ -7,6 +7,8 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import java.util.LinkedList; +import static org.junit.Assert.assertSame; + public class ComponentParametersViewTest { private ComponentParametersView createTestSubject() { @@ -448,6 +450,26 @@ public class ComponentParametersViewTest { } + @Test + public void testIsIgnoreNodeFilterWithTrue() throws Exception { + ComponentParametersView testSubject; + + testSubject = createTestSubject(); + testSubject.setIgnoreNodeFilter(true); + assertSame(testSubject.isIgnoreNodeFilter(), true); + } + + + @Test + public void testIsIgnoreNodeFilterWithFalse() throws Exception { + ComponentParametersView testSubject; + + testSubject = createTestSubject(); + testSubject.setIgnoreNodeFilter(false); + assertSame(testSubject.isIgnoreNodeFilter(), false); + } + + @Test public void testDetectParseFlag() throws Exception { ComponentParametersView testSubject; @@ -457,4 +479,4 @@ public class ComponentParametersViewTest { testSubject = createTestSubject(); result = testSubject.detectParseFlag(); } -} \ No newline at end of file +} diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java index 72ca0c0cab..c13ddd3970 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java @@ -5,6 +5,7 @@ import java.util.Map; import org.junit.Test; import org.openecomp.sdc.be.datatypes.elements.*; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; +import org.openecomp.sdc.be.model.DataTypeDefinition; public class TopologyTemplateTest { @@ -366,9 +367,28 @@ public class TopologyTemplateTest { } + @Test + public void testGetDataTypes() throws Exception { + TopologyTemplate testSubject; + Map result; + // default test + testSubject = createTestSubject(); + result = testSubject.getDataTypes(); + } + @Test + public void testSetDataTypes() throws Exception { + TopologyTemplate testSubject; + Map dataTypes = null; + + // default test + testSubject = createTestSubject(); + testSubject.setDataTypes(dataTypes); + } + + @Test public void testGetComponentInstances() throws Exception { TopologyTemplate testSubject; 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 index 8bb252ea12..4ace70b34f 100644 --- 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 @@ -26,11 +26,10 @@ import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; +import java.util.*; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; @@ -106,6 +105,23 @@ public class TopologyTemplateOperationTest { assertEquals(StorageOperationStatus.OK, result); } + @Test + public void testSetDataTypesFromGraph() { + GraphVertex containerVertex = new GraphVertex(); + ComponentParametersView filter = new ComponentParametersView(true); + filter.setIgnoreComponentInstancesInterfaces(true); + filter.setIgnoreDataType(false); + String componentName = "componentName"; + String componentId = UniqueIdBuilder.buildResourceUniqueId(); + containerVertex.setVertex(Mockito.mock(TitanVertex.class)); + containerVertex.setJsonMetadataField(JsonPresentationFields.NAME, componentName); + containerVertex.setUniqueId(componentId); + containerVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE); + when(titanDao.getChildVertex(any(GraphVertex.class), any(EdgeLabelEnum.class), any(JsonParseFlagEnum.class))).thenReturn(Either.right(TitanOperationStatus.GENERAL_ERROR)); + Either storageOperationStatus = topologyTemplateOperation.getToscaElement(containerVertex, filter); + assertThat(storageOperationStatus).isEqualTo(Either.right(StorageOperationStatus.GENERAL_ERROR)); + } + @Test public void testUpdateDistributionStatus() { Either result; 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 63856e6515..0eb0b3c6d2 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 @@ -61,6 +61,9 @@ import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement; import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum; import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.PropertyDefinition; +import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition; import static org.assertj.core.api.Assertions.assertThat; @@ -73,6 +76,8 @@ import java.util.Set; import java.util.HashSet; import java.util.stream.Collectors; import java.util.stream.IntStream; +import java.util.Collections; +import java.util.Arrays; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; @@ -81,11 +86,11 @@ import static org.mockito.Mockito.when; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @RunWith(MockitoJUnitRunner.class) public class ToscaOperationFacadeTest { - @InjectMocks private ToscaOperationFacade testInstance; @@ -482,6 +487,103 @@ public class ToscaOperationFacadeTest { return toscaElement; } + @Test + public void addDataTypesToComponentSuccessTest(){ + Either, StorageOperationStatus> result = addDataTypesToComponentWithStatus(StorageOperationStatus.OK); + assertTrue(result.isLeft()); + } + + @Test + public void addDataTypesToComponentFailureTest_BadRequest(){ + Either, StorageOperationStatus> result = addDataTypesToComponentWithStatus(StorageOperationStatus.BAD_REQUEST); + assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.BAD_REQUEST); + } + + private Either, StorageOperationStatus> addDataTypesToComponentWithStatus(StorageOperationStatus status) { + Map dataTypes = new HashMap<>(); + String componentId = "componentid"; + String Id = "id"; + + PropertyDefinition noDefaultProp = new PropertyDefinition(); + noDefaultProp.setName("noDefaultProp"); + PropertyDefinition prop1 = new PropertyDefinition(); + prop1.setDefaultValue("def1"); + prop1.setName("prop1"); + PropertyDefinition prop2 = new PropertyDefinition(); + prop2.setType("dataType1"); + prop2.setName("prop2"); + PropertyDefinition prop3 = new PropertyDefinition(); + prop3.setDefaultValue("def3"); + prop3.setName("prop3"); + + DataTypeDefinition noDefaultValue = new DataTypeDefinition(); + noDefaultValue.setProperties(Collections.singletonList(noDefaultProp)); + noDefaultValue.setDerivedFromName("name0"); + + DataTypeDefinition dataType1 = new DataTypeDefinition(); + dataType1.setProperties(Arrays.asList(prop1, prop3)); + dataType1.setName("name1"); + dataType1.setDerivedFromName("derivedfromname1"); + + DataTypeDefinition dataType2 = new DataTypeDefinition(); + dataType2.setDerivedFrom(dataType1); + dataType2.setName("name2"); + dataType2.setDerivedFromName("derivedfromname2"); + + DataTypeDefinition dataType3 = new DataTypeDefinition(); + dataType3.setProperties(Collections.singletonList(prop2)); + dataType3.setDerivedFrom(noDefaultValue); + dataType3.setName("name3"); + dataType3.setDerivedFromName("derivedfromname3"); + + dataTypes.put("noDefault", noDefaultValue); + dataTypes.put("dataType1", dataType1); + dataTypes.put("dataType2", dataType2); + dataTypes.put("dataType3", dataType3); + + GraphVertex vertex; + if(status == StorageOperationStatus.OK){ + vertex = getTopologyTemplateVertex(); + } else { + vertex = getNodeTypeVertex(); + } + Either getVertexEither = Either.left(vertex); + when(titanDaoMock.getVertexById(componentId, JsonParseFlagEnum.NoParse)).thenReturn(getVertexEither); + when(topologyTemplateOperationMock.addToscaDataToToscaElement(eq(vertex), + eq(EdgeLabelEnum.DATA_TYPES), eq(VertexTypeEnum.DATA_TYPES), anyMap(), eq(JsonPresentationFields.NAME))).thenReturn(status); + return testInstance.addDataTypesToComponent(dataTypes, componentId); + } + + @Test + public void testDataTypesToComponentFailureTest_NotFound() { + Either, StorageOperationStatus> result; + String componentId = "componentId"; + GraphVertex vertex = getNodeTypeVertex(); + Map dataTypes = new HashMap<>(); + when(titanDaoMock.getVertexById(componentId, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND)); + result = testInstance.addDataTypesToComponent(dataTypes, componentId); + assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.NOT_FOUND); + } + + @Test + public void testDeleteDataTypeOfComponent() { + StorageOperationStatus result; + Component component = new Resource(); + String id = "id"; + component.setUniqueId(id); + String datatype = null; + + DataTypeDefinition dataType1 = new DataTypeDefinition(); + dataType1.setName("name1"); + Map dataTypeDataMap = new HashMap<>(); + dataTypeDataMap.put("datatype1", dataType1); + List dataTypeMap = dataTypeDataMap.values().stream().map(e -> { DataTypeDefinition dataType = new DataTypeDefinition(e);return dataType; }).collect(Collectors.toList()); + component.setDataTypes(dataTypeMap); + GraphVertex graphVertex = getTopologyTemplateVertex(); + result = testInstance.deleteDataTypeOfComponent(component, "datatype1"); + assertEquals(datatype, result); + } + private Either associatePolicyToComponentWithStatus(StorageOperationStatus status) { PolicyDefinition policy = new PolicyDefinition(); String componentId = "componentId"; -- cgit 1.2.3-korg