aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorSindhuri.A <arcot.sindhuri@huawei.com>2018-11-13 16:51:18 +0530
committerTal Gitelman <tal.gitelman@att.com>2018-11-19 16:04:09 +0000
commite9552d06e0733e9bdf3a5868427097a49851c7a6 (patch)
treea5fd182a3e3b6d95a26cc78739964e95f7a8a19e /catalog-be/src/test
parent8a55dbeb457c71843ef9bae3b600ba6b6e3dbd1e (diff)
UT-ElementBusinessLogic3
UT for catalog be ElementBusinessLogicTest class Issue-ID: SDC-1775 Change-Id: I73581cf34ef3f35880776f11cd17c5365876e1c9 Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com>
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBLTest.java77
1 files changed, 71 insertions, 6 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBLTest.java
index e9e462d68e..d445c9c88c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBLTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBLTest.java
@@ -2,6 +2,7 @@ package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -24,6 +25,7 @@ import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
@@ -37,6 +39,7 @@ import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
import org.openecomp.sdc.be.resources.data.ServiceMetadataData;
import org.openecomp.sdc.be.resources.data.category.CategoryData;
+import org.openecomp.sdc.be.ui.model.UiCategories;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.util.ValidationUtils;
@@ -47,6 +50,8 @@ import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
@@ -88,6 +93,12 @@ public class ElementBLTest {
@Mock
protected ComponentsUtils componentsUtils;
+ @Mock
+ private SubCategoryDefinition subCategoryDef;
+
+ @Mock
+ private CategoryDefinition categoryDef;
+
@InjectMocks
private ElementBusinessLogic elementBusinessLogic;
@@ -194,11 +205,10 @@ public class ElementBLTest {
User user = new User();
String userId = "userId";
user.setUserId(userId);
- CategoryDefinition categoryDef = new CategoryDefinition();
when(elementBusinessLogic.validateUserExists(anyString(), anyString(), eq(false))).thenReturn(user);
when(elementOperation.deleteCategory(NodeTypeEnum.ResourceNewCategory, CATEGORY_UNIQUE_ID)).thenReturn(Either.left(categoryDef));
result = elementBusinessLogic.deleteCategory(CATEGORY_UNIQUE_ID, ComponentTypeEnum.RESOURCE_PARAM_NAME, userId);
- assertThat(result.isLeft());
+ Assert.assertTrue(result.isLeft());
}
@Test
@@ -207,11 +217,10 @@ public class ElementBLTest {
User user = new User();
String userId = "userId";
user.setUserId(userId);
- SubCategoryDefinition subCategoryDef = new SubCategoryDefinition();
when(elementBusinessLogic.validateUserExists(anyString(), anyString(), eq(false))).thenReturn(user);
when(elementOperation.deleteSubCategory(NodeTypeEnum.ResourceSubcategory, CATEGORY_UNIQUE_ID)).thenReturn(Either.left(subCategoryDef));
result = elementBusinessLogic.deleteSubCategory(CATEGORY_UNIQUE_ID, ComponentTypeEnum.RESOURCE_PARAM_NAME, userId);
- assertThat(result.isLeft());
+ Assert.assertTrue(result.isLeft());
}
@Test
@@ -220,7 +229,7 @@ public class ElementBLTest {
GroupingDefinition groupDef = Mockito.mock(GroupingDefinition.class);
when(elementOperation.deleteGrouping(null, "groupId")).thenReturn(Either.left(groupDef));
result = elementBusinessLogic.deleteGrouping("groupId", ComponentTypeEnum.RESOURCE_PARAM_NAME, "userId");
- assertThat(result.isLeft());
+ Assert.assertTrue(result.isLeft());
}
@Test
@@ -237,6 +246,62 @@ public class ElementBLTest {
when(elementOperation.isCategoryUniqueForType(NodeTypeEnum.ResourceNewCategory, name)).thenReturn(Either.left(true));
when(elementOperation.createCategory(categoryDef, NodeTypeEnum.ResourceNewCategory)).thenReturn(Either.left(categoryDef));
result = elementBusinessLogic.createCategory(categoryDef, ComponentTypeEnum.RESOURCE_PARAM_NAME, userId);
- assertThat(result.isLeft());
+ Assert.assertTrue(result.isLeft());
+ }
+
+ @Test
+ public void testGetAllCategories() {
+ Either<UiCategories, ResponseFormat> result;
+ String userId = "userId";
+ List<CategoryDefinition> categoryDefList = new ArrayList<>();
+ when(elementOperation.getAllCategories(NodeTypeEnum.ResourceNewCategory, false)).thenReturn(Either.left(categoryDefList));
+ when(elementOperation.getAllCategories(NodeTypeEnum.ServiceNewCategory, false)).thenReturn(Either.left(categoryDefList));
+ when(elementOperation.getAllCategories(NodeTypeEnum.ProductCategory, false)).thenReturn(Either.left(categoryDefList));
+ result = elementBusinessLogic.getAllCategories(userId);
+ Assert.assertTrue(result.isLeft());
+ }
+
+ @Test
+ public void testGetAllCategories_NodeType() {
+ Either<List<CategoryDefinition>, ResponseFormat> result;
+ String userId = "userId";
+ List<CategoryDefinition> categoryDefList = new ArrayList<>();
+ when(elementOperation.getAllCategories(NodeTypeEnum.ResourceNewCategory, false)).thenReturn(Either.left(categoryDefList));
+ result = elementBusinessLogic.getAllCategories("resources", userId);
+ assertEquals(0, result.left().value().size());
+ }
+
+ @Test
+ public void testGetCatalogComp_UuidAndAssetType() {
+ Either<List<? extends Component>, ResponseFormat> result;
+ String uuid = "userId";
+ List<Component> components = new ArrayList<>();
+ when(toscaOperationFacade.getComponentListByUuid(anyString(), anyMap())).thenReturn(Either.left(components));
+ result = elementBusinessLogic.getCatalogComponentsByUuidAndAssetType("resources", uuid);
+ Assert.assertTrue(result.isLeft());
+ }
+
+ @Test
+ public void testCreateGrouping() {
+ Either<GroupingDefinition, ResponseFormat> result;
+ GroupingDefinition groupDef = new GroupingDefinition();
+ String name = "name";
+ groupDef.setName(name);
+ String componentTypeParamName = "products";
+ String grandParentCatId = "gpCatId";
+ String parentSubCatId = "pSubCatId";
+ User user = new User();
+ String userId = "userId";
+ user.setUserId(userId);
+ user.setRole(Role.PRODUCT_STRATEGIST.name());
+ when(elementBusinessLogic.validateUserExists(userId, "create Grouping", false)).thenReturn(user);
+ when(elementOperation.getCategory(NodeTypeEnum.ProductCategory, grandParentCatId)).thenReturn(Either.left(categoryDef));
+ when(elementOperation.getSubCategory(NodeTypeEnum.ProductSubcategory, parentSubCatId)).thenReturn(Either.left(subCategoryDef));
+ when(elementOperation.isGroupingUniqueForSubCategory(NodeTypeEnum.ProductGrouping, name, parentSubCatId)).thenReturn(Either.left(true));
+ when(elementOperation.getGroupingUniqueForType(NodeTypeEnum.ProductGrouping, name)).thenReturn(Either.left(groupDef));
+ when(elementOperation.createGrouping(parentSubCatId, groupDef, NodeTypeEnum.ProductGrouping)).thenReturn(Either.left(groupDef));
+
+ result = elementBusinessLogic.createGrouping(groupDef, componentTypeParamName, grandParentCatId, parentSubCatId, userId);
+ Assert.assertTrue(result.isLeft());
}
}