summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorstasys10 <stasys.jurgaitis@est.tech>2021-11-29 19:52:58 +0000
committerAndr� Schmid <andre.schmid@est.tech>2022-01-27 16:59:25 +0000
commit9bd18657d2048d3396d15a394b4493b283c47e4d (patch)
treee4bd0deef57d238fab57621a1b9382d9cbb5c031 /catalog-be/src/test
parentc2fa1b7e8d43a236219d1f6ad2831de1af296cb4 (diff)
Add a display name for the category
Issue-ID: SDC-3858 Change-Id: Ic818b3b4bc4f4e91c9da0cdacb40549a3f071c68 Signed-off-by: stasys10 <stasys.jurgaitis@est.tech>
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"