From b6e7850484ba61df259e38fd6b59e94c2a7de5b6 Mon Sep 17 00:00:00 2001 From: shrikantawachar Date: Mon, 17 Dec 2018 12:26:43 +0530 Subject: API for get all interface lifecycle types API for get all interface lifecycle types Change-Id: I64471c98ff9626ac53562a075a34f506c2e263ab Issue-ID: SDC-1999 Signed-off-by: shrikantawachar --- .../sdc/be/components/impl/BaseBusinessLogic.java | 8 + .../impl/InterfaceOperationBusinessLogic.java | 13 + .../sdc/be/servlets/TypesFetchServlet.java | 51 ++++ .../main/resources/config/error-configuration.yaml | 7 +- .../impl/InterfaceOperationBusinessLogicTest.java | 23 +- .../org/openecomp/sdc/be/dao/api/ActionStatus.java | 5 +- .../api/IInterfaceLifecycleOperation.java | 2 + .../impl/InterfaceLifecycleOperation.java | 38 ++- .../impl/InterfaceLifecycleOperationTest.java | 302 +++++++++++++++++++++ .../operations/impl/InterfaceOperationTest.java | 254 ----------------- openecomp-bdd/config.json | 6 + .../TestInterfaceLifecycleTypes.feature | 8 + openecomp-bdd/stepDefinitions/GlobalTypes.js | 24 ++ 13 files changed, 483 insertions(+), 258 deletions(-) create mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java delete mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceOperationTest.java create mode 100644 openecomp-bdd/features/GlobalTypes/TestInterfaceLifecycleTypes.feature create mode 100644 openecomp-bdd/stepDefinitions/GlobalTypes.js diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index 453564e2f8..02e64334f9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -45,6 +45,7 @@ import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.*; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; +import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils; @@ -129,6 +130,9 @@ public abstract class BaseBusinessLogic { @Autowired protected InterfaceOperationBusinessLogic interfaceOperationBusinessLogic; + @Autowired + protected InterfaceLifecycleOperation interfaceLifecycleOperation; + @javax.annotation.Resource private UserValidations userValidations; @@ -171,6 +175,10 @@ public abstract class BaseBusinessLogic { } + public void setInterfaceLifecycleOperation(InterfaceLifecycleOperation interfaceLifecycleOperation) { + this.interfaceLifecycleOperation = interfaceLifecycleOperation; + } + User validateUserNotEmpty(User user, String ecompErrorContext) { return userValidations.validateUserNotEmpty(user, ecompErrorContext); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index fed2cac518..a0efddbdda 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -41,6 +41,7 @@ import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; @Component("interfaceOperationBusinessLogic") public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { @@ -324,4 +325,16 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } return Either.left( interfaceDefinition); } + + public Either, ResponseFormat> getAllInterfaceLifecycleTypes() { + + Either, StorageOperationStatus> interfaceLifecycleTypes = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(); + if(interfaceLifecycleTypes.isRight()) { + return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND)); + } + interfaceLifecycleTypes.left().value().values().stream().forEach( + id -> id.setOperations(id.getOperations().keySet().stream().collect(Collectors.toMap(key -> key.replaceFirst(id.getUniqueId()+".",""), i -> id.getOperations().get(i))))); + + return Either.left(interfaceLifecycleTypes.left().value()); + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java index 8bb93a7d3d..ddb405779d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java @@ -26,11 +26,13 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic; import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; @@ -109,4 +111,53 @@ public class TypesFetchServlet extends AbstractValidationsServlet { return webApplicationContext.getBean(PropertyBusinessLogic.class); } + @GET + @Path("interfaceLifecycleTypes") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Get interface lifecycle types", httpMethod = "GET", notes = "Returns interface lifecycle types", response = Response.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Interface lifecycle types"), + @ApiResponse(code = 403, message = "Restricted operation"), + @ApiResponse(code = 400, message = "Invalid content / Missing content"), + @ApiResponse(code = 404, message = "Interface lifecycle types not found") + }) + public Response getInterfaceLifecycleTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + + Wrapper responseWrapper = new Wrapper<>(); + Wrapper userWrapper = new Wrapper<>(); + ServletContext context = request.getSession().getServletContext(); + + try { + validateUserExist(responseWrapper, userWrapper, userId); + + if (responseWrapper.isEmpty()) { + String url = request.getMethod() + " " + request.getRequestURI(); + log.info("Start handle request of {} | modifier id is {}", url, userId); + + InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); + Either, ResponseFormat> allInterfaceLifecycleTypes = + businessLogic.getAllInterfaceLifecycleTypes(); + + if (allInterfaceLifecycleTypes.isRight()) { + log.info("Failed to get all interface lifecycle types. Reason - {}", + allInterfaceLifecycleTypes.right().value()); + Response errorResponse = buildErrorResponse(allInterfaceLifecycleTypes.right().value()); + responseWrapper.setInnerElement(errorResponse); + + } else { + String interfaceLifecycleTypeJson = gson.toJson(allInterfaceLifecycleTypes.left().value()); + Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), interfaceLifecycleTypeJson); + responseWrapper.setInnerElement(okResponse); + + } + } + + return responseWrapper.getInnerElement(); + } catch (Exception e) { + log.debug("get all interface lifecycle types failed with exception", e); + ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR); + return buildErrorResponse(responseFormat); + } + } } diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml index aa000f14a7..84213bbe8d 100644 --- a/catalog-be/src/main/resources/config/error-configuration.yaml +++ b/catalog-be/src/main/resources/config/error-configuration.yaml @@ -2153,4 +2153,9 @@ errors: message: "Error: Interface operation output parameter name should not be empty.", messageId: "SVC4706" } - +#---------SVC4712----------------------------- + INTERFACE_LIFECYCLE_TYPES_NOT_FOUND: { + code: 404, + message: "Error: Interface Lifecycle types not found.", + messageId: "SVC4712" + } \ No newline at end of file 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 4227e5d5cc..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 @@ -70,6 +70,7 @@ 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.user.Role; import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.ConfigurationSource; @@ -106,6 +107,7 @@ public class InterfaceOperationBusinessLogicTest { 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; @@ -192,6 +194,7 @@ public class InterfaceOperationBusinessLogicTest { bl.setUserValidations(userValidations); bl.setInterfaceOperation(interfaceOperation); bl.setInterfaceOperationValidation(operationValidator); + bl.setInterfaceLifecycleOperation(interfaceLifecycleOperation); Resource resourceCsar = createResourceObjectCsar(true); setCanWorkOnResource(resourceCsar); Either oldResourceRes = Either.left(resourceCsar); @@ -423,6 +426,24 @@ public class InterfaceOperationBusinessLogicTest { return resource; } + @Test + public void testGetAllInterfaceLifecycleTypes_TypesNotFound() { + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + Either, 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(UNIQUE_ID); + interfaceDefinition.setType(TYPE); + Map interfaceDefinitionMap = new HashMap<>(); + interfaceDefinitionMap.put(interfaceDefinition.getUniqueId(), interfaceDefinition); + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceDefinitionMap)); + Either, ResponseFormat> response = bl.getAllInterfaceLifecycleTypes(); + Assert.assertEquals(response.left().value().size(),1); + } } \ No newline at end of file diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java index e5caee5f01..fa96c45472 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java @@ -121,6 +121,9 @@ public enum ActionStatus { INTERFACE_OPERATION_NOT_FOUND, INTERFACE_OPERATION_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_NAME_MANDATORY, INTERFACE_OPERATION_NAME_INVALID, INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH, INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE,INTERFACE_OPERATION_NOT_DELETED, INTERFACE_OPERATION_INPUT_NAME_MANDATORY, INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY, - INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT + INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT, + + //InterfaceLifeCycleType + INTERFACE_LIFECYCLE_TYPES_NOT_FOUND ; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java index fd9addd0ec..06622ebba6 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java @@ -50,4 +50,6 @@ public interface IInterfaceLifecycleOperation { public Either getInterface(String interfaceId); public String getShortInterfaceName(InterfaceDataDefinition interfaceDefinition); + + Either,StorageOperationStatus> getAllInterfaceLifecycleTypes(); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java index 3482a25bc4..c842e5b59d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java @@ -47,8 +47,8 @@ import java.util.*; import java.util.Map.Entry; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; +import java.util.stream.Collectors; @Component("interface-operation") public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation { @@ -891,4 +891,40 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation return createInterfaceType(interf, false); } + @Override + public Either, StorageOperationStatus> getAllInterfaceLifecycleTypes() { + + Either, TitanOperationStatus> allInterfaceLifecycleTypes = + titanGenericDao.getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), InterfaceData.class); + if (allInterfaceLifecycleTypes.isRight()) { + return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus + (allInterfaceLifecycleTypes.right().value())); + } + + Map interfaceTypes = new HashMap<>(); + List interfaceDataList = allInterfaceLifecycleTypes.left().value(); + List interfaceDefinitions = interfaceDataList.stream() + .map(this::convertInterfaceDataToInterfaceDefinition) + .filter(interfaceDefinition -> interfaceDefinition.getUniqueId().equalsIgnoreCase((interfaceDefinition.getType()))) + .collect(Collectors.toList()); + + for (InterfaceDefinition interfaceDefinition : interfaceDefinitions) { + + Either>, TitanOperationStatus> + childrenNodes = titanGenericDao.getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), + interfaceDefinition.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class); + if(childrenNodes.isRight()) { + return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childrenNodes.right().value())); + } + + Map operationsDataDefinitionMap = new HashMap<>(); + for(ImmutablePair operation : childrenNodes.left().value()) { + OperationData operationData = operation.getLeft(); + operationsDataDefinitionMap.put(operationData.getUniqueId(), operationData.getOperationDataDefinition()); + } + interfaceDefinition.setOperations(operationsDataDefinitionMap); + interfaceTypes.put(interfaceDefinition.getUniqueId(), interfaceDefinition); + } + return Either.left(interfaceTypes); + } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java new file mode 100644 index 0000000000..3e8b087fb2 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java @@ -0,0 +1,302 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.model.operations.impl; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import fj.data.Either; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; +import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; +import org.openecomp.sdc.be.dao.titan.TitanGenericDao; +import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; +import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.ModelTestBase; +import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil; +import org.openecomp.sdc.be.resources.data.category.CategoryData; +import org.openecomp.sdc.be.resources.data.InterfaceData; +import org.openecomp.sdc.be.resources.data.OperationData; +import org.openecomp.sdc.be.resources.data.UserData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import org.junit.Assert; + +import static org.junit.Assert.assertNotNull; + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("classpath:application-context-test.xml") +public class InterfaceLifecycleOperationTest { + private static final Logger log = LoggerFactory.getLogger(InterfaceLifecycleOperationTest.class); + private Gson prettyGson = new GsonBuilder().setPrettyPrinting().create(); + private static String USER_ID = "muUserId"; + private static String CATEGORY_NAME = "category/mycategory"; + + TitanGenericDao titanGenericDao = Mockito.mock(TitanGenericDao.class); + @InjectMocks + private InterfaceLifecycleOperation interfaceLifecycleOperation = new InterfaceLifecycleOperation(); + + @javax.annotation.Resource(name = "property-operation") + private PropertyOperation propertyOperation; + + // @Resource(name = "artifact-operation") + // private ArtifactOperation artifactOperation; + + @Before + public void createUserAndCategory() { + MockitoAnnotations.initMocks(this); + final String UNIQUE_ID = "UNIQUE_ID"; + CategoryData categoryData = new CategoryData(NodeTypeEnum.ResourceCategory); + when(titanGenericDao.createNode(any(),any())).thenReturn(Either.left(categoryData)); + deleteAndCreateCategory(CATEGORY_NAME); + deleteAndCreateUser(USER_ID, "first_" + USER_ID, "last_" + USER_ID); + } + + @BeforeClass + public static void setupBeforeClass() { + // ExternalConfiguration.setAppName("catalog-model"); + // String appConfigDir = "src/test/resources/config/catalog-model"; + // ConfigurationSource configurationSource = new + // FSConfigurationSource(ExternalConfiguration.getChangeListener(), + // appConfigDir); + + ModelTestBase.init(); + + } + + @Test + public void testDummy() { + + assertNotNull(interfaceLifecycleOperation); + + } + +/* @Test + public void addInterfaceToResourceTest() { + + String capabilityTypeName = "mycapability1"; + String reqName = "host"; + String reqNodeName = "tosca.nodes.Compute1"; + String rootName = "Root100"; + String softwareCompName = "tosca.nodes.SoftwareComponent"; + String computeNodeName = "tosca.nodes.Compute"; + String myResourceVersion = "300.0"; + String reqRelationship = "myrelationship"; + + ResourceOperationTest resourceOperationTest = new ResourceOperationTest(); + resourceOperationTest.setOperations(titanDao, resourceOperation, propertyOperation); + + Resource rootResource = resourceOperationTest.createResource(USER_ID, CATEGORY_NAME, rootName, "100.0", null, true, true); + + String interfaceName = "standard"; + InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); + + Operation op = buildOperationDefinition(); + Map operations = new HashMap(); + operations.put("Create", op); + interfaceDefinition.setOperations(operations); + + Either result = interfaceOperation.addInterfaceToResource(interfaceDefinition, rootResource.getUniqueId(), "standard"); + + assertTrue(result.isLeft()); + log.debug("{}", result.left().value()); + + Either getResourceRes = resourceOperation.getResource(rootResource.getUniqueId()); + assertTrue(getResourceRes.isLeft()); + Resource resourceWithInterface = getResourceRes.left().value(); + Map interfaces = resourceWithInterface.getInterfaces(); + assertNotNull(interfaces); + assertFalse(interfaces.isEmpty()); + InterfaceDefinition interfaceDefinition2 = interfaces.get(interfaceName); + assertNotNull(interfaceDefinition2.getOperations()); + assertFalse(interfaceDefinition2.getOperations().isEmpty()); + + } + + @Test + public void updateInterfaceToResourceTest() { + + String reqName = "host"; + String rootName = "Root200"; + String softwareCompName = "tosca.nodes.SoftwareComponent"; + + ResourceOperationTest resourceOperationTest = new ResourceOperationTest(); + resourceOperationTest.setOperations(titanDao, resourceOperation, propertyOperation); + + Resource rootResource = resourceOperationTest.createResource(USER_ID, CATEGORY_NAME, rootName, "200.0", null, true, true); + + String interfaceName = "standard"; + InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); + + Operation op = buildOperationDefinition(); + Map operations = new HashMap(); + operations.put("create", op); + interfaceDefinition.setOperations(operations); + + Either result = interfaceOperation.addInterfaceToResource(interfaceDefinition, rootResource.getUniqueId(), "standard"); + + ResourceMetadataData resourceData = new ResourceMetadataData(); + resourceData.getMetadataDataDefinition().setUniqueId(rootResource.getUniqueId()); + resourceData.getMetadataDataDefinition().setState(LifecycleStateEnum.CERTIFIED.name()); + Either updateNode = titanDao.updateNode(resourceData, ResourceMetadataData.class); + assertTrue(updateNode.isLeft()); + + Either fetchRootResource = resourceOperation.getResource(rootResource.getUniqueId()); + + assertTrue(fetchRootResource.isLeft()); + String rootResourceJson = prettyGson.toJson(fetchRootResource.left().value()); + log.debug(rootResourceJson); + + Resource softwareComponent = resourceOperationTest.createResource(USER_ID, CATEGORY_NAME, softwareCompName, "400.0", rootResource.getName(), true, true); + + assertTrue(result.isLeft()); + log.debug("{}", result.left().value()); + + addImplementationToOperation(op); + // String resourceId, String interfaceName, String + // operationName,Operation interf + + Either opResult = interfaceOperation.updateInterfaceOperation(softwareComponent.getUniqueId(), "standard", "create", op); + // PrintGraph pg = new PrintGraph(); + // System.out.println(pg.buildGraphForWebgraphWiz(titanDao.getGraph().left().value())); + assertTrue(opResult.isLeft()); + log.debug("{}", opResult.left().value()); + + Either getResourceRes = resourceOperation.getResource(softwareComponent.getUniqueId()); + assertTrue(getResourceRes.isLeft()); + Resource resourceWithInterface = getResourceRes.left().value(); + Map interfaces = resourceWithInterface.getInterfaces(); + assertNotNull(interfaces); + assertFalse(interfaces.isEmpty()); + InterfaceDefinition interfaceDefinition2 = interfaces.get(interfaceName); + assertNotNull(interfaceDefinition2.getOperations()); + assertFalse(interfaceDefinition2.getOperations().isEmpty()); + Operation operation = interfaceDefinition2.getOperations().get("create"); + assertNotNull(operation); + assertNotNull(operation.getImplementation()); + } +*/ + private void addImplementationToOperation(Operation op) { + ArtifactDataDefinition artifactDataDef = new ArtifactDataDefinition(); + artifactDataDef.setArtifactChecksum("YTg2Mjg4MWJhNmI5NzBiNzdDFkMWI="); + artifactDataDef.setArtifactName("create_myRoot.sh"); + artifactDataDef.setArtifactLabel("create_myRoot"); + artifactDataDef.setArtifactType("SHELL"); + artifactDataDef.setDescription("good description"); + artifactDataDef.setEsId("esId"); + artifactDataDef.setUniqueId(op.getUniqueId() + "." + artifactDataDef.getArtifactLabel()); + ArtifactDefinition artifactDef = new ArtifactDefinition(artifactDataDef, "UEsDBAoAAAAIAAeLb0bDQz"); + op.setImplementation(artifactDef); + } + + private InterfaceDefinition buildInterfaceDefinition() { + InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); + interfaceDefinition.setType("tosca.interfaces.standard"); + interfaceDefinition.setCreationDate(new Long(101232)); + + return interfaceDefinition; + } + + private Operation buildOperationDefinition() { + Operation op = new Operation(); + op.setCreationDate(new Long(101232)); + op.setDescription("asda"); + + return op; + } + + private void deleteAndCreateCategory(String category) { + String[] names = category.split("/"); + OperationTestsUtil.deleteAndCreateResourceCategory(names[0], names[1], titanGenericDao); + + /* + * CategoryData categoryData = new CategoryData(); categoryData.setName(category); + * + * titanDao.deleteNode(categoryData, CategoryData.class); Either createNode = titanDao .createNode(categoryData, CategoryData.class); System.out.println("after creating caetgory " + createNode); + */ + + } + + private UserData deleteAndCreateUser(String userId, String firstName, String lastName) { + UserData userData = new UserData(); + userData.setUserId(userId); + userData.setFirstName(firstName); + userData.setLastName(lastName); + + titanGenericDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.User), userId, + UserData.class); + titanGenericDao.createNode(userData, UserData.class); + titanGenericDao.commit(); + + return userData; + } + + @Test + public void testGetAllInterfaceLifecycleTypes_TypesNotFound() { + when(titanGenericDao.getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), + InterfaceData.class)).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND)); + Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(); + Assert.assertEquals(types.isRight(), Boolean.TRUE); + } + + @Test + public void testGetAllInterfaceLifecycleTypes_Success() { + final String UNIQUE_ID = "UNIQUE_ID"; + final String TYPE = "UNIQUE_ID"; + InterfaceData interfaceData = new InterfaceData(); + interfaceData.getInterfaceDataDefinition().setUniqueId(UNIQUE_ID); + interfaceData.getInterfaceDataDefinition().setType(TYPE); + List interfaceDataList = new ArrayList<>(); + interfaceDataList.add(interfaceData); + Either, TitanOperationStatus> allInterfaceTypes = Either.left(interfaceDataList); + when(titanGenericDao.getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), InterfaceData.class)).thenReturn(allInterfaceTypes); + + List> list = new ArrayList<>(); + Either>, TitanOperationStatus> childrenNodes = Either.left(list); + when(titanGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(childrenNodes); + + Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(); + Assert.assertEquals(types.left().value().size(),1); + } + +} diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceOperationTest.java deleted file mode 100644 index a50435b30c..0000000000 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceOperationTest.java +++ /dev/null @@ -1,254 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.model.operations.impl; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openecomp.sdc.be.dao.titan.TitanGenericDao; -import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.model.ArtifactDefinition; -import org.openecomp.sdc.be.model.InterfaceDefinition; -import org.openecomp.sdc.be.model.ModelTestBase; -import org.openecomp.sdc.be.model.Operation; -import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil; -import org.openecomp.sdc.be.resources.data.UserData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") -public class InterfaceOperationTest { - private static final Logger log = LoggerFactory.getLogger(InterfaceOperationTest.class); - private Gson prettyGson = new GsonBuilder().setPrettyPrinting().create(); - - private static String USER_ID = "muUserId"; - private static String CATEGORY_NAME = "category/mycategory"; - // InterfaceLifecycleOperation interfaceOperation = new - // InterfaceLifecycleOperation(); - - // TitanGenericDao titanGenericDao = Mockito.mock(TitanGenericDao.class); - @javax.annotation.Resource(name = "titan-generic-dao") - private TitanGenericDao titanDao; - - @javax.annotation.Resource(name = "interface-operation") - private InterfaceLifecycleOperation interfaceOperation; - - @javax.annotation.Resource(name = "property-operation") - private PropertyOperation propertyOperation; - - // @Resource(name = "artifact-operation") - // private ArtifactOperation artifactOperation; - - @Before - public void createUserAndCategory() { - deleteAndCreateCategory(CATEGORY_NAME); - deleteAndCreateUser(USER_ID, "first_" + USER_ID, "last_" + USER_ID); - } - - @BeforeClass - public static void setupBeforeClass() { - // ExternalConfiguration.setAppName("catalog-model"); - // String appConfigDir = "src/test/resources/config/catalog-model"; - // ConfigurationSource configurationSource = new - // FSConfigurationSource(ExternalConfiguration.getChangeListener(), - // appConfigDir); - - ModelTestBase.init(); - - } - - @Test - public void testDummy() { - - assertNotNull(interfaceOperation); - - } - -/* @Test - public void addInterfaceToResourceTest() { - - String capabilityTypeName = "mycapability1"; - String reqName = "host"; - String reqNodeName = "tosca.nodes.Compute1"; - String rootName = "Root100"; - String softwareCompName = "tosca.nodes.SoftwareComponent"; - String computeNodeName = "tosca.nodes.Compute"; - String myResourceVersion = "300.0"; - String reqRelationship = "myrelationship"; - - ResourceOperationTest resourceOperationTest = new ResourceOperationTest(); - resourceOperationTest.setOperations(titanDao, resourceOperation, propertyOperation); - - Resource rootResource = resourceOperationTest.createResource(USER_ID, CATEGORY_NAME, rootName, "100.0", null, true, true); - - String interfaceName = "standard"; - InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); - - Operation op = buildOperationDefinition(); - Map operations = new HashMap(); - operations.put("Create", op); - interfaceDefinition.setOperations(operations); - - Either result = interfaceOperation.addInterfaceToResource(interfaceDefinition, rootResource.getUniqueId(), "standard"); - - assertTrue(result.isLeft()); - log.debug("{}", result.left().value()); - - Either getResourceRes = resourceOperation.getResource(rootResource.getUniqueId()); - assertTrue(getResourceRes.isLeft()); - Resource resourceWithInterface = getResourceRes.left().value(); - Map interfaces = resourceWithInterface.getInterfaces(); - assertNotNull(interfaces); - assertFalse(interfaces.isEmpty()); - InterfaceDefinition interfaceDefinition2 = interfaces.get(interfaceName); - assertNotNull(interfaceDefinition2.getOperations()); - assertFalse(interfaceDefinition2.getOperations().isEmpty()); - - } - - @Test - public void updateInterfaceToResourceTest() { - - String reqName = "host"; - String rootName = "Root200"; - String softwareCompName = "tosca.nodes.SoftwareComponent"; - - ResourceOperationTest resourceOperationTest = new ResourceOperationTest(); - resourceOperationTest.setOperations(titanDao, resourceOperation, propertyOperation); - - Resource rootResource = resourceOperationTest.createResource(USER_ID, CATEGORY_NAME, rootName, "200.0", null, true, true); - - String interfaceName = "standard"; - InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); - - Operation op = buildOperationDefinition(); - Map operations = new HashMap(); - operations.put("create", op); - interfaceDefinition.setOperations(operations); - - Either result = interfaceOperation.addInterfaceToResource(interfaceDefinition, rootResource.getUniqueId(), "standard"); - - ResourceMetadataData resourceData = new ResourceMetadataData(); - resourceData.getMetadataDataDefinition().setUniqueId(rootResource.getUniqueId()); - resourceData.getMetadataDataDefinition().setState(LifecycleStateEnum.CERTIFIED.name()); - Either updateNode = titanDao.updateNode(resourceData, ResourceMetadataData.class); - assertTrue(updateNode.isLeft()); - - Either fetchRootResource = resourceOperation.getResource(rootResource.getUniqueId()); - - assertTrue(fetchRootResource.isLeft()); - String rootResourceJson = prettyGson.toJson(fetchRootResource.left().value()); - log.debug(rootResourceJson); - - Resource softwareComponent = resourceOperationTest.createResource(USER_ID, CATEGORY_NAME, softwareCompName, "400.0", rootResource.getName(), true, true); - - assertTrue(result.isLeft()); - log.debug("{}", result.left().value()); - - addImplementationToOperation(op); - // String resourceId, String interfaceName, String - // operationName,Operation interf - - Either opResult = interfaceOperation.updateInterfaceOperation(softwareComponent.getUniqueId(), "standard", "create", op); - // PrintGraph pg = new PrintGraph(); - // System.out.println(pg.buildGraphForWebgraphWiz(titanDao.getGraph().left().value())); - assertTrue(opResult.isLeft()); - log.debug("{}", opResult.left().value()); - - Either getResourceRes = resourceOperation.getResource(softwareComponent.getUniqueId()); - assertTrue(getResourceRes.isLeft()); - Resource resourceWithInterface = getResourceRes.left().value(); - Map interfaces = resourceWithInterface.getInterfaces(); - assertNotNull(interfaces); - assertFalse(interfaces.isEmpty()); - InterfaceDefinition interfaceDefinition2 = interfaces.get(interfaceName); - assertNotNull(interfaceDefinition2.getOperations()); - assertFalse(interfaceDefinition2.getOperations().isEmpty()); - Operation operation = interfaceDefinition2.getOperations().get("create"); - assertNotNull(operation); - assertNotNull(operation.getImplementation()); - } -*/ - private void addImplementationToOperation(Operation op) { - ArtifactDataDefinition artifactDataDef = new ArtifactDataDefinition(); - artifactDataDef.setArtifactChecksum("YTg2Mjg4MWJhNmI5NzBiNzdDFkMWI="); - artifactDataDef.setArtifactName("create_myRoot.sh"); - artifactDataDef.setArtifactLabel("create_myRoot"); - artifactDataDef.setArtifactType("SHELL"); - artifactDataDef.setDescription("good description"); - artifactDataDef.setEsId("esId"); - artifactDataDef.setUniqueId(op.getUniqueId() + "." + artifactDataDef.getArtifactLabel()); - ArtifactDefinition artifactDef = new ArtifactDefinition(artifactDataDef, "UEsDBAoAAAAIAAeLb0bDQz"); - op.setImplementation(artifactDef); - } - - private InterfaceDefinition buildInterfaceDefinition() { - InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); - interfaceDefinition.setType("tosca.interfaces.standard"); - interfaceDefinition.setCreationDate(new Long(101232)); - - return interfaceDefinition; - } - - private Operation buildOperationDefinition() { - Operation op = new Operation(); - op.setCreationDate(new Long(101232)); - op.setDescription("asda"); - - return op; - } - - private void deleteAndCreateCategory(String category) { - String[] names = category.split("/"); - OperationTestsUtil.deleteAndCreateResourceCategory(names[0], names[1], titanDao); - - /* - * CategoryData categoryData = new CategoryData(); categoryData.setName(category); - * - * titanDao.deleteNode(categoryData, CategoryData.class); Either createNode = titanDao .createNode(categoryData, CategoryData.class); System.out.println("after creating caetgory " + createNode); - */ - - } - - private UserData deleteAndCreateUser(String userId, String firstName, String lastName) { - UserData userData = new UserData(); - userData.setUserId(userId); - userData.setFirstName(firstName); - userData.setLastName(lastName); - - titanDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.User), userId, UserData.class); - titanDao.createNode(userData, UserData.class); - titanDao.commit(); - - return userData; - } - -} diff --git a/openecomp-bdd/config.json b/openecomp-bdd/config.json index c28bc9d390..4bf5f95ac5 100644 --- a/openecomp-bdd/config.json +++ b/openecomp-bdd/config.json @@ -13,6 +13,12 @@ "server" : "vf.server", "user" : "user" }, + "catalog" : { + "port" : 8080, + "prefix" : "sdc2/rest/v1", + "server" : "CatalogBE.server", + "user" : "user" + }, "activity_spec" : { "port" : 8080, "prefix" : "activity-spec-api/v1.0", diff --git a/openecomp-bdd/features/GlobalTypes/TestInterfaceLifecycleTypes.feature b/openecomp-bdd/features/GlobalTypes/TestInterfaceLifecycleTypes.feature new file mode 100644 index 0000000000..ef98fa5b42 --- /dev/null +++ b/openecomp-bdd/features/GlobalTypes/TestInterfaceLifecycleTypes.feature @@ -0,0 +1,8 @@ +Feature: Interface Lifecycle Types + +Scenario: Test Interface Lifecycle Types + + When I want to get interface lifecycle types + Then I want to check property "tosca.interfaces.node.lifecycle.standard" exists + Then I want to check property "tosca.interfaces.nfv.vnf.lifecycle.nfv" exists + diff --git a/openecomp-bdd/stepDefinitions/GlobalTypes.js b/openecomp-bdd/stepDefinitions/GlobalTypes.js new file mode 100644 index 0000000000..461fee74a7 --- /dev/null +++ b/openecomp-bdd/stepDefinitions/GlobalTypes.js @@ -0,0 +1,24 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const {Then, When} = require('cucumber'); +const assert = require('assert'); +const util = require('./Utils.js'); + +When('I want to get interface lifecycle types', function () { + let path = '/catalog/interfaceLifecycleTypes'; + return util.request(this.context, 'GET', path, null, false, 'catalog'); +}); \ No newline at end of file -- cgit 1.2.3-korg