diff options
author | zhaoxiangjun666 <xjzhaop@isoftstone.com> | 2020-09-10 14:01:50 +0800 |
---|---|---|
committer | zhaoxiangjun666 <xjzhaop@isoftstone.com> | 2020-09-21 20:39:48 +0800 |
commit | a8d3e1b8c759c21227690a425552a245da883e97 (patch) | |
tree | 4e9731f7e7c4df8088187e7501a0d9a8a516f215 /catalog-model/src | |
parent | 591810df468a8e2c59569e701f514bff61203940 (diff) |
Support for Test Topology Auto Design- Service Import
Add some test code and use lombok in catalog-model
Test Topology Auto Design (NFV Testing Automatic Platform)
Delete useless test code and add test code for new function
Issue-ID: SDC-3179
Issue-ID: SDC-3085
Signed-off-by: zhaoxiangjun666 <xjzhaop@isoftstone.com>
Change-Id: I7f555633a00848c273014caa18ea0e30d0b22113
Diffstat (limited to 'catalog-model/src')
6 files changed, 472 insertions, 3 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java index 3e33fd490c..2e326ce691 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java @@ -46,6 +46,7 @@ public class Service extends Component { private Map<String, ArtifactDefinition> serviceApiArtifacts; private Map<String, ForwardingPathDataDefinition> forwardingPaths; + private String toscaServiceName; public Service() { super(new ServiceMetadataDefinition()); @@ -178,4 +179,24 @@ public class Service extends Component { public void setSpecificComponetTypeArtifacts(Map<String, ArtifactDefinition> specificComponentTypeArtifacts) { setServiceApiArtifacts(specificComponentTypeArtifacts); } + + + public void setServiceVendorModelNumber(String serviceVendorModelNumber) { + getServiceMetadataDefinition().setServiceVendorModelNumber(serviceVendorModelNumber); + } + + public void setAbstract(Boolean isAbstract) { + ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) + .setIsAbstract(isAbstract); + } + + public void setVendorName(String vendorName) { + ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) + .setVendorName(vendorName); + } + + public void setVendorRelease(String vendorRelease) { + ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) + .setVendorRelease(vendorRelease); + } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java new file mode 100644 index 0000000000..29d6fa40fd --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java @@ -0,0 +1,144 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2020 CMCC 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; + +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import org.openecomp.sdc.be.model.category.CategoryDefinition; +import org.openecomp.sdc.be.model.category.SubCategoryDefinition; +import org.openecomp.sdc.common.api.UploadArtifactInfo; + +@Getter +@Setter +public class UploadServiceInfo { + + private String payloadData; + private String payloadName; + private String description; + private List<String> tags; + private List<CategoryDefinition> categories; + + private String invariantUUID; + private String UUID; + private String type; + private String category; + private String subcategory; + private String resourceVendor; + private String resourceVendorRelease; + private String serviceRole; + private String serviceEcompNaming; + private String ecompGeneratedNaming; + private String namingPolicy; + private String projectCode; + + + private List<UploadArtifactInfo> artifactList; + private String contactId, name, serviceIconPath, icon, vendorName, vendorRelease, serviceVendorModelNumber; + + private String serviceType = ""; + + public UploadServiceInfo(String payloadData, String payloadName, String description, + List<String> tags, String invariantUUID, String UUID, String type, + String category, String subcategory, String resourceVendor, + String resourceVendorRelease, String serviceRole, String serviceEcompNaming, + String ecompGeneratedNaming, String namingPolicy, + List<UploadArtifactInfo> artifactList, String contactId, String name, + String resourceIconPath, String icon, String vendorName, String vendorRelease, + String serviceVendorModelNumber, String serviceType, String projectCode) { + this.payloadData = payloadData; + this.payloadName = payloadName; + this.description = description; + this.tags = tags; + this.invariantUUID = invariantUUID; + this.UUID = UUID; + this.type = type; + this.category = category; + this.subcategory = subcategory; + this.resourceVendor = resourceVendor; + this.resourceVendorRelease = resourceVendorRelease; + this.serviceRole = serviceRole; + this.serviceEcompNaming = serviceEcompNaming; + this.ecompGeneratedNaming = ecompGeneratedNaming; + this.namingPolicy = namingPolicy; + this.artifactList = artifactList; + this.contactId = contactId; + this.name = name; + this.serviceIconPath = serviceIconPath; + this.icon = icon; + this.vendorName = vendorName; + this.vendorRelease = vendorRelease; + this.serviceVendorModelNumber = serviceVendorModelNumber; + this.serviceType = serviceType; + this.projectCode = projectCode; + + if (category != null) { + String[] arr = category.split("/"); + if (arr.length >= 2) { + categories = new ArrayList<>(); + CategoryDefinition catDef = new CategoryDefinition(); + catDef.setName(arr[0]); + SubCategoryDefinition subCat = new SubCategoryDefinition(); + subCat.setName(arr[1]); + catDef.addSubCategory(subCat); + categories.add(catDef); + } + } + } + + public UploadServiceInfo() { + } + public void addSubCategory(String category, String subCategory) { + if (category != null || subCategory != null) { + if (categories == null) { + categories = new ArrayList<>(); + } + CategoryDefinition selectedCategory = null; + for (CategoryDefinition categoryDef : categories) { + if (categoryDef.getName().equals(category)) { + selectedCategory = categoryDef; + } + } + if (selectedCategory == null) { + selectedCategory = new CategoryDefinition(); + selectedCategory.setName(category); + categories.add(selectedCategory); + } + List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories(); + if (subcategories == null) { + subcategories = new ArrayList<>(); + selectedCategory.setSubcategories(subcategories); + } + SubCategoryDefinition selectedSubcategory = null; + for (SubCategoryDefinition subcategory : subcategories) { + if (subcategory.getName().equals(subCategory)) { + selectedSubcategory = subcategory; + } + } + if (selectedSubcategory == null) { + selectedSubcategory = new SubCategoryDefinition(); + selectedSubcategory.setName(subCategory); + subcategories.add(selectedSubcategory); + } + } + } +}
\ No newline at end of file diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java index 7a399a1f69..5fb07a01b3 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java @@ -776,8 +776,14 @@ public class NodeTemplateOperation extends BaseOperation { listCapabilities.forEach(cap -> { cap.setSource(componentInstance.getComponentUid()); cap.addToPath(componentInstance.getUniqueId()); + log.debug("enter populateCapability,get Capability OwnerId:{},get componentInstance UniqueId:{}", + cap.getOwnerId(), componentInstance.getUniqueId()); cap.setOwnerId(componentInstance.getUniqueId()); - cap.setOwnerName(componentInstance.getName()); + log.debug("enter populateCapability,get Capability OwnerName:{},get componentInstance Name:{}", + cap.getOwnerName(), componentInstance.getName()); + if (cap.getOwnerName() == null || cap.getOwnerName().isEmpty()) { + cap.setOwnerName(componentInstance.getName()); + } cap.setLeftOccurrences(cap.getMaxOccurrences()); allCalculatedCap.add(key, cap); }); @@ -803,8 +809,15 @@ public class NodeTemplateOperation extends BaseOperation { listRequirements.forEach(req -> { req.setSource(componentInstance.getComponentUid()); req.addToPath(componentInstance.getUniqueId()); - req.setOwnerId(componentInstance.getUniqueId()); - req.setOwnerName(componentInstance.getName()); + log.debug("enter populateRequirement,get init Requirements OwnerId:{},get componentInstance UniqueId:{}", + req.getOwnerId(), componentInstance.getUniqueId()); + if (req.getOwnerId() == null || req.getOwnerId().isEmpty()) { + req.setOwnerId(componentInstance.getUniqueId()); + } + log.debug("enter populateRequirement,get init Requirements OwnerName:{}", req.getOwnerName()); + if (req.getOwnerName() == null || req.getOwnerName().isEmpty()) { + req.setOwnerName(componentInstance.getName()); + } req.setLeftOccurrences(req.getMaxOccurrences()); allCalculatedReq.add(key, req); }); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index dc9174e464..50b2ae45b4 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -405,6 +405,52 @@ public class ToscaOperationFacade { } ); } + + public Either<Resource, StorageOperationStatus> getLatestResourceByToscaResourceName(String toscaResourceName) { + if (toscaResourceName != null && toscaResourceName.contains("org.openecomp.resource.vf")) + return getLatestResourceByToscaResourceName(toscaResourceName, VertexTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.ParseMetadata); + else + return getLatestResourceByToscaResourceName(toscaResourceName, VertexTypeEnum.NODE_TYPE, JsonParseFlagEnum.ParseMetadata); + } + + public Either<Resource, StorageOperationStatus> getLatestResourceByToscaResourceName(String toscaResourceName, VertexTypeEnum vertexType, JsonParseFlagEnum parseFlag) { + + Either<Resource, StorageOperationStatus> result = null; + Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class); + props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName); + props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); + if (!toscaResourceName.contains("org.openecomp.resource.vf")) { + props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + } + + Either<List<GraphVertex>, JanusGraphOperationStatus> getLatestRes = janusGraphDao.getByCriteria(vertexType, props, parseFlag); + + if (getLatestRes.isRight()) { + JanusGraphOperationStatus status = getLatestRes.right().value(); + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch {} with name {}. status={} ", vertexType, toscaResourceName, status); + result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); + } + if (result == null) { + List<GraphVertex> resources = getLatestRes.left().value(); + double version = 0.0; + GraphVertex highestResource = null; + for (GraphVertex resource : resources) { + double resourceVersion = Double.parseDouble((String) resource.getJsonMetadataField(JsonPresentationFields.VERSION)); + if (resourceVersion > version) { + version = resourceVersion; + highestResource = resource; + } + } + + if (highestResource != null) { + result = getToscaFullElement(highestResource.getUniqueId()); + } else { + log.debug("The vertex with the highest version could not be found for {}", toscaResourceName); + result = Either.right(StorageOperationStatus.GENERAL_ERROR); + } + } + return result; + } public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExists(String templateName) { Either<Boolean, StorageOperationStatus> validateUniquenessRes = validateToscaResourceNameUniqueness(templateName); @@ -1429,6 +1475,53 @@ public class ToscaOperationFacade { return Optional.empty(); } + public StorageOperationStatus associateCapabilitiesToService(Map<String,ListCapabilityDataDefinition> capabilities, String componentId) { + + Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); + if (getVertexEither.isRight()) { + log.debug(COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, componentId, getVertexEither.right().value()); + return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getVertexEither.right().value()); + + } + + GraphVertex vertex = getVertexEither.left().value(); + if(MapUtils.isNotEmpty(capabilities)) { + Either<GraphVertex, StorageOperationStatus> associateElementToData = topologyTemplateOperation. + associateElementToData(vertex, VertexTypeEnum.CAPABILITIES, + EdgeLabelEnum.CAPABILITIES, capabilities); + if (associateElementToData.isRight()) { + return associateElementToData.right().value(); + } + } + + + return StorageOperationStatus.OK; + + } + + public StorageOperationStatus associateRequirementsToService(Map<String, ListRequirementDataDefinition> requirements, String componentId) { + + Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); + if (getVertexEither.isRight()) { + log.debug(COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, componentId, getVertexEither.right().value()); + return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getVertexEither.right().value()); + + } + + GraphVertex vertex = getVertexEither.left().value(); + if(MapUtils.isNotEmpty(requirements)) { + Either<GraphVertex, StorageOperationStatus> associateElementToData = topologyTemplateOperation. + associateElementToData(vertex, VertexTypeEnum.REQUIREMENTS, + EdgeLabelEnum.REQUIREMENTS, requirements); + if (associateElementToData.isRight()) { + return associateElementToData.right().value(); + } + } + + return StorageOperationStatus.OK; + + } + public StorageOperationStatus associateDeploymentArtifactsToInstances(Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts, Component component, User user) { Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(component.getUniqueId(), JsonParseFlagEnum.NoParse); @@ -2886,4 +2979,9 @@ public class ToscaOperationFacade { topologyTemplateOperation .updateCapReqPropertiesOwnerId(componentId, getTopologyTemplate(componentId)); } + + public <T extends Component> Either<T, StorageOperationStatus> getLatestByServiceName(String serviceName) { + return getLatestByName(GraphPropertyEnum.NAME, serviceName); + + } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadServiceInfoTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadServiceInfoTest.java new file mode 100644 index 0000000000..ca17663a2c --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadServiceInfoTest.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 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; + + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.sdc.be.model.category.CategoryDefinition; +import org.openecomp.sdc.be.model.category.SubCategoryDefinition; + +import java.util.LinkedList; +import java.util.List; + + +public class UploadServiceInfoTest { + + private UploadServiceInfo createTestSubject() { + return new UploadServiceInfo(); + } + + @Test + public void testCtor() { + new UploadServiceInfo("mock", "mock", "mock", new LinkedList<>(), "mock", "mock", "mock", "mock/mock/mock", + "mock", "mock", "mock", "mock", "mock", "mock", "mock", new LinkedList<>(), "mock", "mock", "mock", + "mock", "mock", "mock", "mock", "mock", "mock"); + } + + @Test + public void testAddSubCategory() { + UploadServiceInfo testSubject; + String category = ""; + String subCategory = ""; + + // test 1 + testSubject = createTestSubject(); + category = null; + subCategory = null; + testSubject.addSubCategory(category, subCategory); + List<CategoryDefinition> categories = testSubject.getCategories(); + Assert.assertNull(categories); + + // test 2 + testSubject = createTestSubject(); + category = ""; + subCategory = null; + testSubject.addSubCategory(category, subCategory); + List<CategoryDefinition> categories2 = testSubject.getCategories(); + for (CategoryDefinition categoryDefinition : categories2) { + Assert.assertEquals("", categoryDefinition.getName()); + } + + // test 3 + testSubject = createTestSubject(); + subCategory = ""; + category = null; + testSubject.addSubCategory(category, subCategory); + List<CategoryDefinition> categories3 = testSubject.getCategories(); + for (CategoryDefinition categoryDefinition : categories3) { + List<SubCategoryDefinition> subcategories = categoryDefinition.getSubcategories(); + for (SubCategoryDefinition subcategory : subcategories) { + Assert.assertEquals("", subcategory.getName()); + } + } + + // test 4 + testSubject = createTestSubject(); + subCategory = "mock"; + category = "mock"; + testSubject.addSubCategory(category, subCategory); + List<CategoryDefinition> categories4 = testSubject.getCategories(); + for (CategoryDefinition categoryDefinition : categories4) { + Assert.assertEquals("mock", categoryDefinition.getName()); + } + } +}
\ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java index 0aaae48dc8..971f4f79ab 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java @@ -30,6 +30,7 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; import fj.data.Either; +import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.Before; import org.junit.Test; @@ -47,6 +48,8 @@ import org.openecomp.sdc.be.dao.jsongraph.HealingJanusGraphDao; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; @@ -437,6 +440,37 @@ public class ToscaOperationFacadeTest { assertTrue(result.isLeft()); } + + @Test + public void testGetLatestResourceByToscaResourceName() { + Either<Resource, StorageOperationStatus> result; + String toscaResourceName = "org.openecomp.resource.vf"; + ToscaElement toscaElement = getToscaElementForTest(); + + Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); + propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName); + propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); + if (!toscaResourceName.contains("org.openecomp.resource.vf")) { + propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + } + + List<GraphVertex> graphVertexList = new ArrayList<>(); + GraphVertex graphVertex = getTopologyTemplateVertex(); + graphVertex.setUniqueId(toscaResourceName); + Map<JsonPresentationFields, Object> props = new HashMap<>(); + props.put(JsonPresentationFields.VERSION, "1.0"); + graphVertex.setJsonMetadataField(JsonPresentationFields.VERSION, props.get(JsonPresentationFields.VERSION)); + graphVertexList.add(graphVertex); + + when(janusGraphDaoMock.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(graphVertexList)); + when(topologyTemplateOperationMock.getToscaElement(any(GraphVertex.class), any(ComponentParametersView.class))).thenReturn(Either.left(toscaElement)); + + when(janusGraphDaoMock.getVertexById(toscaResourceName, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(graphVertex)); + + result = testInstance.getLatestResourceByToscaResourceName(toscaResourceName); + assertTrue(result.isLeft()); + } + @Test public void testGetFollowed() { Either<Set<Component>, StorageOperationStatus> result; @@ -732,6 +766,72 @@ public class ToscaOperationFacadeTest { } + @Test + public void associateCapabilitiesToServiceFailureTest(){ + StorageOperationStatus result = associateCapabilitiesToServiceWithStatus(StorageOperationStatus.BAD_REQUEST); + assertTrue(result == StorageOperationStatus.BAD_REQUEST); + } + + @Test + public void associateCapabilitiesToServiceSuccessTest(){ + StorageOperationStatus result = associateCapabilitiesToServiceWithStatus(StorageOperationStatus.OK); + assertTrue(result == StorageOperationStatus.OK); + } + + private StorageOperationStatus associateCapabilitiesToServiceWithStatus(StorageOperationStatus status) { + Map<String, ListCapabilityDataDefinition> capabilitiesMap = new HashedMap(); + String componentId = "componentid"; + + ListCapabilityDataDefinition listCapabilityDataDefinition1 = new ListCapabilityDataDefinition(); + capabilitiesMap.put("capabilities1", listCapabilityDataDefinition1); + + GraphVertex vertex; + if(status == StorageOperationStatus.OK){ + vertex = getTopologyTemplateVertex(); + } else { + vertex = getNodeTypeVertex(); + } + + Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = Either.left(vertex); + when(janusGraphDaoMock.getVertexById(componentId, JsonParseFlagEnum.NoParse)).thenReturn(getVertexEither); + when(topologyTemplateOperationMock.associateElementToData(eq(vertex), + eq(VertexTypeEnum.CAPABILITIES), eq(EdgeLabelEnum.CAPABILITIES), anyMap())).thenReturn(Either.right(status)); + return testInstance.associateCapabilitiesToService(capabilitiesMap, componentId); + } + + @Test + public void associateRequirementsToServiceFailureTest(){ + StorageOperationStatus result = associateRequirementsToServiceWithStatus(StorageOperationStatus.BAD_REQUEST); + assertTrue(result == StorageOperationStatus.BAD_REQUEST); + } + + @Test + public void associateRequirementsToServiceSuccessTest(){ + StorageOperationStatus result = associateRequirementsToServiceWithStatus(StorageOperationStatus.OK); + assertTrue(result == StorageOperationStatus.OK); + } + + private StorageOperationStatus associateRequirementsToServiceWithStatus(StorageOperationStatus status) { + Map<String, ListRequirementDataDefinition> requirementsMap = new HashedMap(); + String componentId = "componentid"; + + ListRequirementDataDefinition listRequirementDataDefinition1 = new ListRequirementDataDefinition(); + requirementsMap.put("requirements1", listRequirementDataDefinition1); + + GraphVertex vertex; + if(status == StorageOperationStatus.OK){ + vertex = getTopologyTemplateVertex(); + } else { + vertex = getNodeTypeVertex(); + } + + Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = Either.left(vertex); + when(janusGraphDaoMock.getVertexById(componentId, JsonParseFlagEnum.NoParse)).thenReturn(getVertexEither); + when(topologyTemplateOperationMock.associateElementToData(eq(vertex), + eq(VertexTypeEnum.REQUIREMENTS), eq(EdgeLabelEnum.REQUIREMENTS), anyMap())).thenReturn(Either.right(status)); + return testInstance.associateRequirementsToService(requirementsMap, componentId); + } + private Either<PolicyDefinition, StorageOperationStatus> associatePolicyToComponentWithStatus(StorageOperationStatus status) { PolicyDefinition policy = new PolicyDefinition(); String componentId = "componentId"; |