aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be-plugins/etsi-nfv-nsd-csar-plugin
diff options
context:
space:
mode:
authorstasys10 <stasys.jurgaitis@est.tech>2022-02-11 10:26:10 +0000
committerStasys Jurgaitis <stasys.jurgaitis@est.tech>2022-02-15 13:38:22 +0000
commit1105a525206d3c8e36cfdd77d6b033e821617e21 (patch)
treef4dfc4c7c9dae300df923dc9dd305768854a3498 /catalog-be-plugins/etsi-nfv-nsd-csar-plugin
parent8549cdded4f452a52aea32be1c97c820fa79b5af (diff)
Fix NSD plugin get version from model name
Issue-ID: SDC-3881 Signed-off-by: stasys10 <stasys.jurgaitis@est.tech> Change-Id: Ib90020e46079866b5846b50aa3f183ae5bf74f6c
Diffstat (limited to 'catalog-be-plugins/etsi-nfv-nsd-csar-plugin')
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java6
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java25
2 files changed, 30 insertions, 1 deletions
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java
index 4640492441..f5d7828e2d 100644
--- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java
@@ -90,7 +90,11 @@ public class EtsiNfvNsCsarEntryGenerator implements CsarEntryGenerator {
}
private EtsiVersion getComponentEtsiVersion(Component component) {
- final String etsiVersion = component.getCategorySpecificMetadata().get(ETSI_VERSION_METADATA);
+ String etsiVersion = component.getCategorySpecificMetadata().get(ETSI_VERSION_METADATA);
+ final String modelName = component.getModel();
+ if (etsiVersion == null && modelName.matches(".*\\d+\\.\\d+\\.\\d+.*" )){
+ etsiVersion = modelName.replaceAll(".*?(\\d+\\.\\d+\\.\\d+).*", "$1");
+ }
return EtsiVersion.convertOrNull(etsiVersion);
}
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java
index d52bf5c7f0..72bc8247a4 100644
--- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java
@@ -80,6 +80,19 @@ class EtsiNfvNsCsarEntryGeneratorTest {
}
@Test
+ void successfullyEntryGenerationWithVersionFromModelNameTest() throws NsdException {
+ mockServiceComponentWithoutMetadata();
+ final NsdCsar nsdCsar = new NsdCsar(SERVICE_NORMALIZED_NAME);
+ nsdCsar.setCsarPackage(new byte[5]);
+ when(etsiNfvNsdCsarGenerator.generateNsdCsar(service)).thenReturn(nsdCsar);
+ final Map<String, byte[]> entryMap = etsiNfvNsCsarEntryGenerator.generateCsarEntries(service);
+ assertThat("Csar Entries should contain only one entry", entryMap.size(), is(1));
+ assertThat("Csar Entries should contain the expected entry", entryMap,
+ hasEntry(String.format(NSD_FILE_PATH_FORMAT, ETSI_PACKAGE, SERVICE_NORMALIZED_NAME, UNSIGNED_CSAR_EXTENSION),
+ nsdCsar.getCsarPackage()));
+ }
+
+ @Test
void knownNsdGenerationErrorTest() throws NsdException {
mockServiceComponent();
when(etsiNfvNsdCsarGenerator.generateNsdCsar(service)).thenThrow(new NsdException(""));
@@ -128,4 +141,16 @@ class EtsiNfvNsCsarEntryGeneratorTest {
categoryDefinitionList.add(nsComponentCategoryDefinition);
when(service.getCategories()).thenReturn(categoryDefinitionList);
}
+
+ private void mockServiceComponentWithoutMetadata() {
+ when(service.getName()).thenReturn("anyName");
+ when(service.getComponentType()).thenReturn(ComponentTypeEnum.SERVICE);
+ when(service.getNormalizedName()).thenReturn(SERVICE_NORMALIZED_NAME);
+ when(service.getModel()).thenReturn("Any Name with Version v2.5.1");
+ final List<CategoryDefinition> categoryDefinitionList = new ArrayList<>();
+ final CategoryDefinition nsComponentCategoryDefinition = new CategoryDefinition();
+ nsComponentCategoryDefinition.setName(CategoriesToGenerateNsd.ETSI_NS_COMPONENT_CATEGORY.getCategoryName());
+ categoryDefinitionList.add(nsComponentCategoryDefinition);
+ when(service.getCategories()).thenReturn(categoryDefinitionList);
+ }
}