diff options
author | Vitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com> | 2017-11-01 14:58:07 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-11-01 14:58:07 +0000 |
commit | a4bc189257eed8d466fced2894c9a72c0beffb5d (patch) | |
tree | 4fefe7d8857c8a387823c782637c39aca4d23cb0 | |
parent | 9c92ea71a785f0c85dd87fcaf2a291809cac5a51 (diff) | |
parent | 81f94dffafb4eea8da79b30e89338adc4e338c7d (diff) |
Merge "duplicate ids"
6 files changed, 39 insertions, 29 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java index a0034a3828..ddbcaf72b9 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java @@ -25,14 +25,12 @@ import org.openecomp.config.api.ConfigurationManager; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; import org.openecomp.sdc.heat.datatypes.manifest.FileData; import org.openecomp.sdc.heat.datatypes.manifest.ManifestFile; import org.openecomp.sdc.heat.datatypes.model.Resource; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; -import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.ToscaUtil; import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource; @@ -42,6 +40,7 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants; import org.openecomp.sdc.translator.services.heattotosca.Constants; import org.openecomp.sdc.translator.services.heattotosca.NameExtractor; +import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder; import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator; import java.io.InputStream; @@ -385,10 +384,7 @@ public class TranslationContext { } if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){ - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage("Resource with id " - + originalNodeTemplateId + " occures more than once in different addOn files") - .build()); + throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build()); } nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId); this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode( diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java index b86038d175..5d1bb1c61e 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java @@ -31,6 +31,7 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.RequirementAssignmentData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.TypeComputeConsolidationData; +import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder; import java.util.ArrayList; import java.util.Collection; @@ -154,10 +155,7 @@ public class ConsolidationDataUtil { if(isNestedResourceIdOccuresInDifferentNestedFiles(context, nestedHeatFileName, nestedNodeTemplateId)){ - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage("Resource with id " - + nestedNodeTemplateId + " occures more than once in different addOn " - + "files").build()); + throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(nestedNodeTemplateId).build()); } ConsolidationData consolidationData = context.getConsolidationData(); diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java index 16a6301968..d3f2a721c9 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java @@ -24,6 +24,7 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.RequirementAssignmentData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.TypeComputeConsolidationData; +import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder; import java.util.ArrayList; import java.util.Collection; @@ -637,20 +638,16 @@ public class ConsolidationService { NodeTemplate startingPortNodeTemplate = nodeTemplates.get(portNodeTemplateIdList.get(0)); if (Objects.isNull(startingPortNodeTemplate)) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage("Resource with id " - + portNodeTemplateIdList.get(0) + " occures more than once in different addOn files") - .build()); + throw new CoreException( + new DuplicateResourceIdsInDifferentFilesErrorBuilder(portNodeTemplateIdList.get(0)).build()); } for (int i = 1; i < portNodeTemplateIdList.size(); i++) { NodeTemplate portNodeTemplate = nodeTemplates.get(portNodeTemplateIdList.get(i)); if (Objects.isNull(portNodeTemplate)) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage("Resource with id " - + portNodeTemplateIdList.get(i) + " occures more than once in different addOn " - + "files").build()); + throw new CoreException( + new DuplicateResourceIdsInDifferentFilesErrorBuilder(portNodeTemplateIdList.get(i)).build()); } if (!isPropertySimilarBetweenNodeTemplates(propertyToCheck, portNodeTemplateIdList, nodeTemplates)) { @@ -695,9 +692,8 @@ public class ConsolidationService { for (int i = 1; i < entityNodeTemplateIds.size(); i++) { NodeTemplate currentNodeTemplate = idToNodeTemplate.get(entityNodeTemplateIds.get(i)); if (Objects.isNull(currentNodeTemplate)) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage("Resource with id " - + entityNodeTemplateIds.get(i) + " occures more than once in different addOn files").build()); + throw new CoreException( + new DuplicateResourceIdsInDifferentFilesErrorBuilder(entityNodeTemplateIds.get(i)).build()); } if(propertyExistCondition != isPropertyExistInNodeTemplate(propertyToCheck, currentNodeTemplate)){ return false; diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/DuplicateResourceIdsInDifferentFilesErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/DuplicateResourceIdsInDifferentFilesErrorBuilder.java new file mode 100644 index 0000000000..a75e8b391d --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/DuplicateResourceIdsInDifferentFilesErrorBuilder.java @@ -0,0 +1,16 @@ +package org.openecomp.sdc.translator.services.heattotosca.errors; + +import org.openecomp.sdc.common.errors.BaseErrorBuilder; +import org.openecomp.sdc.common.errors.ErrorCategory; + +public final class DuplicateResourceIdsInDifferentFilesErrorBuilder extends BaseErrorBuilder { + + private static final String DUPLICATE_RESOURCE_ID_MSG = "Resource with id %s occurs more than once in " + + "different addOn files"; + + public DuplicateResourceIdsInDifferentFilesErrorBuilder(String resourceId) { + getErrorCodeBuilder().withId(TranslatorErrorCodes.DUPLICATE_RESOURCE_ID_IN_DIFFERENT_FILES) + .withCategory(ErrorCategory.APPLICATION) + .withMessage(String.format(DUPLICATE_RESOURCE_ID_MSG, resourceId)); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/TranslatorErrorCodes.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/TranslatorErrorCodes.java index bfcf834ae1..5afb1ae3c2 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/TranslatorErrorCodes.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/TranslatorErrorCodes.java @@ -29,4 +29,5 @@ public class TranslatorErrorCodes { "REFERENCE_TO_UNSUPPORTED_RESOURCE"; public static final String NOT_IN_SYNC_NUMBER_OF_INTERFACES = "NOT_IN_SYNC_NUMBER_OF_INTERFACES"; public static final String INVALID_PROPERTY_VALUE = "INVALID_PROPERTY_VALUE"; + public static final String DUPLICATE_RESOURCE_ID_IN_DIFFERENT_FILES = "DUPLICATE_RESOURCE_ID_IN_DIFFERENT_FILES"; } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/fulltest/UnifiedCompositionMixPatternFullTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/fulltest/UnifiedCompositionMixPatternFullTest.java index b1946b3f9b..9399b91ce1 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/fulltest/UnifiedCompositionMixPatternFullTest.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/fulltest/UnifiedCompositionMixPatternFullTest.java @@ -2,7 +2,10 @@ package org.openecomp.sdc.translator.services.heattotosca.impl.fulltest; import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.BaseFullTranslationTest; @@ -19,6 +22,9 @@ public class UnifiedCompositionMixPatternFullTest extends BaseFullTranslationTes // do not delete this function. it prevents the superclass setup from running } + @Rule + public ExpectedException exception = ExpectedException.none(); + @Test public void testMixPatterns() throws IOException { inputFilesPath = @@ -52,16 +58,13 @@ public class UnifiedCompositionMixPatternFullTest extends BaseFullTranslationTes @Test public void testDuplicateResourceIdsInDiffAddOnFiles() throws IOException { + exception.expect(CoreException.class); + exception.expectMessage("Resource with id lb_0_int_oam_int_0_port occurs more " + + "than once in different addOn files"); + inputFilesPath = "/mock/services/heattotosca/fulltest/mixPatterns/duplicateResourceIdsInDiffAddOnFiles/in"; - - try { - testTranslationWithInit(); - }catch(Exception e){ - log.debug("",e); - Assert.assertEquals(e.getMessage(), "Resource with id lb_0_int_oam_int_0_port occures more " + - "than once in different addOn files"); - } + testTranslationWithInit(); } @Test |