Revert "vLAN . Support Policies." 23/33223/2
authorMichael Lando <ml636r@att.com>
Tue, 27 Feb 2018 18:13:46 +0000 (20:13 +0200)
committerMichael Lando <ml636r@att.com>
Sat, 3 Mar 2018 17:20:37 +0000 (19:20 +0200)
This reverts commit fe7a82b3a8f416fd87519caa07124261d9f117f3.

Issue-ID: SDC-1056
Change-Id: I79a00f8b5d6897d65317f9504cde177c186a6221
Signed-off-by: Michael Lando <ml636r@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/SdcPropertyNames.java
src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java
src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java
src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
src/test/java/org/openecomp/sdc/impl/ToscaParserValidationIssueTest.java
src/test/resources/csars/resource-Policy-csar.csar [deleted file]
src/test/resources/csars/service-AlService-csar.csar [deleted file]

index cd5b018..df9e47d 100644 (file)
@@ -450,98 +450,5 @@ public interface ISdcCsarHelper {
         * @return the leaf value as String, or null if there's no such property, or it's not a leaf.
         */
        public String getCapabilityPropertyLeafValue(CapabilityAssignment capability, String pathToPropertyLeafValue);
-       
-       /**
-        * Get all the policies of the main topology template (either VF or service)
-        * @return      the list of the policies
-        */
-       public List<Map<String, Map<String, Object>>> getPoliciesOfTopologyTemplate();
-       
-       /**
-        * Get all the policies of the main topology template (either VF or service) specified by policy type
-        * @param policyTypeName        the name of the policy type
-        * @return                                      the list of the policies                                                
-        */
-       public List<Map<String, Map<String, Object>>> getPoliciesOfTopologyTemplateByToscaPolicyType(String policyTypeName);
-       
-       /**
-        * Get all the policies of the origin component (nested topology template) of the node template
-        * @param nodeTemplate  the node template
-        * @return                              the list of the policies
-        */
-       public List<Map<String,Object>> getPoliciesOfOriginOfNodeTemplate(NodeTemplate nodeTemplate);
-       
-       /**
-        * Get all the policies of the origin component (nested topology template) of the node template specified by policy type
-        * @param nodeTemplate          the node template
-        * @param policyTypeName        the name of the policy type
-        * @return                                      the list of the policies
-        */
-       public List<Map<String, Object>> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName);
-       
-       /**
-        * Get all the node templates of the topology template, which are the targets of the policy specified by name
-        * @param policyName    the name of the policy
-        * @return                              the list of the node templates
-        */
-       public List<NodeTemplate> getPolicyTargetsFromTopologyTemplate(String policyName);
-       
-       /**
-        * Get all the node templates of the origin component (nested topology template) of node template, which are the targets of the policy specified by name
-        * @param nodeTemplate  the node template
-        * @param policyName    the name of the policy
-        * @return                              the list of the node templates
-        */
-       public List<Map<String, Object>> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName);
-       
-       /**
-        * Get the node template of the topology template specified by name
-        * @param nodeTemplateName      the name of the node template
-        * @return                                      the node template
-        */
-       public NodeTemplate getNodeTemplateByName(String nodeTemplateName);
-    
-    /**
-     * Get all the policies, which contain the specified node template as a target
-     * @param targetNode       the node template
-     * @return                         the list of the policies
-     */
-       public List<Map<String, Map<String, Object>>> getPoliciesOfTarget(NodeTemplate targetNode);
-       
-       /**
-        * Get all the policies of the specified type, which contain the specified node template as a target
-        * @param nodeTemplate          the node template
-        * @param policyTypeName        the name of the policy type
-        * @return                                      the list of the policies
-        */
-    public List<Map<String, Map<String, Object>>> getPoliciesOfTargetByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName);
-    
-    /**
-     * Get all groups of this of the main topology template (either VF or service)
-     * @return  the list of the groups
-     */
-    public List<Map<String, Map<String, Object>>> getGroupsOfTopologyTemplate();
-
-    /**
-     * Get all groups of this of the main topology template (either VF or service) by specified tosca group type
-     * @param groupType     the group type
-     * @return  the list of the groups
-     */
-    public List<Map<String, Map<String, Object>>> getGroupsOfTopologyTemplateByToscaGroupType(String groupType);
-    
-    
-    /**
-     * Get all the groups of the origin component (nested topology template) of the node template
-     * @param               nodeTemplate  the node template
-     * @return              the list of the groups
-     */
-    public List<Map<String,Object>> getGroupsOfOriginOfNodeTemplate(NodeTemplate nodeTemplate);
-    
-    /**
-     * Get group members of the group belongs to the main topology template (either VF or service) by group name
-     * @param groupName     the name of the group
-     * @return
-     */
-    public List<NodeTemplate> getGroupMembersFromTopologyTemplate(String groupName);
 
 }
\ No newline at end of file
index a963189..901b315 100644 (file)
@@ -22,12 +22,15 @@ package org.openecomp.sdc.tosca.parser.impl;
 
 import java.util.*;
 import java.util.Map.Entry;
