From fbd23ad8f6c29c8f1c24eca5e03c47995b89a5ea Mon Sep 17 00:00:00 2001 From: "Sindhuri.A" Date: Sat, 3 Nov 2018 21:49:31 +0530 Subject: UT-GroupBusinessLogic UT for catalog be GroupBusinessLogicTest class Issue-ID: SDC-1775 Change-Id: I59ae7cbfdf11ba7f1b94313c9c359bb5b19c56d5 Signed-off-by: Sindhuri.A --- .../be/components/impl/GroupBusinessLogicTest.java | 830 +++------------------ 1 file changed, 85 insertions(+), 745 deletions(-) (limited to 'catalog-be') 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 d9ca7b06c2..3afb86da2c 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 @@ -1,767 +1,107 @@ -package org.openecomp.sdc.be.components.impl; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.junit.Test; -import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.info.ArtifactTemplateInfo; -import org.openecomp.sdc.be.info.GroupDefinitionInfo; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.ComponentInstance; -import org.openecomp.sdc.be.model.DataTypeDefinition; -import org.openecomp.sdc.be.model.GroupDefinition; -import org.openecomp.sdc.be.model.GroupInstance; -import org.openecomp.sdc.be.model.GroupInstanceProperty; -import org.openecomp.sdc.be.model.GroupProperty; -import org.openecomp.sdc.be.model.PropertyDefinition; -import org.openecomp.sdc.be.model.PropertyDefinition.PropertyNames; -import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.openecomp.sdc.exception.ResponseFormat; - -import com.google.common.base.Function; - -import fj.data.Either; - - -public class GroupBusinessLogicTest { - - private GroupBusinessLogic createTestSubject() { - return new GroupBusinessLogic(); - } - - - @Test - public void testGetComponentTypeForResponse() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - String result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testVerifyArtifactsBelongsToComponent() throws Exception { - GroupBusinessLogic testSubject;Component component = null; - List artifacts = null; - String context = ""; - Either result; - - // test 1 - testSubject=createTestSubject();artifacts = null; - - - } - - - @Test - public void testVerifyComponentInstancesAreValidMembers() throws Exception { - GroupBusinessLogic testSubject;Component component = null; - ComponentTypeEnum componentType = null; - String groupName = ""; - String groupType = ""; - Map groupMembers = null; - List memberToscaTypes = null; - Either result; - - // test 1 - testSubject=createTestSubject();groupMembers = null; - - - - // test 2 - testSubject=createTestSubject();memberToscaTypes = null; - - - } - - - @Test - public void testValidateAndUpdateGroupMetadata() throws Exception { - GroupBusinessLogic testSubject; - String componentId = ""; - User user = null; - ComponentTypeEnum componentType = null; - GroupDefinition updatedGroup = null; - boolean inTransaction = false; - boolean shouldLock = false; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testUpdateGroupMetadata() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - GroupDefinition currentGroup = null; - GroupDefinition updatedGroup = null; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testUpdateGroup() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - GroupDefinition updatedGroup = null; - String currentGroupName = ""; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateAndUpdateGroupProperties() throws Exception { - GroupBusinessLogic testSubject; - String componentId = ""; - String groupUniqueId = ""; - User user = null; - ComponentTypeEnum componentType = null; - List groupPropertiesToUpdate = null; - boolean inTransaction = false; - Either, ResponseFormat> result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testResetEmptyValueWithDefaults() throws Exception { - GroupBusinessLogic testSubject;List groupPropertiesToUpdate = null; - GroupDefinition originalGroup = null; - - - // default test - } - - - @Test - public void testValidateGroupPropertyAndResetEmptyValue() throws Exception { - GroupBusinessLogic testSubject;GroupDefinition originalGroup = null; - List groupPropertiesToUpdate = null; - Either,ResponseFormat> result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testValidatePropertyBusinessLogic() throws Exception { - GroupBusinessLogic testSubject;List groupPropertiesToUpdate = null; - GroupDefinition originalGroup = null; - Either,ResponseFormat> result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testPrepareMapWithOriginalProperties() throws Exception { - GroupBusinessLogic testSubject; - GroupDefinition originalGroup = null; - Map result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateOnlyValueChanged() throws Exception { - GroupBusinessLogic testSubject;List groupPropertiesToUpdate = null; - GroupDefinition originalGroup = null; - Either,ResponseFormat> result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testIsOnlyGroupPropertyValueChanged() throws Exception { - GroupBusinessLogic testSubject; - GroupProperty groupProperty = null; - GroupProperty groupProperty2 = null; - boolean result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateAndUpdateGroupMetadata_1() throws Exception { - GroupBusinessLogic testSubject; - GroupDefinition currentGroup = null; - GroupDefinition groupUpdate = null; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateAndUpdateGroupName() throws Exception { - GroupBusinessLogic testSubject; - GroupDefinition currentGroup = null; - GroupDefinition groupUpdate = null; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateGroupName() throws Exception { - GroupBusinessLogic testSubject; - String currentGroupName = ""; - String groupUpdateName = ""; - boolean isforceNameModification = false; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testGetGroupWithArtifactsById() throws Exception { - GroupBusinessLogic testSubject; - ComponentTypeEnum componentType = null; - String componentId = ""; - String groupId = ""; - String userId = ""; - boolean inTransaction = false; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testFindGroupOnComponent() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - String groupId = ""; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateGroupsBeforeUpdate() throws Exception { - GroupBusinessLogic testSubject;String componentId = ""; - String userId = ""; - ComponentTypeEnum componentType = null; - List groups = null; - boolean inTransaction = false; - Either result; - - // default test - testSubject=createTestSubject(); - } +/* - - @Test - public void testValidateGroupsInComponentByFunc() throws Exception { - GroupBusinessLogic testSubject;List groups = null; - Component component = null; - Function getByParam = null; - ResponseFormat result; - - // default test - testSubject=createTestSubject(); - } + * Copyright (c) 2018 AT&T Intellectual Property. - - @Test - public void testGetAsString() throws Exception { - GroupBusinessLogic testSubject; - List list = null; - String result; + * - // test 1 - testSubject = createTestSubject(); - list = null; - - - } + * Licensed under the Apache License, Version 2.0 (the "License"); - - @Test - public void testUpdateGroupPropertiesValue() throws Exception { - GroupBusinessLogic testSubject;String componentId = ""; - GroupDefinition currentGroup = null; - List groupPropertyToUpdate = null; - boolean inTransaction = false; - Either,ResponseFormat> result; - - // default test - testSubject=createTestSubject(); - } + * you may not use this file except in compliance with the License. - - @Test - public void testValidateGenerateVfModuleGroupNames() throws Exception { - GroupBusinessLogic testSubject; - List allGroups = null; - String resourceSystemName = ""; - int startGroupCounter = 0; - Either result; + * You may obtain a copy of the License at - // default test - testSubject = createTestSubject(); - - } + * - - @Test - public void testValidateGenerateVfModuleGroupName() throws Exception { - GroupBusinessLogic testSubject; - String resourceSystemName = ""; - String description = ""; - int groupCounter = 0; - Either result; + * http://www.apache.org/licenses/LICENSE-2.0 - // test 1 - testSubject = createTestSubject(); - resourceSystemName = null; - description = null; - - + * - // test 2 - testSubject = createTestSubject(); - resourceSystemName = ""; - description = null; - - + * Unless required by applicable law or agreed to in writing, software - // test 3 - testSubject = createTestSubject(); - description = null; - resourceSystemName = null; - - + * distributed under the License is distributed on an "AS IS" BASIS, - // test 4 - testSubject = createTestSubject(); - description = ""; - resourceSystemName = null; - - - } + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - - @Test - public void testValidateUpdateVfGroupNames() throws Exception { - GroupBusinessLogic testSubject; - Map groups = null; - String resourceSystemName = ""; - Either, ResponseFormat> result; + * See the License for the specific language governing permissions and - // default test - testSubject = createTestSubject(); - - } + * limitations under the License. - - @Test - public void testGetNextVfModuleNameCounter() throws Exception { - GroupBusinessLogic testSubject; - Map groups = null; - int result; - - // test 1 - testSubject = createTestSubject(); - groups = null; - - - } - - - @Test - public void testGetNextVfModuleNameCounter_1() throws Exception { - GroupBusinessLogic testSubject; - Collection groups = null; - int result; - - // test 1 - testSubject = createTestSubject(); - groups = null; - - - } - - - @Test - public void testValidateUpdateVfGroupNamesOnGraph() throws Exception { - GroupBusinessLogic testSubject; - List groups = null; - Component component = null; - boolean inTransaction = false; - Either, ResponseFormat> result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testGetGroupInstWithArtifactsById() throws Exception { - GroupBusinessLogic testSubject; - ComponentTypeEnum componentType = null; - String componentId = ""; - String componentInstanceId = ""; - String groupInstId = ""; - String userId = ""; - boolean inTransaction = false; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testFindComponentInstanceAndGroupInstanceOnComponent() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - String componentInstanceId = ""; - String groupInstId = ""; - Either, StorageOperationStatus> result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testGetLatestIntProperty() throws Exception { - GroupBusinessLogic testSubject;Map newValues = null; - Map parentValues = null; - PropertyNames propertyKey = null; - int result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testIsPropertyChanged() throws Exception { - GroupBusinessLogic testSubject;Map newValues = null; - Map parentValues = null; - PropertyNames minInstances = null; - boolean result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testValidateMinMaxAndInitialCountPropertyLogicVF() throws Exception { - GroupBusinessLogic testSubject;Map newValues = null; - Map parentValues = null; - Either result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testValidateMinMaxAndInitialCountPropertyLogic() throws Exception { - GroupBusinessLogic testSubject;Map newValues = null; - Map currValues = null; - Map parentValues = null; - Either result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testValidateValueInRange() throws Exception { - GroupBusinessLogic testSubject;ImmutablePair newValue = null; - ImmutablePair min = null; - ImmutablePair max = null; - Either result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testParseIntValue() throws Exception { - GroupBusinessLogic testSubject; - String value = ""; - PropertyNames propertyName = null; - int result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateAndUpdateGroupInstancePropertyValues() throws Exception { - GroupBusinessLogic testSubject; - String componentId = ""; - String instanceId = ""; - GroupInstance oldGroupInstance = null; - List newProperties = null; - boolean inTransaction = false; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateReduceGroupInstancePropertiesBeforeUpdate() throws Exception { - GroupBusinessLogic testSubject;GroupInstance oldGroupInstance = null; - List newProperties = null; - Either,ResponseFormat> result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testFillValuesAndParentValuesFromExistingProperties() throws Exception { - GroupBusinessLogic testSubject;Map existingProperties = null; - Map propertyValues = null; - Map parentPropertyValues = null; - - - // default test - } - - - @Test - public void testHandleAndAddProperty() throws Exception { - GroupBusinessLogic testSubject;List reducedProperties = null; - Map newPropertyValues = null; - GroupInstanceProperty currNewProperty = null; - GroupInstanceProperty currExistingProperty = null; - Either result; - - // default test - testSubject=createTestSubject(); - } - - - @Test - public void testIsUpdatable() throws Exception { - GroupBusinessLogic testSubject; - PropertyNames updatablePropertyName = null; - boolean result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testAddPropertyUpdatedValues() throws Exception { - GroupBusinessLogic testSubject;List reducedProperties = null; - PropertyNames propertyName = null; - Map newPropertyValues = null; - GroupInstanceProperty newProperty = null; - GroupInstanceProperty existingProperty = null; - - - // default test - } - - - @Test - public void testIsEmptyMinInitialCountValue() throws Exception { - GroupBusinessLogic testSubject; - PropertyNames propertyName = null; - String newValue = ""; - boolean result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testConvertIfUnboundMax() throws Exception { - GroupBusinessLogic testSubject; - String value = ""; - int result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateAndUpdatePropertyValue() throws Exception { - GroupBusinessLogic testSubject; - GroupInstanceProperty newProperty = null; - GroupInstanceProperty existingProperty = null; - Either result; - - // default test - testSubject = createTestSubject(); - - } - - - @Test - public void testValidateImmutableProperty() throws Exception { - GroupBusinessLogic testSubject; - GroupProperty oldProperty = null; - GroupProperty newProperty = null; - - // default test - testSubject = createTestSubject(); - } - - - @Test - public void testCreateGroups() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - User user = null; - ComponentTypeEnum componentType = null; - List groupDefinitions = null; - Either, ResponseFormat> result; - - // test 1 - testSubject = createTestSubject(); - groupDefinitions = null; - - - } - - - @Test - public void testAddGroups() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - User user = null; - ComponentTypeEnum componentType = null; - List groupDefinitions = null; - Either, ResponseFormat> result; - - // test 1 - testSubject = createTestSubject(); - groupDefinitions = null; - - - } - - - @Test - public void testDeleteGroups() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - User user = null; - ComponentTypeEnum componentType = null; - List groupDefinitions = null; - Either, ResponseFormat> result; + */ +package org.openecomp.sdc.be.components.impl; - // default test - testSubject = createTestSubject(); - - } +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +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.operations.GroupsOperation; +import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.exception.ResponseFormat; +import fj.data.Either; - - @Test - public void testUpdateGroups() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - ComponentTypeEnum componentType = null; - List groupDefinitions = null; - Either, ResponseFormat> result; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; - // default test - testSubject = createTestSubject(); - - } - - @Test - public void testHandleGroup() throws Exception { - GroupBusinessLogic testSubject; - Component component = null; - User user = null; - ComponentTypeEnum componentType = null; - GroupDefinition groupDefinition = null; - Map allDAtaTypes = null; - Either result; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; - // default test - testSubject = createTestSubject(); - - } - - @Test - public void testHandleProperty() throws Exception { - GroupBusinessLogic testSubject; - GroupProperty groupProperty = null; - PropertyDefinition prop = null; - Integer index = 0; - Map allDataTypes = null; - Either result; +@RunWith(MockitoJUnitRunner.class) +public class GroupBusinessLogicTest { - // test 1 - testSubject = createTestSubject(); - prop = null; - - - } + @InjectMocks + private GroupBusinessLogic test; + + @Mock + private ApplicationDataTypeCache dataTypeCache; + @Mock + private ComponentsUtils componentsUtils; + @Mock + private IGroupTypeOperation groupTypeOperation; + @Mock + private GroupsOperation groupsOperation; + + @Test + public void testCreateGroups_NoDataType() { + Either, ResponseFormat> result; + Component component = new Resource(); + List groupDefinitions = new ArrayList<>(); + GroupDefinition groupDefinition = new GroupDefinition(); + groupDefinitions.add(groupDefinition); + when(dataTypeCache.getAll()).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND)); + result = test.createGroups(component, groupDefinitions, true); + assertThat(result.isRight()); + } + + @Test + public void testCreateGroups() { + Either, ResponseFormat> result; + Component component = new Resource(); + component.setUniqueId("id"); + List groupDefinitions = new ArrayList<>(); + GroupDefinition groupDefinition = new GroupDefinition(); + groupDefinition.setName("name"); + groupDefinitions.add(groupDefinition); + groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE); + GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); + Map map = new HashMap<>(); + when(dataTypeCache.getAll()).thenReturn(Either.left(map)); + when(groupTypeOperation.getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true)).thenReturn(Either.left(groupTypeDefinition)); + 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()); + } } \ No newline at end of file -- cgit 1.2.3-korg