summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java29
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogicTest.java173
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java16
4 files changed, 198 insertions, 28 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
index 336b8ec940..18dc67f752 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
@@ -69,6 +69,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
import org.openecomp.sdc.be.model.tosca.constraints.GreaterOrEqualConstraint;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.tosca.utils.InterfaceTypesNameUtil;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.api.ConfigurationSource;
@@ -203,7 +204,7 @@ public class ResourceImportManagerTest {
testSetRequirments(createResource.left);
}
-
+
@Test
public void testResourceCreationWithInterfaceImplementation() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
@@ -214,7 +215,7 @@ public class ResourceImportManagerTest {
setResourceBusinessLogicMock();
String jsonContent = ImportUtilsTest.loadCustomTypeFileNameToJsonString("custom-types-node-type-with-interface-impl.yml");
-
+
Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>();
final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
@@ -228,7 +229,7 @@ public class ResourceImportManagerTest {
.importNormativeResource(jsonContent, resourceMD, user, true, true);
assertSetInterfaceImplementation(createResource.left);
}
-
+
@Test
public void testResourceCreationWithInterfaceImplementation_UnknownInterface() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
@@ -239,7 +240,7 @@ public class ResourceImportManagerTest {
setResourceBusinessLogicMock();
String jsonContent = ImportUtilsTest.loadCustomTypeFileNameToJsonString("custom-types-node-type-with-unknown-interface-impl.yml");
-
+
Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>();
final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
@@ -252,7 +253,7 @@ public class ResourceImportManagerTest {
ImmutablePair<Resource, ActionStatus> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
assertNull(createResource.left.getInterfaces());
}
-
+
@Test
public void testResourceCreationWitInterfaceImplementation_UnknownOperation() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
@@ -263,7 +264,7 @@ public class ResourceImportManagerTest {
setResourceBusinessLogicMock();
String jsonContent = ImportUtilsTest.loadCustomTypeFileNameToJsonString("custom-types-node-type-with-interface-impl-unknown-operation.yml");
-
+
Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>();
final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
@@ -399,20 +400,16 @@ public class ResourceImportManagerTest {
assertEquals("binding", requirement.getName());
}
-
+
private void assertSetInterfaceImplementation(final Resource resource) {
final Map<String, InterfaceDefinition> interfaces = resource.getInterfaces();
+ assertNotNull(interfaces);
assertEquals(1, interfaces.size());
- assertTrue(interfaces.containsKey("Standard"));
-
final InterfaceDefinition interfaceDefinition = interfaces.get("Standard");
- assertEquals("tosca.interfaces.node.lifecycle.Standard", interfaceDefinition.getType());
- assertEquals("tosca.interfaces.node.lifecycle.standard", interfaceDefinition.getUniqueId());
- final Map<String, OperationDataDefinition> operations = interfaceDefinition.getOperations();
- assertEquals(1, operations.size());
-
- final OperationDataDefinition operation = operations.get("configure");
- assertEquals("'camunda/vnfConfigure'", operation.getImplementation().getArtifactName());
+ assertTrue(interfaces.containsKey(InterfaceTypesNameUtil.buildShortName(interfaceDefinition.getType())));
+ Map<String, OperationDataDefinition> operations = interfaceDefinition.getOperations();
+ operations.values().forEach(operationDataDefinition ->
+ assertTrue(operations.containsKey(operationDataDefinition.getName())));
}
private void testSetDerivedFrom(Resource resource) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogicTest.java
new file mode 100644
index 0000000000..0fd61845e6
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogicTest.java
@@ -0,0 +1,173 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
+import org.openecomp.sdc.be.components.validation.ComponentValidations;
+import org.openecomp.sdc.be.components.validation.UserValidations;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInterface;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+
+@ExtendWith(MockitoExtension.class)
+public class ComponentInterfaceOperationBusinessLogicTest extends BaseBusinessLogicMock {
+
+ @InjectMocks
+ private ComponentInterfaceOperationBusinessLogic componentInterfaceOperationBusinessLogic;
+
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private GraphLockOperation graphLockOperation;
+ @Mock
+ private JanusGraphDao janusGraphDao;
+ @Mock
+ private JanusGraphGenericDao janusGraphGenericDao;
+ @Mock
+ private ComponentsUtils componentsUtils;
+ @Mock
+ private UserValidations userValidations;
+ @Mock
+ private ComponentValidations componentValidations;
+
+ private Component component;
+ private ComponentInstance componentInstance;
+ private ComponentParametersView componentFilter;
+
+ @BeforeEach
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ componentInterfaceOperationBusinessLogic =
+ new ComponentInterfaceOperationBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
+ groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation,
+ componentValidations);
+ componentInterfaceOperationBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
+ componentInterfaceOperationBusinessLogic.setGraphLockOperation(graphLockOperation);
+ componentInterfaceOperationBusinessLogic.setComponentsUtils(componentsUtils);
+ componentInterfaceOperationBusinessLogic.setUserValidations(userValidations);
+ componentInterfaceOperationBusinessLogic.setJanusGraphGenericDao(janusGraphGenericDao);
+ componentInterfaceOperationBusinessLogic.setJanusGraphDao(janusGraphDao);
+
+ initComponentData();
+ }
+
+ @Test
+ public void updateSubstitutionFilterTest() throws BusinessLogicException {
+ final String componentId = component.getUniqueId();
+ final String componentInstanceId = componentInstance.getUniqueId();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
+ interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
+ final Map<String, OperationDataDefinition> operations = new HashMap<>();
+ final OperationDataDefinition operationDataDefinition = new OperationDataDefinition();
+ operationDataDefinition.setUniqueId(UUID.randomUUID().toString());
+ final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
+ artifactDataDefinition.setArtifactName("EO Implementation info");
+ operationDataDefinition.setImplementation(artifactDataDefinition);
+ operations.put("configure", operationDataDefinition);
+ interfaceDefinition.setOperations(operations );
+
+ final ComponentInstanceInterface componentInstanceInterface =
+ new ComponentInstanceInterface("interfaceId", interfaceDefinition);
+ Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap = new HashMap<>();
+ componentInstancesInterfacesMap.put(componentInstanceId, Collections.singletonList(componentInstanceInterface));
+ component.setComponentInstancesInterfaces(componentInstancesInterfacesMap);
+ componentInstance.setInterfaces(
+ (Map<String, Object>) new HashMap<>().put(componentInstanceId, interfaceDefinition));
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
+ when(componentValidations.getComponentInstance(component, componentInstanceId))
+ .thenReturn(Optional.of(componentInstance));
+ when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceInterfaces(component, componentInstanceId))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade
+ .updateComponentInstanceMetadataOfTopologyTemplate(any(Service.class), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(component));
+ when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
+ when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+
+ final Optional<ComponentInstance> result = componentInterfaceOperationBusinessLogic
+ .updateComponentInstanceInterfaceOperation(componentId, componentInstanceId, interfaceDefinition,
+ ComponentTypeEnum.SERVICE, new Wrapper<>(), true);
+ assertThat(result).isPresent();
+ }
+
+ public void initComponentData() {
+ try {
+ component = new Service();
+ component.setName("MyTestService");
+ component.setUniqueId("dac65869-dfb4-40d2-aa20-084324659ec1");
+
+ componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId("dac65869-dfb4-40d2-aa20-084324659ec1.resource0");
+ componentInstance.setOriginType(OriginTypeEnum.VFC);
+ componentInstance.setName("My VFC Instance");
+
+ componentFilter = new ComponentParametersView();
+ componentFilter.disableAll();
+ componentFilter.setIgnoreUsers(false);
+ componentFilter.setIgnoreComponentInstances(false);
+ componentFilter.setIgnoreInterfaces(false);
+ componentFilter.setIgnoreComponentInstancesInterfaces(false);
+
+ } catch (final Exception e) {
+ fail(e.getMessage());
+ }
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
index c83f73b269..548ef1ace9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
@@ -777,8 +777,8 @@ public class InputsBusinessLogicTest {
inputDef.setDefaultValue(NEW_VALUE); // update value
inputDef.setRequired(Boolean.TRUE); // update value
Map<String, String> newMetadata = new HashMap<>();
- newMetadata.put("key1", "value2");
- newMetadata.put("key2", "value3");
+ newMetadata.put("key2", "value2");
+ newMetadata.put("key3", "value3");
inputDef.setMetadata(newMetadata);
newInputDefs.add(inputDef);
@@ -802,8 +802,8 @@ public class InputsBusinessLogicTest {
assertEquals(NEW_VALUE, service.getInputs().get(0).getDefaultValue());
assertEquals(Boolean.TRUE, service.getInputs().get(0).isRequired());
assertEquals(2, service.getInputs().get(0).getMetadata().size());
- assertEquals("value2", service.getInputs().get(0).getMetadata().get("key1"));
- assertEquals("value3", service.getInputs().get(0).getMetadata().get("key2"));
+ assertEquals("value2", service.getInputs().get(0).getMetadata().get("key2"));
+ assertEquals("value3", service.getInputs().get(0).getMetadata().get("key3"));
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
index 4f569f91cd..d4fb60e878 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
@@ -57,6 +57,8 @@ import org.apache.commons.collections4.MapUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.be.DummyConfigurationManager;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
@@ -585,9 +587,6 @@ class InterfacesOperationsConverterTest {
for (Map.Entry<String, Object> inputEntry : inputs.entrySet()) {
String[] inputNameSplit = inputEntry.getKey().split("_");
Map<String, Object> inputValueObject = (Map<String, Object>) inputEntry.getValue();
- assertEquals(inputNameSplit[1], inputValueObject.get("type"));
- Boolean expectedIsRequired = Integer.parseInt(inputNameSplit[2]) % 2 == 0;
- assertEquals(expectedIsRequired, inputValueObject.get("required"));
validateOperationInputDefinitionDefaultValue(interfaceType, operationName, inputNameSplit[1],
Integer.parseInt(inputNameSplit[2]), inputValueObject);
}
@@ -597,15 +596,16 @@ class InterfacesOperationsConverterTest {
private void validateOperationInputDefinitionDefaultValue(String interfaceType, String operationName,
String inputType, int index,
Map<String, Object> inputValueObject) {
- Map<String, Object> mappedInputValue = (Map<String, Object>) inputValueObject.get("default");
- if(mappedInputValue.containsKey(ToscaFunctions.GET_PROPERTY.getFunctionName())) {
+ if (inputValueObject.containsKey(ToscaFunctions.GET_PROPERTY.getFunctionName())) {
String mappedPropertyValue = MAPPED_PROPERTY_NAME + index;
- List<String> mappedPropertyDefaultValue = (List<String>) mappedInputValue.get(ToscaFunctions.GET_PROPERTY.getFunctionName());
+ List<String> mappedPropertyDefaultValue = (List<String>) inputValueObject
+ .get(ToscaFunctions.GET_PROPERTY.getFunctionName());
assertEquals(2, mappedPropertyDefaultValue.size());
assertTrue(mappedPropertyDefaultValue.contains(SELF));
assertTrue(mappedPropertyDefaultValue.contains(mappedPropertyValue));
- } else if(mappedInputValue.containsKey(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName())) {
- List<String> mappedPropertyDefaultValue = (List<String>) mappedInputValue.get(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName());
+ } else if (inputValueObject.containsKey(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName())) {
+ List<String> mappedPropertyDefaultValue = (List<String>) inputValueObject
+ .get(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName());
assertEquals(4, mappedPropertyDefaultValue.size());
String mappedPropertyValue = OUTPUT_NAME_PREFIX + inputType + "_" + index;
assertTrue(mappedPropertyDefaultValue.contains(SELF));