-import static java.util.stream.Collectors.toList;
+import java.util.stream.Collectors;
+
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
 import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
+import org.openecomp.sdc.toscaparser.api.CapabilityAssignments;
 import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
+import org.openecomp.sdc.toscaparser.api.RequirementAssignments;
 import org.openecomp.sdc.tosca.parser.utils.SdcToscaUtility;
 import org.openecomp.sdc.toscaparser.api.*;
 import org.openecomp.sdc.toscaparser.api.elements.Metadata;
@@ -55,232 +58,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         this.toscaTemplate = toscaTemplate;
         this.configurationManager = configurationManager;
     }
-    
-    @Override
-    public List<Map<String, Map<String, Object>>> getPoliciesOfTarget(NodeTemplate nodeTemplate) {
-       return getPoliciesOfNodeTemplate(nodeTemplate.getName())
-       .stream()
-       .sorted(Policy::compareTo)
-       .map(this::convertPolicyToMap)
-       .collect(toList());
-    }
-    
-    @Override
-       public List<Map<String,Object>> getPoliciesOfOriginOfNodeTemplate(NodeTemplate nodeTemplate) {
-               List<Map<String,Object>> policies  = new ArrayList<>();
-               if(toscaTemplate.getNestedTopologyTemplates() != null && !toscaTemplate.getNestedTopologyTemplates().isEmpty()){
-                       String invariantUUID = nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
-                       Optional<Object> nestedTopTmpl = toscaTemplate.getNestedTopologyTemplates()
-                                       .values()
-                                       .stream()
-                                       .filter(nt->invariantUuidEqualsTo(invariantUUID, nt))
-                                       .findFirst();
-                       if(nestedTopTmpl.isPresent()){
-                               policies = getPoliciesSection(nestedTopTmpl.get());
-                       }
-               }
-       return policies;
-    }
-    
-    @Override
-    public List<Map<String, Map<String, Object>>> getPoliciesOfTargetByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName) {
-       return getPoliciesOfNodeTemplate(nodeTemplate.getName())
-       .stream()
-       .filter(p->p.getType().equals(policyTypeName))
-       .sorted(Policy::compareTo)
-       .map(this::convertPolicyToMap)
-       .collect(toList());
-    }
-    
-    @Override
-    public List<Map<String, Object>> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName) {
-       return getPoliciesOfOriginOfNodeTemplate(nodeTemplate)
-       .stream()
-       .filter(p->typeEqualsTo(p, policyTypeName))
-       .sorted(this::comparePolicyMapObjects)
-       .collect(toList());
-    }
-
-    @Override
-    public List<NodeTemplate> getPolicyTargetsFromTopologyTemplate(String policyName) {
-       if(toscaTemplate.getNodeTemplates() == null){
-               return new ArrayList<>();
-       }
-       List<String> targetNames = getPolicyTargets(policyName);
-       return toscaTemplate.getNodeTemplates().stream()
-                       .filter(nt->targetNames.contains(nt.getName()))
-                       .collect(toList());
-    }
-       
-       @Override
-       public List<Map<String, Object>> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName) {
-       List<String> targets = getTargetsOfPolicyOfNestedTopologyTemplate(nodeTemplate, policyName);
-               if(targets.isEmpty()){
-               return new ArrayList<>();
-       }
-       return toscaTemplate.getNestedTopologyTemplates()
-                       .values()
-                       .stream()
-                       .map(this::getNodeTemplatesSection)
-                       .filter(nt->targets.contains(nt.keySet().iterator().next()))
-                       .collect(toList());
-    }
-       
-       @Override
-       public List<Map<String, Map<String, Object>>> getPoliciesOfTopologyTemplate(){
-       if(toscaTemplate.getPolicies() == null)
-               return new ArrayList<>();
-       return toscaTemplate.getPolicies()
-       .stream()
-       .sorted(Policy::compareTo)
-       .map(this::convertPolicyToMap)
-       .collect(toList());
-       }
-       
-       @Override
-       public List<Map<String, Map<String, Object>>> getPoliciesOfTopologyTemplateByToscaPolicyType(String policyTypeName){
-       if(toscaTemplate.getPolicies() == null)
-               return new ArrayList<>();
-       return toscaTemplate.getPolicies()
-       .stream()
-       .filter(p->p.getType().equals(policyTypeName))
-       .sorted(Policy::compareTo)
-       .map(this::convertPolicyToMap)
-       .collect(toList());
-       }
-
-
-       private List<String> getTargetsOfPolicyOfNestedTopologyTemplate(NodeTemplate nodeTemplate, String policyName) {
-               if(toscaTemplate.getNodeTemplates() == null){
-               return new ArrayList<>();
-       }
-       Optional<Map<String, Object>> policy = getPolicyOfNestedTopologyTemplateByName(nodeTemplate, policyName);
-       if(!policy.isPresent()){
-               return new ArrayList<>();
-       }
-       return getTargetsSection(policy.get());
-       }
-       
-       private Optional<Map<String, Object>> getPolicyOfNestedTopologyTemplateByName(NodeTemplate nodeTemplate, String policyName) {
-               return getPoliciesOfOriginOfNodeTemplate(nodeTemplate).stream()
-       .filter(p->policyNameEqualsTo(p, policyName))
-       .findFirst();
-       }
-
-       private boolean policyNameEqualsTo(Map<String, Object> policy, String policyName) {
-               return policy != null && !policy.isEmpty() && policy.keySet().iterator().next().equals(policyName);
-       }
-       
-    public NodeTemplate getNodeTemplateByName(String nodeTemplateName) {
-       if(toscaTemplate.getNodeTemplates() == null)
-               return null;
-       return toscaTemplate.getNodeTemplates()
-       .stream()
-       .filter(nt -> nt.getName().equals(nodeTemplateName))
-       .findFirst().orElse(null);
-    }
-    
-    
-    private int comparePolicyMapObjects(Map<String,Object> policy, Map<String,Object> otherPolicy){
-               if(policy.equals(otherPolicy))
-                       return 0;
-               return getTypeSection(policy).compareTo(getTypeSection(otherPolicy)) == 0 ? getNameSection(policy).compareTo(getNameSection(otherPolicy)) : getTypeSection(policy).compareTo(getTypeSection(otherPolicy));
-    }
-
-    @SuppressWarnings("unchecked")
-       private List<String> getTargetsSection(Map<String, Object> policy) {
-       if(policy == null || policy.isEmpty()){
-               return new ArrayList<>();
-       }
-       List<String> targets = (List<String>) ((Map<String, Object>)policy.values().iterator().next()).get(SdcPropertyNames.PROPERTY_NAME_TARGETS);
-       if(targets == null){
-               return new ArrayList<>();
-       }
-               return targets;
-       }
-       @SuppressWarnings("unchecked")
-       private boolean typeEqualsTo(Map<String, Object> policy, String policyTypeName) {
-       if(policy.values().iterator().hasNext()){
-               return ((Map<String, Object>)policy.values().iterator().next()).get(SdcPropertyNames.PROPERTY_NAME_TYPE).equals(policyTypeName);
-       }
-               return false;
-       }
-    
-    private String getNameSection(Map<String, Object> policy) {
-       Object name = policy.get(SdcPropertyNames.PROPERTY_NAME_NAME);
-       if(name == null)
-               return "";
-               return (String)name;
-       }
-
-       private String getTypeSection(Map<String, Object> policy) {
-       Object type = policy.get(SdcPropertyNames.PROPERTY_NAME_TYPE);
-       if(type == null)
-               return "";
-               return (String)type;
-       }
-       
-       @SuppressWarnings("unchecked")
-       private List<Map<String,Object>> getPoliciesSection(Object nestedTopTmpl) {
-               List<Map<String,Object>> policies  = (List<Map<String,Object>>)getTopologyTemplateSection(nestedTopTmpl).get(SdcPropertyNames.PROPERTY_NAME_POLICIES);
-       if(policies == null || policies.isEmpty())
-               return new ArrayList<>();
-               return policies;
-       }
-       
-       @SuppressWarnings("unchecked")
-       private Map<String,Object> getNodeTemplatesSection(Object topologyTemplate) {
-               Map<String,Object> nodeTemplates  = (Map<String,Object>)getTopologyTemplateSection(topologyTemplate).get(SdcPropertyNames.PROPERTY_NAME_NODE_TEMPLATES);
-       if(nodeTemplates == null || nodeTemplates.isEmpty())
-               return new HashMap<>();
-               return nodeTemplates;
-       }
-
-       @SuppressWarnings("unchecked")
-       private Map<String,Object> getTopologyTemplateSection(Object topologyTemplate) {
-               Map<String,Object> topologyTemplateSection  = (Map<String,Object>)((Map<String,Object>)topologyTemplate).get(SdcPropertyNames.PROPERTY_NAME_TOPOLOGY_TEMPLATE);
-       if(topologyTemplateSection == null || topologyTemplateSection.isEmpty())
-               return new HashMap<>();
-               return topologyTemplateSection;
-       }
 
