From a7b1f9beb7db0c03915b4a69f9a4ddff6dd7c414 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Mon, 30 Aug 2021 12:28:05 +0100 Subject: Fix mismatch in requirement name in sub mapping Signed-off-by: MichaelMorris Issue-ID: SDC-3701 Change-Id: I0898d8b16c6e5cda035f33024f26644d7c6b1ef5 --- .../sdc/be/tosca/CapabilityRequirementConverter.java | 12 ++++++++++-- .../org/openecomp/sdc/be/tosca/ToscaExportHandler.java | 4 ++-- .../org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java | 14 ++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java index 8cc5868341..bf42af8322 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java @@ -322,7 +322,7 @@ public class CapabilityRequirementConverter { (StringUtils.isEmpty(r.getExternalName()) ? addEntry(componentsCache, toscaRequirements, component, new SubstitutionEntry(r.getName(), r.getParentName(), ""), r.getPreviousName(), r.getOwnerId(), r.getPath()): - addEntry(componentsCache, toscaRequirements, component, new SubstitutionEntry(r.getExternalName(), r.getName(), ""), + addEntry(componentsCache, toscaRequirements, component, new SubstitutionEntry(r.getExternalName(), r.getPreviousName() == null ? r.getName(): r.getPreviousName(), ""), r.getPreviousName(), r.getOwnerId(), r.getPath(), false)) ).findAny(); } @@ -667,7 +667,15 @@ public class CapabilityRequirementConverter { * @return */ public Either buildSubstitutedName(Map componentsCache, Component originComponent, List path, - String name, String previousName) { + String name, String previousName) { + return buildSubstitutedName(componentsCache, originComponent, path, name, previousName, null); + } + + public Either buildSubstitutedName(Map componentsCache, Component originComponent, List path, + String name, String previousName, String externalName) { + if (StringUtils.isNotEmpty(externalName)) { + return Either.left(externalName); + } if (StringUtils.isNotEmpty(previousName)) { return Either.left(name); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 1b27857869..6a1ba4ef63 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -1379,7 +1379,7 @@ public class ToscaExportHandler { } final RelationshipInfo relationshipInfo = capabilityRequirementRelationship.getRelation(); final Either capabilityNameEither = capabilityRequirementConverter.buildSubstitutedName(componentCache, - toOriginComponent, reducedPath, relationshipInfo.getCapability(), capability.getPreviousName()); + toOriginComponent, reducedPath, relationshipInfo.getCapability(), capability.getPreviousName(), capability.getExternalName()); if (capabilityNameEither.isRight()) { final String errorMsg = String.format( "Failed to build a substituted capability name for the capability with name %s on a component with uniqueId %s", @@ -1390,7 +1390,7 @@ public class ToscaExportHandler { } final Either requirementNameEither = capabilityRequirementConverter .buildSubstitutedName(componentCache, fromOriginComponent, - requirement.getPath(), relationshipInfo.getRequirement(), requirement.getPreviousName()); + requirement.getPath(), relationshipInfo.getRequirement(), requirement.getPreviousName(), requirement.getExternalName()); if (requirementNameEither.isRight()) { final String errorMsg = String.format("Failed to build a substituted requirement name for the requirement " + "with name %s on a component with uniqueId %s", diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java index 325a003133..d9fc8de623 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java @@ -1409,14 +1409,14 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when( capabilityRequirementConverter .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq(capabilityName), eq( - capabilityPreviousName))) + capabilityPreviousName), any())) .thenReturn(Either.left(builtCapabilityName)); final String builtRequirementName = "builtRequirementName"; when( capabilityRequirementConverter .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq(requirementName), eq( - requirementPreviousName))) + requirementPreviousName), any())) .thenReturn(Either.left(builtRequirementName)); final Map actualRequirementMap = @@ -1487,7 +1487,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when( capabilityRequirementConverter - .buildSubstitutedName(anyMap(), any(Component.class), anyList(), anyString(), anyString())) + .buildSubstitutedName(anyMap(), any(Component.class), anyList(), anyString(), anyString(), any())) .thenReturn(Either.right(false)); final String expectedErrorMsg = @@ -1520,12 +1520,12 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when( capabilityRequirementConverter - .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq("cap"), anyString())) + .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq("cap"), anyString(), any())) .thenReturn(Either.left("buildCapNameRes")); when( capabilityRequirementConverter - .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("req"), anyString())) + .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("req"), anyString(), any())) .thenReturn(Either.left("buildReqNameRes")); // default test @@ -1557,8 +1557,10 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { relationship.setRequirement("req"); final String builtCapabilityOrRequirementName = "builtCapabilityOrRequirementName"; - when(capabilityRequirementConverter.buildSubstitutedName(any(), any(), any(), any(), any())) + when(capabilityRequirementConverter.buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("cap"), any(), any())) .thenReturn(Either.left(builtCapabilityOrRequirementName)); + when(capabilityRequirementConverter.buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq("req"), any(), any())) + .thenReturn(Either.left(builtCapabilityOrRequirementName)); final Map requirementMap = Deencapsulation .invoke(testSubject, "buildRequirement", fromOriginComponent, toOriginComponent, capability, requirement, -- cgit 1.2.3-korg