summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test/java
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-10-13 16:01:51 +0100
committerandre.schmid <andre.schmid@est.tech>2021-10-21 17:07:40 +0100
commit68eed7997aab4aa4f785085303aab61cf8e16a31 (patch)
tree119f4857936e217a063ce5342134b2ce11a6f3c6 /catalog-model/src/test/java
parentcef866edcf8a14ede6762297dd9ab04b1f3d0375 (diff)
Make Service base type optional
Issue-ID: SDC-3759 Change-Id: I8adf112966ee9303fc965a74cec7203274acd735 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/test/java')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java8
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java4
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java14
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java82
4 files changed, 79 insertions, 29 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java
index 3cd14d8b27..1811dff764 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java
@@ -54,7 +54,8 @@ public class ModelTestBase {
appConfigDir);
configurationManager = new ConfigurationManager(configurationSource);
- Configuration configuration = new Configuration();
+ Configuration configuration = configurationManager.getConfiguration();
+ configuration.setCassandraConfig(null);
configuration.setJanusGraphInMemoryGraph(true);
environmentContext.setDefaultValue("General_Revenue-Bearing");
@@ -64,11 +65,10 @@ public class ModelTestBase {
configuration.setHeatArtifactDeploymentTimeout(heatDeploymentArtifactTimeout);
Map<String, Object> deploymentRIArtifacts = new HashMap<>();
ArtifactDataDefinition artifactInfo = new ArtifactDataDefinition();
- Object artifactDataObj = new HashMap<String, Object>();
- ((HashMap) artifactDataObj).put("1", artifactInfo);
+ HashMap<String, Object> artifactDataObj = new HashMap<>();
+ artifactDataObj.put("1", artifactInfo);
deploymentRIArtifacts.put("VfHeatEnv", artifactDataObj);
- configurationManager.setConfiguration(configuration);
configurationManager.getConfiguration().setDeploymentResourceInstanceArtifacts(deploymentRIArtifacts);
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java
index 447b053fea..b48acd0940 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java
@@ -26,10 +26,8 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import org.junit.Assert;
import org.junit.Test;
import org.openecomp.sdc.be.config.Configuration;
-import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest;
@@ -212,7 +210,7 @@ public class ResourceTest extends ModelConfDependentTest {
Configuration existingConfiguration = configurationManager.getConfiguration();
Configuration newConfiguration = new Configuration();
- newConfiguration.setServiceNodeTypes(null);
+ newConfiguration.setServiceBaseNodeTypes(null);
Map<String, String> genericAssetNodeTypes = new HashMap<>();
genericAssetNodeTypes.put("VFC", "org.openecomp.resource.abstract.nodes.VFC");
newConfiguration.setGenericAssetNodeTypes(genericAssetNodeTypes);
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java
index d84d97b547..ebbb3f4f5e 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java
@@ -271,10 +271,10 @@ public class ServiceTest {
}
@Test
- public void testFetchGenericTypeToscaNameFromConfigNoToscaTypesForCategories() throws Exception {
+ public void testFetchGenericTypeToscaNameFromConfigNoToscaTypesForCategories() {
Configuration existingConfiguration = configurationManager.getConfiguration();
Configuration newConfiguration = new Configuration();
- newConfiguration.setServiceNodeTypes(null);
+ newConfiguration.setServiceBaseNodeTypes(null);
Map<String, String> genericAssetNodeTypes = new HashMap<>();
genericAssetNodeTypes.put("Service", "org.openecomp.resource.abstract.nodes.service");
newConfiguration.setGenericAssetNodeTypes(genericAssetNodeTypes);
@@ -290,7 +290,7 @@ public class ServiceTest {
}
@Test
- public void testFetchGenericTypeToscaNameFromConfigNoToscaTypeForRelevantCategory() throws Exception {
+ public void testFetchGenericTypeToscaNameFromConfigNoToscaTypeForRelevantCategory() {
Service testSubject = createTestSubject();
CategoryDefinition category = new CategoryDefinition();
category.setName("CategoryD");
@@ -300,17 +300,17 @@ public class ServiceTest {
}
@Test
- public void testFetchGenericTypeToscaNameFromConfigToscaTypeDefinedForCategory() throws Exception {
+ public void testFetchGenericTypeToscaNameFromConfigToscaTypeDefinedForCategory() {
Service testSubject = createTestSubject();
CategoryDefinition category = new CategoryDefinition();
- category.setName("CategoryB");
+ category.setName("CategoryA");
testSubject.addCategory(category);
String result = testSubject.fetchGenericTypeToscaNameFromConfig();
- assertEquals("org.openecomp.resource.abstract.nodes.B", result);
+ assertEquals("org.openecomp.resource.abstract.nodes.A", result);
Configuration configuration = new Configuration();
- configuration.setServiceNodeTypes(null);
+ configuration.setServiceBaseNodeTypes(null);
configurationManager.setConfiguration(configuration);
}
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java
index cf3b6dad8b..ed9313e697 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java
@@ -20,9 +20,10 @@
package org.openecomp.sdc.be.model.operations.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.isNull;
@@ -43,6 +44,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.config.ArtifactConfiguration;
+import org.openecomp.sdc.be.config.CategoryBaseTypeConfig;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
@@ -77,9 +79,11 @@ public class ElementOperationTest extends ModelTestBase {
@Mock
private JanusGraphGenericDao janusGraphDao;
+ @Mock
+ private HealingJanusGraphDao healingJanusGraphDao;
- private static String CATEGORY = "category";
- private static String SUBCATEGORY = "subcategory";
+ private static final String CATEGORY = "category";
+ private static final String SUBCATEGORY = "subcategory";
@BeforeAll
public static void setupBeforeClass() {
@@ -448,13 +452,15 @@ public class ElementOperationTest extends ModelTestBase {
@Test
public void testBaseTypes_serviceSpecific() {
- Map<String, List<String>> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
+ Map<String, CategoryBaseTypeConfig> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceBaseNodeTypes();
Map<String, String> preExistingGenericNodeTypes = configurationManager.getConfiguration().getGenericAssetNodeTypes();
try {
- Map<String, List<String>> serviceNodeTypes = new HashMap<>();
- serviceNodeTypes.put("serviceCategoryA", List.of("org.base.type"));
- configurationManager.getConfiguration().setServiceNodeTypes(serviceNodeTypes);
+ final Map<String, CategoryBaseTypeConfig> serviceBaseNodeTypeConfigMap = new HashMap<>();
+ final var categoryBaseTypeConfig = new CategoryBaseTypeConfig();
+ categoryBaseTypeConfig.setBaseTypes(List.of("org.base.type"));
+ serviceBaseNodeTypeConfigMap.put("serviceCategoryA", categoryBaseTypeConfig);
+ configurationManager.getConfiguration().setServiceBaseNodeTypes(serviceBaseNodeTypeConfigMap);
Map<String, String> genericNodeTypes = new HashMap<>();
genericNodeTypes.put("service", "org.service.default");
@@ -483,7 +489,7 @@ public class ElementOperationTest extends ModelTestBase {
JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME)).thenReturn("org.parent.type");
- List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null);
+ List<BaseType> baseTypes = elementOperation.getServiceBaseTypes("serviceCategoryA", null);
assertEquals(2, baseTypes.size());
assertEquals("org.base.type", baseTypes.get(0).getToscaResourceName());
@@ -491,14 +497,14 @@ public class ElementOperationTest extends ModelTestBase {
assertEquals("1.0", baseTypes.get(0).getVersions().get(0));
assertEquals("org.parent.type", baseTypes.get(1).getToscaResourceName());
} finally {
- configurationManager.getConfiguration().setServiceNodeTypes(preExistingServiceNodeTypes);
+ configurationManager.getConfiguration().setServiceBaseNodeTypes(preExistingServiceNodeTypes);
configurationManager.getConfiguration().setGenericAssetNodeTypes(preExistingGenericNodeTypes);
}
}
@Test
public void testBaseTypes_default() {
- Map<String, List<String>> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
+ Map<String, CategoryBaseTypeConfig> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceBaseNodeTypes();
Map<String, String> preExistingGenericNodeTypes =
configurationManager.getConfiguration().getGenericAssetNodeTypes();
@@ -506,7 +512,7 @@ public class ElementOperationTest extends ModelTestBase {
Map<String, String> genericNodeTypes = new HashMap<>();
genericNodeTypes.put("Service", "org.service.default");
configurationManager.getConfiguration().setGenericAssetNodeTypes(genericNodeTypes);
- configurationManager.getConfiguration().setServiceNodeTypes(null);
+ configurationManager.getConfiguration().setServiceBaseNodeTypes(null);
HealingJanusGraphDao healingJanusGraphDao = mock(HealingJanusGraphDao.class);
final var elementOperation = new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao);
@@ -519,14 +525,60 @@ public class ElementOperationTest extends ModelTestBase {
when(healingJanusGraphDao.getParentVertices(baseTypeVertex, EdgeLabelEnum.DERIVED_FROM,
JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null);
+ List<BaseType> baseTypes = elementOperation.getServiceBaseTypes("serviceCategoryA", null);
assertEquals(1, baseTypes.size());
assertEquals("org.service.default", baseTypes.get(0).getToscaResourceName());
assertEquals(1, baseTypes.get(0).getVersions().size());
} finally {
- configurationManager.getConfiguration().setServiceNodeTypes(preExistingServiceNodeTypes);
+ configurationManager.getConfiguration().setServiceBaseNodeTypes(preExistingServiceNodeTypes);
configurationManager.getConfiguration().setGenericAssetNodeTypes(preExistingGenericNodeTypes);
}
}
+
+ @Test
+ public void testGetServiceBaseTypes_categoryWithRequiredBaseType() {
+ defaultBaseTypeMock();
+ final List<BaseType> actualBaseTypeList = elementOperation.getServiceBaseTypes("CategoryA", null);
+ assertEquals(actualBaseTypeList.size(), 1);
+ final BaseType expectedBaseType = actualBaseTypeList.get(0);
+ assertEquals(expectedBaseType.getToscaResourceName(), "org.openecomp.resource.abstract.nodes.A");
+
+ }
+
+ @Test
+ public void testGetServiceBaseTypes_categoryWithOptionalBaseType() {
+ defaultBaseTypeMock();
+ final List<BaseType> actualBaseTypeList = elementOperation.getServiceBaseTypes("CategoryC", null);
+ assertEquals(actualBaseTypeList.size(), 2);
+ assertEquals(actualBaseTypeList.get(0).getToscaResourceName(), "org.openecomp.resource.abstract.nodes.C1");
+ assertEquals(actualBaseTypeList.get(1).getToscaResourceName(), "org.openecomp.resource.abstract.nodes.C2");
+ }
+
+ @Test
+ public void testGetServiceBaseTypes_categoryWithNoBaseType() {
+ defaultBaseTypeMock();
+ final List<BaseType> actualBaseTypeList = elementOperation.getServiceBaseTypes("CategoryB", null);
+ assertTrue(actualBaseTypeList.isEmpty());
+ }
+
+ @Test
+ public void testGetServiceBaseTypes_notConfiguredCategoryThatFallsBackToGenericType() {
+ defaultBaseTypeMock();
+ final List<BaseType> actualBaseTypeList = elementOperation.getServiceBaseTypes("CategoryD", null);
+
+ assertEquals(actualBaseTypeList.size(), 1);
+ final BaseType expectedBaseType = actualBaseTypeList.get(0);
+ assertEquals(expectedBaseType.getToscaResourceName(), "org.openecomp.resource.abstract.nodes.service");
+ }
+
+ private void defaultBaseTypeMock() {
+ final GraphVertex baseTypeVertex = mock(GraphVertex.class);
+ when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0");
+ when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap(), isNull(), eq(JsonParseFlagEnum.ParseAll), isNull()))
+ .thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
+ when(healingJanusGraphDao.getParentVertices(eq(baseTypeVertex), eq(EdgeLabelEnum.DERIVED_FROM), eq(JsonParseFlagEnum.ParseAll)))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ }
+
}