-       @SuppressWarnings("unchecked")
-       private boolean invariantUuidEqualsTo(String invariantUUID, Object nt) {
-               return ((Map<String,Object>)((Map<String,Object>)nt).get(SdcPropertyNames.PROPERTY_NAME_METADATA)).get(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID).equals(invariantUUID);
-       }
-       
-    private  Map<String, Map<String, Object>> convertPolicyToMap(Policy policy){
-       Map<String, Map<String, Object>> policyMap = new HashMap<>();
-       Map<String, Object> policyValue = new HashMap<>();
-       policyMap.put(policy.getName(), policyValue);
-       policyValue.put(SdcPropertyNames.PROPERTY_NAME_TYPE, policy.getType());
-       policyValue.put(SdcPropertyNames.PROPERTY_NAME_METADATA, policy.getmetadata());
-       policyValue.put(SdcPropertyNames.PROPERTY_NAME_TARGETS, policy.getTargets());
-       policyValue.put(SdcPropertyNames.PROPERTY_NAME_PROPERTIES, policy.getPolicyProperties());
-       return policyMap;
-    }
-    
-    private List<Policy> getPoliciesOfNodeTemplate(String nodeTemplateName) {
-       if(toscaTemplate.getPolicies() == null)
-               return new ArrayList<>();
-       return toscaTemplate.getPolicies()
-       .stream()
-       .filter(p -> p.getTargets().contains(nodeTemplateName))
-       .collect(toList());
-    }
-    
-    private List<String> getPolicyTargets(String policyName) {
-       return getPolicyByName(policyName).map(Policy::getTargets).orElse(new ArrayList<>());
-    }
-    
-    private Optional<Policy> getPolicyByName(String policyName) {
-       if(toscaTemplate.getPolicies() == null)
-               return Optional.empty();
-       return toscaTemplate.getPolicies()
-       .stream()
-       .filter(p -> p.getName().equals(policyName)).findFirst();
-    }
-    
     @Override
     //Sunny flow  - covered with UT, flat and nested
     public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) {
@@ -332,27 +110,24 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
                 }
             }
 
