aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorSindhuri.A <arcot.sindhuri@huawei.com>2018-11-12 18:27:32 +0530
committerTal Gitelman <tal.gitelman@att.com>2018-11-19 16:02:05 +0000
commit373afa51abcaa124c351ccd28c8dcf3b39a8759f (patch)
tree540dbc90be43b32556f9188c942c87d17f9baa61 /catalog-be/src/test/java
parent18ffcc13dd5e63490a0aca0b4b228ca641e2b4c4 (diff)
UT-GroupBusinessLogic2
UT for catalog be GroupBusinessLogicTest class Issue-ID: SDC-1775 Change-Id: Ib0ce6ff0e0fa33787c6f3dc92003c794d3d0e991 Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com>
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java111
1 files changed, 108 insertions, 3 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java
index 3afb86da2c..de27677a42 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java
@@ -29,28 +29,45 @@
*/
package org.openecomp.sdc.be.components.impl;
+import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.validation.AccessValidations;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.jsontitan.operations.GroupsOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.model.tosca.ToscaType;
+import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
import fj.data.Either;
+import javax.servlet.ServletContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Set;
-
+import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
@@ -72,6 +89,17 @@ public class GroupBusinessLogicTest {
private IGroupTypeOperation groupTypeOperation;
@Mock
private GroupsOperation groupsOperation;
+ @Mock
+ private AccessValidations accessValidations;
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private PropertyOperation propertyOperation;
+
+ private final static ServletContext servletContext = Mockito.mock(ServletContext.class);
+ private final static ConfigurationManager configurationManager = Mockito.mock(ConfigurationManager.class);
+ private final static Configuration configuration = Mockito.mock(Configuration.class);
+ static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be");
@Test
public void testCreateGroups_NoDataType() {
@@ -82,7 +110,7 @@ public class GroupBusinessLogicTest {
groupDefinitions.add(groupDefinition);
when(dataTypeCache.getAll()).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
result = test.createGroups(component, groupDefinitions, true);
- assertThat(result.isRight());
+ Assert.assertTrue(result.isRight());
}
@Test
@@ -102,6 +130,83 @@ public class GroupBusinessLogicTest {
when(groupsOperation.createGroups(any(Component.class), anyMap())).thenReturn(Either.left(groupDefinitions));
when(groupsOperation.addCalculatedCapabilitiesWithProperties(anyString(), anyMap(), anyMap())).thenReturn(StorageOperationStatus.OK);
result = test.createGroups(component, groupDefinitions, true);
- assertThat(result.isLeft());
+ Assert.assertTrue(result.isLeft());
+ }
+
+ @Test
+ public void testValidUpdateVfGrpNameOnGraph() {
+ Either<List<GroupDefinition>, ResponseFormat> result;
+ Component component = new Resource();
+ component.setSystemName("name");
+
+ List<GroupDefinition> groupDefinitions = new ArrayList<>();
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setName("grp_one-1. ::module-1");
+ groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE);
+ groupDefinition.setDescription("desc");
+ groupDefinitions.add(groupDefinition);
+
+ result = test.validateUpdateVfGroupNamesOnGraph(groupDefinitions, component);
+ Assert.assertTrue(result.isLeft());
+ }
+
+ @Test
+ public void testValidAndUpdateGrpInstancePropValues_fail() {
+ Either<GroupInstance, ResponseFormat> result;
+ String componentId = "id";
+ String instanceId = "id";
+ GroupInstance oldGroupInstance = new GroupInstance();
+ List<GroupInstanceProperty> newProperties = new ArrayList<>();
+ List<PropertyDataDefinition> properties = new LinkedList<>();
+ properties.add(new PropertyDataDefinition());
+ oldGroupInstance.setProperties(properties);
+ result = test.validateAndUpdateGroupInstancePropertyValues(componentId, instanceId, oldGroupInstance, newProperties);
+ Assert.assertTrue(result.isRight());
+ }
+
+ @Test
+ public void testCreateGroup() {
+ GroupDefinition result;
+ String componentId = "id";
+ String grpType = "grpType";
+ String userId = "userId";
+ ComponentTypeEnum compTypeEnum = ComponentTypeEnum.RESOURCE;
+ Component component = new Resource();
+ component.setName("name");
+ component.setUniqueId(componentId);
+ component.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
+ List<GroupDefinition> groupDefList = new ArrayList<>();
+ Map<String, Set<String>> excludedGroupTypesMap = new HashMap<>();
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
+ Map<String, DataTypeDefinition> map = new HashMap<>();
+ when(dataTypeCache.getAll()).thenReturn(Either.left(map));
+ when(accessValidations.validateUserCanWorkOnComponent(componentId, compTypeEnum, userId, "CreateGroup")).thenReturn(component);
+
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ configurationManager.setConfiguration(new Configuration());
+ configurationManager.getConfiguration().setExcludedGroupTypesMapping(excludedGroupTypesMap);
+
+ List<PropertyDefinition> properties = asList(
+ buildProperty("network_collection_type", "l3-network", "network collection type, defined with default value"));
+ groupTypeDefinition.setProperties(properties);
+ when(groupTypeOperation.getLatestGroupTypeByType(grpType, false)).thenReturn(Either.left(groupTypeDefinition));
+ when(toscaOperationFacade.canAddGroups(componentId)).thenReturn(true);
+ when(groupTypeOperation.getLatestGroupTypeByType(grpType, true)).thenReturn(Either.left(groupTypeDefinition));
+ when(propertyOperation.checkInnerType(any(PropertyDefinition.class))).thenReturn(Either.left("ok"));
+ when(propertyOperation.validateAndUpdatePropertyValue("string", null, "ok", map)).thenReturn(Either.left(component));
+ when(groupsOperation.addGroups(any(Resource.class), any())).thenReturn(Either.left(groupDefList));
+ when(groupsOperation.addCalculatedCapabilitiesWithProperties(anyString(), anyMap(), anyMap())).thenReturn(StorageOperationStatus.OK);
+ result = test.createGroup(componentId, compTypeEnum, grpType, userId);
+ assertThat(result.getClass().isInstance(GroupDefinition.class));
+ }
+
+ private PropertyDefinition buildProperty(String name, String defaultValue, String description) {
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName(name);
+ property.setDefaultValue(defaultValue);
+ property.setRequired(true);
+ property.setDescription(description);
+ property.setType(ToscaType.STRING.name().toLowerCase());
+ return property;
}
} \ No newline at end of file