Add new category to NSD plugin
[sdc.git] / catalog-be-plugins / etsi-nfv-nsd-csar-plugin / src / test / java / org / openecomp / sdc / be / plugins / etsi / nfv / nsd / generator / EtsiNfvNsCsarEntryGeneratorTest.java
index e02e170..d52bf5c 100644 (file)
@@ -16,7 +16,6 @@
  *  SPDX-License-Identifier: Apache-2.0
  *  ============LICENSE_END=========================================================
  */
-
 package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator;
 
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -24,11 +23,14 @@ 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;
 import static org.openecomp.sdc.common.api.ArtifactTypeEnum.ETSI_PACKAGE;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.junit.jupiter.api.BeforeEach;
@@ -40,10 +42,17 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 import org.openecomp.sdc.be.model.Service;
 import org.openecomp.sdc.be.model.category.CategoryDefinition;
 import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.exception.NsdException;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.factory.EtsiNfvNsdCsarGeneratorFactory;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.EtsiVersion;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.model.NsdCsar;
 
 class EtsiNfvNsCsarEntryGeneratorTest {
 
-
+    private static final String SERVICE_NORMALIZED_NAME = "normalizedName";
+    private static final String CSAR_ENTRY_EMPTY_ASSERT = "Csar Entries should be empty";
+    private static final EtsiVersion nsdVersion = EtsiVersion.VERSION_2_5_1;
+    @Mock
+    private EtsiNfvNsdCsarGeneratorFactory etsiNfvNsdCsarGeneratorFactory;
     @Mock
     private EtsiNfvNsdCsarGenerator etsiNfvNsdCsarGenerator;
     @Mock
@@ -51,25 +60,23 @@ class EtsiNfvNsCsarEntryGeneratorTest {
     @InjectMocks
     private EtsiNfvNsCsarEntryGenerator etsiNfvNsCsarEntryGenerator;
 
-    private static final String SERVICE_NORMALIZED_NAME = "normalizedName";
-    private static final String CSAR_ENTRY_EMPTY_ASSERT = "Csar Entries should be empty";
-
     @BeforeEach
     void setUp() {
-        MockitoAnnotations.initMocks(this);
+        MockitoAnnotations.openMocks(this);
+        when(etsiNfvNsdCsarGeneratorFactory.create(nsdVersion)).thenReturn(etsiNfvNsdCsarGenerator);
     }
 
     @Test
     void successfullyEntryGenerationTest() throws NsdException {
         mockServiceComponent();
-        final byte[] expectedNsdCsar = new byte[5];
-        when(etsiNfvNsdCsarGenerator.generateNsdCsar(service)).thenReturn(expectedNsdCsar);
-
+        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), expectedNsdCsar));
+            hasEntry(String.format(NSD_FILE_PATH_FORMAT, ETSI_PACKAGE, SERVICE_NORMALIZED_NAME, UNSIGNED_CSAR_EXTENSION),
+                nsdCsar.getCsarPackage()));
     }
 
     @Test
@@ -77,7 +84,6 @@ class EtsiNfvNsCsarEntryGeneratorTest {
         mockServiceComponent();
         when(etsiNfvNsdCsarGenerator.generateNsdCsar(service)).thenThrow(new NsdException(""));
         final Map<String, byte[]> entryMap = etsiNfvNsCsarEntryGenerator.generateCsarEntries(service);
-
         assertThat(CSAR_ENTRY_EMPTY_ASSERT, entryMap, is(anEmptyMap()));
     }
 
@@ -86,7 +92,6 @@ class EtsiNfvNsCsarEntryGeneratorTest {
         mockServiceComponent();
         when(etsiNfvNsdCsarGenerator.generateNsdCsar(service)).thenThrow(new RuntimeException());
         final Map<String, byte[]> entryMap = etsiNfvNsCsarEntryGenerator.generateCsarEntries(service);
-
         assertThat(CSAR_ENTRY_EMPTY_ASSERT, entryMap, is(anEmptyMap()));
     }
 
@@ -94,7 +99,6 @@ class EtsiNfvNsCsarEntryGeneratorTest {
     void componentNullOrNotAServiceTest() {
         Map<String, byte[]> entryMap = etsiNfvNsCsarEntryGenerator.generateCsarEntries(service);
         assertThat(CSAR_ENTRY_EMPTY_ASSERT, entryMap, is(anEmptyMap()));
-
         entryMap = etsiNfvNsCsarEntryGenerator.generateCsarEntries(null);
         assertThat(CSAR_ENTRY_EMPTY_ASSERT, entryMap, is(anEmptyMap()));
     }
@@ -115,11 +119,13 @@ class EtsiNfvNsCsarEntryGeneratorTest {
         when(service.getName()).thenReturn("anyName");
         when(service.getComponentType()).thenReturn(ComponentTypeEnum.SERVICE);
         when(service.getNormalizedName()).thenReturn(SERVICE_NORMALIZED_NAME);
-
+        final Map<String, String> categorySpecificMetadataMap = new HashMap<>();
+        categorySpecificMetadataMap.put(ETSI_VERSION_METADATA, nsdVersion.getVersion());
+        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);
     }
-}
\ No newline at end of file
+}