From 7a81ddecef54cc8d37c264bc22c01851595d81f2 Mon Sep 17 00:00:00 2001 From: siddharth0905 Date: Tue, 8 May 2018 12:45:29 +0530 Subject: Junit Test Failure Junit test were failing in local due to folder name change in common Change-Id: Ie78e2b8cbe41ce568b3f77928e7dd746d9ed3c95 Issue-ID: SDC-1312 Signed-off-by: siddharth0905 --- .../translator/services/heattotosca/Constants.java | 57 ++++---- .../globaltypes/GlobalTypesServiceTemplates.java | 149 ++++++++++----------- 2 files changed, 103 insertions(+), 103 deletions(-) diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java index d0b1dd0096..848e6d7040 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java @@ -17,30 +17,37 @@ package org.openecomp.sdc.translator.services.heattotosca; public class Constants { - //Service Template - Template Names - public static final String GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME = "GlobalSubstitutionTypes"; - public static final String MAIN_TEMPLATE_NAME = "Main"; - //properties - public static final String MAX_INSTANCES_PROPERTY_NAME = "max_instances"; - public static final String DESCRIPTION_PROPERTY_NAME = "description"; - public static final String NAME_PROPERTY_NAME = "name"; - public static final String SECURITY_GROUPS_PROPERTY_NAME = "security_groups"; - public static final String PORT_PROPERTY_NAME = "port"; - static final String VFC_PARENT_PORT_ROLE = "vfc_parent_port_role"; - static final String SUB_INTERFACE_ROLE = "subinterface_role"; - //General - public static final String PROP = "properties"; - public static final String ATTR = "attributes"; - public static final String SERVICE_INSTANCE_PORT_PREFIX = "port_"; - public static final String SERVICE_INSTANCE_LINK_PREFIX = "link_"; - static final String GROUP = "group"; - //Unified model - static final String COMPUTE_IDENTICAL_VALUE_PROPERTY_PREFIX = "vm_"; - static final String COMPUTE_IDENTICAL_VALUE_PROPERTY_SUFFIX = "_name"; - static final String PORT_IDENTICAL_VALUE_PROPERTY_PREFIX = "port_"; - static final String SUB_INTERFACE_PROPERTY_VALUE_PREFIX = "subinterface_"; - public static final String ABSTRACT_NODE_TEMPLATE_ID_PREFIX = "abstract_"; - private Constants() { - } + //Service Template - Template Names + public static final String GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME = "GlobalSubstitutionTypes"; + public static final String MAIN_TEMPLATE_NAME = "Main"; + //properties + public static final String MAX_INSTANCES_PROPERTY_NAME = "max_instances"; + public static final String DESCRIPTION_PROPERTY_NAME = "description"; + public static final String NAME_PROPERTY_NAME = "name"; + public static final String SECURITY_GROUPS_PROPERTY_NAME = "security_groups"; + public static final String PORT_PROPERTY_NAME = "port"; + static final String VFC_PARENT_PORT_ROLE = "vfc_parent_port_role"; + static final String SUB_INTERFACE_ROLE = "subinterface_role"; + //General + public static final String PROP = "properties"; + public static final String ATTR = "attributes"; + public static final String SERVICE_INSTANCE_PORT_PREFIX = "port_"; + public static final String SERVICE_INSTANCE_LINK_PREFIX = "link_"; + static final String GROUP = "group"; + //Unified model + static final String COMPUTE_IDENTICAL_VALUE_PROPERTY_PREFIX = "vm_"; + static final String COMPUTE_IDENTICAL_VALUE_PROPERTY_SUFFIX = "_name"; + static final String PORT_IDENTICAL_VALUE_PROPERTY_PREFIX = "port_"; + static final String SUB_INTERFACE_PROPERTY_VALUE_PREFIX = "subinterface_"; + public static final String ABSTRACT_NODE_TEMPLATE_ID_PREFIX = "abstract_"; + //GlobalTypesServiceTemplates + public static final String INVALID_ONBOARDING_TYPE = "Invalid Onboarding Type"; + public static final String GLOBAL_TYPES_READ_ERROR = "GlobalTypes Read Error"; + public static final String FAILED_TO_GENERATE_GLOBAL_TYPES = "Failed to generate globalTypes"; + public static final String OPENECOMP_INVENTORY = "openecomp-inventory"; + public static final String GLOBAL_TYPES = "globalTypes"; + + private Constants() { + } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesServiceTemplates.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesServiceTemplates.java index f53cf59c95..a982233a23 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesServiceTemplates.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesServiceTemplates.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 European Support Limited + * Copyright © 2016-2018 European Support Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,101 +16,94 @@ package org.openecomp.sdc.translator.services.heattotosca.globaltypes; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; + +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; -import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; -import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.sdc.translator.services.heattotosca.Constants; import org.openecomp.sdc.translator.utils.ResourceWalker; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.Map; - public class GlobalTypesServiceTemplates { - private static final String FAILED_TO_GENERATE_GLOBAL_TYPES = "Failed to generate globalTypes"; + private static final String ONAP_FILEPATH_REGEX = ".*" + Constants.GLOBAL_TYPES + "(/onap/|\\\\onap\\\\).*"; + private static final Map> onboardingGlobalTypesServiceTemplates; - private static final Map> - onboardingGlobalTypesServiceTemplates; - - private GlobalTypesServiceTemplates() { - } + private GlobalTypesServiceTemplates() { + } - static { - Map globalTypes; - try { - globalTypes = ResourceWalker.readResourcesFromDirectory("globalTypes"); - } catch (CoreException coreException) { - throw coreException; - } catch (Exception exception) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage(FAILED_TO_GENERATE_GLOBAL_TYPES) - .withId("GlobalTypes Read Error").withCategory(ErrorCategory.APPLICATION).build(), - exception); + static { + Map globalTypes; + try { + globalTypes = ResourceWalker.readResourcesFromDirectory(Constants.GLOBAL_TYPES); + } catch (CoreException coreException) { + throw coreException; + } catch (Exception exception) { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()) + .withMessage(Constants.FAILED_TO_GENERATE_GLOBAL_TYPES) + .withId(Constants.GLOBAL_TYPES_READ_ERROR) + .withCategory(ErrorCategory.APPLICATION).build(), exception); + } + onboardingGlobalTypesServiceTemplates = init(globalTypes); } - onboardingGlobalTypesServiceTemplates = init(globalTypes); - } - public static Map getGlobalTypesServiceTemplates(OnboardingTypesEnum - onboardingType) { - if (onboardingType == null) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage(FAILED_TO_GENERATE_GLOBAL_TYPES) - .withId("Invalid Onboarding Type").withCategory(ErrorCategory.APPLICATION).build()); + public static Map getGlobalTypesServiceTemplates(OnboardingTypesEnum onboardingType) { + if (onboardingType == null) { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()) + .withMessage(Constants.FAILED_TO_GENERATE_GLOBAL_TYPES) + .withId(Constants.INVALID_ONBOARDING_TYPE) + .withCategory(ErrorCategory.APPLICATION).build()); + } + return onboardingGlobalTypesServiceTemplates.get(onboardingType); } - return onboardingGlobalTypesServiceTemplates.get(onboardingType); - } - private static Map> - init(Map globalTypes) { - Map> - onboardingGlobalTypesServiceTemplates = new EnumMap<>(OnboardingTypesEnum.class); - Map zipOnboardingGlobalTypes = - getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.ZIP); - Map csarOnboardingGlobalTypes = - getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.CSAR); - Map manualOnboardingGlobalTypes = - getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.MANUAL); - Map defaultOnboardingGlobalTypes = - getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.NONE); - onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.ZIP, zipOnboardingGlobalTypes); - onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.CSAR, csarOnboardingGlobalTypes); - onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.MANUAL, - manualOnboardingGlobalTypes); - onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.NONE, - defaultOnboardingGlobalTypes); - return onboardingGlobalTypesServiceTemplates; - } + private static Map> init(Map globalTypes) { + Map> onboardingGlobalTypesServiceTemplates = + new EnumMap<>(OnboardingTypesEnum.class); + Map zipOnboardingGlobalTypes = + getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.ZIP); + Map csarOnboardingGlobalTypes = + getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.CSAR); + Map manualOnboardingGlobalTypes = + getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.MANUAL); + Map defaultOnboardingGlobalTypes = + getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.NONE); + onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.ZIP, zipOnboardingGlobalTypes); + onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.CSAR, csarOnboardingGlobalTypes); + onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.MANUAL, manualOnboardingGlobalTypes); + onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.NONE, defaultOnboardingGlobalTypes); + return onboardingGlobalTypesServiceTemplates; + } - private static Map getOnboardingGlobalTypes(Map - globalTypes, - OnboardingTypesEnum - onboardingType) { - Map globalTypesServiceTemplates = new HashMap<>(); - ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); - for (Map.Entry globalTypeContent : globalTypes.entrySet()) { - if (!isTypeValidCandidateForCsarPacking(globalTypeContent.getKey(), onboardingType)) { - // this global types folders should not be processed to the CSAR - continue; - } - ToscaUtil.addServiceTemplateToMapWithKeyFileName(globalTypesServiceTemplates, - toscaExtensionYamlUtil.yamlToObject(globalTypeContent.getValue(), ServiceTemplate.class)); + private static Map getOnboardingGlobalTypes(Map globalTypes, + OnboardingTypesEnum onboardingType) { + Map globalTypesServiceTemplates = new HashMap<>(); + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + for (Map.Entry globalTypeContent : globalTypes.entrySet()) { + if (!isTypeValidCandidateForCsarPacking(globalTypeContent.getKey(), onboardingType)) { + // this global types folders should not be processed to the CSAR + continue; + } + ToscaUtil.addServiceTemplateToMapWithKeyFileName(globalTypesServiceTemplates, + toscaExtensionYamlUtil.yamlToObject(globalTypeContent.getValue(), ServiceTemplate.class)); + } + return globalTypesServiceTemplates; } - return globalTypesServiceTemplates; - } - private static boolean isTypeValidCandidateForCsarPacking(String globalTypeResourceKey, - OnboardingTypesEnum - onboardingType) { - if (globalTypeResourceKey.contains("openecomp-inventory")) { - // this global types folders should not be processed to the CSAR - return false; + private static boolean isTypeValidCandidateForCsarPacking(String globalTypeResourceKey, + OnboardingTypesEnum onboardingType) { + if (globalTypeResourceKey.contains(Constants.OPENECOMP_INVENTORY)) { + // this global types folders should not be processed to the CSAR + return false; + } + //Global types specific to csar onboarding should not be packed for other onboarding types + return !globalTypeResourceKey.matches(ONAP_FILEPATH_REGEX) || onboardingType == OnboardingTypesEnum.CSAR; } - //Global types specific to csar onboarding should not be packed for other onboarding types - return !globalTypeResourceKey.contains("onap") || onboardingType == OnboardingTypesEnum.CSAR; - } } -- cgit 1.2.3-korg