*/
package org.openecomp.sdc.be.components.impl;
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyObject;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.policy.PolicyTargetsUpdateHandler;
import org.openecomp.sdc.be.components.validation.AccessValidations;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-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.anyList;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyObject;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.when;
-
-
-@RunWith(MockitoJUnitRunner.class)
-public class GroupBusinessLogicTest {
+@ExtendWith(MockitoExtension.class)
+class GroupBusinessLogicTest {
+ static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
+ "src/test/resources/config/catalog-be");
+ static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
@InjectMocks
private GroupBusinessLogic test;
-
@Mock
private ApplicationDataTypeCache dataTypeCache;
@Mock
@Mock
private JanusGraphDao janusGraphDao;
@Mock
- PolicyTargetsUpdateHandler policyTargetsUpdateHandler;
-
- static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
- "src/test/resources/config/catalog-be");
- static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ private PolicyTargetsUpdateHandler policyTargetsUpdateHandler;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
test.setDataTypeCache(dataTypeCache);
test.setToscaOperationFacade(toscaOperationFacade);
}
@Test
- public void testCreateGroups_NoDataType() {
+ void testCreateGroups_NoDataType() {
Either<List<GroupDefinition>, ResponseFormat> result;
Component component = new Resource();
List<GroupDefinition> groupDefinitions = new ArrayList<>();
}
@Test
- public void testCreateGroups() {
+ void testCreateGroups() {
Either<List<GroupDefinition>, ResponseFormat> result;
Component component = new Resource();
component.setUniqueId("id");
}
@Test
- public void testValidUpdateVfGrpNameOnGraph() {
+ void testValidUpdateVfGrpNameOnGraph() {
Either<List<GroupDefinition>, ResponseFormat> result;
Component component = new Resource();
component.setSystemName("name");
}
@Test
- public void testValidAndUpdateGrpInstancePropValues_fail() {
+ void testValidAndUpdateGrpInstancePropValues_fail() {
Either<GroupInstance, ResponseFormat> result;
String componentId = "id";
String instanceId = "id";
oldGroupInstance.setProperties(properties);
try {
result = test.validateAndUpdateGroupInstancePropertyValues(componentId, instanceId, oldGroupInstance, newProperties);
- }catch (ComponentException e){
+ } catch (ComponentException e) {
assertThat(e.getActionStatus()).isEqualTo(ActionStatus.GENERAL_ERROR);
}
}
@Test
- public void testCreateGroup() {
+ void testCreateGroup() {
GroupDefinition result;
String componentId = "id";
String grpType = "grpType";
configurationManager.getConfiguration().setExcludedGroupTypesMapping(excludedGroupTypesMap);
List<PropertyDefinition> properties = asList(
- buildProperty("network_collection_type", "l3-network", "network collection type, defined with default value"));
+ 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);
}
@Test
- public void testUpdateGroup() throws Exception {
+ void testUpdateGroup() throws Exception {
- Component component= new Resource();
+ Component component = new Resource();
GroupDefinition updatedGroup = new GroupDefinition();
List<GroupDefinition> grpdefList = new ArrayList<>();
updatedGroup.setName("GRP.01");
when(accessValidations.validateUserCanWorkOnComponent("compid", ComponentTypeEnum.SERVICE, "USR01", "UpdateGroup")).thenReturn(component);
when(groupsOperation.updateGroup(component, updatedGroup)).thenReturn(Either.left(updatedGroup));
GroupDefinition Gdefinition = test.updateGroup("compid", ComponentTypeEnum.SERVICE, "GRP.01",
- "USR01", updatedGroup);
- Assert.assertEquals(Gdefinition,updatedGroup);
+ "USR01", updatedGroup);
+ Assert.assertEquals(Gdefinition, updatedGroup);
}
+ @Test
+ void testUpdateGroup_Invalidname() throws Exception {
- @Test(expected = ComponentException.class)
- public void testUpdateGroup_Invalidname() throws Exception {
-
- Component component= new Resource();
+ Component component = new Resource();
GroupDefinition updatedGroup = new GroupDefinition();
List<GroupDefinition> grpdefList = new ArrayList<>();
updatedGroup.setName("GRP~01");
component.setUniqueId("GRP.01");
component.setGroups(grpdefList);
when(accessValidations.validateUserCanWorkOnComponent("compid", ComponentTypeEnum.SERVICE, "USR01", "UpdateGroup")).thenReturn(component);
- GroupDefinition Gdefinition = test.updateGroup("compid", ComponentTypeEnum.SERVICE, "GRP.01",
+ assertThrows(ComponentException.class, () -> {
+ GroupDefinition Gdefinition = test.updateGroup("compid", ComponentTypeEnum.SERVICE, "GRP.01",
"USR01", updatedGroup);
-
+ });
}
- @Test(expected = ComponentException.class)
- public void testDeleteGroup_exception() throws Exception {
+ @Test
+ void testDeleteGroup_exception() throws Exception {
- Component component= new Resource();
+ Component component = new Resource();
GroupDefinition updatedGroup = new GroupDefinition();
List<GroupDefinition> grpdefList = new ArrayList<>();
updatedGroup.setName("GRP~01");
component.setUniqueId("GRP.01");
component.setGroups(grpdefList);
when(accessValidations.validateUserCanWorkOnComponent("compid", ComponentTypeEnum.SERVICE, "USR01", "DeleteGroup")).thenReturn(component);
- when(groupsOperation.deleteGroups(anyObject(),anyList())).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
+ when(groupsOperation.deleteGroups(anyObject(), anyList())).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
- GroupDefinition Gdefinition = test.deleteGroup("compid", ComponentTypeEnum.SERVICE, "GRP.01",
+ assertThrows(ComponentException.class, () -> {
+ GroupDefinition Gdefinition = test.deleteGroup("compid", ComponentTypeEnum.SERVICE, "GRP.01",
"USR01");
+ });
}
@Test
- public void testDeleteGroup(){
+ void testDeleteGroup() {
- Component component= new Resource();
+ Component component = new Resource();
List<GroupDefinition> groupDefList = new ArrayList<>();
GroupDefinition updatedGroup = new GroupDefinition();
updatedGroup.setName("GRP~01");
List<GroupDefinition> groupDefListCopy = new ArrayList<>();
groupDefListCopy.add(updatedGroup);
when(accessValidations.validateUserCanWorkOnComponent("compid", ComponentTypeEnum.SERVICE, "USR01", "DeleteGroup")).thenReturn(component);
- when(groupsOperation.deleteGroups(anyObject(),anyList())).thenReturn(Either.left(groupDefListCopy));
+ when(groupsOperation.deleteGroups(anyObject(), anyList())).thenReturn(Either.left(groupDefListCopy));
when(groupsOperation.deleteCalculatedCapabilitiesWithProperties(anyString(), anyObject())).thenReturn(StorageOperationStatus.OK);
- when(policyTargetsUpdateHandler.removePoliciesTargets(anyObject(),anyString(),anyObject())).thenReturn(ActionStatus.OK);
+ when(policyTargetsUpdateHandler.removePoliciesTargets(anyObject(), anyString(), anyObject())).thenReturn(ActionStatus.OK);
GroupDefinition Gdefinition = test.deleteGroup("compid", ComponentTypeEnum.SERVICE, "GRP.01",
- "USR01");
- Assert.assertEquals(Gdefinition,updatedGroup);
+ "USR01");
+ Assert.assertEquals(Gdefinition, updatedGroup);
}
}
\ No newline at end of file