[SDC-243] adding value to SdcTypes 75/10375/1
authorPavel Aharoni <pa0916@att.com>
Tue, 5 Sep 2017 15:57:07 +0000 (18:57 +0300)
committerPavel Aharoni <pa0916@att.com>
Tue, 5 Sep 2017 15:57:07 +0000 (18:57 +0300)
Change-Id: I7e1236d9cecbf2d44744766eb7f27d7145d5a537
Signed-off-by: Pavel Aharoni <pa0916@att.com>
pom.xml
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-PortMirroring.csar [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 3ccca61..dfb1b37 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
        <artifactId>sdc-tosca</artifactId>\r
        <name>SDC Tosca Parser</name>\r
        <description>SDC Tosca Parser JAR file for use by consumers</description>\r
-       <version>1.1.50-SNAPSHOT</version>\r
+       <version>1.1.51-SNAPSHOT</version>\r
        <packaging>jar</packaging>\r
 \r
        <properties>\r
index c320f63..7b94000 100644 (file)
@@ -634,13 +634,13 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
                if (sdcType.equals(SdcTypes.VFC) && isVNF)  {
                        return nodeTemplates.stream()
                                .filter(x -> (x.getMetaData() != null &&
-                                       sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) &&  isVNFType(x))
+                                       sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) &&  isVNFType(x))
                                .collect(Collectors.toList());
                }
                else {
                     return nodeTemplates.stream()
                                .filter(x -> (x.getMetaData() != null &&
-                                       sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) &&  !isVNFType(x))
+                                       sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) &&  !isVNFType(x))
                                .collect(Collectors.toList());
                }
             }
@@ -706,9 +706,9 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         }
 
         if (nodeTemplate.getMetaData() != null) {
-            String type = nodeTemplate.getMetaData().getValue("type");
+            String type = nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE);
             log.debug("hasTopology - node template {} is a {} type", nodeTemplate.getName(), type);
-            return SdcTypes.isComplex(SdcTypes.valueOf(type));
+            return SdcTypes.isComplex(type);
         }
 
         return false;
@@ -852,7 +852,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
 
         if (nodeTemplates != null && nodeTemplates.size() > 0)
-            return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
+            return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
 
         log.debug("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist");
         return new ArrayList<>();
index 5dc9101..03d61a6 100644 (file)
@@ -22,14 +22,25 @@ package org.openecomp.sdc.tosca.parser.impl;
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 public enum SdcTypes {
 
-    CP, VL, VF, VFC, PNF, SERVICE, CVFC, SERVICE_PROXY, CONFIGURATION;
+    CP("CP"), VL("VL"), VF("VF"), VFC("VFC"), PNF("PNF"), SERVICE("Service"), CVFC("CVFC"), SERVICE_PROXY("Service Proxy"), CONFIGURATION("Configuration");
 
-    public static List<SdcTypes> complexTypes = Arrays.asList(VF, PNF, SERVICE, CVFC);
+    private String value;
 
-    public static boolean isComplex(SdcTypes sdcType) {
+    private static List<String> complexTypes = Arrays.asList(VF, PNF, SERVICE, CVFC).stream().map(SdcTypes::getValue).collect(Collectors.toList());
+
+    private SdcTypes(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public static boolean isComplex(String sdcType) {
         return complexTypes.contains(sdcType);
     }
 }
index a73f121..90124c5 100644 (file)
@@ -33,8 +33,10 @@ public abstract class SdcToscaParserBasicTest {
     static ISdcCsarHelper resolveGetInputCsarFalse;
     static ISdcCsarHelper resolveGetInputCsarQA;
     static ISdcCsarHelper resolveReqsCapsCsarQA;
+       static ISdcCsarHelper portMirroring;
 
-    static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data;
+
+       static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data;
     
     @BeforeClass
     public static void init() throws SdcToscaParserException, JToscaException, IOException {
@@ -53,6 +55,7 @@ public abstract class SdcToscaParserBasicTest {
                resolveGetInputCsarQA = getCsarHelper("csars/service-resolve-get-input-csar_QA.csar");
                QAServiceForToscaParserTests = getCsarHelper("csars/service-ServiceForToscaParserTests-csar.csar");
                resolveReqsCapsCsarQA = getCsarHelper("csars/service-sunny-flow2.csar");
+               portMirroring = getCsarHelper("csars/service-PortMirroring.csar");
                
         fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){
                {
index 2c62ca2..ad240b1 100644 (file)
@@ -483,10 +483,17 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
        public void testServiceNodeTemplateBySdcType() {
                List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(SdcTypes.VF);
                assertNotNull(serviceVfList);
-               assertEquals(2, serviceVfList.size());
+               assertEquals(serviceVfList.size(), 2);
                assertEquals(serviceVfList.get(0).getName(), "FDNT 1");
        }
 
+       @Test
+       public void testServiceNodeTemplateBySdcTypeServiceProxy() {
+               List<NodeTemplate> serviceProxies = portMirroring.getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
+               assertNotNull(serviceProxies);
+               assertEquals(serviceProxies.size(), 2);
+       }
+
        @Test
        public void testServiceNodeTemplateByNullSdcType() {
                List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(null);
diff --git a/src/test/resources/csars/service-PortMirroring.csar b/src/test/resources/csars/service-PortMirroring.csar
new file mode 100644 (file)
index 0000000..6186291
Binary files /dev/null and b/src/test/resources/csars/service-PortMirroring.csar differ