summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-11-23 21:35:12 +0000
committerMichael Morris <michael.morris@est.tech>2021-11-26 14:49:11 +0000
commitf2eb0c84057d745b8cc7e77a027dcd47122a7a5b (patch)
tree9c0a10e55391637f1d5c3d5a6a945be1d536bd4e /catalog-be/src/test/java/org
parent5a92b1a1a74db13771947f3175682095bd91b7e3 (diff)
Set default base type when none is provided
Sets a default base type (substitution type) when no base type is provided during the creation of a service with a category that requires a base type. Previous to the introduction of the optional base type, the system would always add a base type to a Service. Change-Id: I32e892fc23719fd569062ee806eb0be7b5af4ac6 Issue-ID: SDC-3791 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogicTest.java122
1 files changed, 98 insertions, 24 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogicTest.java
index 11b4fa0556..564e02dca5 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogicTest.java
@@ -21,29 +21,36 @@
*/
package org.openecomp.sdc.be.components.impl.generic;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
-import org.junit.Before;
-import org.junit.Test;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.config.CategoryBaseTypeConfig;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-public class GenericTypeBusinessLogicTest {
+class GenericTypeBusinessLogicTest {
@InjectMocks
private GenericTypeBusinessLogic testInstance;
@@ -54,37 +61,52 @@ public class GenericTypeBusinessLogicTest {
@Mock
private ComponentsUtils componentsUtils;
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
+ @BeforeEach
+ public void setUp() {
+ MockitoAnnotations.openMocks(this);
testInstance = new GenericTypeBusinessLogic(componentsUtils, toscaOperationFacadeMock);
+ final var configurationManager = new ConfigurationManager();
+
+ final var configuration = new Configuration();
+ CategoryBaseTypeConfig categoryBaseTypeConfig1 = new CategoryBaseTypeConfig();
+ categoryBaseTypeConfig1.setRequired(true);
+ CategoryBaseTypeConfig categoryBaseTypeConfig2 = new CategoryBaseTypeConfig();
+ categoryBaseTypeConfig2.setRequired(false);
+ Map<String, CategoryBaseTypeConfig> serviceBaseNodeTypeMap = Map.of(
+ "category1", categoryBaseTypeConfig1,
+ "category2", categoryBaseTypeConfig2
+ );
+ configuration.setServiceBaseNodeTypes(serviceBaseNodeTypeMap);
+ configurationManager.setConfiguration(configuration);
}
@Test
- public void fetchDerivedFromGenericType_cvfv_getGenericResourceTypeFromDerivedFrom() throws Exception {
+ void fetchDerivedFromGenericType_cvfv_getGenericResourceTypeFromDerivedFrom() {
Resource cvfc = new Resource();
cvfc.setResourceType(ResourceTypeEnum.CVFC);
cvfc.setDerivedFrom(Arrays.asList("genericType", "someOtherType"));
cvfc.setDerivedFromGenericType("genericType");
Resource genericResource = new Resource();
- when(toscaOperationFacadeMock.getLatestCertifiedNodeTypeByToscaResourceName("genericType")).thenReturn(Either.left(genericResource));
+ when(toscaOperationFacadeMock.getLatestCertifiedNodeTypeByToscaResourceName(cvfc.getDerivedFromGenericType()))
+ .thenReturn(Either.left(genericResource));
Either<Resource, ResponseFormat> fetchedGenericType = testInstance.fetchDerivedFromGenericType(cvfc);
assertEquals(genericResource, fetchedGenericType.left().value());
}
@Test
- public void fetchDerivedFromGenericType_getGenericResourceTypeFromConfiguration() throws Exception {
- Resource resource = Mockito.mock(Resource.class);
+ void fetchDerivedFromGenericType_getGenericResourceTypeFromConfiguration() {
+ Resource resource = mock(Resource.class);
when(resource.getResourceType()).thenReturn(ResourceTypeEnum.VF);
- when(resource.fetchGenericTypeToscaNameFromConfig()).thenReturn("genericType");
+ final var genericType = "genericType";
+ when(resource.fetchGenericTypeToscaNameFromConfig()).thenReturn(genericType);
Resource genericResource = new Resource();
- when(toscaOperationFacadeMock.getLatestCertifiedNodeTypeByToscaResourceName("genericType")).thenReturn(Either.left(genericResource));
+ when(toscaOperationFacadeMock.getLatestCertifiedNodeTypeByToscaResourceName(genericType)).thenReturn(Either.left(genericResource));
Either<Resource, ResponseFormat> fetchedGenericType = testInstance.fetchDerivedFromGenericType(resource);
assertEquals(genericResource, fetchedGenericType.left().value());
}
@Test
- public void generateInputsFromGenericTypeProperties() throws Exception {
+ void generateInputsFromGenericTypeProperties() {
Resource genericNodeType = new Resource();
genericNodeType.setUniqueId("genericUid");
PropertyDefinition propertyDefinition = generatePropDefinition("prop1");
@@ -99,13 +121,66 @@ public class GenericTypeBusinessLogicTest {
}
@Test
- public void generateInputsFromGenericTypeProperties_genericHasNoProps() throws Exception {
+ void generateInputsFromGenericTypeProperties_genericHasNoProps() {
Resource genericNodeType = new Resource();
assertTrue(testInstance.generateInputsFromGenericTypeProperties(genericNodeType).isEmpty());
}
+ @Test
+ void hasMandatorySubstitutionForServiceTest() {
+ final var component = mock(Component.class);
+ when(component.isService()).thenReturn(true);
+ final var categoryDefinition = new CategoryDefinition();
+ categoryDefinition.setName("category1");
+ when(component.getCategories()).thenReturn(List.of(categoryDefinition));
+ assertTrue(testInstance.hasMandatorySubstitutionType(component));
+ }
+
+ @Test
+ void hasMandatorySubstitutionForServiceWithNotRequiredCategoryTest() {
+ final var component = mock(Component.class);
+ when(component.isService()).thenReturn(true);
+ final var categoryDefinition = new CategoryDefinition();
+ categoryDefinition.setName("category2");
+ when(component.getCategories()).thenReturn(List.of(categoryDefinition));
+ assertFalse(testInstance.hasMandatorySubstitutionType(component));
+ }
+
+ @Test
+ void hasMandatorySubstitutionForServiceWithNotConfiguredCategoryTest() {
+ final var component = mock(Component.class);
+ when(component.isService()).thenReturn(true);
+ final var categoryDefinition = new CategoryDefinition();
+ categoryDefinition.setName("category3");
+ when(component.getCategories()).thenReturn(List.of(categoryDefinition));
+ assertTrue(testInstance.hasMandatorySubstitutionType(component));
+ }
+
+ @Test
+ void hasMandatorySubstitutionForServiceWithNonExistentConfigTest() {
+ final var configurationManager = new ConfigurationManager();
+ configurationManager.setConfiguration(new Configuration());
+ final var component = mock(Component.class);
+ when(component.isService()).thenReturn(true);
+ assertTrue(testInstance.hasMandatorySubstitutionType(component));
+ }
+
+ @Test
+ void hasMandatorySubstitutionServiceMissingCategoryTest() {
+ final Component component = mock(Component.class);
+ when(component.isService()).thenReturn(true);
+ assertThrows(IllegalArgumentException.class, () -> testInstance.hasMandatorySubstitutionType(component));
+ }
+
+ @Test
+ void hasMandatorySubstitutionTypeForNonServiceComponentTest() {
+ final Component component = mock(Component.class);
+ when(component.isService()).thenReturn(false);
+ assertTrue(testInstance.hasMandatorySubstitutionType(component));
+ }
+
private void assertInput(InputDefinition inputDefinition, PropertyDefinition propertyDefinition) {
- assertEquals(inputDefinition.getOwnerId(), "genericUid");
+ assertEquals("genericUid", inputDefinition.getOwnerId());
assertEquals(inputDefinition.getValue(), propertyDefinition.getValue());
assertEquals(inputDefinition.getName(), propertyDefinition.getName());
}
@@ -117,5 +192,4 @@ public class GenericTypeBusinessLogicTest {
return propertyDefinition;
}
-
} \ No newline at end of file