aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java83
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java419
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java7
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java17
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java22
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentAttributeServletTest.java148
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/OutputsServletTest.java263
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java66
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java7
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java38
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OutputConverterTest.java67
11 files changed, 1077 insertions, 60 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
index 891d2c83ca..8a2cdef16e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
@@ -27,14 +27,15 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum.RESOURCE_PARAM_NAME;
import fj.data.Either;
import java.util.ArrayList;
@@ -90,10 +91,10 @@ import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
@@ -1740,7 +1741,7 @@ class ComponentInstanceBusinessLogicTest {
when(containerInstanceTypeData.isAllowedForResourceComponent(eq(ResourceTypeEnum.VF), eq(ResourceTypeEnum.VF)))
.thenReturn(false);
actualException = assertThrows(ByActionStatusComponentException.class, () -> {
- componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.RESOURCE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
+ componentInstanceBusinessLogic.createComponentInstance(RESOURCE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
});
//then
assertThat(actualException.getActionStatus()).isEqualTo(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE);
@@ -1875,14 +1876,85 @@ class ComponentInstanceBusinessLogicTest {
// Check graph db change was committed
verify(janusGraphDao, times(1)).commit();
}
-
+
+ @Test
+ void testGetComponentInstanceAttributesById_success() {
+ final ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute();
+ componentInstanceAttribute.setComponentInstanceId(TO_INSTANCE_ID);
+
+ final HashMap<String, List<ComponentInstanceAttribute>> map = new HashMap<>();
+ map.put(TO_INSTANCE_ID, Arrays.asList(componentInstanceAttribute));
+ resource.setComponentInstancesAttributes(map);
+
+ final Either<Component, StorageOperationStatus> leftServiceOp = Either.left(resource);
+ doReturn(leftServiceOp).when(toscaOperationFacade).getToscaElement(COMPONENT_ID);
+
+ final List<ComponentInstanceAttribute> result = componentInstanceBusinessLogic
+ .getComponentInstanceAttributesById(RESOURCE_PARAM_NAME, COMPONENT_ID, TO_INSTANCE_ID, USER_ID);
+ assertThat(result).isNotNull().isNotEmpty();
+ verify(toscaOperationFacade, times(1)).getToscaElement(COMPONENT_ID);
+ }
+
+ @Test
+ void testGetComponentInstanceAttributesById_fail_missing_ComponentInstancesAttributes() {
+ final Either<Component, StorageOperationStatus> leftServiceOp = Either.left(resource);
+ doReturn(leftServiceOp).when(toscaOperationFacade).getToscaElement(COMPONENT_ID);
+
+ final List<ComponentInstanceAttribute> result = componentInstanceBusinessLogic
+ .getComponentInstanceAttributesById(RESOURCE_PARAM_NAME, COMPONENT_ID, TO_INSTANCE_ID, USER_ID);
+ assertThat(result).isNotNull().isEmpty();
+ verify(toscaOperationFacade, times(1)).getToscaElement(COMPONENT_ID);
+ }
+
+ @Test
+ void testGetComponentInstanceAttributesById_fail_getToscaElement() {
+ final ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute();
+ componentInstanceAttribute.setComponentInstanceId(TO_INSTANCE_ID);
+
+ final HashMap<String, List<ComponentInstanceAttribute>> map = new HashMap<>();
+ map.put(TO_INSTANCE_ID, Arrays.asList(componentInstanceAttribute));
+ resource.setComponentInstancesAttributes(map);
+
+ final Either<Object, StorageOperationStatus> right = Either.right(StorageOperationStatus.BAD_REQUEST);
+ doReturn(right).when(toscaOperationFacade).getToscaElement(COMPONENT_ID);
+ doReturn(ActionStatus.BAD_REQUEST_MISSING_RESOURCE).when(componentsUtils).convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST);
+
+ assertThrows(ByActionStatusComponentException.class, () -> {
+ final List<ComponentInstanceAttribute> result = componentInstanceBusinessLogic
+ .getComponentInstanceAttributesById(RESOURCE_PARAM_NAME, COMPONENT_ID, TO_INSTANCE_ID, USER_ID);
+
+ });
+
+ }
+
+ @Test
+ void testGetComponentInstanceAttributesById_fail_getResourceInstanceById() {
+ final ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute();
+ componentInstanceAttribute.setComponentInstanceId(TO_INSTANCE_ID);
+
+ final HashMap<String, List<ComponentInstanceAttribute>> map = new HashMap<>();
+ map.put(TO_INSTANCE_ID, Arrays.asList(componentInstanceAttribute));
+ resource.setComponentInstancesAttributes(map);
+
+ final Either<Component, StorageOperationStatus> leftServiceOp = Either.left(resource);
+ doReturn(leftServiceOp).when(toscaOperationFacade).getToscaElement(COMPONENT_ID);
+ doReturn(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE).when(componentsUtils).convertFromStorageResponse(StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND);
+
+ assertThrows(ByActionStatusComponentException.class, () -> {
+ final List<ComponentInstanceAttribute> result = componentInstanceBusinessLogic
+ .getComponentInstanceAttributesById(RESOURCE_PARAM_NAME, COMPONENT_ID, "", USER_ID);
+
+ });
+
+ }
+
private ComponentInstance createServiceSubstitutionComponentInstance() {
final ComponentInstance instanceToBeCreated = new ComponentInstance();
instanceToBeCreated.setName(COMPONENT_INSTANCE_NAME);
instanceToBeCreated.setUniqueId(COMPONENT_INSTANCE_ID);
instanceToBeCreated.setComponentUid(ORIGIN_COMPONENT_ID);
instanceToBeCreated.setOriginType(OriginTypeEnum.ServiceSubstitution);
-
+
return instanceToBeCreated;
}
@@ -1896,7 +1968,6 @@ class ComponentInstanceBusinessLogicTest {
return originComponent;
}
-
private Component createServiceSubstitutionServiceDerivedFromComponent() {
final Resource component = new Resource();
component.setLifecycleState(LifecycleStateEnum.CERTIFIED);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java
new file mode 100644
index 0000000000..4c74b5f640
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java
@@ -0,0 +1,419 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021, Nordix Foundation. 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.components.impl;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.attribute.AttributeDeclarationOrchestrator;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
+import org.openecomp.sdc.be.components.validation.UserValidations;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstOutputsMap;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceOutput;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribOutput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.OutputDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.AttributeOperation;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+class OutputsBusinessLogicTest {
+
+ private static final String COMPONENT_INSTANCE_ID = "instanceId";
+ private static final String COMPONENT_ID = "componentId";
+ private static final String USER_ID = "userId";
+ private static final String OUTPUT_ID = "outputId";
+ private static final String OUTPUT_TYPE = "string";
+ private static final String LISTOUTPUT_NAME = "listOutput";
+ private static final String LISTOUTPUT_SCHEMA_TYPE = "org.onap.datatypes.listoutput";
+ private static final String LISTOUTPUT_PROP1_NAME = "prop1";
+ private static final String LISTOUTPUT_PROP1_TYPE = "string";
+ private static final String LISTOUTPUT_PROP2_NAME = "prop2";
+ private static final String LISTOUTPUT_PROP2_TYPE = "integer";
+ private static final String OLD_VALUE = "old value";
+ private static final String NEW_VALUE = "new value";
+ private final ConfigurationManager configurationManager =
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+
+ @Mock
+ private ComponentsUtils componentsUtilsMock;
+
+ @Mock
+ private UserBusinessLogic userAdminMock;
+
+ @Mock
+ private ToscaOperationFacade toscaOperationFacadeMock;
+
+ @Mock
+ private UserValidations userValidations;
+
+ @Mock
+ private IGraphLockOperation graphLockOperation;
+
+ @Mock
+ private AttributeDeclarationOrchestrator attributeDeclarationOrchestrator;
+
+ @Mock
+ private ApplicationDataTypeCache applicationDataTypeCache;
+
+ @Mock
+ private AttributeOperation attributeOperation;
+
+ @Mock
+ private JanusGraphDao janusGraphDao;
+
+ @InjectMocks
+ private OutputsBusinessLogic testInstance;
+
+ private Service service;
+
+ private Map<String, List<ComponentInstanceOutput>> instanceOutputMap;
+ private List<ComponentInstanceOutput> outputsList;
+
+ @BeforeEach
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ service = new Service();
+ service.setUniqueId(COMPONENT_ID);
+ service.setLastUpdaterUserId(USER_ID);
+ service.setIsDeleted(false);
+ service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+
+ testInstance.setUserValidations(userValidations);
+ testInstance.setToscaOperationFacade(toscaOperationFacadeMock);
+ testInstance.setGraphLockOperation(graphLockOperation);
+ testInstance.setComponentsUtils(componentsUtilsMock);
+ testInstance.setJanusGraphDao(janusGraphDao);
+ testInstance.setApplicationDataTypeCache(applicationDataTypeCache);
+ testInstance.setAttributeOperation(attributeOperation);
+
+ // add a ComponentInstance
+ final ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(COMPONENT_INSTANCE_ID);
+ service.setComponentInstances(Collections.singletonList(componentInstance));
+
+ instanceOutputMap = new HashMap<>();
+ final ComponentInstanceOutput componentInstanceOutput = new ComponentInstanceOutput();
+ componentInstanceOutput.setOutputId(OUTPUT_ID);
+ componentInstanceOutput.setName(OUTPUT_ID);
+ outputsList = Collections.singletonList(componentInstanceOutput);
+ instanceOutputMap.put(COMPONENT_INSTANCE_ID, outputsList);
+ instanceOutputMap.put("someOutputId", Collections.singletonList(new ComponentInstanceOutput()));
+ service.setComponentInstancesOutputs(instanceOutputMap);
+ when(userValidations.validateUserExists(USER_ID)).thenReturn(new User());
+ when(userAdminMock.getUser(USER_ID, false)).thenReturn(new User());
+ }
+
+ @Test
+ void getComponentInstanceOutputs_ComponentInstanceNotExist() {
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ final Either<List<ComponentInstanceOutput>, ResponseFormat> componentInstanceOutputs = testInstance
+ .getComponentInstanceOutputs(USER_ID, COMPONENT_ID, "nonExisting");
+ assertThat(componentInstanceOutputs.isRight()).isTrue();
+ verify(componentsUtilsMock).getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND);
+ }
+
+ @Test
+ void getComponentInstanceOutputs_emptyOutputsMap() {
+ service.setComponentInstancesOutputs(Collections.emptyMap());
+ getComponents_emptyOutputs(service);
+ }
+
+ @Test
+ void getComponentInstanceOutputs_nullOutputsMap() {
+ service.setComponentInstancesOutputs(null);
+ getComponents_emptyOutputs(service);
+ }
+
+ @Test
+ void getComponentInstanceOutputs_instanceHasNoOutputs() {
+ service.setComponentInstancesOutputs(Collections.singletonMap("someOutputId", new ArrayList<>()));
+ getComponents_emptyOutputs(service);
+ }
+
+ @Test
+ void getComponentInstanceOutputs() {
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ final Either<List<ComponentInstanceOutput>, ResponseFormat> componentInstanceOutputs = testInstance
+ .getComponentInstanceOutputs(USER_ID, COMPONENT_ID, COMPONENT_INSTANCE_ID);
+ assertEquals("outputId", componentInstanceOutputs.left().value().get(0).getOutputId());
+ }
+
+ @Test
+ void testDeclareAttributes() {
+ service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ service.setLastUpdaterUserId(USER_ID);
+ final ComponentInstOutputsMap componentInstOutputsMap = new ComponentInstOutputsMap();
+ final Map<String, List<ComponentInstanceAttribOutput>> propertiesForDeclaration = new HashMap<>();
+ propertiesForDeclaration.put(COMPONENT_ID, getPropertiesListForDeclaration());
+
+ final List<OutputDefinition> declaredPropertiesToOutputs = getDeclaredProperties();
+ initMockitoStubbings(declaredPropertiesToOutputs);
+
+ final Either<List<OutputDefinition>, ResponseFormat> declaredPropertiesEither =
+ testInstance.declareAttributes(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, componentInstOutputsMap);
+
+ assertThat(declaredPropertiesEither.isLeft()).isTrue();
+
+ final List<OutputDefinition> declaredProperties = declaredPropertiesEither.left().value();
+ assertThat(CollectionUtils.isNotEmpty(declaredProperties)).isTrue();
+ assertEquals(1, declaredProperties.size());
+ assertEquals(declaredProperties, declaredPropertiesToOutputs);
+ }
+
+ @Test
+ void testDeclareAttributes_fail() {
+ service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ service.setLastUpdaterUserId(USER_ID);
+ final ComponentInstOutputsMap componentInstOutputsMap = new ComponentInstOutputsMap();
+ final Map<String, List<ComponentInstanceAttribOutput>> propertiesForDeclaration = new HashMap<>();
+ propertiesForDeclaration.put(COMPONENT_ID, getPropertiesListForDeclaration());
+
+ final List<OutputDefinition> declaredPropertiesToOutputs = getDeclaredProperties();
+ initMockitoStubbings(declaredPropertiesToOutputs);
+ when(attributeDeclarationOrchestrator.declareAttributesToOutputs(any(), any())).thenThrow(ByResponseFormatComponentException.class);
+ final Either<List<OutputDefinition>, ResponseFormat> declaredPropertiesEither =
+ testInstance.declareAttributes(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, componentInstOutputsMap);
+
+ assertThat(declaredPropertiesEither.isRight()).isTrue();
+
+ }
+
+ private void initMockitoStubbings(List<OutputDefinition> declaredPropertiesToOutputs) {
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(
+ Either.left(service));
+ when(attributeDeclarationOrchestrator.declareAttributesToOutputs(any(), any())).thenReturn(Either.left(
+ declaredPropertiesToOutputs));
+ when(toscaOperationFacadeMock.addOutputsToComponent(any(), any())).thenReturn(Either.left(declaredPropertiesToOutputs));
+ when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
+ when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
+ when(graphLockOperation.unlockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
+ }
+
+ private void getComponents_emptyOutputs(Service service) {
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ final Either<List<ComponentInstanceOutput>, ResponseFormat> componentInstanceOutputs = testInstance
+ .getComponentInstanceOutputs(USER_ID, COMPONENT_ID, COMPONENT_INSTANCE_ID);
+ assertEquals(Collections.emptyList(), componentInstanceOutputs.left().value());
+ }
+
+ private List<ComponentInstanceAttribOutput> getPropertiesListForDeclaration() {
+ return outputsList.stream().map(this::getPropertyForDeclaration).collect(Collectors.toList());
+ }
+
+ private ComponentInstanceAttribOutput getPropertyForDeclaration(ComponentInstanceOutput componentInstanceOutput) {
+ final ComponentInstanceAttribOutput propOutput = new ComponentInstanceAttribOutput();
+ propOutput.setOutput(componentInstanceOutput);
+ propOutput.setAttributesName(componentInstanceOutput.getName());
+
+ return propOutput;
+ }
+
+ private List<OutputDefinition> getDeclaredProperties() {
+ return outputsList.stream().map(OutputDefinition::new).collect(Collectors.toList());
+ }
+
+ private OutputDefinition setUpListOutput() {
+ final OutputDefinition listOutput = new OutputDefinition();
+ listOutput.setName(LISTOUTPUT_NAME);
+ listOutput.setType("list");
+ return listOutput;
+ }
+
+ @Test
+ void test_deleteOutput_listOutput_fail_getComponent() throws Exception {
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(componentsUtilsMock.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND)).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
+
+ try {
+ testInstance.deleteOutput(COMPONENT_ID, USER_ID, LISTOUTPUT_NAME);
+ } catch (ComponentException e) {
+ assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
+ verify(toscaOperationFacadeMock, times(1)).getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class));
+ return;
+ }
+ fail();
+ }
+
+ @Test
+ void test_deleteOutput_listOutput_fail_validateOutput() throws Exception {
+ final OutputDefinition listOutput = setUpListOutput();
+ final String outputId = COMPONENT_ID + "." + listOutput.getName();
+ listOutput.setUniqueId(outputId);
+ service.setOutputs(Collections.singletonList(listOutput));
+ final String NONEXIST_OUTPUT_NAME = "myOutput";
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+
+ try {
+ testInstance.deleteOutput(COMPONENT_ID, USER_ID, NONEXIST_OUTPUT_NAME);
+ } catch (ComponentException e) {
+ assertEquals(ActionStatus.OUTPUT_IS_NOT_CHILD_OF_COMPONENT, e.getActionStatus());
+ verify(toscaOperationFacadeMock, times(1)).getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class));
+ return;
+ }
+ fail();
+ }
+
+ @Test
+ void test_deleteOutput_listOutput_fail_lockComponent() throws Exception {
+ final OutputDefinition listOutput = setUpListOutput();
+ final String outputId = COMPONENT_ID + "." + listOutput.getName();
+ listOutput.setUniqueId(outputId);
+ service.setOutputs(Collections.singletonList(listOutput));
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.NOT_FOUND);
+ when(componentsUtilsMock.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.SERVICE))
+ .thenReturn(ActionStatus.SERVICE_NOT_FOUND);
+
+ try {
+ testInstance.deleteOutput(COMPONENT_ID, USER_ID, outputId);
+ } catch (ComponentException e) {
+ assertEquals(ActionStatus.SERVICE_NOT_FOUND, e.getActionStatus());
+ verify(toscaOperationFacadeMock, times(1)).getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class));
+ verify(graphLockOperation, times(1)).lockComponent(COMPONENT_ID, NodeTypeEnum.Service);
+ return;
+ }
+ fail();
+ }
+
+ @Test
+ void test_deleteOutput_listOutput_fail_deleteOutput() throws Exception {
+ final OutputDefinition listOutput = setUpListOutput();
+ final String outputId = COMPONENT_ID + "." + listOutput.getName();
+ listOutput.setUniqueId(outputId);
+ service.setOutputs(Collections.singletonList(listOutput));
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.deleteOutputOfResource(service, listOutput.getName())).thenReturn(StorageOperationStatus.BAD_REQUEST);
+ when(componentsUtilsMock.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST)).thenReturn(ActionStatus.INVALID_CONTENT);
+
+ try {
+ testInstance.deleteOutput(COMPONENT_ID, USER_ID, outputId);
+ } catch (ComponentException e) {
+ assertEquals(ActionStatus.INVALID_CONTENT, e.getActionStatus());
+ verify(toscaOperationFacadeMock, times(1)).getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class));
+ verify(graphLockOperation, times(1)).lockComponent(COMPONENT_ID, NodeTypeEnum.Service);
+ verify(toscaOperationFacadeMock, times(1)).deleteOutputOfResource(service, listOutput.getName());
+ return;
+ }
+ fail();
+ }
+
+ @Test
+ void test_deleteOutput_output_fail_unDeclare() throws Exception {
+ final OutputDefinition listOutput = setUpListOutput();
+ final String outputId = COMPONENT_ID + "." + listOutput.getName();
+ listOutput.setUniqueId(outputId);
+ service.setOutputs(Collections.singletonList(listOutput));
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.deleteOutputOfResource(service, listOutput.getName())).thenReturn(StorageOperationStatus.OK);
+ when(attributeDeclarationOrchestrator.unDeclareAttributesAsOutputs(service, listOutput)).thenReturn(StorageOperationStatus.BAD_REQUEST);
+ when(componentsUtilsMock.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST)).thenReturn(ActionStatus.INVALID_CONTENT);
+
+ try {
+ testInstance.deleteOutput(COMPONENT_ID, USER_ID, outputId);
+ } catch (ComponentException e) {
+ assertEquals(ActionStatus.INVALID_CONTENT, e.getActionStatus());
+ verify(attributeDeclarationOrchestrator, times(1)).unDeclareAttributesAsOutputs(service, listOutput);
+ return;
+ }
+ fail();
+ }
+
+ @Test
+ void test_deleteOutput_output_success() throws Exception {
+ final OutputDefinition listOutput = setUpListOutput();
+ final String outputId = COMPONENT_ID + "." + listOutput.getName();
+ listOutput.setUniqueId(outputId);
+ service.setOutputs(Collections.singletonList(listOutput));
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.deleteOutputOfResource(service, listOutput.getName())).thenReturn(StorageOperationStatus.OK);
+ when(attributeDeclarationOrchestrator.unDeclareAttributesAsOutputs(service, listOutput)).thenReturn(StorageOperationStatus.OK);
+
+ testInstance.deleteOutput(COMPONENT_ID, USER_ID, outputId);
+ verify(attributeDeclarationOrchestrator, times(1)).unDeclareAttributesAsOutputs(service, listOutput);
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index d219347fc4..09f4ac72de 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -241,7 +241,7 @@ public class ResourceBusinessLogicTest {
user.setRole(Role.ADMIN.name());
when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
- when(userValidations.validateUserExists(eq(user.getUserId()))).thenReturn(user);
+ when(userValidations.validateUserExists(user.getUserId())).thenReturn(user);
when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(user);
// Servlet Context attributes
when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
@@ -1620,7 +1620,7 @@ public class ResourceBusinessLogicTest {
assertThat(createOrUpdateResource).isNotNull();
Mockito.verify(toscaOperationFacade, times(1))
- .createToscaComponent(eq(resourceToUpdtae));
+ .createToscaComponent(resourceToUpdtae);
Mockito.verify(toscaOperationFacade, Mockito.times(0))
.overrideComponent(any(Resource.class), any(Resource.class));
Mockito.verify(lifecycleBl, Mockito.times(0))
@@ -1663,7 +1663,7 @@ public class ResourceBusinessLogicTest {
assertThat(createOrUpdateResource).isNotNull();
Mockito.verify(toscaOperationFacade, times(1))
- .createToscaComponent(eq(resourceToUpdate));
+ .createToscaComponent(resourceToUpdate);
Mockito.verify(toscaOperationFacade, times(0))
.overrideComponent(any(Resource.class), any(Resource.class));
Mockito.verify(lifecycleBl, times(0))
@@ -2187,6 +2187,7 @@ public class ResourceBusinessLogicTest {
Resource resource = getResourceWithType("HEAT_VOL", "org.openecomp.groups.VfModule");
resource.setGroups(null);
bl.updateVolumeGroup(resource);
+ assertThat(resource.getGroups()).isNull();
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java
index 0c6ba53491..0dad76ebfe 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ComponentBuilder.java
@@ -30,6 +30,7 @@ import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
@@ -132,6 +133,22 @@ public abstract class ComponentBuilder<T extends Component, B extends ComponentB
return self();
}
+ public ComponentBuilder<T, B> addOutput(final OutputDefinition output) {
+ if (component.getOutputs() == null) {
+ component.setOutputs(new ArrayList<>());
+ }
+ component.getOutputs().add(output);
+ return self();
+ }
+
+ public ComponentBuilder<T, B> addOutput(final String outputName) {
+ final OutputDefinition outputDefinition = new OutputDefinition();
+ outputDefinition.setName(outputName);
+ outputDefinition.setUniqueId(outputName);
+ this.addOutput(outputDefinition);
+ return self();
+ }
+
public ComponentBuilder<T, B> addInstanceProperty(String instanceId, ComponentInstanceProperty prop) {
if (component.getComponentInstancesProperties() == null) {
component.setComponentInstancesProperties(new HashMap<>());
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
index ffe3d06e2a..f163b51f66 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
@@ -48,6 +48,7 @@ import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
@@ -61,6 +62,7 @@ public class UiComponentDataConverterTest {
private PolicyDefinition policy1, policy2;
private GroupDefinition group1, group2;
private InputDefinition input1;
+ private OutputDefinition output;
private PropertyDefinition propertyDef;
private InterfaceDefinition interfaceDef;
@@ -149,6 +151,7 @@ public class UiComponentDataConverterTest {
public void getUiDataTransferFromResourceByParams_All() {
Resource resourceWithGroups = buildResourceWithGroups();
Resource resourceWithInputs = buildResourceWithInputs();
+ Resource resourceWithOutputs = buildResourceWithOutputs();
UiComponentDataTransfer componentDTO1 = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resourceWithGroups, Collections.singletonList("PROPERTIES"));
UiComponentDataTransfer componentDTO2 = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resourceWithGroups, Collections.singletonList("properties"));
@@ -160,6 +163,7 @@ public class UiComponentDataConverterTest {
UiComponentDataTransfer componentDTO8 = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resourceWithGroups, Collections.singletonList("inputs"));
UiComponentDataTransfer componentDTO81 = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resourceWithInputs, Collections.singletonList("inputs"));
+ UiComponentDataTransfer componentDTO82 = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resourceWithOutputs, Collections.singletonList("outputs"));
UiComponentDataTransfer componentDTO9 = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resourceWithGroups, Collections.singletonList("users"));
UiComponentDataTransfer componentDTO10 = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resourceWithGroups, Collections.singletonList("componentInstances"));
@@ -202,7 +206,7 @@ public class UiComponentDataConverterTest {
@Test
public void getUiDataTransferFromServiceByParams_METADATA() {
UiServiceDataTransfer componentDTO = (UiServiceDataTransfer) uiComponentDataConverter.getUiDataTransferFromServiceByParams(new Service(), Collections.singletonList("metadata"));
- assertThat(componentDTO.getMetadata().getNamingPolicy()).isEqualTo("");
+ assertThat(componentDTO.getMetadata().getNamingPolicy()).isEmpty();
}
@Test
@@ -348,22 +352,30 @@ public class UiComponentDataConverterTest {
.build();
}
- private Resource buildResourceWithParameter(String field) {
- ResourceBuilder res = new ResourceBuilder();
+ private Resource buildResourceWithOutputs() {
+ return new ResourceBuilder()
+ .addOutput(output)
+ .build();
+ }
+
+ private Resource buildResourceWithParameter(final String field) {
+ final ResourceBuilder res = new ResourceBuilder();
switch(field){
case "inputs":
res.addInput(input1);
break;
+ case "outputs":
+ res.addOutput(output);
+ break;
case "properties":
//res.addProperty(propertyDef);
break;
}
-
-
return new ResourceBuilder()
.addInput(input1)
+ .addOutput(output)
.build();
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentAttributeServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentAttributeServletTest.java
new file mode 100644
index 0000000000..123ef9a5ec
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentAttributeServletTest.java
@@ -0,0 +1,148 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021, Nordix Foundation. 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.servlets;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.Arrays;
+import java.util.List;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.core.Response;
+import org.assertj.core.api.Assertions;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+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.Spy;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.components.impl.AttributeBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.AttributeDefinition;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.web.context.WebApplicationContext;
+
+@ExtendWith(MockitoExtension.class)
+class ComponentAttributeServletTest extends JerseySpringBaseTest {
+
+ @Mock
+ private ServletContext context;
+ @Mock
+ private WebAppContextWrapper wrapper;
+ @Mock
+ private WebApplicationContext webAppContext;
+ @Mock
+ private HttpSession session;
+ @Mock
+ private AttributeBusinessLogic attributeBusinessLogic;
+ @Mock
+ private ComponentsUtils componentsUtils;
+ @InjectMocks
+ @Spy
+ private ComponentAttributeServlet componentAttributeServlet;
+
+ private static final String SERVICE_ID = "service1";
+ private static final String RESOURCE_ID = "resource1";
+ private static final String USER_ID = "jh0003";
+ private static final String VALID_PROPERTY_NAME = "valid_name_123";
+ private static final String INVALID_PROPERTY_NAME = "invalid_name_$.&";
+ private static final String STRING_TYPE = "string";
+
+ @BeforeEach
+ public void initClass() throws Exception {
+ super.setUp();
+ when(request.getSession()).thenReturn(session);
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ @Test
+ void getAttributeListInService_success() {
+ AttributeDefinition attributeDefinition = new AttributeDefinition();
+ attributeDefinition.setName(VALID_PROPERTY_NAME);
+ attributeDefinition.setType(STRING_TYPE);
+
+ List<AttributeDefinition> attributeDefinitionEntryData = Arrays.asList(attributeDefinition);
+ when(attributeBusinessLogic.getAttributesList(any(), any())).thenReturn(Either.left(attributeDefinitionEntryData));
+
+ Response attributeInService = componentAttributeServlet.getAttributeListInService(SERVICE_ID, request, USER_ID);
+
+ Assert.assertEquals(HttpStatus.OK_200.getStatusCode(), attributeInService.getStatus());
+ }
+
+ @Test
+ void getAttributeListInService_fail() {
+ when(attributeBusinessLogic.getAttributesList(any(), any()))
+ .thenReturn(Either.right(new ResponseFormat(Response.Status.NOT_FOUND.getStatusCode())));
+
+ Response attributeInService = componentAttributeServlet.getAttributeListInService(SERVICE_ID, request, USER_ID);
+
+ Assertions.assertThat(attributeInService).isNotNull();
+ Assertions.assertThat(attributeInService.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode());
+ }
+
+ @Test
+ void getAttributeListInResource_success() {
+ AttributeDefinition attributeDefinition = new AttributeDefinition();
+ attributeDefinition.setName(VALID_PROPERTY_NAME);
+ attributeDefinition.setType(STRING_TYPE);
+
+ List<AttributeDefinition> attributeDefinitionEntryData = Arrays.asList(attributeDefinition);
+ when(attributeBusinessLogic.getAttributesList(any(), any())).thenReturn(Either.left(attributeDefinitionEntryData));
+ when(attributeBusinessLogic.getAttributesList(any(), any())).thenReturn(Either.left(attributeDefinitionEntryData));
+
+ Response attributeInService =
+ componentAttributeServlet.getAttributeListInResource(RESOURCE_ID, request, USER_ID);
+
+ Assert.assertEquals(HttpStatus.OK_200.getStatusCode(), attributeInService.getStatus());
+ }
+
+ @Test
+ void getAttributeListInResource_fail() {
+ when(session.getServletContext()).thenReturn(context);
+ when(context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(wrapper);
+ when(wrapper.getWebAppContext(any())).thenReturn(webAppContext);
+ when(webAppContext.getBean(ComponentsUtils.class)).thenReturn(componentsUtils);
+ when(attributeBusinessLogic.getAttributesList(any(), any())).thenThrow(new RuntimeException());
+
+ ResponseFormat responseFormat = new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode());
+
+ when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(responseFormat);
+
+ Response attributeInService = componentAttributeServlet.getAttributeListInResource(SERVICE_ID, request, USER_ID);
+
+ Assertions.assertThat(attributeInService).isNotNull();
+ Assertions.assertThat(attributeInService.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/OutputsServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/OutputsServletTest.java
new file mode 100644
index 0000000000..6b0cf70ecb
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/OutputsServletTest.java
@@ -0,0 +1,263 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021, Nordix Foundation. 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.servlets;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum.RESOURCE;
+
+import fj.data.Either;
+import java.util.ArrayList;
+import java.util.List;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import org.assertj.core.api.Assertions;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestInstance.Lifecycle;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.OutputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.config.SpringConfig;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ComponentInstOutputsMap;
+import org.openecomp.sdc.be.model.OutputDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
+
+@TestInstance(Lifecycle.PER_CLASS)
+class OutputsServletTest extends JerseyTest {
+
+ private static final String USER_ID = "jh0003";
+ private static final String COMPONENT_ID = "componentId";
+ private static final String RESOURCES = "resources";
+ private static final String COMPONENT_INST_OUTPUTS_MAP_OBJ = "componentInstOutputsMapObj";
+ private static final String OUTPUT_ID = "outputId";
+ private static final String INSTANCE_ID = "instanceId";
+ private static final String COMPONENT_UID = "originComponentUid";
+
+ private final UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class);
+ private final OutputsBusinessLogic outputsBusinessLogic = mock(OutputsBusinessLogic.class);
+ private final ComponentInstanceBusinessLogic componentInstanceBL = mock(ComponentInstanceBusinessLogic.class);
+ private final HttpSession httpSession = mock(HttpSession.class);
+ private final ServletContext servletContext = mock(ServletContext.class);
+ private final WebApplicationContext webApplicationContext = mock(WebApplicationContext.class);
+ private final ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
+ private final ServletUtils servletUtils = mock(ServletUtils.class);
+ private final ResourceImportManager resourceImportManager = mock(ResourceImportManager.class);
+ private final HttpServletRequest request = mock(HttpServletRequest.class);
+ private final WebAppContextWrapper wrapper = mock(WebAppContextWrapper.class);
+
+ @Override
+ @BeforeEach
+ public void setUp() throws Exception {
+ super.setUp();
+ when(request.getSession()).thenReturn(httpSession);
+ when(httpSession.getServletContext()).thenReturn(servletContext);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(wrapper);
+ when(wrapper.getWebAppContext(any())).thenReturn(webApplicationContext);
+ when(webApplicationContext.getBean(OutputsBusinessLogic.class)).thenReturn(outputsBusinessLogic);
+ when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ @Test
+ void test_getComponentInstanceOutputs_success() {
+ final Either<List<OutputDefinition>, ResponseFormat> listResponseFormatEither = Either.left(new ArrayList<>());
+ doReturn(listResponseFormatEither).when(outputsBusinessLogic).getComponentInstanceOutputs(USER_ID, COMPONENT_ID, INSTANCE_ID);
+
+ final ResponseFormat responseFormat = new ResponseFormat(HttpStatus.OK_200.getStatusCode());
+ doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.OK);
+
+ final OutputsServlet outputsServlet = createTestObject();
+ Assertions.assertThat(outputsServlet).isNotNull();
+
+ final Response response = outputsServlet.getComponentInstanceOutputs(RESOURCES, COMPONENT_ID, INSTANCE_ID, COMPONENT_UID, request, USER_ID);
+ Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
+ verify(componentsUtils, times(2)).getResponseFormat(ActionStatus.OK);
+ }
+
+ @Test
+ void test_getComponentInstanceOutputs_isRight() {
+ final ResponseFormat responseFormat = new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ final Either<Object, ResponseFormat> right = Either.right(responseFormat);
+ doReturn(right).when(outputsBusinessLogic).getComponentInstanceOutputs(USER_ID, COMPONENT_ID, INSTANCE_ID);
+
+ doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.GENERAL_ERROR);
+
+ final OutputsServlet outputsServlet = createTestObject();
+ Assertions.assertThat(outputsServlet).isNotNull();
+
+ final Response response = outputsServlet.getComponentInstanceOutputs(RESOURCES, COMPONENT_ID, INSTANCE_ID, COMPONENT_UID, request, USER_ID);
+ Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ verify(componentsUtils, times(0)).getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+
+ @Test
+ void test_getComponentInstanceOutputs_fail() {
+ final ResponseFormat responseFormat = new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ final Either<Object, ResponseFormat> right = Either.right(responseFormat);
+ doReturn(right).when(outputsBusinessLogic).getComponentInstanceOutputs(USER_ID, COMPONENT_ID, INSTANCE_ID);
+
+ doThrow(new RuntimeException()).when(componentsUtils).getResponseFormat(ActionStatus.GENERAL_ERROR);
+
+ final OutputsServlet outputsServlet = createTestObject();
+ Assertions.assertThat(outputsServlet).isNotNull();
+
+ final Response response = outputsServlet.getComponentInstanceOutputs(RESOURCES, COMPONENT_ID, INSTANCE_ID, COMPONENT_UID, request, USER_ID);
+ Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ verify(componentsUtils, times(0)).getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+
+ @Test
+ void test_createMultipleOutputs_success() {
+ final ComponentInstOutputsMap componentInstOutputsMap = new ComponentInstOutputsMap();
+ final Either<ComponentInstOutputsMap, ResponseFormat> left = Either.left(componentInstOutputsMap);
+
+ doReturn(left).when(componentsUtils)
+ .convertJsonToObjectUsingObjectMapper(any(String.class), any(User.class), eq(ComponentInstOutputsMap.class),
+ eq(AuditingActionEnum.CREATE_RESOURCE), eq(RESOURCE));
+ final Either<List<OutputDefinition>, ResponseFormat> listResponseFormatEither = Either.left(new ArrayList<>());
+ doReturn(listResponseFormatEither).when(outputsBusinessLogic).declareAttributes(USER_ID, COMPONENT_ID, RESOURCE, componentInstOutputsMap);
+
+ final ResponseFormat responseFormat = new ResponseFormat(HttpStatus.OK_200.getStatusCode());
+ doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.OK);
+
+ final OutputsServlet outputsServlet = createTestObject();
+ Assertions.assertThat(outputsServlet).isNotNull();
+
+ final Response response = outputsServlet.createMultipleOutputs(RESOURCES, COMPONENT_ID, request, USER_ID, COMPONENT_INST_OUTPUTS_MAP_OBJ);
+ Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
+ verify(componentsUtils, times(3)).getResponseFormat(ActionStatus.OK);
+ }
+
+ @Test
+ void test_createMultipleOutputs_isRight() {
+ final ResponseFormat responseFormat = new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ final Either<Object, ResponseFormat> right = Either.right(responseFormat);
+ doReturn(right).when(outputsBusinessLogic).declareAttributes(USER_ID, COMPONENT_ID, RESOURCE, new ComponentInstOutputsMap());
+
+ doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.GENERAL_ERROR);
+
+ final OutputsServlet outputsServlet = createTestObject();
+ Assertions.assertThat(outputsServlet).isNotNull();
+
+ final Response response = outputsServlet.createMultipleOutputs(RESOURCES, COMPONENT_ID, request, USER_ID, COMPONENT_INST_OUTPUTS_MAP_OBJ);
+ Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ verify(componentsUtils, times(3)).getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+
+ @Test
+ void test_createMultipleOutputs_fail() {
+ final ResponseFormat responseFormat = new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ doThrow(new RuntimeException()).when(outputsBusinessLogic).declareAttributes(USER_ID, COMPONENT_ID, RESOURCE, new ComponentInstOutputsMap());
+
+ doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.GENERAL_ERROR);
+
+ final OutputsServlet outputsServlet = createTestObject();
+ Assertions.assertThat(outputsServlet).isNotNull();
+
+ final Response response = outputsServlet.createMultipleOutputs(RESOURCES, COMPONENT_ID, request, USER_ID, COMPONENT_INST_OUTPUTS_MAP_OBJ);
+ Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ verify(componentsUtils, times(2)).getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+
+ @Test
+ void test_deleteOutput_success() {
+ doReturn(new OutputDefinition()).when(outputsBusinessLogic).deleteOutput(COMPONENT_ID, USER_ID, OUTPUT_ID);
+
+ final ResponseFormat responseFormat = new ResponseFormat(HttpStatus.OK_200.getStatusCode());
+ doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.OK);
+
+ final OutputsServlet outputsServlet = createTestObject();
+ Assertions.assertThat(outputsServlet).isNotNull();
+
+ final Response response = outputsServlet.deleteOutput(RESOURCES, COMPONENT_ID, OUTPUT_ID, request, USER_ID, COMPONENT_INST_OUTPUTS_MAP_OBJ);
+ Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
+ verify(componentsUtils, times(1)).getResponseFormat(ActionStatus.OK);
+ }
+
+ @Test
+ void test_deleteOutput_fail() {
+ final ResponseFormat responseFormat = new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ doThrow(new ComponentException(responseFormat)).when(outputsBusinessLogic).deleteOutput(COMPONENT_ID, USER_ID, OUTPUT_ID);
+
+ doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.GENERAL_ERROR);
+
+ final OutputsServlet outputsServlet = createTestObject();
+ Assertions.assertThat(outputsServlet).isNotNull();
+
+ final Response response = outputsServlet.deleteOutput(RESOURCES, COMPONENT_ID, OUTPUT_ID, request, USER_ID, COMPONENT_INST_OUTPUTS_MAP_OBJ);
+ Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ verify(componentsUtils, times(1)).getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+
+ private OutputsServlet createTestObject() {
+ return new OutputsServlet(userBusinessLogic, outputsBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ }
+
+ @Override
+ protected Application configure() {
+ final OutputsServlet outputsServlet = createTestObject();
+ final ResourceConfig resourceConfig = new ResourceConfig()
+ .register(outputsServlet)
+ .register(new ComponentExceptionMapper(componentsUtils))
+ .register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(request).to(HttpServletRequest.class);
+ }
+ });
+
+ resourceConfig.property("contextConfig", new AnnotationConfigApplicationContext(SpringConfig.class));
+ return resourceConfig;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
index 993e68b97e..214d1a7aba 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
@@ -48,7 +48,11 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestInstance.Lifecycle;
+import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.SpringConfig;
@@ -69,21 +73,32 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.context.WebApplicationContext;
+@TestInstance(Lifecycle.PER_CLASS)
class TypesUploadServletTest extends JerseyTest {
- public static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- private static final HttpSession session = Mockito.mock(HttpSession.class);
- public static final ServletContext servletContext = Mockito.mock(ServletContext.class);
- public static final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
- private static final WebApplicationContext webApplicationContext = Mockito.mock(WebApplicationContext.class);
- private static final CapabilityTypeImportManager importManager = Mockito.mock(CapabilityTypeImportManager.class);
- private static final ServletUtils servletUtils = Mockito.mock(ServletUtils.class);
- private static final UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
- private static final ComponentsUtils componentUtils = Mockito.mock(ComponentsUtils.class);
- private static final ResponseFormat responseFormat = Mockito.mock(ResponseFormat.class);
+ @Mock
+ private HttpServletRequest request;
+ @Mock
+ private HttpSession session;
+ @Mock
+ private ServletContext servletContext;
+ @Mock
+ private WebAppContextWrapper webAppContextWrapper;
+ @Mock
+ private WebApplicationContext webApplicationContext;
+ @Mock
+ private CapabilityTypeImportManager importManager;
+ @Mock
+ private ServletUtils servletUtils;
+ @Mock
+ private UserBusinessLogic userAdmin;
+ @Mock
+ private ComponentsUtils componentUtils;
+ @Mock
+ private ResponseFormat responseFormat;
@BeforeAll
- public static void setup() {
+ public void setup() {
ExternalConfiguration.setAppName("catalog-be");
when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
.thenReturn(webAppContextWrapper);
@@ -92,15 +107,13 @@ class TypesUploadServletTest extends JerseyTest {
when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
- String userId = "jh0003";
- User user = new User();
- user.setUserId(userId);
+ final String userId = "jh0003";
+ final User user = new User(userId);
user.setRole(Role.ADMIN.name());
when(userAdmin.getUser(userId)).thenReturn(user);
when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn(userId);
when(responseFormat.getStatus()).thenReturn(HttpStatus.CREATED_201);
when(componentUtils.getResponseFormat(ActionStatus.CREATED)).thenReturn(responseFormat);
-
}
@BeforeEach
@@ -115,19 +128,16 @@ class TypesUploadServletTest extends JerseyTest {
@Test
void creatingCapabilityTypeSuccessTest() {
- Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either
- .left(emptyList());
+ final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(emptyList());
when(importManager.createCapabilityTypes(Mockito.anyString())).thenReturn(either);
- FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip",
- new File("src/test/resources/types/capabilityTypes.zip"));
+ final FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip", new File("src/test/resources/types/capabilityTypes.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
- Response response = target().path("/v1/catalog/uploadType/capability").request(MediaType.APPLICATION_JSON)
+ final Response response = target().path("/v1/catalog/uploadType/capability").request(MediaType.APPLICATION_JSON)
.post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
assertEquals(HttpStatus.CREATED_201, response.getStatus());
-
}
@Override
@@ -137,17 +147,17 @@ class TypesUploadServletTest extends JerseyTest {
@Override
protected ResourceConfig configure() {
+ MockitoAnnotations.openMocks(this);
- TypesUploadServlet typesUploadServlet = new TypesUploadServlet(null, null, componentUtils,
+ forceSet(TestProperties.CONTAINER_PORT, "0");
+ final TypesUploadServlet typesUploadServlet = new TypesUploadServlet(null, null, componentUtils,
servletUtils, null, importManager, null,
null, null,
null, null, null);
- ResourceConfig resourceConfig = new ResourceConfig()
- .register(typesUploadServlet);
+ final ResourceConfig resourceConfig = new ResourceConfig().register(typesUploadServlet);
resourceConfig.register(MultiPartFeature.class);
resourceConfig.register(new AbstractBinder() {
-
@Override
protected void configure() {
// The below code was cut-pasted to here from setup() because
@@ -160,17 +170,15 @@ class TypesUploadServletTest extends JerseyTest {
ConfigurationSource configurationSource = new FSConfigurationSource(
ExternalConfiguration.getChangeListener(), appConfigDir);
ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
- for (String mandatoryHeader : configurationManager.getConfiguration().getIdentificationHeaderFields()) {
-
+ for (final String mandatoryHeader : configurationManager.getConfiguration().getIdentificationHeaderFields()) {
when(request.getHeader(mandatoryHeader)).thenReturn(mandatoryHeader);
-
}
when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR))
.thenReturn(configurationManager);
}
});
- ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
+ final ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
resourceConfig.property("contextConfig", context);
return resourceConfig;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java
index 8292568d8e..2bd529541b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java
@@ -19,7 +19,6 @@
package org.openecomp.sdc.be.tosca;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -130,7 +129,6 @@ class AttributeConverterTest {
assertAttribute(attributeDefinition, defaultValueMap, actualToscaAttribute);
}
-
@Test
void testInvalidDefaultValueJsonConversion() {
//given
@@ -143,8 +141,7 @@ class AttributeConverterTest {
assertEquals("Failed to parse json value", toscaConversionException.getMessage());
}
- private void assertAttribute(final AttributeDefinition expectedAttributeDefinition,
- final ToscaAttribute actualToscaAttribute) {
+ private void assertAttribute(final AttributeDefinition expectedAttributeDefinition, final ToscaAttribute actualToscaAttribute) {
assertAttribute(expectedAttributeDefinition, expectedAttributeDefinition.get_default(), actualToscaAttribute);
}
@@ -170,4 +167,4 @@ class AttributeConverterTest {
return objectMapper.writeValueAsString(value);
}
-} \ No newline at end of file
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
index 4b55a730fb..bca8827736 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
@@ -82,6 +82,8 @@ import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribOutput;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
@@ -90,6 +92,7 @@ import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupInstance;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RelationshipInfo;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
@@ -102,6 +105,7 @@ import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
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.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.tosca.exception.ToscaConversionException;
import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
import org.openecomp.sdc.be.tosca.model.ToscaCapability;
import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
@@ -378,11 +382,11 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
@Test
public void testConvertToscaTemplate() throws Exception {
- Component component = getNewResource();
- ToscaTemplate toscaNode = new ToscaTemplate("");
+ final Component component = getNewResource();
+ final ToscaTemplate toscaNode = new ToscaTemplate("");
Either<ToscaTemplate, ToscaError> result;
- List<ComponentInstance> resourceInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
+ final List<ComponentInstance> resourceInstances = new ArrayList<>();
+ final ComponentInstance instance = new ComponentInstance();
instance.setOriginType(OriginTypeEnum.SERVICE);
instance.setSourceModelUid("targetModelUid");
@@ -391,8 +395,11 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
component.setComponentInstances(resourceInstances);
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
- any(ComponentInstance.class))).thenReturn(Either.right(false));
+ when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.right(false));
+
+ final Map<String, ToscaProperty> map = new HashMap<>();
+ map.put("mock", new ToscaProperty());
+ doReturn(map).when(outputConverter).convert(any(), any());
// default test
result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
@@ -400,7 +407,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
}
@Test
- public void testConvertToscaTemplateWhenComponentContainsGroup() {
+ public void testConvertToscaTemplateWhenComponentContainsGroup() throws ToscaConversionException {
Component component = getNewResource();
ToscaTemplate toscaNode = new ToscaTemplate("");
Either<ToscaTemplate, ToscaError> result;
@@ -432,6 +439,10 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
when(groupExportParser.getGroups(component)).thenReturn(null);
+ final Map<String, ToscaProperty> map = new HashMap<>();
+ map.put("mock", new ToscaProperty());
+ doReturn(map).when(outputConverter).convert(any(), any());
+
// test component contains group
result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
Assert.assertNotNull(result);
@@ -467,6 +478,10 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
when(inputConverter.convertInputs(anyList(), anyMap())).thenReturn(new HashMap<>());
+ final Map<String, ToscaProperty> map = new HashMap<>();
+ map.put("mock", new ToscaProperty());
+ doReturn(map).when(outputConverter).convert(any(), any());
+
// test component contains group
result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
Assert.assertNotNull(result);
@@ -536,6 +551,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
// default test
Deencapsulation.invoke(testSubject, "createDependency", componentCache, imports, dependecies, ci);
+ Assert.assertFalse(componentCache.isEmpty());
}
@Test
@@ -1524,11 +1540,9 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
@Test
public void testIsCvfc() throws Exception {
- Component component = new Resource();
+ Component component = new Service();
boolean result;
- component = new Service();
-
result = Deencapsulation.invoke(testSubject, "isCvfc", component);
Assert.assertFalse(result);
}
@@ -1576,8 +1590,8 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
result = Deencapsulation.invoke(testSubject, "convertToNodeTemplateArtifacts", container);
Assert.assertNotNull(result);
Assert.assertTrue(MapUtils.isNotEmpty(result));
- Assert.assertEquals("test_file",result.get("test_art").getFile());
- Assert.assertEquals("test_type",result.get("test_art").getType());
+ Assert.assertEquals("test_file", result.get("test_art").getFile());
+ Assert.assertEquals("test_type", result.get("test_art").getType());
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OutputConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OutputConverterTest.java
new file mode 100644
index 0000000000..392c524471
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OutputConverterTest.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021, Nordix Foundation. 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.tosca.utils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.model.OutputDefinition;
+import org.openecomp.sdc.be.tosca.AttributeConverter;
+import org.openecomp.sdc.be.tosca.exception.ToscaConversionException;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.springframework.beans.factory.ObjectProvider;
+
+@ExtendWith(MockitoExtension.class)
+class OutputConverterTest {
+
+ @InjectMocks
+ private OutputConverter testSubject;
+
+ @Mock
+ private ObjectProvider<AttributeConverter> attributeConverterProvider;
+
+ @Test
+ void test_convert_success() throws ToscaConversionException {
+ final List<OutputDefinition> outputDefinitionList = new ArrayList<>();
+ final OutputDefinition outputDefinition = new OutputDefinition();
+ outputDefinitionList.add(outputDefinition);
+
+ doReturn(new AttributeConverter(new HashMap<>())).when(attributeConverterProvider).getObject(any());
+ final Map<String, ToscaProperty> result = testSubject.convert(outputDefinitionList, new HashMap<>());
+ assertThat(result).isNotNull();
+ }
+
+ @Test
+ void test_convert_isEmpty() throws ToscaConversionException {
+ final Map<String, ToscaProperty> result = testSubject.convert(new ArrayList<>(), new HashMap<>());
+ assertThat(result).isNotNull().isEmpty();
+ }
+
+}