aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp
diff options
context:
space:
mode:
authorpriyanshu <pagarwal@amdocs.com>2018-12-27 14:50:30 +0530
committerpriyanshu <pagarwal@amdocs.com>2018-12-27 14:50:30 +0530
commit63a216338c392a587eb88f9fa89010495f79e03c (patch)
tree387e873795b0c860e411564274e4e6c8e2148094 /catalog-be/src/test/java/org/openecomp
parent56ad07f5a6e107f198b239bbf6a10b1792dd5903 (diff)
Revert "Interface operation feature enhancements"
This reverts commit 01f825bc Change-Id: I9e41da46a410be335283a27758cb1e77a087046f Issue-ID: SDC-1999 Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java521
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java11
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java80
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java320
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java104
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java27
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java76
8 files changed, 654 insertions, 493 deletions
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
index 997d32691b..f2d8b57dbf 100644
--- 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
@@ -18,321 +18,432 @@ package org.openecomp.sdc.be.components.impl;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import fj.data.Either;
-import java.util.Arrays;
-import java.util.Collections;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.servlet.ServletContext;
import org.junit.Assert;
import org.junit.Before;
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.utils.ResourceBuilder;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.ElementOperationMock;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
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.cassandra.ArtifactCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
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.model.InputDefinition;
+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.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.IGraphLockOperation;
+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.model.operations.impl.InterfaceLifecycleOperation;
-import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+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.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
+import org.springframework.web.context.WebApplicationContext;
-@RunWith(MockitoJUnitRunner.class)
public class InterfaceOperationBusinessLogicTest {
- @InjectMocks
- private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
- @Mock
- private UserValidations userValidations;
- @Mock
- private ToscaOperationFacade toscaOperationFacade;
- @Mock
- private ComponentsUtils componentsUtils;
- @Mock
- private IGraphLockOperation graphLockOperation;
- @Mock
- private TitanDao titanDao;
- @Mock
- private InterfaceLifecycleOperation interfaceLifecycleOperation;
- @Mock
- private InterfaceOperationValidation interfaceOperationValidation;
- @Mock
- private InterfaceOperation interfaceOperation;
- @Mock
- private ArtifactCassandraDao artifactCassandraDao;
-
- private static final String resourceId = "resourceId";
- private static final String interfaceId = "interfaceId";
- private static final String operationId = "operationId";
- private static final String inputId = "inputId";
+ private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
+ private static final String RESOURCE_SUBCATEGORY = "Router";
+
+ private final String resourceId = "resourceId1";
+ private final String operationId = "uniqueId1";
+ private Operation operation;
+
private static final String RESOURCE_NAME = "Resource1";
- private static final String operationId1 = "operationId1";
- private static final String interfaceId1 = "interfaceId1";
- private User user;
- private Resource resource;
+ private final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ private final TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
+ private final UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
+ private final NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
+ private final NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
+ private final TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
+ private final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
+ private final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
+ private final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ private final UserValidations userValidations = Mockito.mock(UserValidations.class);
+ private final WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ private final ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class);
+ private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
+ private final InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class);
+ private InterfaceLifecycleOperation interfaceLifecycleOperation = Mockito.mock(InterfaceLifecycleOperation.class);
+
+ private final GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
+ private User user = null;
+ private final ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic();
+
+ @InjectMocks
+ private
+ InterfaceOperationBusinessLogic bl = new InterfaceOperationBusinessLogic();
@Before
public void setup() {
- resource = new ResourceBuilder()
- .setComponentType(ComponentTypeEnum.RESOURCE)
- .setUniqueId(resourceId)
- .setName(RESOURCE_NAME)
- .build();
- resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
- resource.setInputs(createInputsForResource());
+ MockitoAnnotations.initMocks(this);
+ Mockito.reset(propertyOperation);
- user = new User();
- when(userValidations.validateUserExists(eq(user.getUserId()), anyString(), eq(true))).thenReturn(user);
- when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
- when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
- when(interfaceOperationValidation.validateInterfaceOperations(anyObject(), anyObject(), any(), anyMap(), anyBoolean())).thenReturn(Either.left(true));
- when(titanDao.commit()).thenReturn(TitanOperationStatus.OK);
- }
+ ExternalConfiguration.setAppName("catalog-be");
- @Test
- public void createInterfaceOperationTestOnExistingInterface() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither = interfaceOperationBusinessLogic
- .createInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true);
- Assert.assertTrue(interfaceOperationEither.isLeft());
- }
+ // init Configuration
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
- @Test
- public void createInterfaceOperationWithoutInterfaceTest() {
- resource.getInterfaces().clear();
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- when(interfaceOperation.addInterfaces(any(), any())).thenReturn(Either.left(Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
- when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither = interfaceOperationBusinessLogic
- .createInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true);
- Assert.assertTrue(interfaceOperationEither.isLeft());
- }
+ // Elements
+ IElementOperation mockElementDao = new ElementOperationMock();
- @Test
- public void createInterfaceOperationWithoutInterfaceTestFail() {
- resource.getInterfaces().clear();
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- when(interfaceOperation.addInterfaces(any(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither = interfaceOperationBusinessLogic
- .createInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true);
- Assert.assertTrue(interfaceOperationEither.isRight());
+ // 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(user);
+ when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(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
+ Resource resourceResponse = createResourceObject(true);
+ Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
+ when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
+ //TODO Remove if passes
+ /*when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);*/
+ Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
+
+ //InterfaceOperation
+ when(operationValidator.validateInterfaceOperations(anyCollection(), anyObject(), anyBoolean())).thenReturn(Either.left(true));
+ 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);
+ toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
+ toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
+ bl.setToscaOperationFacade(toscaOperationFacade);
+ bl.setUserValidations(userValidations);
+ bl.setInterfaceOperation(interfaceOperation);
+ bl.setInterfaceOperationValidation(operationValidator);
+ bl.setInterfaceLifecycleOperation(interfaceLifecycleOperation);
+ Resource resourceCsar = createResourceObjectCsar(true);
+ setCanWorkOnResource(resourceCsar);
+ Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
+ when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
}
@Test
- public void shouldFailWhenCreateInterfaceOperationFailedTest() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true).isRight());
- }
+ public void createInterfaceOperationTest() {
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ operation = InterfaceOperationTestUtils.createMockOperation();
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
- @Test
- public void updateInterfaceOperationTestWithArtifactSuccess() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- when(artifactCassandraDao.getCountOfArtifactById(any(String.class))).thenReturn(Either.left(new Long(1)));
- when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
- when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
- interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true);
+ Either<Operation, ResponseFormat> interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true);
Assert.assertTrue(interfaceOperation.isLeft());
+ Assert.assertNotNull(interfaceOperation.left().value().getWorkflowId());
+ Assert.assertNotNull(interfaceOperation.left().value().getWorkflowVersionId());
}
@Test
- public void updateInterfaceOperationTestWithArtifactFailure() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- when(artifactCassandraDao.getCountOfArtifactById(any(String.class))).thenReturn(Either.left(new Long(1)));
- when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR);
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
- interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true);
- Assert.assertTrue(interfaceOperation.isRight());
- }
+ public void createInterfaceOperationWithoutInterfaceTest() {
+ Resource resource = createResourceObjectCsar(true);
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ resource.setInterfaces(new HashMap<>());
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ operation = InterfaceOperationTestUtils.createMockOperation();
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+ when(interfaceOperation.addInterface(anyString(), any())).thenReturn(Either.left(new InterfaceDefinition()));
- @Test
- public void updateInterfaceOperationTestWithoutArtifact() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- when(artifactCassandraDao.getCountOfArtifactById(any(String.class))).thenReturn(Either.right(CassandraOperationStatus.NOT_FOUND));
- when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
- interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true);
+ Either<Operation, ResponseFormat> interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true);
Assert.assertTrue(interfaceOperation.isLeft());
+
}
@Test
- public void updateInterfaceOperationTestDoesntExist() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
- interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId1)), user, true);
+ public void shouldFailCreateInterfaceOperationWhenCreateOperationFailedTest() {
+ Resource resource = createResourceObjectCsar(true);
+ resource.setInterfaces(new HashMap<>());
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ operation = InterfaceOperationTestUtils.createMockOperation();
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+ when(interfaceOperation.addInterface(anyString(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+
+ Either<Operation, ResponseFormat> interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true);
Assert.assertTrue(interfaceOperation.isRight());
- }
- @Test
- public void createInterfaceOperationTestFailOnException() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- when(interfaceOperation.updateInterfaces(any(), any())).thenThrow(new RuntimeException());
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither = interfaceOperationBusinessLogic
- .createInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true);
- Assert.assertTrue(interfaceOperationEither.isRight());
}
- @Test
- public void createInterfaceOperationTestFailOnFetchinGlobalTypes() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither = interfaceOperationBusinessLogic
- .createInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true);
- Assert.assertTrue(interfaceOperationEither.isRight());
- }
+ @Test()
+ public void shouldFailWhenCreateInterfaceOperationFailedTest() {
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ operation = InterfaceOperationTestUtils.createMockOperation();
- @Test
- public void createInterfaceOperationTestFailOnValidation() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- when(interfaceOperationValidation.validateInterfaceOperations(anyObject(), anyObject(), any(), anyMap(), anyBoolean())).thenReturn(Either.right(new ResponseFormat()));
- Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither = interfaceOperationBusinessLogic
- .createInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true);
- Assert.assertTrue(interfaceOperationEither.isRight());
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ Assert.assertTrue(bl.createInterfaceOperation(resourceId, operation, user, true).isRight());
}
@Test
- public void deleteInterfaceOperationTestInterfaceDoesntExist() {
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId1, Collections.singletonList(operationId), user, true).isRight());
+ public void updateInterfaceOperationTest() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ operation = InterfaceOperationTestUtils.createMockOperation();
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(interfaceOperation.updateInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+
+ Either<Operation, ResponseFormat> interfaceOperation = bl.updateInterfaceOperation(resourceId, operation, user, true);
+ Assert.assertTrue(interfaceOperation.isLeft());
}
- @Test
- public void deleteInterfaceOperationTestOperationDoesntExist() {
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId1), user, true).isRight());
+ @Test()
+ public void shouldFailWhenFailedToUpdateInterfaceOperationTest() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ operation = InterfaceOperationTestUtils.createMockOperation();
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ Either<Operation, ResponseFormat> interfaceOperation = bl.updateInterfaceOperation(resourceId, operation, user, true);
+ Assert.assertTrue(interfaceOperation.isRight());
}
@Test
- public void deleteInterfaceOperationTestSuccess() {
- resource.getInterfaces().get(interfaceId).getOperations().putAll(InterfaceOperationTestUtils.createMockOperationMap(operationId1));
+ public void deleteInterfaceOperationTest() {
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
- when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isLeft());
+ Either<Operation, ResponseFormat> deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, operationId, user, true);
+ Assert.assertTrue(deleteResourceResponseFormatEither.isLeft());
}
- @Test
+ @Test()
public void shouldFailWhenDeleteInterfaceOperationFailedTest() {
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
- when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isRight());
- }
+ Assert.assertTrue(bl.deleteInterfaceOperation(resourceId, operationId, user, true).isRight());
- @Test
- public void deleteInterfaceOperationTestFailOnArtifactDeletion() {
- when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR);
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isRight());
}
-
@Test
- public void deleteInterfaceOperationTestFailOnException() {
- when(artifactCassandraDao.deleteArtifact(any(String.class))).thenThrow(new RuntimeException());
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isRight());
+ public void getInterfaceOperationTest() {
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ Either<Operation, ResponseFormat> getResourceResponseFormatEither = bl.getInterfaceOperation(resourceId, operationId, user, true);
+ Assert.assertTrue(getResourceResponseFormatEither.isLeft());
}
@Test
- public void deleteInterfaceTestSuccess() {
- when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
- when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
- when(interfaceOperation.deleteInterface(any(), any())).thenReturn(Either.left(interfaceId));
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isLeft());
+ public void updateToscaResourceNameWhenComponentNameChanged() {
+ Component newComponent = new Resource();
+ newComponent.setName("newComponent");
+ Component oldComponent = createResourceForInterfaceOperation();
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(interfaceOperation.updateInterface(anyString(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
+ Assert.assertTrue(bl.validateComponentNameAndUpdateInterfaces(oldComponent, newComponent).isLeft());
}
@Test
- public void deleteInterfaceTestFailure() {
- when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
- when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
- when(interfaceOperation.deleteInterface(any(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isRight());
+ public void shouldFailWhenComponentNameChangedButUpdateOperationFailed() {
+ Component newComponent = new Resource();
+ newComponent.setName("newComponent");
+ Component oldComponent = createResourceForInterfaceOperation();
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
+ Assert.assertTrue(bl.validateComponentNameAndUpdateInterfaces(oldComponent, newComponent).isRight());
}
- @Test
- public void getInterfaceOperationTestInterfaceDoesntExist() {
- Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId1, Collections.singletonList(operationId), user, true).isRight());
+ @Test(expected = Exception.class)
+ public void shouldThrowExceptionWhenComponentNameChangedButUpdateOperationFailed() {
+ Component newComponent = new Resource();
+ newComponent.setName("newComponent");
+ Component oldComponent = createResourceForInterfaceOperation();
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(interfaceOperation.updateInterface(anyString(), anyObject())).thenThrow(new Exception());
+ bl.validateComponentNameAndUpdateInterfaces(oldComponent, newComponent).isRight();
}
- @Test
- public void getInterfaceOperationTestOperationDoesntExist() {
- Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId1), user, true).isRight());
+ private void validateUserRoles(Role... roles) {
+ List<Role> listOfRoles = Stream.of(roles).collect(Collectors.toList());
}
- @Test
- public void getInterfaceOperationTest() {
- Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isLeft());
+ private void setCanWorkOnResource(Resource resource) {
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setLastUpdaterUserId(user.getUserId());
}
- @Test
- public void getInterfaceOperationTestFailOnException() {
- when(titanDao.commit()).thenThrow(new RuntimeException());
- Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isRight());
+ 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(InterfaceOperationTestUtils.createMockInterfaceDefinition(RESOURCE_NAME));
+ return resource;
}
- @Test
- public void shouldFailWhenLockComponentFailedTest() {
- when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.NOT_FOUND);
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isRight());
- Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isRight());
- Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true).isRight());
+ 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<>();
+ tgs.add("test");
+ tgs.add(resource.getName());
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<>();
+ 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;
}
- @Test
- public void shouldFailWhenGetComponentFailedTest() {
- when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isRight());
- Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId, Collections.singletonList(operationId), user, true).isRight());
- Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId, Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)), user, true).isRight());
+ 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<>();
+ tgs.add("test");
+ tgs.add(resource.getName());
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<>();
+ 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;
}
@Test
public void testGetAllInterfaceLifecycleTypes_TypesNotFound() {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- Either<Map<String, InterfaceDefinition>, ResponseFormat> response = interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> response = bl.getAllInterfaceLifecycleTypes();
Assert.assertTrue(response.isRight());
}
@Test
public void testGetAllInterfaceLifecycleTypes_Success() {
+ final String UNIQUE_ID = "UNIQUE_ID";
+ final String TYPE = "UNIQUE_ID";
InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
- interfaceDefinition.setUniqueId(interfaceId);
- interfaceDefinition.setType(interfaceId);
+ interfaceDefinition.setUniqueId(UNIQUE_ID);
+ interfaceDefinition.setType(TYPE);
Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
interfaceDefinitionMap.put(interfaceDefinition.getUniqueId(), interfaceDefinition);
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceDefinitionMap));
- Either<Map<String, InterfaceDefinition>, ResponseFormat> response = interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> response = bl.getAllInterfaceLifecycleTypes();
Assert.assertEquals(response.left().value().size(),1);
}
-
- private List<InputDefinition> createInputsForResource(){
- InputDefinition inputDefinition = new InputDefinition();
- inputDefinition.setName(inputId);
- inputDefinition.setInputId(inputId);
- inputDefinition.setUniqueId(inputId);
- inputDefinition.setValue(inputId);
- inputDefinition.setDefaultValue(inputId);
- return Arrays.asList(inputDefinition);
- }
} \ 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 8e35981722..b6a7c98efa 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
@@ -32,6 +32,7 @@ import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
import org.openecomp.sdc.be.model.operations.StorageException;
+import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
@@ -59,6 +60,7 @@ 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;
@@ -154,6 +156,8 @@ public class ResourceBusinessLogicTest {
UserValidations userValidations = Mockito.mock(UserValidations.class);
WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
+ InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
+ InterfaceOperationBusinessLogic interfaceOperationBl = Mockito.mock(InterfaceOperationBusinessLogic.class);
@InjectMocks
ResourceBusinessLogic bl = new ResourceBusinessLogic();
@@ -224,6 +228,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(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
@@ -240,6 +245,7 @@ public class ResourceBusinessLogicTest {
Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK);
+ when(interfaceOperationBl.validateComponentNameAndUpdateInterfaces(any(Component.class), any(Component.class))).thenReturn(Either.left(true));
// BL object
artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
@@ -261,6 +267,8 @@ public class ResourceBusinessLogicTest {
bl.setToscaOperationFacade(toscaOperationFacade);
bl.setUserValidations(userValidations);
bl.setInterfaceTypeOperation(interfaceTypeOperation);
+ bl.setInterfaceOperation(interfaceOperation);
+ bl.setInterfaceOperationBusinessLogic(interfaceOperationBl);
csarBusinessLogic.setCsarOperation(csarOperation);
Resource resourceCsar = createResourceObjectCsar(true);
@@ -942,6 +950,7 @@ public class ResourceBusinessLogicTest {
@Test
public void testResourceNameWrongFormat_UPDATE() {
Resource resource = createResourceObject(true);
+ resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinition(RESOURCE_NAME));
Resource updatedResource = createResourceObject(true);
// this is in order to prevent failing with 403 earlier
@@ -963,6 +972,7 @@ public class ResourceBusinessLogicTest {
@Test
public void testResourceNameAfterCertify_UPDATE() {
Resource resource = createResourceObject(true);
+ resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinition(RESOURCE_NAME));
Resource updatedResource = createResourceObject(true);
// this is in order to prevent failing with 403 earlier
@@ -986,6 +996,7 @@ public class ResourceBusinessLogicTest {
@Test
public void testResourceNameAlreadyExist_UPDATE() {
Resource resource = createResourceObject(true);
+ resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinition(RESOURCE_NAME));
Resource updatedResource = createResourceObject(true);
// this is in order to prevent failing with 403 earlier
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java
deleted file mode 100644
index 8884f9f2d6..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.openecomp.sdc.be.components.utils;
-
-import java.util.Map;
-import java.util.Optional;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
-import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
-
-public class InterfaceOperationUtilsTest {
-
- private static final String TEST_RESOURCE_NAME = "TestResource";
- private static final String operationId = "operationId";
- private static final String interfaceId = "interfaceId";
- private static Resource resource;
-
- @Before
- public void setup() {
- resource = new ResourceBuilder()
- .setComponentType(ComponentTypeEnum.RESOURCE)
- .setName(TEST_RESOURCE_NAME)
- .build();
- resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
- }
-
- @Test
- public void testGetInterfaceDefinitionFromComponentByInterfaceTypeSuccess(){
- Assert.assertTrue(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId).isPresent());
- }
-
- @Test
- public void testGetInterfaceDefinitionFromComponentByInterfaceTypeFailure(){
- Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, TEST_RESOURCE_NAME).isPresent());
- }
-
- @Test
- public void testGetInterfaceDefinitionFromComponentByInterfaceTypeNoInterface(){
- resource.getInterfaces().clear();
- Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId).isPresent());
- }
-
- @Test
- public void testGetInterfaceDefinitionFromComponentByInterfaceIdSuccess(){
- Assert.assertTrue(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId).isPresent());
- }
-
- @Test
- public void testGetInterfaceDefinitionFromComponentByInterfaceIdFailure(){
- Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, TEST_RESOURCE_NAME).isPresent());
- }
-
- @Test
- public void testGetInterfaceDefinitionFromComponentByInterfaceIdNoInterface(){
- resource.getInterfaces().clear();
- Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId).isPresent());
- }
-
- @Test
- public void testGetOperationFromInterfaceDefinitionSuccess(){
- Assert.assertTrue(InterfaceOperationUtils.getOperationFromInterfaceDefinition(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), operationId).isPresent());
- }
-
- @Test
- public void testGetOperationFromInterfaceDefinitionFailure(){
- Assert.assertFalse(InterfaceOperationUtils.getOperationFromInterfaceDefinition(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), TEST_RESOURCE_NAME).isPresent());
- }
-
- @Test
- public void testGetOperationFromInterfaceDefinitionNoOperationMap(){
- InterfaceDefinition interfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId);
- interfaceDefinition.getOperations().clear();
- Optional<Map.Entry<String, Operation>> operationEntry = InterfaceOperationUtils.getOperationFromInterfaceDefinition(interfaceDefinition, TEST_RESOURCE_NAME);
- Assert.assertFalse(operationEntry.isPresent());
- }
-
-} \ No newline at end of file
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 43d2fe884f..1a112c583b 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
@@ -19,246 +19,264 @@ package org.openecomp.sdc.be.components.validation;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
-import java.util.Arrays;
-import java.util.Collections;
+import com.google.common.collect.Sets;
+import fj.data.Either;
+
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
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.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
-import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.exception.ResponseFormat;
import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
public class InterfaceOperationValidationTest {
+ private final Component component = setUpComponentMock();
+ private ResponseFormatManager responseFormatManagerMock;
+
private final InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest();
private final ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
private final ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
- private static final String resourceId = "resourceId";
- private static final String interfaceId = "interfaceId";
- private static final String operationId = "operationId";
- private static final String interfaceType = "interfaceType";
- private static final String operationType = "operationType";
- private static final String operationId2 = "operationId2";
- private static final String inputId = "inputId";
- private static final String outputId = "outputId";
-
- private Component component;
- private ResponseFormatManager responseFormatManagerMock;
@Before
- public void setup() {
+ public void init() {
MockitoAnnotations.initMocks(this);
responseFormatManagerMock = Mockito.mock(ResponseFormatManager.class);
when(responseFormatManagerMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
when(responseFormatManagerMock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
when(responseFormatManagerMock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
-
- component = new ResourceBuilder()
- .setComponentType(ComponentTypeEnum.RESOURCE)
- .setUniqueId(resourceId)
- .setName(resourceId)
- .build();
- component.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
- component.setInputs(createInputsForComponent());
}
@Test
public void shouldPassOperationValidationForHappyScenario() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"upgrade");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(), false).isLeft());
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"upgrade");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
@Test
- public void shouldFailWhenOperationNameIsEmpty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList, "");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isRight());
+ public void shouldFailWhenOperationOperationDescriptionLengthInvalid() {
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2 - The Spring Initializer provides a project generator to make you " +
+ "productive with the certain technology stack from the beginning. You can create a skeleton project" +
+ "with web, data access (relational and NoSQL data stores), cloud, or messaging support",
+ new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
}
+
+
@Test
- public void shouldFailWhenOperationNamesAreNotUniqueForCreate() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList, operationId);
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isRight());
+ public void shouldFailWhenOperationNameIsEmpty() {
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList, "");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@Test
- public void shouldNotFailWhenOperationNamesAreNotUniqueForUpdate() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList, operationId);
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),true).isLeft());
+ public void shouldFailWhenOperationNamesAreNotUnique() {
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"CREATE");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@Test
public void shouldFailWhenOperationNameLengthIsInvalid() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2,new ArtifactDefinition(), operationInputDefinitionList,
- operationOutputDefinitionList,"interface operation2 - The Spring Initializer provides a project generator to make you " +
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,
+ "interface operation2 - The Spring Initializer provides a project generator to make you " +
"productive with the certain technology stack from the beginning. You can create a skeleton project" +
"with web, data access (relational and NoSQL data stores), cloud, or messaging support");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isRight());
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
}
+
@Test
public void shouldFailWhenOperationInputParamNamesAreNotUnique() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(outputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"create");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isRight());
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2"));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"create");
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@Test
public void shouldPassWhenOperationInputParamNamesAreUnique() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(outputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isLeft());
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
@Test
public void shouldPassWhenOperationInputParamNamesHasSubProperty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
- operationInputDefinitionList.getListToscaDataDefinition().get(0).setInputId(operationInputDefinitionList.getListToscaDataDefinition().get(0).getInputId().concat(".subproperty"));
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isLeft());
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
+ operationInputDefinitionList.getListToscaDataDefinition().get(0).setInputId(operationInputDefinitionList
+ .getListToscaDataDefinition().get(0).getInputId().concat(".subproperty"));
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
@Test
public void shouldFailWhenOperationInputParamNameEmpty() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(" "));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isRight());
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@Test
public void shouldFailWhenOperationOutputParamNameEmpty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("inputParam"));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(" "));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isRight());
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@Test
public void shouldPassWhenInterfaceOperationOutputParamNamesUnique() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isLeft());
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label2"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
@Test
public void shouldFailWhenOperationOutputParamNamesAreNotUnique() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isRight());
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("inputParam1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("outParam1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("outParam2"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("outParam2"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
}
- @Test
- public void shouldPassWhenOperationInputParamExistInComponentProperty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isLeft());
+ private Set<Operation> createInterfaceOperationData( String uniqueID, String description, ArtifactDefinition artifactDefinition,
+ ListDataDefinition<OperationInputDefinition> inputs,
+ ListDataDefinition<OperationOutputDefinition> outputs, String name) {
+ return Sets.newHashSet(InterfaceOperationTestUtils.createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, outputs, name));
}
- @Test
- public void shouldFailWhenOperationInputParamDoesntExistInComponentProperty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(operationId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId2, operationId2,new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(interfaceDefinition, component, component.getInterfaces().get(interfaceId), Collections.emptyMap(),false).isRight());
- }
-
- @Test
- public void shouldFailValidateAllowedOperationCountOnLocalInterfaceType() {
- InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceId, operationType);
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition, component, component.getInterfaces().get(interfaceId), InterfaceOperationTestUtils.createMockInterfaceTypeMap(interfaceType, operationType),false).isRight());
- }
-
- @Test
- public void shouldFailValidateAllowedOperationsOnGlobalInterfaceType() {
- InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType, operationId);
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition, component, component.getInterfaces().get(interfaceId), InterfaceOperationTestUtils.createMockInterfaceTypeMap(interfaceType, operationType),false).isRight());
- }
+ private Component setUpComponentMock(){
+ Component component = new Resource();
- @Test
- public void shouldPassValidateAllowedOperationsOnGlobalInterfaceType() {
- InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType, operationType);
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition, component, component.getInterfaces().get(interfaceId), InterfaceOperationTestUtils.createMockInterfaceTypeMap(interfaceType, operationType),false).isLeft());
- }
+ List<InputDefinition> inputs = new ArrayList<>();
+ InputDefinition inputDefinition = new InputDefinition();
+ InputDefinition inputDefinition1 = new InputDefinition();
- @Test
- public void shouldFailValidateOperationNameUniquenessInCollection() {
- InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType, operationType);
- inputInterfaceDefinition.getOperations().put(operationId, InterfaceOperationTestUtils.createMockOperation(operationType));
- Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition, component, component.getInterfaces().get(interfaceId), InterfaceOperationTestUtils.createMockInterfaceTypeMap(interfaceType, operationType),false).isRight());
+ List<ComponentInstanceInput> componentInstanceInputs = new ArrayList<>();
+ ComponentInstanceInput componentInstanceInput1 = new ComponentInstanceInput();
+ componentInstanceInput1.setComponentInstanceName("componentInstance1");
+ componentInstanceInput1.setUniqueId("inputId1");
+ ComponentInstanceInput componentInstanceInput2 = new ComponentInstanceInput();
+ componentInstanceInput2.setComponentInstanceName("componentInstance2");
+ componentInstanceInput2.setUniqueId("inputId2");
+
+ componentInstanceInputs.add(componentInstanceInput1);
+ componentInstanceInputs.add(componentInstanceInput2);
+
+ inputDefinition.setUniqueId("inputId1");
+ inputDefinition.setInputs(componentInstanceInputs);
+ inputDefinition1.setUniqueId("uniqueId3");
+
+ inputs.add(inputDefinition);
+ inputs.add(inputDefinition1);
+ component.setInputs(inputs);
+ component.setInterfaces(createMockInterfaceDefinition());
+ return component;
}
- private InterfaceDefinition createInterfaceOperationData(String uniqueID, String description, ArtifactDefinition artifactDefinition,
- ListDataDefinition<OperationInputDefinition> inputs,
- ListDataDefinition<OperationOutputDefinition> outputs, String name) {
- Operation operation = new Operation();
- operation.setUniqueId(uniqueID);
- operation.setDescription(description);
- operation.setImplementation(artifactDefinition);
- operation.setInputs(inputs);
- operation.setOutputs(outputs);
- operation.setName(name);
- Map<String, Operation> operationMap = new HashMap<>();
- operationMap.put(operation.getUniqueId(), operation);
- InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
- interfaceDefinition.setOperationsMap(operationMap);
- return interfaceDefinition;
- }
+ private Map<String, InterfaceDefinition> createMockInterfaceDefinition() {
+ Map<String, Operation> operationMap = InterfaceOperationTestUtils.createMockOperationMap();
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
+ interfaceDefinitionMap.put("int1", InterfaceOperationTestUtils.createInterface("int1", "Interface 1",
+ "lifecycle", "tosca", operationMap));
- private List<InputDefinition> createInputsForComponent(){
- InputDefinition inputDefinition1 = new InputDefinition();
- inputDefinition1.setName(inputId);
- inputDefinition1.setInputId(inputId);
- inputDefinition1.setUniqueId(inputId);
- inputDefinition1.setValue(inputId);
- inputDefinition1.setDefaultValue(inputId);
-
- InputDefinition inputDefinition2 = new InputDefinition();
- inputDefinition2.setName(outputId);
- inputDefinition2.setInputId(outputId);
- inputDefinition2.setUniqueId(outputId);
- inputDefinition2.setValue(outputId);
- inputDefinition2.setDefaultValue(outputId);
-
- return Arrays.asList(inputDefinition1, inputDefinition2);
+ return interfaceDefinitionMap;
}
private class InterfaceOperationValidationUtilTest extends InterfaceOperationValidation {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java
new file mode 100644
index 0000000000..0c02e71bd2
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java
@@ -0,0 +1,104 @@
+package org.openecomp.sdc.be.datamodel.utils;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationParamDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
+import org.openecomp.sdc.be.model.Operation;
+
+import static org.openecomp.sdc.test.utils.InterfaceOperationTestUtils.createMockOperationInputDefinition;
+import static org.openecomp.sdc.test.utils.InterfaceOperationTestUtils.createMockOperationOutputDefinition;
+
+public class InterfaceUIDataConverterTest {
+
+ @Test
+ public void testConvertInterfaceDataToOperationData() {
+ InterfaceOperationDataDefinition interfaceOperation = createIODD("test",
+ "test description",
+ createParamDataList("inpName", "property", true, "String"),
+ createParamDataList("OutName", null, true, "String"),
+ "workflowId",
+ "workflowVersionId");
+ Operation result;
+ result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertInterfaceDataToOperationDataWithoutMandatory() {
+ ListDataDefinition<InterfaceOperationParamDataDefinition> iopd = new ListDataDefinition<>();
+ iopd.add(createParamData("test", "property", "String"));
+ InterfaceOperationDataDefinition interfaceOperation = createIODD("test",
+ "test description", iopd, iopd,
+ "workflowId",
+ "workflowVersionId");
+ Operation result;
+ result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertInterfaceDataToOperationDataWithoutOptionalFields() {
+ InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition();
+ interfaceOperation.setOperationType("operationType");
+ Operation result;
+ result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertOperationDataToInterfaceData() {
+ Operation operationData = new Operation();
+ InterfaceOperationDataDefinition result;
+ ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
+ inputs.add(createMockOperationInputDefinition("Inp1"));
+ ListDataDefinition<OperationOutputDefinition> outputs = new ListDataDefinition<>();
+ outputs.add(createMockOperationOutputDefinition("out1"));
+ operationData.setInputs(inputs);
+ operationData.setOutputs(outputs);
+ operationData.setImplementation(new ArtifactDataDefinition());
+ result = InterfaceUIDataConverter.convertOperationDataToInterfaceData(operationData);
+ Assert.assertNotNull(result);
+ }
+
+ private InterfaceOperationDataDefinition createIODD(String operationType, String description,
+ ListDataDefinition<InterfaceOperationParamDataDefinition> inputParams,
+ ListDataDefinition<InterfaceOperationParamDataDefinition> outputParams,
+ String workflowId,
+ String workflowVersionId) {
+ InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition();
+ interfaceOperation.setOperationType(operationType);
+ interfaceOperation.setDescription(description);
+ interfaceOperation.setInputParams(inputParams);
+ interfaceOperation.setOutputParams(outputParams);
+ interfaceOperation.setWorkflowId(workflowId);
+ interfaceOperation.setWorkflowVersionId(workflowVersionId);
+ return interfaceOperation;
+ }
+
+ private InterfaceOperationParamDataDefinition createParamData(String name, String property, boolean mandatory, String type) {
+ InterfaceOperationParamDataDefinition definition = createParamData(name, property, type);
+ definition.setMandatory(mandatory);
+ return definition;
+ }
+
+ private InterfaceOperationParamDataDefinition createParamData(String name, String property, String type) {
+ InterfaceOperationParamDataDefinition definition = new InterfaceOperationParamDataDefinition();
+ definition.setName(name);
+ definition.setProperty(property);
+ definition.setType(type);
+ return definition;
+ }
+
+ private ListDataDefinition<InterfaceOperationParamDataDefinition> createParamDataList(String name,
+ String property, boolean mandatory, String type) {
+ ListDataDefinition<InterfaceOperationParamDataDefinition> list = new ListDataDefinition<>();
+ list.add(createParamData(name, property, mandatory, type));
+ return list;
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
index 592d27ec5d..2fabe43733 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
@@ -1,7 +1,6 @@
package org.openecomp.sdc.be.tosca;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -47,7 +46,6 @@ import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
import org.openecomp.sdc.be.tosca.model.ToscaCapability;
import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
@@ -84,9 +82,6 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
@Mock
GroupExportParserImpl groupExportParserImpl;
- @Mock
- InterfaceLifecycleOperation interfaceLifecycleOperation;
-
@Before
public void setUpMock() throws Exception {
MockitoAnnotations.initMocks(this);
@@ -165,7 +160,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
((Resource) component).setInterfaces(new HashMap<>());
Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
+
// default test when convertInterfaceNodeType is right
result = testSubject.exportComponentInterface(component, false);
@@ -397,7 +392,6 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
component.setInputs(inputs);
Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
Mockito.when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class), Mockito.any(Resource.class),
Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
index 983ef91a8c..8f34e0e29b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
@@ -19,7 +19,6 @@ package org.openecomp.sdc.be.tosca.utils;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@@ -64,15 +63,15 @@ public class InterfacesOperationsToscaUtilTest {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
- addedInterface.setType("interface.types.test_resource_name");
+ addedInterface.setToscaResourceName("interface.types.test_resource_name");
addOperationsToInterface(addedInterface, 5, 3, true);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
final Map<String, Object> interfaceTypeElement =
- InterfacesOperationsToscaUtil.addInterfaceTypeElement(component, new ArrayList<>());
+ InterfacesOperationsToscaUtil.addInterfaceTypeElement(component);
- ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
+ ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
ToscaTemplate template = new ToscaTemplate("test");
template.setInterface_types(interfaceTypeElement);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
@@ -86,15 +85,15 @@ public class InterfacesOperationsToscaUtilTest {
Component component = new Service();
component.setNormalizedName("normalizedServiceComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
- addedInterface.setType("interface.types.test_service_name");
+ addedInterface.setToscaResourceName("interface.types.test_service_name");
addOperationsToInterface(addedInterface, 5, 3, true);
final String interfaceType = "normalizedServiceComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
final Map<String, Object> interfaceTypeElement =
- InterfacesOperationsToscaUtil.addInterfaceTypeElement(component, new ArrayList<>());
+ InterfacesOperationsToscaUtil.addInterfaceTypeElement(component);
- ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
+ ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
ToscaTemplate template = new ToscaTemplate("testService");
template.setInterface_types(interfaceTypeElement);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
@@ -108,7 +107,7 @@ public class InterfacesOperationsToscaUtilTest {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
- addedInterface.setType("com.some.resource.or.other.resourceName");
+ addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
addOperationsToInterface(addedInterface, 3, 2, true);
final String interfaceType = "normalizedComponentName-interface";
@@ -117,7 +116,7 @@ public class InterfacesOperationsToscaUtilTest {
ToscaNodeType nodeType = new ToscaNodeType();
InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false);
- ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
+ ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME);
Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
nodeTypes.put(NODE_TYPE_NAME, nodeType);
@@ -140,7 +139,8 @@ public class InterfacesOperationsToscaUtilTest {
Component component = new Service();
component.setNormalizedName("normalizedServiceComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
- addedInterface.setType("com.some.service.or.other.serviceName");
+ addedInterface.setToscaResourceName("com.some.service.or.other.serviceName");
+
addOperationsToInterface(addedInterface, 3, 2, true);
final String interfaceType = "normalizedServiceComponentName-interface";
component.setInterfaces(new HashMap<>());
@@ -148,7 +148,7 @@ public class InterfacesOperationsToscaUtilTest {
ToscaNodeType nodeType = new ToscaNodeType();
InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false);
- ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
+ ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
ToscaTemplate template = new ToscaTemplate("testService");
Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
nodeTypes.put(NODE_TYPE_NAME, nodeType);
@@ -170,7 +170,8 @@ public class InterfacesOperationsToscaUtilTest {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
- addedInterface.setType("com.some.resource.or.other.resourceNameNoInputs");
+ addedInterface.setToscaResourceName("com.some.resource.or.other.resourceNameNoInputs");
+
addOperationsToInterface(addedInterface, 3, 3, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
@@ -178,7 +179,7 @@ public class InterfacesOperationsToscaUtilTest {
ToscaNodeType nodeType = new ToscaNodeType();
InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false);
- ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
+ ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
ToscaTemplate template = new ToscaTemplate("test");
Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
nodeTypes.put("test", nodeType);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java
index 4bda41671d..10acd69a79 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java
@@ -27,7 +27,7 @@ import org.openecomp.sdc.be.model.Operation;
public class InterfaceOperationTestUtils {
- private static InterfaceDefinition createInterface(String uniqueID, String description, String type,
+ public static InterfaceDefinition createInterface(String uniqueID, String description, String type,
String toscaResourceName, Map<String, Operation> op) {
InterfaceDefinition id = new InterfaceDefinition();
id.setType(type);
@@ -38,35 +38,48 @@ public class InterfaceOperationTestUtils {
return id;
}
- public static Map<String, InterfaceDefinition> createMockInterfaceDefinitionMap(String interfaceId, String operationId) {
- Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
- interfaceDefinitionMap.put(interfaceId, createMockInterface(interfaceId, operationId));
- return interfaceDefinitionMap;
+ public static Operation createInterfaceOperation(String uniqueID, String description, ArtifactDefinition artifactDefinition,
+ ListDataDefinition<OperationInputDefinition> inputs,
+ ListDataDefinition<OperationOutputDefinition> outputs, String name) {
+ Operation operation = new Operation();
+ operation.setUniqueId(uniqueID);
+ operation.setDescription(description);
+ operation.setImplementation(artifactDefinition);
+ operation.setInputs(inputs);
+ operation.setOutputs(outputs);
+ operation.setName(name);
+ return operation;
+ }
+
+ public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceName) {
+ Map<String, Operation> operationMap = createMockOperationMap();
+ return createInterface("int1", "Interface 1",
+ "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceName, operationMap);
}
- public static InterfaceDefinition createMockInterface(String interfaceId, String operationId) {
- return createInterface(interfaceId, interfaceId, interfaceId, interfaceId, createMockOperationMap(operationId));
+ public static Operation mockOperationToReturn() {
+ return createMockOperation();
}
- public static Map<String, Operation> createMockOperationMap(String operationId) {
+ public static Map<String, Operation> createMockOperationMap() {
Map<String, Operation> operationMap = new HashMap<>();
- operationMap.put(operationId, createMockOperation(operationId));
+ operationMap.put("op1", createMockOperation());
return operationMap;
}
- public static Operation createMockOperation(String operationId) {
+ public static Operation createMockOperation() {
Operation operation = new Operation();
ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
- operationInputDefinitionList.add(createMockOperationInputDefinition("inputId"));
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
operation.setInputs(operationInputDefinitionList);
ListDataDefinition<OperationOutputDefinition> operationOutputDefList = new ListDataDefinition<>();
- operationOutputDefList.add(createMockOperationOutputDefinition("outputId"));
+ operationOutputDefList.add(createMockOperationOutputDefinition("op1"));
operation.setOutputs(operationOutputDefList);
operation.setDefinition(false);
- operation.setName(operationId);
- operation.setUniqueId(operationId);
+ operation.setName("CREATE");
+ operation.setUniqueId("uniqueId1");
ArtifactDefinition implementation = new ArtifactDefinition();
implementation.setUniqueId("uniqId");
implementation.setArtifactUUID("artifactId");
@@ -76,39 +89,28 @@ public class InterfaceOperationTestUtils {
return operation;
}
- public static OperationInputDefinition createMockOperationInputDefinition(String inputId) {
+ public static OperationInputDefinition createMockOperationInputDefinition(String name) {
OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
- operationInputDefinition.setName(inputId);
- operationInputDefinition.setUniqueId(inputId);
- operationInputDefinition.setInputId(inputId);
- operationInputDefinition.setValue(inputId);
- operationInputDefinition.setDefaultValue(inputId);
+ operationInputDefinition.setName(name);
+ operationInputDefinition.setUniqueId("uniqueId1");
+ operationInputDefinition.setInputId("inputId1");
return operationInputDefinition;
}
- public static OperationOutputDefinition createMockOperationOutputDefinition(String outputId) {
+ public static OperationOutputDefinition createMockOperationOutputDefinition(String name) {
OperationOutputDefinition operationOutputDefinition = new OperationOutputDefinition();
- operationOutputDefinition.setName(outputId);
- operationOutputDefinition.setUniqueId(outputId);
- operationOutputDefinition.setInputId(outputId);
- operationOutputDefinition.setValue(outputId);
- operationOutputDefinition.setDefaultValue(outputId);
+ operationOutputDefinition.setName(name);
+ operationOutputDefinition.setUniqueId("uniqueId1");
+ operationOutputDefinition.setInputId("inputId1");
return operationOutputDefinition;
}
- public static Map<String, InterfaceDefinition> createMockInterfaceTypeMap(String interfaceType, String operationType) {
- Map<String, Operation> operationMap = createMockOperationTypeMap(operationType);
+ public static Map<String, InterfaceDefinition> createMockInterfaceDefinition(String resourceName) {
+ Map<String, Operation> operationMap = createMockOperationMap();
Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
- interfaceDefinitionMap.put(interfaceType, createInterface(interfaceType, interfaceType, interfaceType, interfaceType, operationMap));
+ interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1",
+ "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceName, operationMap));
return interfaceDefinitionMap;
}
- private static Map<String, Operation> createMockOperationTypeMap(String operationType) {
- Operation operation = new Operation();
- operation.setUniqueId(operationType);
- Map<String, Operation> operationMap = new HashMap<>();
- operationMap.put(operationType, operation);
- return operationMap;
- }
-
}