summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authormojahidi <mojahidul.islam@amdocs.com>2018-04-10 12:32:47 +0530
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-04-22 08:45:17 +0000
commiteb4b9fb0f4d3b62f3b9e2da81ebe581e7d0fc6eb (patch)
tree99563378878da01bfe708ea55be3db2b5982ea43 /catalog-be/src/test/java/org
parent4182fc36985570881dba09680d4a4bbd8d946a79 (diff)
Fixed Review Comments - operation Business logic
Added interface operation Business logic and amended validation logic Change-Id: Ia98c625d732a31b03dec2d24504ecabb367e0582 Issue-ID: SDC-1060 Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java39
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java394
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java37
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java16
4 files changed, 463 insertions, 23 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
index 65dbe87a48..52b71c5743 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
@@ -22,6 +22,7 @@ import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
+import java.util.HashMap;
import java.util.Map;
public interface InterfaceOperationTestUtils {
@@ -36,6 +37,12 @@ public interface InterfaceOperationTestUtils {
id.setOperationsMap(op);
return id;
}
+ default InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceNamme) {
+ Map<String, Operation> operationMap = createMockOperationMap();
+ return createInterface("int1", "Interface 1",
+ "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceNamme, operationMap);
+ }
+
default Operation createInterfaceOperation(String uniqueID, String description, ArtifactDefinition artifactDefinition,
@@ -51,5 +58,37 @@ public interface InterfaceOperationTestUtils {
return operation;
}
+
+
+ default Map<String, Operation> createMockOperationMap() {
+ Operation operation = new Operation();
+ ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operation.setInputs(operationInputDefinitionList);
+
+ operation.setDefinition(false);
+ operation.setName("CREATE");
+ operation.setUniqueId("uniqueId1");
+ Map<String, Operation> operationMap = new HashMap<>();
+ operationMap.put("op1", operation);
+ return operationMap;
+ }
+
+ default OperationInputDefinition createMockOperationInputDefinition(String name) {
+ OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
+ operationInputDefinition.setName(name);
+ operationInputDefinition.setUniqueId("uniqueId1");
+ return operationInputDefinition;
+ }
+
+ default Map<String, InterfaceDefinition> createMockInterfaceDefinition(String resourceName) {
+ Map<String, Operation> operationMap = createMockOperationMap();
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
+ interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1",
+ "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceName, operationMap));
+
+ return interfaceDefinitionMap;
+ }
+
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
new file mode 100644
index 0000000000..f51d06d53a
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
@@ -0,0 +1,394 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import fj.data.Either;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.ElementOperationMock;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.InterfaceOperationTestUtils;
+import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
+import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
+import org.openecomp.sdc.be.components.validation.UserValidations;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+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 org.springframework.web.context.WebApplicationContext;
+
+import javax.servlet.ServletContext;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.mockito.ArgumentMatchers.anyCollection;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyObject;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
+
+public class InterfaceOperationBusinessLogicTest implements InterfaceOperationTestUtils{
+
+ public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
+ public static final String RESOURCE_SUBCATEGORY = "Router";
+
+
+ private String resourceId = "resourceId1";
+ private String operationId = "uniqueId1";
+ Resource resourceUpdate;
+
+ public static final String RESOURCE_NAME = "My-Resource_Name with space";
+
+ final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ IElementOperation mockElementDao;
+ TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
+ UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
+ NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
+ NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
+ TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
+ final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
+ final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
+ WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ UserValidations userValidations = Mockito.mock(UserValidations.class);
+ WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+
+ InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
+ InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class);
+
+ ResponseFormatManager responseManager = null;
+ GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
+ User user = null;
+ Resource resourceResponse = null;
+ ComponentsUtils componentsUtils;
+ ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic();
+ private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
+
+
+ @InjectMocks
+ InterfaceOperationBusinessLogic bl = new InterfaceOperationBusinessLogic();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.reset(propertyOperation);
+
+ ExternalConfiguration.setAppName("catalog-be");
+
+ // init Configuration
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
+
+ // Elements
+ mockElementDao = new ElementOperationMock();
+
+ // User data and management
+ user = new User();
+ user.setUserId("jh0003");
+ user.setFirstName("Jimmi");
+ user.setLastName("Hendrix");
+ user.setRole(Role.ADMIN.name());
+
+ Either<User, ActionStatus> eitherGetUser = Either.left(user);
+ when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
+ when(userValidations.validateUserExists(eq(user.getUserId()), anyString(), eq(false))).thenReturn(Either.left(user));
+ when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(Either.left(user));
+ // Servlet Context attributes
+ when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
+ when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
+
+ Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(true);
+ when(toscaOperationFacade.validateComponentNameExists("Root", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE)).thenReturn(eitherFalse);
+
+ Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
+ when(toscaOperationFacade.validateComponentNameExists("alreadyExists", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCountExist);
+
+ Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
+ when(toscaOperationFacade.validateComponentNameExists(eq(RESOURCE_NAME), any(ResourceTypeEnum.class), eq(ComponentTypeEnum.RESOURCE))).thenReturn(eitherCount);
+
+ Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
+ when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
+
+ Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
+ when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
+ when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
+ when(graphLockOperation.lockComponentByName(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
+
+ // createResource
+ resourceResponse = createResourceObject(true);
+ Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
+ Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null);
+ when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
+ when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);
+ Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
+
+ //InterfaceOperation
+
+ when(operationValidator.validateInterfaceOperations(anyCollection(), anyString(), anyBoolean())).thenReturn(Either.left(true));
+ when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
+ when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
+ when(interfaceOperation.deleteInterface(anyObject(), anyObject())).thenReturn(Either.left(new HashSet<>()));
+ when(interfaceOperation.deleteInterface(any(),any())).thenReturn(Either.left(new HashSet<>()));
+ when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
+ when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK);
+
+ // BL object
+ artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
+ bl = new InterfaceOperationBusinessLogic();
+
+ bl.setUserAdmin(mockUserAdmin);
+ bl.setComponentsUtils(componentsUtils);
+ bl.setGraphLockOperation(graphLockOperation);
+ bl.setTitanGenericDao(mockTitanDao);
+ bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
+ toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
+ toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
+ bl.setToscaOperationFacade(toscaOperationFacade);
+ bl.setUserValidations(userValidations);
+ bl.setInterfaceOperation(interfaceOperation);
+ bl.setInterfaceOperationValidation(operationValidator);
+ Resource resourceCsar = createResourceObjectCsar(true);
+ setCanWorkOnResource(resourceCsar);
+ Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
+ when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
+ responseManager = ResponseFormatManager.getInstance();
+
+ }
+
+ @Test
+ public void createInterfaceOperationTest() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(createMockResourceForAddInterface()));
+ resourceUpdate = setUpResourceMock();
+ Either<Resource, ResponseFormat> interfaceOperation = bl.createInterfaceOperation(resourceId, resourceUpdate, user, true);
+ Assert.assertTrue(interfaceOperation.isLeft());
+ }
+
+
+ @Test
+ public void updateInterfaceOperationTest() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ resourceUpdate = setUpResourceMock();
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(createResourceForInterfaceOperation()));
+ Either<Resource, ResponseFormat> interfaceOperation = bl.updateInterfaceOperation(resourceId, resourceUpdate, user, true);
+ Assert.assertTrue(interfaceOperation.isLeft());
+ }
+
+
+ @Test
+ public void deleteInterfaceOperationTest() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(createResourceForInterfaceOperation()));
+ Set<String> idsToDelete = new HashSet<>();
+ idsToDelete.add(operationId);
+
+ Either<Resource, ResponseFormat> deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, idsToDelete, user, true);
+ Assert.assertTrue(deleteResourceResponseFormatEither.isLeft());
+ }
+
+ @Test
+ public void deleteInterfaceOperationTestShouldFailWrongId() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Set<String> idsToDelete = new HashSet<>();
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(createResourceForInterfaceOperation()));
+ idsToDelete.add(resourceId);
+ Either<Resource, ResponseFormat> deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, idsToDelete, user, true);
+ Assert.assertFalse(deleteResourceResponseFormatEither.isLeft());
+ }
+
+ @Test
+ public void interfaceOperationFailedScenarioTest() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Resource resourceWithoutInterface = new Resource();
+ resourceWithoutInterface.setUniqueId(resourceId);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resourceWithoutInterface));
+ Either<Resource, ResponseFormat> interfaceOperation = bl.updateInterfaceOperation(resourceId, resourceWithoutInterface, user, true);
+ Assert.assertTrue(interfaceOperation.isRight());
+ }
+
+ private void validateUserRoles(Role... roles) {
+ List<Role> listOfRoles = Stream.of(roles).collect(Collectors.toList());
+ when(userValidations.validateUserRole(user, listOfRoles)).thenReturn(Either.left(true));
+ }
+ private Resource createMockResourceForAddInterface () {
+ Resource resource = new Resource();
+ resource.setUniqueId(resourceId);
+ resource.setName(RESOURCE_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("My short description");
+
+ Map<String, Operation> operationMap = new HashMap<>();
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
+ interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1",
+ "lifecycle", "org.openecomp.interfaces.node.lifecycle." + RESOURCE_NAME, operationMap));
+ resource.setInterfaces(interfaceDefinitionMap);
+ List<InputDefinition> inputDefinitionList = new ArrayList<>();
+ inputDefinitionList.add(createInputDefinition("uniqueId1"));
+ resource.setInputs(inputDefinitionList);
+
+ return resource;
+ }
+
+ private Resource setCanWorkOnResource(Resource resource) {
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setLastUpdaterUserId(user.getUserId());
+ return resource;
+ }
+
+ private Resource setUpResourceMock(){
+ Resource resource = new Resource();
+ resource.setUniqueId(resourceId);
+ resource.setName(RESOURCE_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("My short description");
+ resource.setInterfaces(createMockInterfaceDefinition(RESOURCE_NAME));
+
+ List<InputDefinition> inputDefinitionList = new ArrayList<>();
+ inputDefinitionList.add(createInputDefinition("uniqueId1"));
+ resource.setInputs(inputDefinitionList);
+
+ return resource;
+ }
+
+ private InputDefinition createInputDefinition(String inputId) {
+ InputDefinition inputDefinition = new InputDefinition();
+ inputDefinition.setInputId(inputId);
+ inputDefinition.setDescription("Input Description");
+
+ return inputDefinition;
+
+ }
+ private Resource createResourceForInterfaceOperation() {
+ Resource resource = new Resource();
+ resource.setUniqueId(resourceId);
+ resource.setName(RESOURCE_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("Resource name for response");
+ resource.setInterfaces(createMockInterfaceDefinition(RESOURCE_NAME));
+ return resource;
+ }
+
+ private Resource createResourceObjectCsar(boolean afterCreate) {
+ Resource resource = new Resource();
+ resource.setName(RESOURCE_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("My short description");
+ List<String> tgs = new ArrayList<String>();
+ tgs.add("test");
+ tgs.add(resource.getName());
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<String>();
+ template.add("Root");
+ resource.setDerivedFrom(template);
+ resource.setVendorName("Motorola");
+ resource.setVendorRelease("1.0.0");
+ resource.setResourceVendorModelNumber("");
+ resource.setContactId("ya5467");
+ resource.setIcon("MyIcon");
+ resource.setCsarUUID("valid_vf.csar");
+ resource.setCsarVersion("1");
+
+ if (afterCreate) {
+ resource.setName(resource.getName());
+ resource.setVersion("0.1");
+
+ resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ }
+ return resource;
+ }
+
+ private Resource createResourceObject(boolean afterCreate) {
+ Resource resource = new Resource();
+ resource.setName(RESOURCE_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("My short description");
+ List<String> tgs = new ArrayList<String>();
+ tgs.add("test");
+ tgs.add(resource.getName());
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<String>();
+ template.add("Root");
+ resource.setDerivedFrom(template);
+ resource.setVendorName("Motorola");
+ resource.setVendorRelease("1.0.0");
+ resource.setContactId("ya5467");
+ resource.setIcon("MyIcon");
+
+ if (afterCreate) {
+ resource.setName(resource.getName());
+ resource.setVersion("0.1");
+ resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ }
+ return resource;
+ }
+
+
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index 8054baf15f..75aa10aa64 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -29,8 +29,8 @@ import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.ElementOperationMock;
-import org.openecomp.sdc.be.auditing.impl.AuditingLogFormatUtil;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.InterfaceOperationTestUtils;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
@@ -39,6 +39,9 @@ import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -48,18 +51,22 @@ import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
@@ -98,11 +105,14 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyCollection;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
-public class ResourceBusinessLogicTest {
+public class ResourceBusinessLogicTest implements InterfaceOperationTestUtils{
private static final Logger log = LoggerFactory.getLogger(ResourceBusinessLogicTest.class);
public static final String RESOURCE_CATEGORY = "Network Layer 2-3/Router";
@@ -112,6 +122,10 @@ public class ResourceBusinessLogicTest {
public static final String UPDATED_CATEGORY = "Network Layer 2-3/Gateway";
public static final String UPDATED_SUBCATEGORY = "Gateway";
+ private String resourceId = "resourceId1";
+ private String operationId = "uniqueId1";
+ Resource resourceUpdate;
+
public static final String RESOURCE_NAME = "My-Resource_Name with space";
private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
private static final String GENERIC_CR_NAME = "org.openecomp.resource.abstract.nodes.CR";
@@ -133,7 +147,9 @@ public class ResourceBusinessLogicTest {
WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
UserValidations userValidations = Mockito.mock(UserValidations.class);
WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
- AuditingLogFormatUtil auditingLogFormatter = Mockito.mock(AuditingLogFormatUtil.class);
+ IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
+ InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
+
@InjectMocks
ResourceBusinessLogic bl = new ResourceBusinessLogic();
ResponseFormatManager responseManager = null;
@@ -201,7 +217,7 @@ public class ResourceBusinessLogicTest {
/*when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.PNF, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);*/
-
+ when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
@@ -218,6 +234,7 @@ public class ResourceBusinessLogicTest {
when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);
Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
+ when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK);
// BL object
artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
@@ -239,6 +256,9 @@ public class ResourceBusinessLogicTest {
toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
bl.setToscaOperationFacade(toscaOperationFacade);
bl.setUserValidations(userValidations);
+ bl.setInterfaceTypeOperation(interfaceTypeOperation);
+ bl.setInterfaceOperation(interfaceOperation);
+
Resource resourceCsar = createResourceObjectCsar(true);
setCanWorkOnResource(resourceCsar);
Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
@@ -334,7 +354,8 @@ public class ResourceBusinessLogicTest {
when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
-
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
Either<Resource, ResponseFormat> updateResponse = bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId());
@@ -868,6 +889,7 @@ public class ResourceBusinessLogicTest {
@Test
public void testResourceNameWrongFormat_UPDATE() {
Resource resource = createResourceObject(true);
+ resource.setInterfaces(createMockInterfaceDefinition(RESOURCE_NAME));
Resource updatedResource = createResourceObject(true);
// this is in order to prevent failing with 403 earlier
@@ -889,6 +911,7 @@ public class ResourceBusinessLogicTest {
@Test
public void testResourceNameAfterCertify_UPDATE() {
Resource resource = createResourceObject(true);
+ resource.setInterfaces(createMockInterfaceDefinition(RESOURCE_NAME));
Resource updatedResource = createResourceObject(true);
// this is in order to prevent failing with 403 earlier
@@ -932,6 +955,8 @@ public class ResourceBusinessLogicTest {
@Test
public void testResourceNameAlreadyExist_UPDATE() {
Resource resource = createResourceObject(true);
+ resource.setInterfaces(createMockInterfaceDefinition(RESOURCE_NAME));
+
Resource updatedResource = createResourceObject(true);
// this is in order to prevent failing with 403 earlier
@@ -1815,6 +1840,4 @@ public class ResourceBusinessLogicTest {
List<Role> listOfRoles = Stream.of(roles).collect(Collectors.toList());
when(userValidations.validateUserRole(user, listOfRoles)).thenReturn(Either.left(true));
}
-
-
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
index c05dbda974..792521c484 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
@@ -192,22 +192,6 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
return interfaceDefinitionMap;
}
- private Map<String, Operation> createMockOperationMap() {
- Operation operation = new Operation();
- operation.setDefinition(false);
- operation.setName("CREATE");
- Map<String, Operation> operationMap = new HashMap<>();
- operationMap.put("op1", operation);
- return operationMap;
- }
-
-
- private OperationInputDefinition createMockOperationInputDefinition(String label) {
- OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
- operationInputDefinition.setLabel(label);
- return operationInputDefinition;
- }
-
private class InterfaceOperationValidationUtilTest extends InterfaceOperationValidation {
protected ResponseFormatManager getResponseFormatManager() {