diff options
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java | 50 |
1 files changed, 43 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); |