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/test/java/org | |
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/test/java/org')
2 files changed, 193 insertions, 0 deletions
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"; |