-            findPutAllPortsProperties(cps, props);
+            if (cps.size() > 0) {
+                // ports found - find all their properties
+                for (String portName : cps.keySet()) {
+                    for (Map.Entry<String, Property> property: props.entrySet()) {
+                        if (property.getKey().startsWith(portName)) {
+                            String portProperty = property.getKey().replaceFirst(portName + "_", "");
+                            if (property.getValue() != null) {
+                                cps.get(portName).put(portProperty, property.getValue().getValue());
+                            }
+                        }
+                    }
+                }
+            }
         }
 
         return cps;
     }
 
-       private void findPutAllPortsProperties(Map<String, Map<String, Object>> cps, Map<String, Property> props) {
-               if (!cps.isEmpty()) {
-                   for (Entry<String, Map<String, Object>> port : cps.entrySet()) {
-                       for (Map.Entry<String, Property> property: props.entrySet()) {
-                           if (property.getKey().startsWith(port.getKey())) {
-                               String portProperty = property.getKey().replaceFirst(port.getKey() + "_", "");
-                               if (property.getValue() != null) {
-                                   cps.get(port.getKey()).put(portProperty, property.getValue().getValue());
-                               }
-                           }
-                       }
-                   }
-               }
-       }
-
     public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc) {
 
         if (vfc == null) {
@@ -372,27 +147,26 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
                     cps.put(portName, new HashMap<>());
                 }
             }
-            findBuildPutAllPortsProperties(cps, props);
+
+            if (cps.size() > 0) {
+                // ports found - find all their properties
+                for (String portName : cps.keySet()) {
+                    for (Map.Entry<String, Property> property: props.entrySet()) {
+                        if (property.getKey().startsWith(portName)) {
+                            Map<String, Object> portPaths = new HashMap<>();
+                            String portProperty = property.getKey().replaceFirst(portName + "_", "");
+                            buildPathMappedToValue(portProperty, property.getValue().getValue(), portPaths);
+
+                            cps.get(portName).putAll(portPaths);
+                        }
+                    }
+                }
+            }
         }
 
         return cps;
     }
 
-       private void findBuildPutAllPortsProperties(Map<String, Map<String, Object>> cps, Map<String, Property> props) {
-               if (!cps.isEmpty()) {
-                   for (Entry<String, Map<String, Object>> port : cps.entrySet()) {
-                       for (Map.Entry<String, Property> property: props.entrySet()) {
-                           if (property.getKey().startsWith(port.getKey())) {
-                               Map<String, Object> portPaths = new HashMap<>();
-                               String portProperty = property.getKey().replaceFirst(port.getKey() + "_", "");
-                               buildPathMappedToValue(portProperty, property.getValue().getValue(), portPaths);
-                               cps.get(port.getKey()).putAll(portPaths);
-                           }
-                       }
-                   }
-               }
-       }
-
     @SuppressWarnings("unchecked")
     private void buildPathMappedToValue(String path, Object property, Map<String, Object> pathsMap) {
         if (property instanceof Map) {
@@ -416,13 +190,15 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
     @Override
     //Sunny flow - covered with UT
     public List<NodeTemplate> getServiceVlList() {
-        return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL);
+        List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL);
+        return serviceVlList;
     }
 
     @Override
     //Sunny flow - covered with UT
     public List<NodeTemplate> getServiceVfList() {
-        return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF);
+        List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF);
+        return serviceVfList;
     }
 
     @Override
@@ -436,7 +212,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             log.error("getMetadataPropertyValue - the metadata is null");
             return null;
         }
