aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java50
-rw-r--r--catalog-be/src/test/resources/types/categoryTypes.yml10
2 files changed, 53 insertions, 7 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
index f7d0709307..c3975b9f89 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.components.impl;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@@ -32,15 +33,16 @@ import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
@@ -48,14 +50,14 @@ import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.exception.ResponseFormat;
-public class CategoriesImportManagerTest {
+class CategoriesImportManagerTest {
@InjectMocks
static CategoriesImportManager importManager = new CategoriesImportManager();
public static final IElementOperation elementOperation = Mockito.mock(IElementOperation.class);
public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
private static SubCategoryDefinition subcategory;
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws IOException {
subcategory = new SubCategoryDefinition();
subcategory.setUniqueId("123");
@@ -78,13 +80,13 @@ public class CategoriesImportManagerTest {
// when(Mockito.any(SubCategoryDefinition.class).getUniqueId()).thenReturn("123");
}
- @Before
+ @BeforeEach
public void initMocks() {
MockitoAnnotations.openMocks(this);
}
@Test
- public void importCategoriesTest() throws IOException {
+ void importCategoriesTest() throws IOException {
String ymlContent = getYmlContent();
Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCapabilityTypes = importManager.createCategories(ymlContent);
@@ -104,6 +106,40 @@ public class CategoriesImportManagerTest {
assertFalse(categoryWithServiceSubstitutionFalse.get().isUseServiceSubstitutionForNestedServices());
}
+ @Test
+ void categoriesNameAndDisplayNameTest() throws IOException {
+ final String categoryName = "Category With DisplayName And metadata";
+ final String expectedCategoryDisplayName = "Display Name For Category";
+ final String ymlContent = getYmlContent();
+ final Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCapabilityTypes = importManager.createCategories(ymlContent);
+ final Map<String, List<CategoryDefinition>> categories = createCapabilityTypes.left().value();
+
+ final Optional<CategoryDefinition> categoryWithNameAndDisplayName = categories.get("services").stream().filter(category -> category.getName().equals(categoryName)).findAny();
+ final String categoryDisplayName = categoryWithNameAndDisplayName.get().getDisplayName();
+
+ assertTrue(categoryWithNameAndDisplayName.isPresent());
+ assertEquals(expectedCategoryDisplayName, categoryDisplayName);
+ }
+
+ @Test
+ void getMetadataKeysTest() throws IOException {
+ final String categoryName = "Category With DisplayName And metadata";
+ final String expectedMetadataName = "ETSI Version";
+ final String expectedEtsiVersion = "2.5.1";
+ final String ymlContent = getYmlContent();
+ final Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCapabilityTypes = importManager.createCategories(ymlContent);
+ final Map<String, List<CategoryDefinition>> categories = createCapabilityTypes.left().value();
+
+ final Optional<CategoryDefinition> categoryWithMetadata = categories.get("services").stream().filter(category -> category.getName().equals(categoryName)).findAny();
+ final List<MetadataKeyDataDefinition> categoryMetadataList = categoryWithMetadata.get().getMetadataKeys();
+ final MetadataKeyDataDefinition categoryMetadata = categoryMetadataList.get(0);
+
+ assertEquals(expectedMetadataName, categoryMetadata.getName());
+ assertEquals(expectedEtsiVersion, categoryMetadata.getValidValues().get(0));
+ assertEquals(expectedEtsiVersion, categoryMetadata.getDefaultValue());
+ assertTrue(categoryMetadata.isMandatory());
+ }
+
private String getYmlContent() throws IOException {
Path filePath = Paths.get("src/test/resources/types/categoryTypes.yml");
byte[] fileContent = Files.readAllBytes(filePath);
diff --git a/catalog-be/src/test/resources/types/categoryTypes.yml b/catalog-be/src/test/resources/types/categoryTypes.yml
index 36268b1fff..293b16062e 100644
--- a/catalog-be/src/test/resources/types/categoryTypes.yml
+++ b/catalog-be/src/test/resources/types/categoryTypes.yml
@@ -19,6 +19,16 @@ services:
name: "Category With Service Substitution False"
icons: ['network_l_4']
useServiceSubstitutionForNestedServices: false
+ Category_With_DisplayName_And_metadata:
+ name: "Category With DisplayName And metadata"
+ displayName: "Display Name For Category"
+ icons: [ 'etsi_nfv_network_service' ]
+ metadataKeys:
+ etsiVersion:
+ name: "ETSI Version"
+ validValues: [ '2.5.1' ]
+ default: '2.5.1'
+ mandatory: true
resources:
NetworkLayer23:
name: "Network Layer 2-3"