summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/test')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java24
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java20
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java24
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java104
4 files changed, 166 insertions, 6 deletions
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() {
@@ -449,6 +451,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;
JsonParseFlagEnum result;
@@ -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,10 +367,29 @@ public class TopologyTemplateTest {
}
+ @Test
+ public void testGetDataTypes() throws Exception {
+ TopologyTemplate testSubject;
+ Map<String, DataTypeDataDefinition> result;
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getDataTypes();
+ }
@Test
+ public void testSetDataTypes() throws Exception {
+ TopologyTemplate testSubject;
+ Map<String, DataTypeDataDefinition> dataTypes = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setDataTypes(dataTypes);
+ }
+
+
+ @Test
public void testGetComponentInstances() throws Exception {
TopologyTemplate testSubject;
Map<String, ComponentInstanceDataDefinition> result;
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;
@@ -107,6 +106,23 @@ public class TopologyTemplateOperationTest {
}
@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<ToscaElement, StorageOperationStatus> storageOperationStatus = topologyTemplateOperation.getToscaElement(containerVertex, filter);
+ assertThat(storageOperationStatus).isEqualTo(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ }
+
+ @Test
public void testUpdateDistributionStatus() {
Either<GraphVertex, StorageOperationStatus> result;
String uniqueId = "uniqueId";
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<List<DataTypeDefinition>, StorageOperationStatus> result = addDataTypesToComponentWithStatus(StorageOperationStatus.OK);
+ assertTrue(result.isLeft());
+ }
+
+ @Test
+ public void addDataTypesToComponentFailureTest_BadRequest(){
+ Either<List<DataTypeDefinition>, StorageOperationStatus> result = addDataTypesToComponentWithStatus(StorageOperationStatus.BAD_REQUEST);
+ assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.BAD_REQUEST);
+ }
+
+ private Either<List<DataTypeDefinition>, StorageOperationStatus> addDataTypesToComponentWithStatus(StorageOperationStatus status) {
+ Map<String, DataTypeDefinition> 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<GraphVertex, TitanOperationStatus> 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<List<DataTypeDefinition>, StorageOperationStatus> result;
+ String componentId = "componentId";
+ GraphVertex vertex = getNodeTypeVertex();
+ Map<String, DataTypeDefinition> 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<String, DataTypeDataDefinition> dataTypeDataMap = new HashMap<>();
+ dataTypeDataMap.put("datatype1", dataType1);
+ List<DataTypeDefinition> 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<PolicyDefinition, StorageOperationStatus> associatePolicyToComponentWithStatus(StorageOperationStatus status) {
PolicyDefinition policy = new PolicyDefinition();
String componentId = "componentId";