-        return metadata.getValue(metadataPropertyName);
+        String metadataPropertyValue = metadata.getValue(metadataPropertyName);
+        return metadataPropertyValue;
     }
 
 
@@ -462,7 +239,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
 
     @Override
     public List<NodeTemplate> getServiceNodeTemplates() {
-        return toscaTemplate.getNodeTemplates();
+        List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
+        return nodeTemplates;
     }
 
     @Override
@@ -487,15 +265,25 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         List<NodeTemplate> serviceVfList = getServiceVfList();
         NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
         if (nodeTemplateByCustomizationUuid != null) {
+            /*SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings();
+                       if (substitutionMappings != null){
+                               List<Group> groups = substitutionMappings.getGroups();
+                               if (groups != null){
+                                       List<Group> collect = groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList());
+                                       log.debug("getVfModulesByVf - VfModules are {}", collect);
+                                       return collect;
+                               }
+                       }*/
             String name = nodeTemplateByCustomizationUuid.getName();
             String normaliseComponentInstanceName = SdcToscaUtility.normaliseComponentInstanceName(name);
             List<Group> serviceLevelGroups = toscaTemplate.getTopologyTemplate().getGroups();
             log.debug("getVfModulesByVf - VF node template name {}, normalized name {}. Searching groups on service level starting with VF normalized name...", name, normaliseComponentInstanceName);
             if (serviceLevelGroups != null) {
-                return serviceLevelGroups
+                List<Group> collect = serviceLevelGroups
                         .stream()
                         .filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType()) && x.getName().startsWith(normaliseComponentInstanceName))
-                        .collect(toList());
+                        .collect(Collectors.toList());
+                return collect;
             }
         }
         return new ArrayList<>();
@@ -680,7 +468,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         }
 
         List<NodeTemplate> serviceVfList = getServiceVfList();
-        if (serviceVfList == null || serviceVfList.isEmpty()) {
+        if (serviceVfList == null || serviceVfList.size() == 0) {
             log.error("getCpListByVf Vfs not exist for vfCustomizationId {}", vfCustomizationId);
             return cpList;
         }
@@ -690,7 +478,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             return cpList;
         }
         cpList = getNodeTemplateBySdcType(vfInstance, SdcTypes.CP);
-        if (cpList == null || cpList.isEmpty())
+        if (cpList == null || cpList.size() == 0)
             log.debug("getCpListByVf cps not exist for vfCustomizationId {}", vfCustomizationId);
         return cpList;
     }
@@ -719,7 +507,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
                 if (findFirst.isPresent()) {
                     List<String> members = findFirst.get().getMembers();
                     if (members != null) {
-                        return substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(toList());
+                        List<NodeTemplate> collect = substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList());
+                        return collect;
                     }
                 }
             }
@@ -728,6 +517,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
     }
 
     @Override
