[SDC-136] support CVFC type 53/5853/1
authorPavel Aharoni <pa0916@att.com>
Mon, 17 Jul 2017 13:26:48 +0000 (16:26 +0300)
committerPavel Aharoni <pa0916@att.com>
Mon, 17 Jul 2017 13:27:08 +0000 (16:27 +0300)
Change-Id: I36af758d5bff633972245d7100a8c892a47527fb
Signed-off-by: Pavel Aharoni <pa0916@att.com>
src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java
src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java
src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
src/test/resources/csars/service-nested-vfc-csar.csar [new file with mode: 0644]

index 45d8392..6c8f5df 100644 (file)
@@ -368,6 +368,11 @@ public interface ISdcCsarHelper {
         * @return VNF Configuration Node Template.
         */
        public NodeTemplate getVnfConfig(String vfCustomizationUuid);
-       
-       
+
+       /**
+        * Check if Node Template has Topology Template
+        * @param nodeTemplate - Node Template to check
+        * @return true if node template has topology template, false if not.
+        */
+       public boolean hasTopology(NodeTemplate nodeTemplate);
 }
index 0ed4c97..7b901ec 100644 (file)
@@ -215,7 +215,10 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
 
         List<NodeTemplate> serviceVfList = getServiceVfList();
         NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
-        return getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC);
+        List<NodeTemplate> vfcs = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC);
+        vfcs.addAll(getNodeTemplateBySdcType(vfInstance, SdcTypes.CVFC));
+
+        return vfcs;
     }
 
     @Override
@@ -649,6 +652,22 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
                return vnfConfig;
        }
 
+    @Override
+    public boolean hasTopology(NodeTemplate nodeTemplate) {
+        if (nodeTemplate == null) {
+            log.error("hasTopology - nodeTemplate - is null");
+            return false;
+        }
+
+        if (nodeTemplate.getMetaData() != null) {
+            String type = nodeTemplate.getMetaData().getValue("type");
+            log.debug("hasTopology - node template {} is a {} type", nodeTemplate.getName(), type);
+            return SdcTypes.isComplex(SdcTypes.valueOf(type));
+        }
+
+        return false;
+    }
+
     /************************************* helper functions ***********************************/
     private Map<String, String> filterProperties(Object property, String path, FilterType filterType, String pattern, Map<String, String> filterMap) {
 
index 5b68aea..9f885f4 100644 (file)
 
 package org.openecomp.sdc.tosca.parser.impl;
 
+import java.util.Arrays;
+import java.util.List;
+
 public enum SdcTypes {
 
-        CP, VL, VF, VFC, PNF, SERVICE
+    CP, VL, VF, VFC, PNF, SERVICE, CVFC;
+
+    public static List<SdcTypes> complexTypes = Arrays.asList(VF, PNF, SERVICE, CVFC);
 
+    public static boolean isComplex(SdcTypes sdcType) {
+        return complexTypes.contains(sdcType);
+    }
 }
index 3af654e..471fbc0 100644 (file)
@@ -27,6 +27,7 @@ public abstract class SdcToscaParserBasicTest {
     static ISdcCsarHelper complexCps;
     static ISdcCsarHelper fdntCsarHelperWithInputs;
     static ISdcCsarHelper nfodCsarHlper;
+       static ISdcCsarHelper nestedVfcCsarHlper;
     static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data;
     
     @BeforeClass
@@ -39,6 +40,7 @@ public abstract class SdcToscaParserBasicTest {
         complexCps = getCsarHelper("csars/service-consolidated-props-csar.csar");
                fdntCsarHelperWithInputs = getCsarHelper("csars/service-ServiceFdnt-with-get-input.csar");
                nfodCsarHlper =  getCsarHelper("csars/service-NfodService-csar.csar");
+               nestedVfcCsarHlper = getCsarHelper("csars/service-nested-vfc-csar.csar");
         fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){
                {
                        HashMap<String, List<String>> FDNT ;
index 8470cbd..d8e065b 100644 (file)
@@ -520,9 +520,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
        }
        //endregion
            
-
-
-    
+       //region getVnfConfig
     @Test
     public void testGetVnfConfig() {
        NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("9bb2ef82-f8f6-4391-bc71-db063f15bf57");
@@ -554,5 +552,59 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
        assertNotNull(vfcList);
        assertEquals(2, vfcList.size());
     }
-    
+    //endregion
+
+       //region nested vfc
+       @Test
+       public void testNestedVfcByExistCvfc() {
+               List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615");
+               assertNotNull(vfcList);
+               assertEquals(1, vfcList.size());
+               assertEquals("VF_VNF", vfcList.get(0).getName());
+       }
+
+       @Test
+       public void testNestedVfcByNullVf() {
+               List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf(null);
+               assertNotNull(vfcList);
+               assertEquals(0, vfcList.size());
+       }
+
+       @Test
+       public void testNestedVfcByDummyVf() {
+               List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf("dummy");
+               assertNotNull(vfcList);
+               assertEquals(0, vfcList.size());
+       }
+       //endregion
+
+       //region hasTopology
+       @Test
+       public void testHasTopologyByVF() {
+               List<NodeTemplate> vfList = nestedVfcCsarHlper.getServiceVfList();
+               boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfList.get(0));
+               assertEquals(true, hasTopology);
+       }
+
+       @Test
+       public void testHasTopologyByCVFC() {
+               List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615");
+               boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfcList.get(0));
+               assertEquals(true, hasTopology);
+       }
+
+       @Test
+       public void testHasTopologyByVL() {
+               List<NodeTemplate> serviceVlList = fdntCsarHelper.getServiceVlList();
+               boolean hasTopology = fdntCsarHelper.hasTopology(serviceVlList.get(0));
+               assertEquals(false, hasTopology);
+       }
+
+       @Test
+       public void testHasTopologyByNull() {
+               boolean hasTopology = fdntCsarHelper.hasTopology(null);
+               assertEquals(false, hasTopology);
+       }
+       //endregion
+
 }
diff --git a/src/test/resources/csars/service-nested-vfc-csar.csar b/src/test/resources/csars/service-nested-vfc-csar.csar
new file mode 100644 (file)
index 0000000..b141fe2
Binary files /dev/null and b/src/test/resources/csars/service-nested-vfc-csar.csar differ