Add new category to NSD plugin 14/127014/2
authorstasys10 <stasys.jurgaitis@est.tech>
Thu, 3 Feb 2022 16:16:07 +0000 (16:16 +0000)
committerMichael Morris <michael.morris@est.tech>
Wed, 9 Feb 2022 17:37:38 +0000 (17:37 +0000)
Issue-ID: SDC-3870
Signed-off-by: stasys10 <stasys.jurgaitis@est.tech>
Change-Id: Ibb46b401f635192a680eb472eb8d7f3fb3380f57

catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java
catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/CategoriesToGenerateNsd.java [new file with mode: 0644]
catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java
catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImplTest.java

index 9a7312b..4640492 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.CategoriesToGenerateNsd;
 import org.openecomp.sdc.be.model.Component;
 import org.openecomp.sdc.be.plugins.CsarEntryGenerator;
 import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.exception.NsdException;
@@ -39,7 +40,6 @@ import org.slf4j.LoggerFactory;
 @org.springframework.stereotype.Component("etsiNfvNsCsarEntryGenerator")
 public class EtsiNfvNsCsarEntryGenerator implements CsarEntryGenerator {
 
-    static final String ETSI_NS_COMPONENT_CATEGORY = "ETSI NFV Network Service";
     static final String NSD_FILE_PATH_FORMAT = "Artifacts/%s/%s.%s";
     static final String SIGNED_CSAR_EXTENSION = "zip";
     static final String UNSIGNED_CSAR_EXTENSION = "csar";
@@ -52,8 +52,8 @@ public class EtsiNfvNsCsarEntryGenerator implements CsarEntryGenerator {
     }
 
     /**
-     * Generates a Network Service CSAR based on a SERVICE component of category {@link EtsiNfvNsCsarEntryGenerator#ETSI_NS_COMPONENT_CATEGORY} and
-     * wraps it in a SDC CSAR entry.
+     * Generates a Network Service CSAR based on a SERVICE component that has category configured in
+     * {@link CategoriesToGenerateNsd } enum and wraps it in a SDC CSAR entry.
      *
      * @param component the component to create the NS CSAR from
      * @return an entry to be added in the Component CSAR by SDC
@@ -65,10 +65,11 @@ public class EtsiNfvNsCsarEntryGenerator implements CsarEntryGenerator {
             LOGGER.debug("Ignoring NSD CSAR generation for component '{}' as it is not a SERVICE", componentName);
             return Collections.emptyMap();
         }
-        final boolean isEOTemplate = component.getCategories().stream().anyMatch(category -> ETSI_NS_COMPONENT_CATEGORY.equals(category.getName()));
+        final boolean isEOTemplate = component.getCategories().stream().anyMatch(category ->
+                CategoriesToGenerateNsd.hasCategoryName(category.getName()));
         if (!isEOTemplate) {
-            LOGGER.debug("Ignoring NSD CSAR generation for component '{}' as it does not belong to the category '{}'", componentName,
-                ETSI_NS_COMPONENT_CATEGORY);
+            LOGGER.debug("Ignoring NSD CSAR generation for component '{}' as it does not belong to any of the categories '{}'",
+                    componentName, CategoriesToGenerateNsd.getCategories());
             return Collections.emptyMap();
         }
 
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/CategoriesToGenerateNsd.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/CategoriesToGenerateNsd.java
new file mode 100644 (file)
index 0000000..864d63d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+@Getter
+@AllArgsConstructor
+public enum CategoriesToGenerateNsd {
+    ETSI_NS_COMPONENT_CATEGORY ("ETSI NFV Network Service"),
+    ETSI_NS_COMPONENT_CATEGORY_FOR_ETSI_MODEL("ETSI NFV Network Service For ETSI Model");
+
+    private final String categoryName;
+
+    public static boolean hasCategoryName(String categoryNameToCheck) {
+        return Arrays.stream(CategoriesToGenerateNsd.values()).anyMatch(CategoriesToGenerateNsd ->
+                CategoriesToGenerateNsd.getCategoryName().equals(categoryNameToCheck));
+    }
+
+    public static String getCategories(){
+        return Arrays.stream(CategoriesToGenerateNsd.values()).map(CategoriesToGenerateNsd::getCategoryName)
+                .collect(Collectors.joining(", "));
+    }
+}
index 6cf6e06..d52bf5c 100644 (file)
@@ -23,7 +23,7 @@ import static org.hamcrest.Matchers.anEmptyMap;
 import static org.hamcrest.Matchers.hasEntry;
 import static org.hamcrest.core.Is.is;
 import static org.mockito.Mockito.when;
-import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsCsarEntryGenerator.ETSI_NS_COMPONENT_CATEGORY;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.CategoriesToGenerateNsd;
 import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsCsarEntryGenerator.ETSI_VERSION_METADATA;
 import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsCsarEntryGenerator.NSD_FILE_PATH_FORMAT;
 import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsCsarEntryGenerator.UNSIGNED_CSAR_EXTENSION;
@@ -124,7 +124,7 @@ class EtsiNfvNsCsarEntryGeneratorTest {
         when(service.getCategorySpecificMetadata()).thenReturn(categorySpecificMetadataMap);
         final List<CategoryDefinition> categoryDefinitionList = new ArrayList<>();
         final CategoryDefinition nsComponentCategoryDefinition = new CategoryDefinition();
-        nsComponentCategoryDefinition.setName(ETSI_NS_COMPONENT_CATEGORY);
+        nsComponentCategoryDefinition.setName(CategoriesToGenerateNsd.ETSI_NS_COMPONENT_CATEGORY.getCategoryName());
         categoryDefinitionList.add(nsComponentCategoryDefinition);
         when(service.getCategories()).thenReturn(categoryDefinitionList);
     }
index 31798ef..163b6bb 100644 (file)
@@ -26,7 +26,7 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsCsarEntryGenerator.ETSI_NS_COMPONENT_CATEGORY;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.CategoriesToGenerateNsd;
 import static org.openecomp.sdc.common.api.ArtifactTypeEnum.ONBOARDED_PACKAGE;
 
 import fj.data.Either;
@@ -136,7 +136,7 @@ class EtsiNfvNsdCsarGeneratorImplTest {
 
         final List<CategoryDefinition> categoryDefinitionList = new ArrayList<>();
         final CategoryDefinition nsComponentCategoryDefinition = new CategoryDefinition();
-        nsComponentCategoryDefinition.setName(ETSI_NS_COMPONENT_CATEGORY);
+        nsComponentCategoryDefinition.setName(CategoriesToGenerateNsd.ETSI_NS_COMPONENT_CATEGORY.getCategoryName());
         categoryDefinitionList.add(nsComponentCategoryDefinition);
         when(service.getCategories()).thenReturn(categoryDefinitionList);
     }