+    //Sunny flow - covered with UT
+    @SuppressWarnings("unchecked")
     public List<Pair<NodeTemplate, NodeTemplate>> getNodeTemplatePairsByReqName(
             List<NodeTemplate> listOfReqNodeTemplates, List<NodeTemplate> listOfCapNodeTemplates, String reqName) {
 
@@ -766,6 +557,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
 
     @Override
     //Sunny flow - covered with UT
+    //TODO constant strings
     public List<NodeTemplate> getAllottedResources() {
         List<NodeTemplate> nodeTemplates = null;
         nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates();
@@ -774,10 +566,12 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         }
         nodeTemplates = nodeTemplates.stream().filter(
                 x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resource"))
-                .collect(toList());
+                .collect(Collectors.toList());
         if (nodeTemplates.isEmpty()) {
             log.debug("getAllottedResources -  allotted resources not exist");
+        } else {
         }
+
         return nodeTemplates;
     }
 
@@ -859,18 +653,18 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
 
         if (substitutionMappings != null) {
             List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates();
-            if (nodeTemplates != null && !nodeTemplates.isEmpty()) {
+            if (nodeTemplates != null && nodeTemplates.size() > 0) {
                if (sdcType.equals(SdcTypes.VFC) && isVNF)  {
                        return nodeTemplates.stream()
                                .filter(x -> (x.getMetaData() != null &&
                                        sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) &&  isVNFType(x))
-                               .collect(toList());
+                               .collect(Collectors.toList());
                }
                else {
                     return nodeTemplates.stream()
                                .filter(x -> (x.getMetaData() != null &&
                                        sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) &&  !isVNFType(x))
-                               .collect(toList());
+                               .collect(Collectors.toList());
                }
             }
             else {
@@ -923,7 +717,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
 
         List<NodeTemplate> serviceVfList = getServiceVfList();
         NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
-        return getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC, true).stream().findAny().orElse(null);
+        NodeTemplate vnfConfig = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC, true).stream().findAny().orElse(null);
+               return vnfConfig;
        }
 
     @Override
@@ -952,11 +747,11 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate();
         if (substitutionMappings != null) {
             List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates();
-            if (nodeTemplates != null && !nodeTemplates.isEmpty()) {
+            if (nodeTemplates != null && nodeTemplates.size() > 0) {
 
                 return nodeTemplates.stream()
                         .filter(x -> !isVNFType(x))
-                        .collect(toList());
+                        .collect(Collectors.toList());
             }
             else {
                 log.debug("getNodeTemplateChildren - SubstitutionMappings' node Templates not exist");
@@ -1027,31 +822,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         Object property = processProperties(split, properties);
         return property == null || property instanceof Function ? null : String.valueOf(property);
     }
-    
-    @Override
-    public List<Map<String, Map<String, Object>>> getGroupsOfTopologyTemplate() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public List<Map<String, Map<String, Object>>> getGroupsOfTopologyTemplateByToscaGroupType(String groupType) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public List<NodeTemplate> getGroupMembersFromTopologyTemplate(String groupName) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-    
-    @Override
-    public List<Map<String, Object>> getGroupsOfOriginOfNodeTemplate(NodeTemplate nodeTemplate) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
 
     /************************************* helper functions ***********************************/
     private boolean isVNFType(NodeTemplate nt) {
@@ -1104,8 +874,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
 
         List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
 
-        if (nodeTemplates != null && !nodeTemplates.isEmpty())
-            return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(toList());
+        if (nodeTemplates != null && nodeTemplates.size() > 0)
+            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<>();
@@ -1135,4 +905,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         return null;
     }
 
+       
+
+    
+    
 }
index 367aa7f..7d34c6f 100644 (file)
@@ -106,12 +106,4 @@ public class SdcPropertyNames {
     
     public static String PROPERTY_NAME_NETWORKFLOWS_ISBOUNDTOVPN="network_flows#is_bound_to_vpn";
     public static String PROPERTY_NAME_NETWORKFLOWS_VPNBINDING="network_flows#vpn_binding";
-    
-    //Policy
-    public static String PROPERTY_NAME_TOPOLOGY_TEMPLATE = "topology_template";
-    public static String PROPERTY_NAME_NODE_TEMPLATES = "node_templates";
-    public static String PROPERTY_NAME_POLICIES = "policies";
-       public static String PROPERTY_NAME_METADATA = "metadata";
-       public static String PROPERTY_NAME_PROPERTIES = "properties";
-       public static String PROPERTY_NAME_TARGETS = "targets";
 }
index b65d70b..1695671 100644 (file)
@@ -36,8 +36,7 @@ public abstract class SdcToscaParserBasicTest {
     static ISdcCsarHelper resolveReqsCapsCsarQA;
        static ISdcCsarHelper portMirroring;
        static ISdcCsarHelper csarHelperServiceWithCrs;
-       static ISdcCsarHelper csarHelperServicePolicy;
-       static ISdcCsarHelper csarHelperVfPolicy;
+
 
        static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data;
     
@@ -60,10 +59,8 @@ public abstract class SdcToscaParserBasicTest {
                resolveReqsCapsCsarQA = getCsarHelper("csars/service-sunny-flow2.csar");
                portMirroring = getCsarHelper("csars/service-PortMirroring.csar");
                csarHelperServiceWithCrs = getCsarHelper("csars/service-CrTestService-csar.csar");
-               csarHelperVfPolicy = getCsarHelper("csars/resource-Policy-csar.csar");
-               csarHelperServicePolicy = getCsarHelper("csars/service-AlService-csar.csar");
-
-               fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){
+               
+        fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){
                {
                        HashMap<String, List<String>> FDNT ;
                        
index b815064..b57522d 100644 (file)
@@ -6,15 +6,13 @@ import org.testng.annotations.Test;
 import org.openecomp.sdc.tosca.parser.config.Configuration;
 import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
 
-import java.io.IOException;
-
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 
 public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest {
 
     @Test
-    public void testConfigurationConformanceLevel() throws IOException {
+    public void testConfigurationConformanceLevel()  {
         Configuration config = ConfigurationManager.getInstance().getConfiguration();
         assertNotNull(config);
         assertNotNull(config.getConformanceLevel());
@@ -24,28 +22,42 @@ public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest {
 
 
     @Test
-    public void testErrorConfigurations() throws IOException {
+    public void testErrorConfigurations()  {
         ErrorConfiguration errorConfig = ConfigurationManager.getInstance().getErrorConfiguration();
         assertNotNull(errorConfig);
         assertNotNull(errorConfig.getErrors());
     }
 
     @Test
-    public void testSetErrorConfiguration() throws IOException {
+    public void testSetErrorConfiguration() {
         ConfigurationManager configurationManager = ConfigurationManager.getInstance();
-        configurationManager.setErrorConfiguration("error-configuration-test.yaml");
-        ErrorConfiguration errorConfig = configurationManager.getErrorConfiguration();
-        assertEquals(false, errorConfig.getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError());
-        assertEquals(true, errorConfig.getErrorInfo("FILE_NOT_FOUND").getFailOnError());
+        try {
+            configurationManager.setErrorConfiguration("error-configuration-test.yaml");
+            ErrorConfiguration errorConfig = configurationManager.getErrorConfiguration();
+            assertEquals(false,
+                errorConfig.getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError());
+            assertEquals(true, errorConfig.getErrorInfo("FILE_NOT_FOUND").getFailOnError());
+        }
+        finally {
+            // Reset the configuration for other tests
+            configurationManager.setErrorConfiguration("error-configuration.yaml");
+        }
     }
 
     @Test
-    public void testSetJtoscaValidationIssueConfiguration() throws IOException {
+    public void testSetJtoscaValidationIssueConfiguration() {
         ConfigurationManager configurationManager = ConfigurationManager.getInstance();
-        configurationManager.setJtoscaValidationIssueConfiguration(
-            "jtosca-validation-issue-configuration-test.yaml");
-        JtoscaValidationIssueConfiguration issueConfig = configurationManager
-            .getJtoscaValidationIssueConfiguration();
-        assertNotNull(issueConfig);
+        try {
+            configurationManager.setJtoscaValidationIssueConfiguration(
+                "jtosca-validation-issue-configuration-test.yaml");
+            JtoscaValidationIssueConfiguration issueConfig = configurationManager
+                .getJtoscaValidationIssueConfiguration();
+            assertNotNull(issueConfig);
+        }
+        finally {
+            // Reset the configuration for other tests
+            configurationManager.setJtoscaValidationIssueConfiguration
+                ("jtosca-validation-issue-configuration.yaml");
+        }
     }
 }
index 0725cb9..1746042 100644 (file)
@@ -3,7 +3,6 @@ package org.openecomp.sdc.impl;
 import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
 import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
 import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
-import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
 import org.openecomp.sdc.toscaparser.api.NodeTemplate;
 import org.openecomp.sdc.toscaparser.api.elements.Metadata;
 import org.testng.annotations.Test;
@@ -206,19 +205,23 @@ public class ToscaParserMetadataTest extends SdcToscaParserBasicTest {
   @Test
   public void testCSARMissingConformanceLevelWithCustomErrorConfig() throws
       SdcToscaParserException {
+
     ConfigurationManager configurationManager = ConfigurationManager.getInstance();
-    configurationManager.setErrorConfiguration("error-configuration-test.yaml");
-    SdcToscaParserFactory.setConfigurationManager(configurationManager);
-
-    ISdcCsarHelper missingCSARMetaCsarCustomConfig = getCsarHelper
-        ("csars/service-missing-csar-meta-file.csar");
-    String conformanceLevel = missingCSARMetaCsarCustomConfig.getConformanceLevel();
-    assertNotNull(conformanceLevel);
-    assertEquals(conformanceLevel, configurationManager.getConfiguration().getConformanceLevel()
-        .getMaxVersion());
-
-    configurationManager.setErrorConfiguration("error-configuration.yaml");
-    SdcToscaParserFactory.setConfigurationManager(configurationManager);
+    try {
+      configurationManager.setErrorConfiguration("error-configuration-test.yaml");
+      factory.setConfigurationManager(configurationManager);
+      ISdcCsarHelper missingCSARMetaCsarCustomConfig = getCsarHelper
+          ("csars/service-missing-csar-meta-file.csar");
+      String conformanceLevel = missingCSARMetaCsarCustomConfig.getConformanceLevel();
+      assertNotNull(conformanceLevel);
+      assertEquals(conformanceLevel, configurationManager.getConfiguration().getConformanceLevel()
+          .getMaxVersion());
+    }
+    finally {
+      configurationManager.setErrorConfiguration("error-configuration.yaml");
+      factory.setConfigurationManager(configurationManager);
+    }
+
   }
 
   @Test(expectedExceptions = SdcToscaParserException.class)
index 32336af..04675b4 100644 (file)
@@ -5,6 +5,8 @@ import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 import java.util.*;
+import static org.hamcrest.CoreMatchers.is;
+
 import com.google.common.collect.ImmutableMap;
 import org.apache.commons.lang3.tuple.Pair;
 import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
@@ -12,8 +14,11 @@ import org.openecomp.sdc.tosca.parser.impl.FilterType;
 import org.openecomp.sdc.tosca.parser.impl.SdcTypes;
 import org.openecomp.sdc.toscaparser.api.Group;
 import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.Property;
 import org.testng.annotations.Test;
 
+import fj.data.fingertrees.Node;
+
 public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
 
        //region getServiceVfList
@@ -960,84 +965,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
                assertEquals(crTemplate.getPropertyValue("nf_naming").toString(), ImmutableMap.of("ecomp_generated_naming", "true").toString());
                assertEquals(crTemplate.getPropertyValue("contrailport0_virtual_network"), "chaya");
        }
-       
-       @Test
-       public void testGetPoliciesOfOriginOfNodeTemplate() {
-               NodeTemplate nt0 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 0");
-               NodeTemplate nt1 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 1");
-               List<Map<String, Object>> policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplate(nt0);
-               assertNotNull(policies);
-               assertEquals(policies.size(), 3);
-               policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplate(nt1);
-               assertNotNull(policies);
-               assertEquals(policies.size(), 3);
-       }
-       
-       @Test
-       public void testGetPoliciesOfOriginOfNodeTemplateByToscaPolicyType() {
-               NodeTemplate nt0 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 0");
-               NodeTemplate nt1 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 1");
-               List<Map<String, Object>> policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt0, "org.openecomp.policies.placement.Colocate");
-               assertNotNull(policies);
-               assertEquals(policies.size(), 1);
-               
-               policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt0, "org.openecomp.policies.placement.Antilocate");
-               assertNotNull(policies);
-               assertEquals(policies.size(), 1);
-               
-               policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt0, "org.openecomp.policies.placement.valet.Diversity");
-               assertNotNull(policies);
-               assertEquals(policies.size(), 1);
-               
-               policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt1, "org.openecomp.policies.placement.Colocate");
-               assertNotNull(policies);
-               assertEquals(policies.size(), 1);
-               
-               policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt1, "org.openecomp.policies.placement.Antilocate");
-               assertNotNull(policies);
-               assertEquals(policies.size(), 1);
-               
-               policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt1, "org.openecomp.policies.placement.valet.Diversity");
-               assertNotNull(policies);
-               assertEquals(policies.size(), 1);
-       }
-       
-       @Test
-       public void testGetPolicyTargetNodeTemplatesFromOrigin() {
-               List<Map<String, Object>> nodeTemplates = csarHelperServicePolicy.getPolicyTargetsFromOrigin(csarHelperServicePolicy.getNodeTemplateByName("al_vf 1"),"policy..Colocate..0");
-               assertNotNull(nodeTemplates);
-               assertEquals(nodeTemplates.size(), 2);
-       }
-       
-       @Test
-       public void testGetPoliciesOfNodeTemplate() {
-               NodeTemplate nt0 = csarHelperVfPolicy.getNodeTemplateByName("al_vfc 1");
-               List<Map<String, Map<String, Object>>> policies = csarHelperVfPolicy.getPoliciesOfTarget(nt0);
-               assertNotNull(policies);
-               assertEquals(policies.size(), 1);
-       }
-       
-       @Test
-       public void testGetPoliciesOfNodeTemplateByToscaPolicyType() {
-               NodeTemplate nt0 = csarHelperVfPolicy.getNodeTemplateByName("al_vfc 1");
-               List<Map<String, Map<String, Object>>> policies = csarHelperVfPolicy.getPoliciesOfTargetByToscaPolicyType(nt0, "org.openecomp.policies.placement.Colocate");
-               assertNotNull(policies);
-               assertEquals(policies.size(), 1);
-       }
-       
-       @Test
-       public void testGetPoliciesOfTopologyTemplate() {
-               List<Map<String, Map<String, Object>>> policies = csarHelperVfPolicy.getPoliciesOfTopologyTemplate();
-               assertNotNull(policies);
-               assertEquals(policies.size(), 1);
-       }
-       
-       @Test
-       public void testGetPolicyTargetNodeTemplates() {
-               List<NodeTemplate> nodeTemplates = csarHelperVfPolicy.getPolicyTargetsFromTopologyTemplate("policy..Colocate..0");
-               assertNotNull(nodeTemplates);
-               assertEquals(nodeTemplates.size(), 2);
-       }
+
 
 }
 
index 87d8f09..60119c4 100644 (file)
@@ -80,14 +80,16 @@ public class ToscaParserValidationIssueTest extends SdcToscaParserBasicTest {
                        System.out.println("SdcToscaParserException is caught here - this is WAD in this specific test.");
                }
                List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
-               assertEquals(2, notAnalyzedReport.size());
+               assertEquals(3, notAnalyzedReport.size());
                List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
                assertEquals( 0, warningsReport.size());
                List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
-               assertEquals( 24, criticalsReport.size());
+               assertEquals( 22, criticalsReport.size());
                //JE006 multy values sinceCsarConformanceLevel
-               assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE006")).collect(Collectors.toList()).size(), 18);
-               assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE003")).collect(Collectors.toList()).size(), 6);
+               assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE006")).collect
+                               (Collectors.toList()).size(), 18);
+               assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE003")).collect
+                               (Collectors.toList()).size(), 4);
        }
 
 
diff --git a/src/test/resources/csars/resource-Policy-csar.csar b/src/test/resources/csars/resource-Policy-csar.csar
deleted file mode 100644 (file)
index d6d7b42..0000000
Binary files a/src/test/resources/csars/resource-Policy-csar.csar and /dev/null differ
diff --git a/src/test/resources/csars/service-AlService-csar.csar b/src/test/resources/csars/service-AlService-csar.csar
deleted file mode 100644 (file)
index 2532683..0000000
Binary files a/src/test/resources/csars/service-AlService-csar.csar and /dev/null differ