summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2019-10-15 10:23:08 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-01-26 09:17:08 +0000
commitcb7a00bf89efca5b784120e990f79c475347e89d (patch)
tree2e434c227f7ac2bf3ba024f9496ded1f399554b9 /catalog-be
parentc113cc3f10f72013a66c2eb5a52ab8460da196f9 (diff)
Increase junit TCs
1. Re-enable disabled TCs (enable = true) 2. Enable @Ignored TCs 3. Add some Assert when missing 4. Remove old unused TCs (covered in UI) Change-Id: I900e52f4860b1fdc5bd1e529a1fe7f5c3491465b Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-2672
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java541
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java2636
2 files changed, 1634 insertions, 1543 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 75bf5a43ea..1bbe0fac88 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
@@ -20,7 +20,27 @@
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.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anySet;
+import static org.mockito.ArgumentMatchers.eq;
+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.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import mockit.Deencapsulation;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.assertj.core.util.Lists;
@@ -59,6 +79,7 @@ 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.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
@@ -86,27 +107,6 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anySet;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-
/**
* The test suite designed for test functionality of ComponentInstanceBusinessLogic class
*/
@@ -119,6 +119,7 @@ public class ComponentInstanceBusinessLogicTest {
private final static String ORIGIN_COMPONENT_ID = "originComponentId";
private final static String COMPONENT_INST_ID = "componentInstId";
private final static String TO_INSTANCE_ID = "toInstanceId";
+ private final static String TO_INSTANCE_NAME = "toInstanceName";
private final static String COMPONENT_INSTANCE_ID = "componentInstanceId";
private final static String FROM_INSTANCE_ID = "fromInstanceId";
private final static String RELATION_ID = "relationId";
@@ -137,13 +138,16 @@ public class ComponentInstanceBusinessLogicTest {
private final static String PROP_NAME = "propName";
private final static String NON_EXIST_NAME = "nonExistName";
- static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
- "src/test/resources/config/catalog-be");
+ static ConfigurationSource configurationSource = new FSConfigurationSource(
+ ExternalConfiguration.getChangeListener(),
+ "src/test/resources/config/catalog-be");
static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
@InjectMocks
private static ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
@Mock
+ private ComponentInstancePropInput componentInstancePropInput;
+ @Mock
ArtifactsBusinessLogic artifactsBusinessLogic;
@Mock
private ComponentsUtils componentsUtils;
@@ -180,7 +184,6 @@ public class ComponentInstanceBusinessLogicTest {
private RequirementDataDefinition requirement;
private RequirementCapabilityRelDef relation;
-
@Before
public void init() {
MockitoAnnotations.initMocks(componentInstanceBusinessLogic);
@@ -220,7 +223,7 @@ public class ComponentInstanceBusinessLogicTest {
assertFalse(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_5));
}
- private void getforwardingPathOnVersionChange(){
+ private void getforwardingPathOnVersionChange() {
String containerComponentParam = "services";
String containerComponentID = "121-cont";
String componentInstanceID = "121-cont-1-comp";
@@ -249,22 +252,22 @@ public class ComponentInstanceBusinessLogicTest {
//Mock for getting component
when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
- .thenReturn(Either.left(component));
+ .thenReturn(Either.left(component));
when(toscaOperationFacade.validateComponentExists(any(String.class))).thenReturn(Either.left(Boolean.TRUE));
when(toscaOperationFacade.getToscaFullElement(eq(new_Comp_UID))).thenReturn(Either.left(component2));
Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic
- .forwardingPathOnVersionChange(containerComponentParam,
- containerComponentID, componentInstanceID,
- newComponentInstance);
+ .forwardingPathOnVersionChange(containerComponentParam,
+ containerComponentID, componentInstanceID,
+ newComponentInstance);
assertEquals(1, resultOp.left().value().size());
assertEquals("FP-ID-1", resultOp.left().value().iterator().next());
}
@Test
- public void testCreateOrUpdatePropertiesValues2(){
- String containerComponentID="containerId";
+ public void testCreateOrUpdatePropertiesValues2() {
+ String containerComponentID = "containerId";
String resourceInstanceId = "resourceId";
String componentInstanceID = "componentInstance";
List<ComponentInstanceProperty> properties = new ArrayList<>();
@@ -294,35 +297,40 @@ public class ComponentInstanceBusinessLogicTest {
ComponentInstance ci = createComponentInstance("ci1");
ci.setUniqueId("resourceId");
component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
- createComponentInstance(componentInstanceID)));
+ createComponentInstance(componentInstanceID)));
HashMap<String, DataTypeDefinition> dataTypeDefinitionHashMap = new HashMap<>();
DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
dataTypeDefinition.setName("string");
dataTypeDefinitionHashMap.put("string", dataTypeDefinition);
//when(userValidations.validateUserExists(user.getUserId(), false)).thenReturn(user);
- when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(component));
- when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
+ .thenReturn(Either.left(component));
+ when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
+ .thenReturn(StorageOperationStatus.OK);
when(dataTypeCache.getAll()).thenReturn(Either.left(types));
when(propertyOperation.validateAndUpdatePropertyValue(property.getType(), "newVal", true, null, types))
- .thenReturn(Either.left("newVal"));
+ .thenReturn(Either.left("newVal"));
when(propertyOperation.validateAndUpdateRules("string", property.getRules(),
- null, types, true)).thenReturn(ImmutablePair.of("string", null));
+ null, types, true)).thenReturn(ImmutablePair.of("string", null));
when(toscaOperationFacade.updateComponentInstanceProperty(component, ci.getUniqueId(),
- origProperty)).thenReturn(StorageOperationStatus.OK);
+ origProperty)).thenReturn(StorageOperationStatus.OK);
origProperties.get(0).setValue("newVal");
- when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(component)).thenReturn(Either.left(component));
- when (janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
- when(graphLockOperation.unlockComponent(containerComponentID, NodeTypeEnum.ResourceInstance)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(component))
+ .thenReturn(Either.left(component));
+ when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
+ when(graphLockOperation.unlockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
+ .thenReturn(StorageOperationStatus.OK);
- Either<List<ComponentInstanceProperty>, ResponseFormat> responseFormatEither = componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
+ Either<List<ComponentInstanceProperty>, ResponseFormat> responseFormatEither = componentInstanceBusinessLogic
+ .createOrUpdatePropertiesValues(
ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
assertThat(responseFormatEither.left().value()).isEqualTo(properties);
}
@Test
- public void testCreateOrUpdatePropertiesValuesPropertyNotExists(){
- String containerComponentID="containerId";
+ public void testCreateOrUpdatePropertiesValuesPropertyNotExists() {
+ String containerComponentID = "containerId";
String resourceInstanceId = "resourceId";
String componentInstanceID = "componentInstance";
List<ComponentInstanceProperty> properties = new ArrayList<>();
@@ -347,32 +355,34 @@ public class ComponentInstanceBusinessLogicTest {
ComponentInstance ci = createComponentInstance("ci1");
ci.setUniqueId("resourceId");
component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
- createComponentInstance(componentInstanceID)));
+ createComponentInstance(componentInstanceID)));
HashMap<String, DataTypeDefinition> dataTypeDefinitionHashMap = new HashMap<>();
DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
dataTypeDefinition.setName("string");
dataTypeDefinitionHashMap.put("string", dataTypeDefinition);
//when(userValidations.validateUserExists(user.getUserId(), false)).thenReturn(user);
- when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(component));
- when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
+ .thenReturn(Either.left(component));
+ when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
+ .thenReturn(StorageOperationStatus.OK);
//when(dataTypeCache.getAll()).thenReturn(Either.left(types));
//when (janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
- when(graphLockOperation.unlockComponent(containerComponentID, NodeTypeEnum.ResourceInstance)).thenReturn(StorageOperationStatus.OK);
+ when(graphLockOperation.unlockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
+ .thenReturn(StorageOperationStatus.OK);
try {
componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
- ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
+ ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
} catch (ComponentException e) {
assertThat(e.getActionStatus()).isEqualTo(ActionStatus.PROPERTY_NOT_FOUND);
}
}
-
@Test
- public void testCreateOrUpdatePropertiesValuesValidationFailure(){
- String containerComponentID="containerId";
+ public void testCreateOrUpdatePropertiesValuesValidationFailure() {
+ String containerComponentID = "containerId";
String resourceInstanceId = "resourceId";
String componentInstanceID = "componentInstance";
List<ComponentInstanceProperty> properties = new ArrayList<>();
@@ -402,24 +412,27 @@ public class ComponentInstanceBusinessLogicTest {
ComponentInstance ci = createComponentInstance("ci1");
ci.setUniqueId("resourceId");
component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
- createComponentInstance(componentInstanceID)));
+ createComponentInstance(componentInstanceID)));
HashMap<String, DataTypeDefinition> dataTypeDefinitionHashMap = new HashMap<>();
DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
dataTypeDefinition.setName("string");
dataTypeDefinitionHashMap.put("string", dataTypeDefinition);
//when(userValidations.validateUserExists(user.getUserId(), false)).thenReturn(user);
- when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(component));
- when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
+ .thenReturn(Either.left(component));
+ when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
+ .thenReturn(StorageOperationStatus.OK);
when(dataTypeCache.getAll()).thenReturn(Either.left(types));
when(propertyOperation.validateAndUpdatePropertyValue(property.getType(), "newVal", true, null, types))
- .thenReturn(Either.right(false));
- when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST)).thenReturn(ActionStatus.INVALID_CONTENT);
+ .thenReturn(Either.right(false));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST))
+ .thenReturn(ActionStatus.INVALID_CONTENT);
- try{
+ try {
componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
- ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
- } catch(ComponentException e){
+ ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
+ } catch (ComponentException e) {
assertThat(e.getActionStatus()).isEqualTo(ActionStatus.INVALID_CONTENT);
return;
}
@@ -427,8 +440,8 @@ public class ComponentInstanceBusinessLogicTest {
}
@Test
- public void testCreateOrUpdatePropertiesValuesMissingFieldFailure(){
- String containerComponentID="containerId";
+ public void testCreateOrUpdatePropertiesValuesMissingFieldFailure() {
+ String containerComponentID = "containerId";
String resourceInstanceId = "resourceId";
String componentInstanceID = "componentInstance";
List<ComponentInstanceProperty> properties = new ArrayList<>();
@@ -453,7 +466,7 @@ public class ComponentInstanceBusinessLogicTest {
ComponentInstance ci = createComponentInstance("ci1");
ci.setUniqueId("resourceId");
component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
- createComponentInstance(componentInstanceID)));
+ createComponentInstance(componentInstanceID)));
HashMap<String, DataTypeDefinition> dataTypeDefinitionHashMap = new HashMap<>();
DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
@@ -461,13 +474,15 @@ public class ComponentInstanceBusinessLogicTest {
dataTypeDefinitionHashMap.put("string", dataTypeDefinition);
//when(userValidations.validateUserExists(user.getUserId(), false)).thenReturn(user);
- when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(component));
- when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
+ .thenReturn(Either.left(component));
+ when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
+ .thenReturn(StorageOperationStatus.OK);
- try{
+ try {
componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
- ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
- } catch(ComponentException e){
+ ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
+ } catch (ComponentException e) {
assertThat(e.getActionStatus()).isEqualTo(ActionStatus.MISSING_PROPERTY_NAME);
}
}
@@ -479,20 +494,22 @@ public class ComponentInstanceBusinessLogicTest {
String containerComponentID = "Service-comp";
String componentInstanceID = "NodeA1";
Service component = new Service();
- component.setComponentInstances(Arrays.asList(createComponentInstance("NodeA2"), createComponentInstance("NodeB2"),
- createComponentInstance(componentInstanceID)));
+ component
+ .setComponentInstances(Arrays.asList(createComponentInstance("NodeA2"), createComponentInstance("NodeB2"),
+ createComponentInstance(componentInstanceID)));
component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1"));
component.addForwardingPath(createPath("Path2", "NodeA2", "NodeB2", "2"));
when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
- .thenReturn(Either.left(component));
+ .thenReturn(Either.left(component));
when(toscaOperationFacade.getToscaElement(eq(containerComponentID))).thenReturn(Either.left(component));
when(forwardingPathOperation.deleteForwardingPath(any(Service.class), anySet()))
- .thenReturn(Either.left(new HashSet<>()));
+ .thenReturn(Either.left(new HashSet<>()));
final ComponentInstance ci = new ComponentInstance();
ci.setName(componentInstanceID);
- ComponentInstance responseFormatEither = componentInstanceBusinessLogic.deleteForwardingPathsRelatedTobeDeletedComponentInstance(
- containerComponentID, containerComponentType, ci);
+ ComponentInstance responseFormatEither = componentInstanceBusinessLogic
+ .deleteForwardingPathsRelatedTobeDeletedComponentInstance(
+ containerComponentID, containerComponentType, ci);
assertThat(!responseFormatEither.isEmpty()).isEqualTo(true);
}
@@ -508,14 +525,18 @@ public class ComponentInstanceBusinessLogicTest {
Map<String, ArtifactDefinition> artifacts = new HashMap<>();
ArtifactDefinition deploymentArtifact1 = getArtifact("deploymentArtifact1", ArtifactTypeEnum.HEAT.getType());
artifacts.put(deploymentArtifact1.getArtifactLabel(), deploymentArtifact1);
- ArtifactDefinition deploymentArtifact2 = getArtifact("deploymentArtifact2", ArtifactTypeEnum.HEAT_ENV.getType());
+ ArtifactDefinition deploymentArtifact2 = getArtifact("deploymentArtifact2",
+ ArtifactTypeEnum.HEAT_ENV.getType());
artifacts.put(deploymentArtifact2.getArtifactLabel(), deploymentArtifact2);
- ArtifactDefinition deploymentArtifact3 = getArtifact("deploymentArtifact3", ArtifactTypeEnum.HEAT_VOL.getType());
+ ArtifactDefinition deploymentArtifact3 = getArtifact("deploymentArtifact3",
+ ArtifactTypeEnum.HEAT_VOL.getType());
artifacts.put(deploymentArtifact3.getArtifactLabel(), deploymentArtifact3);
ArtifactDefinition heatEnvPlaceHolder = getArtifact("deploymentArtifact4", ArtifactTypeEnum.HEAT_ENV.getType());
- ArtifactDefinition heatEnvPlaceHolder2 = getArtifact("deploymentArtifact5", ArtifactTypeEnum.HEAT_ENV.getType());
+ ArtifactDefinition heatEnvPlaceHolder2 = getArtifact("deploymentArtifact5",
+ ArtifactTypeEnum.HEAT_ENV.getType());
- Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = Either.left(artifacts);
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = Either
+ .left(artifacts);
Map<String, ArtifactDefinition> finalDeploymentArtifacts = new HashMap<>();
finalDeploymentArtifacts.put(deploymentArtifact1.getArtifactLabel(), deploymentArtifact1);
@@ -523,26 +544,28 @@ public class ComponentInstanceBusinessLogicTest {
finalDeploymentArtifacts.put(heatEnvPlaceHolder.getArtifactLabel(), heatEnvPlaceHolder);
finalDeploymentArtifacts.put(heatEnvPlaceHolder2.getArtifactLabel(), heatEnvPlaceHolder2);
-
when(artifactsBusinessLogic.getArtifacts(componentInstance.getComponentUid(), NodeTypeEnum.Resource,
- ArtifactGroupTypeEnum.DEPLOYMENT, null)).thenReturn(getResourceDeploymentArtifacts);
+ ArtifactGroupTypeEnum.DEPLOYMENT, null)).thenReturn(getResourceDeploymentArtifacts);
when(artifactsBusinessLogic.createHeatEnvPlaceHolder(new ArrayList<>(),
- deploymentArtifact1, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(),
- NodeTypeEnum.ResourceInstance, componentInstance.getName(), user, containerComponent,
- null)).thenReturn(heatEnvPlaceHolder);
+ deploymentArtifact1, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(),
+ NodeTypeEnum.ResourceInstance, componentInstance.getName(), user, containerComponent,
+ null)).thenReturn(heatEnvPlaceHolder);
when(artifactsBusinessLogic.createHeatEnvPlaceHolder(new ArrayList<>(),
- deploymentArtifact3, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(),
- NodeTypeEnum.ResourceInstance, componentInstance.getName(), user, containerComponent,
- null)).thenReturn(heatEnvPlaceHolder2);
-
-
- when(toscaOperationFacade.addDeploymentArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, finalDeploymentArtifacts)).thenReturn(StorageOperationStatus.OK);
- when(toscaOperationFacade.addGroupInstancesToComponentInstance(containerComponent, componentInstance, null, new HashMap<>())).thenReturn(StorageOperationStatus.OK);
- when(toscaOperationFacade.addInformationalArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, null)).thenReturn(StorageOperationStatus.OK);
-
+ deploymentArtifact3, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(),
+ NodeTypeEnum.ResourceInstance, componentInstance.getName(), user, containerComponent,
+ null)).thenReturn(heatEnvPlaceHolder2);
+
+ when(toscaOperationFacade.addDeploymentArtifactsToInstance(containerComponent.getUniqueId(), componentInstance,
+ finalDeploymentArtifacts)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade
+ .addGroupInstancesToComponentInstance(containerComponent, componentInstance, null, new HashMap<>()))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade
+ .addInformationalArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, null))
+ .thenReturn(StorageOperationStatus.OK);
ActionStatus status = componentInstanceBusinessLogic.addComponentInstanceArtifacts(containerComponent,
- componentInstance, originComponent, user, null);
+ componentInstance, originComponent, user, null);
assertThat(status).isEqualTo(ActionStatus.OK);
@@ -551,7 +574,7 @@ public class ComponentInstanceBusinessLogicTest {
private Component fillOriginComponent(Resource originComponent) {
originComponent.setUniqueId("resourceId");
originComponent.setUniqueId(ORIGIN_COMPONENT_ID);
- originComponent.setComponentInstances(Lists.newArrayList(toInstance,fromInstance));
+ originComponent.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
originComponent.setComponentType(ComponentTypeEnum.RESOURCE);
originComponent.setState(LifecycleStateEnum.CERTIFIED);
return originComponent;
@@ -578,16 +601,15 @@ public class ComponentInstanceBusinessLogicTest {
forwardingPath.setDestinationPortNumber("port");
forwardingPath.setUniqueId(uniqueId);
ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
- new ListDataDefinition<>();
+ new ListDataDefinition<>();
forwardingPathElementListDataDefinition
- .add(new ForwardingPathElementDataDefinition(fromNode, toNode, "nodeAcpType", "nodeBcpType",
- "nodeDcpName", "nodeBcpName"));
+ .add(new ForwardingPathElementDataDefinition(fromNode, toNode, "nodeAcpType", "nodeBcpType",
+ "nodeDcpName", "nodeBcpName"));
forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
return forwardingPath;
}
-
private Map<String, ForwardingPathDataDefinition> generateForwardingPath(String componentInstanceID) {
ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition("fpName");
String protocol = "protocol";
@@ -597,31 +619,32 @@ public class ComponentInstanceBusinessLogicTest {
ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
new ListDataDefinition<>();
forwardingPathElementListDataDefinition
- .add(new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
- "nodeBcpType", "nodeDcpName", "nodeBcpName"));
+ .add(new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
+ "nodeBcpType", "nodeDcpName", "nodeBcpName"));
forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
forwardingPaths.put("1122", forwardingPath);
return forwardingPaths;
}
- @SuppressWarnings("unchecked")
- private void getServiceRelationByIdSuccess(Component component){
+ @SuppressWarnings("unchecked")
+ private void getServiceRelationByIdSuccess(Component component) {
Either<Component, StorageOperationStatus> getComponentRes = Either.left(component);
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
- .thenReturn(getComponentRes);
+ .thenReturn(getComponentRes);
Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
- .getRelationById(COMPONENT_ID,
- RELATION_ID, USER_ID,
- component.getComponentType());
+ .getRelationById(COMPONENT_ID,
+ RELATION_ID, USER_ID,
+ component.getComponentType());
assertTrue(response.isLeft());
}
private void getServiceRelationByIdUserValidationFailure(Component component) {
- when(userValidations.validateUserExists(eq(USER_ID))).thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND));
+ when(userValidations.validateUserExists(eq(USER_ID)))
+ .thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND));
try {
componentInstanceBusinessLogic
- .getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
+ .getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
} catch (ByActionStatusComponentException e) {
assertSame(e.getActionStatus(), ActionStatus.USER_NOT_FOUND);
}
@@ -631,19 +654,20 @@ public class ComponentInstanceBusinessLogicTest {
Either<User, ActionStatus> eitherCreator = Either.left(user);
Either<Component, StorageOperationStatus> getComponentRes = Either.right(StorageOperationStatus.NOT_FOUND);
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
- .thenReturn(getComponentRes);
+ .thenReturn(getComponentRes);
Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
- .getRelationById(COMPONENT_ID,
- RELATION_ID, USER_ID,
- component.getComponentType());
+ .getRelationById(COMPONENT_ID,
+ RELATION_ID, USER_ID,
+ component.getComponentType());
assertTrue(response.isRight());
}
private void stubMethods() {
when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
- when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.GENERAL_ERROR),any(ComponentTypeEnum.class)))
- .thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentsUtils
+ .convertFromStorageResponse(eq(StorageOperationStatus.GENERAL_ERROR), any(ComponentTypeEnum.class)))
+ .thenReturn(ActionStatus.GENERAL_ERROR);
}
private void createComponents() {
@@ -664,7 +688,6 @@ public class ComponentInstanceBusinessLogicTest {
resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
}
-
private void createService() {
service = new Service();
service.setUniqueId(COMPONENT_ID);
@@ -676,10 +699,10 @@ public class ComponentInstanceBusinessLogicTest {
service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
}
-
private void createInstances() {
toInstance = new ComponentInstance();
toInstance.setUniqueId(TO_INSTANCE_ID);
+ toInstance.setName(TO_INSTANCE_NAME);
fromInstance = new ComponentInstance();
fromInstance.setUniqueId(FROM_INSTANCE_ID);
@@ -690,7 +713,11 @@ public class ComponentInstanceBusinessLogicTest {
capability.setName(CAPABILITY_NAME);
Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
- capabilities.put(capability.getName(), Lists.newArrayList(new CapabilityDefinition(capability)));
+ final CapabilityDefinition capabilityDefinition = new CapabilityDefinition(capability);
+ final ArrayList<ComponentInstanceProperty> properties = new ArrayList<>();
+ properties.add(componentInstancePropInput);
+ capabilityDefinition.setProperties(properties);
+ capabilities.put(capability.getName(), Lists.newArrayList(capabilityDefinition));
requirement = new RequirementDataDefinition();
requirement.setOwnerId(REQUIREMENT_OWNER_ID);
@@ -698,7 +725,6 @@ public class ComponentInstanceBusinessLogicTest {
requirement.setName(REQUIREMENT_NAME);
requirement.setRelationship(RELATIONSHIP_TYPE);
-
Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
requirements.put(requirement.getCapability(), Lists.newArrayList(new RequirementDefinition(requirement)));
@@ -706,7 +732,6 @@ public class ComponentInstanceBusinessLogicTest {
fromInstance.setRequirements(requirements);
}
-
private void createRelation() {
relation = new RequirementCapabilityRelDef();
@@ -734,7 +759,6 @@ public class ComponentInstanceBusinessLogicTest {
return componentInstanceBusinessLogic;
}
-
@Test
public void testChangeServiceProxyVersion() {
ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
@@ -744,9 +768,9 @@ public class ComponentInstanceBusinessLogicTest {
// default test
componentInstanceBusinessLogic = createTestSubject();
result = componentInstanceBusinessLogic.changeServiceProxyVersion();
+ Assert.assertNotNull(result);
}
-
@Test
public void testCreateServiceProxy() {
ComponentInstanceBusinessLogic testSubject;
@@ -755,12 +779,9 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
result = testSubject.createServiceProxy();
+ Assert.assertNotNull(result);
}
-
-
-
-
@Test
public void testDeleteServiceProxy() {
ComponentInstanceBusinessLogic testSubject;
@@ -770,9 +791,9 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
result = testSubject.deleteServiceProxy();
+ Assert.assertNotNull(result);
}
-
@Test
public void testGetComponentInstanceInputsByInputId() {
ComponentInstanceBusinessLogic testSubject;
@@ -783,9 +804,9 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
result = testSubject.getComponentInstanceInputsByInputId(component, inputId);
+ Assert.assertNotNull(result);
}
-
@Test
public void testGetComponentInstancePropertiesByInputId() {
ComponentInstanceBusinessLogic testSubject;
@@ -796,9 +817,9 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
result = testSubject.getComponentInstancePropertiesByInputId(component, inputId);
+ Assert.assertNotNull(result);
}
-
@Test
public void testGetRelationById() {
ComponentInstanceBusinessLogic testSubject;
@@ -811,10 +832,11 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
result = testSubject.getRelationById(componentId, relationId, userId, componentTypeEnum);
+ Assert.assertNotNull(result);
}
- @Test
- public void testValidateParent() {
+ @Test
+ public void testValidateParent() {
ComponentInstanceBusinessLogic testSubject;
createResource();
String nodeTemplateId = "";
@@ -822,10 +844,10 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "validateParent", new Object[] {resource, nodeTemplateId});
+ result = Deencapsulation.invoke(testSubject, "validateParent", new Object[]{resource, nodeTemplateId});
+ Assert.assertNotNull(result);
}
-
@Test
public void testGetComponentType() {
ComponentInstanceBusinessLogic testSubject;
@@ -833,10 +855,10 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "getComponentType", new Object[] {ComponentTypeEnum.class});
+ result = Deencapsulation.invoke(testSubject, "getComponentType", new Object[]{ComponentTypeEnum.class});
+ Assert.assertNotNull(result);
}
-
@Test
public void testGetNewGroupName() {
ComponentInstanceBusinessLogic testSubject;
@@ -848,10 +870,10 @@ public class ComponentInstanceBusinessLogicTest {
// test 1
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "getNewGroupName",
- new Object[] {oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
+ new Object[]{oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
+ Assert.assertNotNull(result);
}
-
@Test
public void testUpdateComponentInstanceMetadata_3() {
ComponentInstanceBusinessLogic testSubject;
@@ -862,7 +884,8 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
result = Deencapsulation
- .invoke(testSubject, "updateComponentInstanceMetadata", new Object[] {toInstance, toInstance});
+ .invoke(testSubject, "updateComponentInstanceMetadata", new Object[]{toInstance, toInstance});
+ Assert.assertNotNull(result);
}
@Test
@@ -875,10 +898,9 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "findRelation",
- new Object[] {relationId, requirementCapabilityRelations});
+ new Object[]{relationId, requirementCapabilityRelations});
}
-
@Test
public void testCreateOrUpdatePropertiesValues() throws Exception {
ComponentInstanceBusinessLogic testSubject;
@@ -890,29 +912,28 @@ public class ComponentInstanceBusinessLogicTest {
String userId = user.getUserId();
Either<List<ComponentInstanceProperty>, ResponseFormat> result;
-
when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
- .thenReturn(Either.left(resource));
+ .thenReturn(Either.left(resource));
// test 1
testSubject = createTestSubject();
result = testSubject
- .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
- userId);
+ .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
+ userId);
+ Assert.assertNotNull(result);
componentTypeEnum = null;
result = testSubject
- .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
- userId);
+ .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
+ userId);
+ Assert.assertNotNull(result);
- // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
result = testSubject
- .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
- userId);
-
+ .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
+ userId);
+ Assert.assertNotNull(result);
}
-
@Test
public void testUpdateCapabilityPropertyOnContainerComponent() throws Exception {
ComponentInstanceBusinessLogic testSubject;
@@ -927,10 +948,9 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent",
- new Object[] {property, newValue, resource, toInstance, capabilityType, capabilityName});
+ new Object[]{property, newValue, resource, toInstance, capabilityType, capabilityName});
}
-
@Test
public void testCreateOrUpdateInstanceInputValues() throws Exception {
ComponentInstanceBusinessLogic testSubject;
@@ -943,27 +963,26 @@ public class ComponentInstanceBusinessLogicTest {
Either<List<ComponentInstanceInput>, ResponseFormat> result;
when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
- .thenReturn(Either.left(resource));
+ .thenReturn(Either.left(resource));
// test 1
testSubject = createTestSubject();
result = testSubject
- .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
- userId);
+ .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
+ userId);
+ Assert.assertNotNull(result);
componentTypeEnum = null;
result = testSubject
- .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
- userId);
-
+ .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
+ userId);
+ Assert.assertNotNull(result);
- // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
result = testSubject
- .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
- userId);
-
+ .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
+ userId);
+ Assert.assertNotNull(result);
}
-
@Test
public void testCreateOrUpdateGroupInstancePropertyValue() throws Exception {
ComponentInstanceBusinessLogic testSubject;
@@ -976,27 +995,27 @@ public class ComponentInstanceBusinessLogicTest {
String userId = user.getUserId();
Either<ComponentInstanceProperty, ResponseFormat> result;
-
when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata))
- .thenReturn(Either.left(resource));
+ .thenReturn(Either.left(resource));
// test 1
testSubject = createTestSubject();
result = testSubject
- .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
- groupInstanceId, property, userId);
+ .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
+ groupInstanceId, property, userId);
+ Assert.assertNotNull(result);
componentTypeEnum = null;
result = testSubject
- .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
- groupInstanceId, property, userId);
+ .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
+ groupInstanceId, property, userId);
+ Assert.assertNotNull(result);
- // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
result = testSubject
- .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
- groupInstanceId, property, userId);
+ .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
+ groupInstanceId, property, userId);
+ Assert.assertNotNull(result);
}
-
@Test
public void testDeletePropertyValue() throws Exception {
ComponentInstanceBusinessLogic testSubject;
@@ -1009,19 +1028,21 @@ public class ComponentInstanceBusinessLogicTest {
Either<ComponentInstanceProperty, ResponseFormat> result;
when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata))
- .thenReturn(Either.left(service));
+ .thenReturn(Either.left(service));
// test 1
testSubject = createTestSubject();
result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
- userId);
+ userId);
+ Assert.assertNotNull(result);
componentTypeEnum = null;
result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
- userId);
+ userId);
+ Assert.assertNotNull(result);
- // when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
- userId);
+ userId);
+ Assert.assertNotNull(result);
}
@Test
@@ -1032,6 +1053,7 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "getComponentParametersViewForForwardingPath");
+ Assert.assertNotNull(result);
}
@Test
@@ -1043,7 +1065,8 @@ public class ComponentInstanceBusinessLogicTest {
// default test
testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[] {resource, instanceId});
+ result = Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[]{resource, instanceId});
+ Assert.assertNotNull(result);
}
@Test
@@ -1059,16 +1082,17 @@ public class ComponentInstanceBusinessLogicTest {
String userId = user.getUserId();
Either<List<ComponentInstanceProperty>, ResponseFormat> result;
-
when(toscaOperationFacade.getToscaFullElement(containerComponentId))
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
// test 1
testSubject = createTestSubject();
result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
- componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
+ componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
+ Assert.assertNotNull(result);
when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
- componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
+ componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
+ Assert.assertNotNull(result);
}
@Test
@@ -1084,19 +1108,19 @@ public class ComponentInstanceBusinessLogicTest {
Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
- .thenReturn(leftServiceOp);
+ .thenReturn(leftServiceOp);
when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
result = componentInstanceBusinessLogic
- .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
- USER_ID);
+ .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
+ USER_ID);
+ Assert.assertNotNull(result);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
-
assertThat(result.isRight());
}
@@ -1112,15 +1136,16 @@ public class ComponentInstanceBusinessLogicTest {
Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
- .thenReturn(leftServiceOp);
+ .thenReturn(leftServiceOp);
when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
Either<Component, StorageOperationStatus> getComponentRes = Either.left(resource);
result = componentInstanceBusinessLogic
- .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
+ .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
+ Assert.assertNotNull(result);
service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
assertThat(result.isRight());
}
@@ -1139,21 +1164,22 @@ public class ComponentInstanceBusinessLogicTest {
Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
- .thenReturn(leftServiceOp);
+ .thenReturn(leftServiceOp);
when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
Either<Component, StorageOperationStatus> getComponentRes = Either.left(resource);
ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID);
Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = Either
- .left(new HashMap<String, ArtifactDefinition>());
+ .left(new HashMap<String, ArtifactDefinition>());
StorageOperationStatus artStatus = StorageOperationStatus.OK;
result = componentInstanceBusinessLogic
- .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
- USER_ID);
+ .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
+ USER_ID);
+ Assert.assertNotNull(result);
service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
resource.setLifecycleState(oldResourceLifeCycle);
@@ -1175,7 +1201,7 @@ public class ComponentInstanceBusinessLogicTest {
service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
Map<String, List<ComponentInstanceProperty>> instAttrsMap =
- new HashMap<String, List<ComponentInstanceProperty>>();
+ new HashMap<String, List<ComponentInstanceProperty>>();
List<ComponentInstanceProperty> instAttrsList = new ArrayList<ComponentInstanceProperty>();
ComponentInstanceProperty prop = new ComponentInstanceProperty();
prop.setUniqueId(attribute.getUniqueId());
@@ -1185,20 +1211,21 @@ public class ComponentInstanceBusinessLogicTest {
Either<Component, StorageOperationStatus> serviceEitherLeft = Either.left(service);
when(toscaOperationFacade.getToscaElement(serviceComponentInstance.getUniqueId(), JsonParseFlagEnum.ParseAll))
- .thenReturn(serviceEitherLeft);
+ .thenReturn(serviceEitherLeft);
when(toscaOperationFacade.updateComponentInstanceAttribute(service, toInstance.getUniqueId(), attribute))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
- .thenReturn(serviceEitherLeft);
+ .thenReturn(serviceEitherLeft);
Either<ComponentInstanceProperty, ResponseFormat> result = Deencapsulation
- .invoke(componentInstanceBusinessLogic,
- "createOrUpdateAttributeValueForCopyPaste",
- ComponentTypeEnum.SERVICE,
- serviceComponentInstance
- .getUniqueId(),
- toInstance.getUniqueId(), attribute,
- USER_ID);
+ .invoke(componentInstanceBusinessLogic,
+ "createOrUpdateAttributeValueForCopyPaste",
+ ComponentTypeEnum.SERVICE,
+ serviceComponentInstance
+ .getUniqueId(),
+ toInstance.getUniqueId(), attribute,
+ USER_ID);
+ Assert.assertNotNull(result);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
@@ -1220,14 +1247,14 @@ public class ComponentInstanceBusinessLogicTest {
when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(getComponent);
StorageOperationStatus status = StorageOperationStatus.OK;
when(toscaOperationFacade.updateComponentInstanceProperty(service, componentInstanceId, property))
- .thenReturn(status);
+ .thenReturn(status);
Either<Component, StorageOperationStatus> updateContainerRes = Either.left(service);
when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
- .thenReturn(updateContainerRes);
+ .thenReturn(updateContainerRes);
Either<String, ResponseFormat> result = Deencapsulation.invoke(componentInstanceBusinessLogic,
- "updateComponentInstanceProperty", containerComponentId, componentInstanceId, property);
-
+ "updateComponentInstanceProperty", containerComponentId, componentInstanceId, property);
+ Assert.assertNotNull(result);
assertTrue(result.isLeft());
}
@@ -1245,7 +1272,7 @@ public class ComponentInstanceBusinessLogicTest {
service.setInputs(newInputs);
Either<String, ResponseFormat> result =
- Deencapsulation.invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId);
+ Deencapsulation.invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId);
service.setInputs(oldInputs);
@@ -1266,20 +1293,20 @@ public class ComponentInstanceBusinessLogicTest {
deleteErrorIds.add(componentInstanceId);
deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
Either<Component, StorageOperationStatus> cont = Either.left(service);
- when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND),eq(null)))
- .thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(null)))
+ .thenReturn(ActionStatus.GENERAL_ERROR);
when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
- .thenReturn(cont);
+ .thenReturn(cont);
- try{
- result = componentInstanceBusinessLogic
+ try {
+ result = componentInstanceBusinessLogic
.batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
- userId);
- }catch (ComponentException e){
- assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
- }
-
-// assertEquals(deleteErrorMap, result);
+ userId);
+ Assert.assertNotNull(result);
+ assertEquals(deleteErrorMap, result);
+ } catch (ComponentException e) {
+ assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
+ }
}
@Test
@@ -1298,16 +1325,17 @@ public class ComponentInstanceBusinessLogicTest {
Either<Component, StorageOperationStatus> err = Either.right(StorageOperationStatus.GENERAL_ERROR);
when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
- .thenReturn(err);
+ .thenReturn(err);
try {
result = componentInstanceBusinessLogic
- .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
- userId);
- }catch (ComponentException e){
+ .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
+ userId);
+ Assert.assertNotNull(result);
+ assertEquals(deleteErrorMap, result);
+ } catch (ComponentException e) {
assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
}
-// assertEquals(deleteErrorMap, result);
}
@Test
@@ -1329,20 +1357,21 @@ public class ComponentInstanceBusinessLogicTest {
Either<Component, StorageOperationStatus> cont = Either.left(service);
when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID);
Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
when(toscaOperationFacade.deleteComponentInstanceFromTopologyTemplate(service, componentInstanceId))
- .thenReturn(result2);
+ .thenReturn(result2);
when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
- .thenReturn(cont);
+ .thenReturn(cont);
when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
result = componentInstanceBusinessLogic
- .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
- componentInstanceIdList, userId);
+ .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
+ componentInstanceIdList, userId);
+ Assert.assertNotNull(result);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
@@ -1375,28 +1404,29 @@ public class ComponentInstanceBusinessLogicTest {
Either<Component, StorageOperationStatus> cont = Either.left(service);
when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
- .thenReturn(cont);
+ .thenReturn(cont);
when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither;
resultEither = Either.right(StorageOperationStatus.OK);
- when(componentsUtils.convertFromStorageResponseForResourceInstance(eq(StorageOperationStatus.OK),eq(true)))
- .thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentsUtils.convertFromStorageResponseForResourceInstance(eq(StorageOperationStatus.OK), eq(true)))
+ .thenReturn(ActionStatus.GENERAL_ERROR);
when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
- try{
- result = componentInstanceBusinessLogic
- .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
- }catch (ComponentException e){
- assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
- }
+ try {
+ result = componentInstanceBusinessLogic
+ .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
+ Assert.assertNotNull(result);
+ assertEquals(new ArrayList<>(), result);
+ } catch (ComponentException e) {
+ assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
+ }
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
-// assertEquals(new ArrayList<>(), result);
}
@Test
@@ -1416,17 +1446,18 @@ public class ComponentInstanceBusinessLogicTest {
Either<Component, StorageOperationStatus> cont = Either.left(service);
when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
- .thenReturn(cont);
+ .thenReturn(cont);
when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither;
resultEither = Either.left(ref);
when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
result = componentInstanceBusinessLogic
- .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
+ .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
+ Assert.assertNotNull(result);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
@@ -1437,7 +1468,7 @@ public class ComponentInstanceBusinessLogicTest {
@Test
public void testGetComponentInstancePropertyByPolicyId_success() {
Optional<ComponentInstanceProperty> propertyCandidate =
- getComponentInstanceProperty(PROP_NAME);
+ getComponentInstanceProperty(PROP_NAME);
Assert.assertTrue(propertyCandidate.isPresent());
Assert.assertEquals(propertyCandidate.get().getName(), PROP_NAME);
@@ -1446,7 +1477,7 @@ public class ComponentInstanceBusinessLogicTest {
@Test
public void testGetComponentInstancePropertyByPolicyId_failure() {
Optional<ComponentInstanceProperty> propertyCandidate =
- getComponentInstanceProperty(NON_EXIST_NAME);
+ getComponentInstanceProperty(NON_EXIST_NAME);
Assert.assertEquals(propertyCandidate, Optional.empty());
}
@@ -1459,7 +1490,7 @@ public class ComponentInstanceBusinessLogicTest {
componentInstanceProperty.setGetPolicyValues(policyDefinition.getGetPolicyValues());
service.setComponentInstancesProperties(
- Collections.singletonMap(COMPONENT_INST_ID, Collections.singletonList(componentInstanceProperty)));
+ Collections.singletonMap(COMPONENT_INST_ID, Collections.singletonList(componentInstanceProperty)));
return componentInstanceBusinessLogic.getComponentInstancePropertyByPolicyId(service, policyDefinition);
}
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 7d604bbc50..ca4f569cf3 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
@@ -7,9 +7,9 @@
* 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.
@@ -20,14 +20,28 @@
package org.openecomp.sdc.be.tosca;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+
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.stream.Collectors;
import mockit.Deencapsulation;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Triple;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
@@ -81,1290 +95,1336 @@ import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
import org.openecomp.sdc.be.tosca.utils.InputConverter;
-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.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
public class ToscaExportHandlerTest extends BeConfDependentTest {
- private static final String COMPONENT_PROPERTY_NAME = "prop1";
- private static final String COMPONENT_PROPERTY_TYPE = "string";
- private static final String COMPONENT_INPUT_NAME = "input1";
- private static final String COMPONENT_INPUT_TYPE = "integer";
- private static final String RESOURCE_NAME = "resource";
- private static final String TOSCA_VERSION = "tosca_simple_yaml_1_1";
-
- @InjectMocks
- ToscaExportHandler testSubject;
-
- @Mock
- ApplicationDataTypeCache dataTypeCache;
-
- @Mock
- ToscaOperationFacade toscaOperationFacade;
-
- @Mock
- CapabilityRequirementConverter capabiltyRequirementConvertor;
-
- @Mock
- InputConverter inputConverter;
-
- @Mock
- GroupExportParser groupExportParser;
-
- @Mock
- GroupExportParserImpl groupExportParserImpl;
-
- @Mock
- InterfaceLifecycleOperation interfaceLifecycleOperation;
-
- @Before
- public void setUpMock() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
- private Resource getNewResource() {
- Resource resource = new Resource();
- List<CategoryDefinition> categories = new ArrayList<>();
- CategoryDefinition category = new CategoryDefinition();
- List<SubCategoryDefinition> subcategories = new ArrayList<>();
- SubCategoryDefinition subcategory = new SubCategoryDefinition();
- List<DataTypeDefinition> dataTypes = new ArrayList<>();
- DataTypeDefinition dataType = new DataTypeDefinition();
- dataType.setName("dataTypeName");
- dataType.setDerivedFromName("tosca.datatypes.Root");
- PropertyDataDefinition propData = new PropertyDataDefinitionBuilder()
- .setName("property")
- .setType("type")
- .build();
- List<PropertyDataDefinition> propDataList = Arrays.asList(propData);
- dataType.setPropertiesData(propDataList);
- List<PropertyDefinition> propList = propDataList.stream().map(PropertyDefinition::new)
- .collect(Collectors.toList());
- dataType.setProperties(propList);
- dataTypes.add(dataType);
-
- subcategory.setName("name");
- subcategories.add(subcategory);
- category.setName("name");
- category.setSubcategories(subcategories);
- categories.add(category);
-
- resource.setCategories(categories);
- resource.setVersion("version");
- resource.setVendorName("vendorName");
- resource.setVendorRelease("vendorRelease");
- resource.setResourceVendorModelNumber("resourceVendorModelNumber");
- resource.setDataTypes(dataTypes);
-
- return resource;
- }
-
- private Service getNewService() {
- Service service = new Service();
- List<CategoryDefinition> categories = new ArrayList<>();
- CategoryDefinition category = new CategoryDefinition();
- List<SubCategoryDefinition> subcategories = new ArrayList<>();
- SubCategoryDefinition subcategory = new SubCategoryDefinition();
-
- subcategory.setName("name");
- subcategories.add(subcategory);
- category.setName("name");
- category.setSubcategories(subcategories);
- categories.add(category);
-
- service.setCategories(categories);
- service.setComponentType(ComponentTypeEnum.SERVICE);
- service.setServiceType("serviceType");
- service.setServiceRole("serviceRole");
- service.setEnvironmentContext("environmentContext");
-
- return service;
- }
-
- @Test
- public void testExportComponent() throws Exception {
- Component component = getNewResource();
- Either<ToscaRepresentation, ToscaError> result;
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class), Mockito.any(Resource.class),
- Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
-
- // default test when component is Resource
- result = testSubject.exportComponent(component);
-
- component = getNewService();
- Mockito.when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class),Mockito.any(Service.class),
- Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
-
- // default test when component is Service
- result = testSubject.exportComponent(component);
- }
-
- @Test
- public void testExportComponentInterface() throws Exception {
- Component component = getNewResource();
- Either<ToscaRepresentation, ToscaError> result;
-
- ((Resource) component).setInterfaces(new HashMap<>());
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
- // default test when convertInterfaceNodeType is right
- result = testSubject.exportComponentInterface(component, false);
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class),Mockito.any(Resource.class),
- Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
-
- // default test when convertInterfaceNodeType is left
- result = testSubject.exportComponentInterface(component, false);
-
- }
-
- @Test
- public void testConvertInterfaceNodeTypeProperties() throws Exception {
-
- Resource component = getNewResource();
-
- component.setInterfaces(new HashMap<>());
- InputDefinition input = new InputDefinition();
- input.setName(COMPONENT_INPUT_NAME);
- input.setType(COMPONENT_INPUT_TYPE);
- component.setInputs(Collections.singletonList(input));
- PropertyDefinition property = new PropertyDefinition();
- property.setName(COMPONENT_PROPERTY_NAME);
- property.setType(COMPONENT_PROPERTY_TYPE);
- component.setProperties(Collections.singletonList(property));
- component.setName(RESOURCE_NAME);
- component.setToscaResourceName(RESOURCE_NAME);
-
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- // when convertRequirements is called, make it return the same value as 3rd (index=2) argument.
- Mockito
- .when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class), Mockito.any(Resource.class),
- Mockito.any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2)));
-
- Either<ToscaTemplate, ToscaError> result = (Either<ToscaTemplate, ToscaError>) Deencapsulation
- .invoke(testSubject, "convertInterfaceNodeType", new HashMap<String, Component>(), component,
- new ToscaTemplate(TOSCA_VERSION), new HashMap<String, ToscaNodeType>(), false);
- assertThat(result.isLeft(), is(true));
- Map<String, ToscaNodeType> nodeTypeMap = result.left().value().getNode_types();
- assertThat(nodeTypeMap.size(), is(1));
- ToscaNodeType toscaNodeType = nodeTypeMap.values().iterator().next();
- Map<String, ToscaProperty> propertyMap = toscaNodeType.getProperties();
- // Check if inputs and properties in component are merged properly
- assertThat(propertyMap.size(), is(2));
- assertThat(propertyMap.containsKey(COMPONENT_INPUT_NAME), is(true));
- assertThat(propertyMap.containsKey(COMPONENT_PROPERTY_NAME), is(true));
- }
-
- @Test
- public void testCreateToscaRepresentation() throws Exception {
- ToscaTemplate toscaTemplate = new ToscaTemplate("");
- ToscaRepresentation result;
-
- // default test
- result = testSubject.createToscaRepresentation(toscaTemplate);
- }
-
- @Test
- public void testGetDependencies() throws Exception {
-
- Component component = new Resource();
- Either<ToscaTemplate, ToscaError> result;
-
- // default test
- result = testSubject.getDependencies(component);
- }
-
- @Test
- public void testConvertToscaTemplate() throws Exception {
-
- Component component = getNewResource();
- ToscaTemplate toscaNode = new ToscaTemplate("");
- Either<ToscaTemplate, ToscaError> result;
- List<ComponentInstance> resourceInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
-
- instance.setOriginType(OriginTypeEnum.SERVICE);
- instance.setSourceModelUid("targetModelUid");
- resourceInstances.add(instance);
-
- component.setComponentInstances(resourceInstances);
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(Mockito.any(Map.class),
- Mockito.any(ComponentInstance.class))).thenReturn(Either.right(false));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
- }
-
- @Ignore("need to solve problem with groupExportParser injection")
- @Test
- public void testConvertToscaTemplateWhenComponentContainsGroup() {
- Component component = getNewResource();
- ToscaTemplate toscaNode = new ToscaTemplate("");
- Either<ToscaTemplate, ToscaError> result;
- component.setComponentInstances(new ArrayList<>());
-
- List<GroupDefinition> groups = new ArrayList<>();
- GroupDefinition group = new GroupDefinition();
- List<String> artifacts = new ArrayList<>();
- artifacts.add("artifact");
- group.setType("org.openecomp.groups.VfModule");
- group.setArtifacts(artifacts);
- groups.add(group);
- component.setGroups(groups);
-
- Map<String, String[]> substitutionMappingMap = new HashMap<>();
- String[] array = { "value1", "value2" };
- substitutionMappingMap.put("key", array);
-
- Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(Mockito.any(Map.class),
- Mockito.any(Component.class))).thenReturn(Either.left(substitutionMappingMap));
-
- Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingRequirements(Mockito.any(Map.class),
- Mockito.any(Component.class), Mockito.any(SubstitutionMapping.class)))
- .thenReturn(Either.left(new SubstitutionMapping()));
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
-
- Mockito.when(inputConverter.convertInputs(Mockito.any(List.class),Mockito.any(Map.class)))
- .thenReturn(new HashMap<>());
-
- Mockito.when(groupExportParser.getGroups(component))
- .thenReturn(null);
-
- // test component contains group
- result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
- }
-
- @Ignore("need to solve problem with groupExportParser injection")
- @Test
- public void testConvertToscaTemplateWhenComponentIsService() throws Exception {
- Component component = getNewService();
- ToscaTemplate toscaNode = new ToscaTemplate("");
- Either<ToscaTemplate, ToscaError> result;
- component.setComponentInstances(new ArrayList<>());
-
- List<GroupDefinition> groups = new ArrayList<>();
- GroupDefinition group = new GroupDefinition();
- List<String> artifacts = new ArrayList<>();
- artifacts.add("artifact");
- group.setType("org.openecomp.groups.VfModule");
- group.setArtifacts(artifacts);
- groups.add(group);
- component.setGroups(groups);
-
- Map<String, String[]> substitutionMappingMap = new HashMap<>();
- String[] array = { "value1", "value2" };
- substitutionMappingMap.put("key", array);
-
- Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(Mockito.any(Map.class),
- Mockito.any(Component.class))).thenReturn(Either.left(substitutionMappingMap));
-
- Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingRequirements(Mockito.any(Map.class),
- Mockito.any(Component.class), Mockito.any(SubstitutionMapping.class)))
- .thenReturn(Either.left(new SubstitutionMapping()));
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
-
- Mockito.when(inputConverter.convertInputs(Mockito.any(List.class),Mockito.any(Map.class)))
- .thenReturn(new HashMap<>());
- // test component contains group
- result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
- }
-
- @Test
- public void testConvertMetadata_1() throws Exception {
-
- Component component = getNewResource();
- boolean isInstance = true;
- ComponentInstance componentInstance = new ComponentInstance();
- componentInstance.setOriginType(OriginTypeEnum.ServiceProxy);
- componentInstance.setSourceModelInvariant("targetModelInvariant");
-
- ToscaMetadata result;
-
- // default test
-
- result = Deencapsulation.invoke(testSubject, "convertMetadata", component, isInstance, componentInstance);
- }
-
- @Test
- public void testFillImports() throws Exception {
-
- Component component = getNewService();
- ToscaTemplate toscaTemplate = new ToscaTemplate("");
- Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> result;
-
- ComponentInstance instance = new ComponentInstance();
- List<ComponentInstance> resourceInstances = new ArrayList<>();
- instance.setComponentUid("name");
- resourceInstances.add(instance);
- component.setComponentInstances(resourceInstances);
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("name.name2");
- toscaArtifacts.put("assettoscatemplate", artifact);
- component.setToscaArtifacts(toscaArtifacts);
-
- Mockito.when(toscaOperationFacade.getToscaFullElement(Mockito.any(String.class)))
- .thenReturn(Either.left(component));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate);
- }
-
- @Test
- public void testCreateDependency() throws Exception {
-
- Map<String, Component> componentCache = new HashMap<>();
- List<Map<String, Map<String, String>>> imports = new ArrayList<>();
- List<Triple<String, String, Component>> dependecies = new ArrayList<>();
- ComponentInstance ci = new ComponentInstance();
- Component component = getNewResource();
-
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("name.name2");
- toscaArtifacts.put("assettoscatemplate", artifact);
- component.setToscaArtifacts(toscaArtifacts);
- ci.setComponentUid("name");
- ci.setOriginType(OriginTypeEnum.ServiceProxy);
- ci.setSourceModelUid("modelName");
-
- Mockito.when(toscaOperationFacade.getToscaFullElement(Mockito.eq("name"))).thenReturn(Either.left(component));
-
- Mockito.when(toscaOperationFacade.getToscaFullElement(Mockito.eq("modelName")))
- .thenReturn(Either.left(new Service()));
-
- // default test
- Deencapsulation.invoke(testSubject, "createDependency", componentCache, imports, dependecies, ci);
- }
-
- @Test
- public void testGetInterfaceFilename() throws Exception {
- String artifactName = "artifact.name";
- String result;
-
- // default test
- result = ToscaExportHandler.getInterfaceFilename(artifactName);
- }
-
- @Test
- public void testConvertNodeType() throws Exception {
- Component component = new Resource();
- ToscaTemplate toscaNode = new ToscaTemplate("");
- Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- Either<ToscaTemplate, ToscaError> result;
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
- // default test
- result = Deencapsulation.invoke(testSubject, "convertNodeType",new HashMap<>(), component, toscaNode, nodeTypes);
- }
-
- @Test
- public void testConvertInterfaceNodeType() throws Exception {
- Component component = getNewResource();
- ToscaTemplate toscaNode = new ToscaTemplate("");
- Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- Either<ToscaTemplate, ToscaError> result;
- List<InputDefinition> inputs = new ArrayList<>();
- inputs.add(new InputDefinition());
- component.setInputs(inputs);
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
-
- Mockito.when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class), Mockito.any(Resource.class),
- Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertInterfaceNodeType",new HashMap<>(), component, toscaNode
- , nodeTypes, false);
- }
- @Ignore("need to fix change in injected class.")
- @Test
- public void testConvertReqCapAndTypeName() throws Exception {
- Component component = new Resource();
- ToscaTemplate toscaNode = new ToscaTemplate("");
- Map<String, ToscaNodeType> nodeTypes = new HashMap();
- ToscaNodeType toscaNodeType = new ToscaNodeType();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- Either<ToscaTemplate, ToscaError> result;
-
- Mockito.when(
- capabiltyRequirementConvertor.convertCapabilities(Mockito.any(Map.class),Mockito.any(Resource.class), Mockito.any(Map.class)))
- .thenReturn(new HashMap<>());
-
- Mockito.when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class),Mockito.any(Resource.class),
- Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertReqCapAndTypeName",new HashMap<>(), component, toscaNode, nodeTypes,
- toscaNodeType, dataTypes);
-
- component = new Service();
-
- Mockito.when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class),Mockito.any(Service.class),
- Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
-
- // test when component is service
- result = Deencapsulation.invoke(testSubject, "convertReqCapAndTypeName", component, toscaNode, nodeTypes,
- toscaNodeType, dataTypes);
- }
-
- @Ignore
- @Test
- public void testConvertNodeTemplates() throws Exception {
- Component component = getNewResource();
- List<ComponentInstance> componentInstances = new ArrayList<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
- Map<String, Component> componentCache = new HashMap<>();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
- Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
- List<ComponentInstanceInput> inputs = new ArrayList<>();
- inputs.add(new ComponentInstanceInput());
- componentInstancesInputs.put("key", inputs);
- List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
- RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
- reldef.setFromNode("node");
- resourceInstancesRelations.add(reldef);
- component.setComponentInstancesRelations(resourceInstancesRelations);
-
- ComponentInstance instance = new ComponentInstance();
- instance.setUniqueId("id");
- instance.setComponentUid("uid");
- instance.setOriginType(OriginTypeEnum.ServiceProxy);
- List<GroupInstance> groupInstances = new ArrayList<>();
- GroupInstance groupInst = new GroupInstance();
- List<String> artifacts = new ArrayList<>();
- artifacts.add("artifact");
- groupInst.setArtifacts(artifacts);
- groupInst.setType("type");
- groupInstances.add(groupInst);
- instance.setGroupInstances(groupInstances);
- componentInstances.add(instance);
-
- component.setComponentInstancesInputs(componentInstancesInputs);
- component.setInvariantUUID("uuid");
- component.setUUID("uuid");
- component.setDescription("desc");
-
- componentCache.put("uid", component);
-
- componentInstancesProperties.put("id", new ArrayList<>());
- componentInstancesInputs.put("id", new ArrayList<>());
-
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(Mockito.any(Map.class),
- Mockito.any(ComponentInstance.class))).thenReturn(Either.left(component));
-
- Mockito.when(capabiltyRequirementConvertor.convertComponentInstanceCapabilities(
- Mockito.any(ComponentInstance.class), Mockito.any(Map.class), Mockito.any(ToscaNodeTemplate.class)))
- .thenReturn(Either.left(new ToscaNodeTemplate()));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, componentCache, dataTypes, topologyTemplate);
- }
-
- @Test
- public void testConvertNodeTemplatesWhenComponentIsService() throws Exception {
- Component component = getNewService();
- List<ComponentInstance> componentInstances = new ArrayList<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
- Map<String, Component> componentCache = new HashMap<>();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
- Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
- List<ComponentInstanceInput> inputs = new ArrayList<>();
- inputs.add(new ComponentInstanceInput());
- componentInstancesInputs.put("key", inputs);
- List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
- RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
- reldef.setFromNode("node");
- resourceInstancesRelations.add(reldef);
- component.setComponentInstancesRelations(resourceInstancesRelations);
-
- ComponentInstance instance = new ComponentInstance();
- instance.setUniqueId("id");
- instance.setComponentUid("uid");
- instance.setOriginType(OriginTypeEnum.ServiceProxy);
- List<GroupInstance> groupInstances = new ArrayList<>();
- GroupInstance groupInst = new GroupInstance();
- List<String> artifacts = new ArrayList<>();
- artifacts.add("artifact");
- groupInst.setArtifacts(artifacts);
- groupInst.setType("type");
- groupInstances.add(groupInst);
- instance.setGroupInstances(groupInstances);
- componentInstances.add(instance);
-
- component.setComponentInstancesInputs(componentInstancesInputs);
- component.setInvariantUUID("uuid");
- component.setUUID("uuid");
- component.setDescription("desc");
-
- Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
- ForwardingPathDataDefinition path = new ForwardingPathDataDefinition();
- ListDataDefinition<ForwardingPathElementDataDefinition> list = new ListDataDefinition<>();
- path.setPathElements(list);
- forwardingPaths.put("key", path);
-
- ((Service) component).setForwardingPaths(forwardingPaths);
-
- componentCache.put("uid", component);
-
- componentInstancesProperties.put("id", new ArrayList<>());
- componentInstancesInterfaces.put("id", new ArrayList<>());
- componentInstancesInputs.put("id", new ArrayList<>());
-
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(Mockito.any(Map.class),
- Mockito.any(ComponentInstance.class))).thenReturn(Either.left(component));
-
- Mockito.when(capabiltyRequirementConvertor.convertComponentInstanceCapabilities(
- Mockito.any(ComponentInstance.class), Mockito.any(Map.class), Mockito.any(ToscaNodeTemplate.class)))
- .thenReturn(Either.left(new ToscaNodeTemplate()));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
- }
-
- @Test
- public void testConvertNodeTemplatesWhenConvertComponentInstanceCapabilitiesIsRight() throws Exception {
- Component component = getNewResource();
- List<ComponentInstance> componentInstances = new ArrayList<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
- Map<String, Component> componentCache = new HashMap<>();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
- Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
- List<ComponentInstanceInput> inputs = new ArrayList<>();
- inputs.add(new ComponentInstanceInput());
- componentInstancesInputs.put("key", inputs);
- List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
- RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
- reldef.setFromNode("node");
- resourceInstancesRelations.add(reldef);
- component.setComponentInstancesRelations(resourceInstancesRelations);
-
- ComponentInstance instance = new ComponentInstance();
- instance.setUniqueId("id");
- instance.setComponentUid("uid");
- instance.setOriginType(OriginTypeEnum.ServiceProxy);
- componentInstances.add(instance);
-
- component.setComponentInstancesInputs(componentInstancesInputs);
- component.setInvariantUUID("uuid");
- component.setUUID("uuid");
- component.setDescription("desc");
-
- componentCache.put("uid", component);
-
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(Mockito.any(Map.class),
- Mockito.any(ComponentInstance.class))).thenReturn(Either.left(component));
-
- Mockito.when(capabiltyRequirementConvertor.convertComponentInstanceCapabilities(
- Mockito.any(ComponentInstance.class), Mockito.any(Map.class), Mockito.any(ToscaNodeTemplate.class)))
- .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
- }
-
- @Test
- public void testConvetNodeTemplateWhenGetOriginComponentIsRight() throws Exception {
- Component component = getNewResource();
- List<ComponentInstance> componentInstances = new ArrayList<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
- Map<String, Component> componentCache = new HashMap<>();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
- Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
- List<ComponentInstanceInput> inputs = new ArrayList<>();
- inputs.add(new ComponentInstanceInput());
- componentInstancesInputs.put("key", inputs);
- List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
- RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
- reldef.setFromNode("id");
- resourceInstancesRelations.add(reldef);
- component.setComponentInstancesRelations(resourceInstancesRelations);
-
- ComponentInstance instance = new ComponentInstance();
- instance.setUniqueId("id");
- instance.setComponentUid("uid");
- instance.setOriginType(OriginTypeEnum.ServiceProxy);
- componentInstances.add(instance);
-
- component.setComponentInstancesInputs(componentInstancesInputs);
- component.setInvariantUUID("uuid");
- component.setUUID("uuid");
- component.setDescription("desc");
-
- componentCache.put("uid", component);
-
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(Mockito.any(Map.class),
- Mockito.any(ComponentInstance.class))).thenReturn(Either.right(false));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
- }
-
- @Test
- public void testConvertNodeTemplatesWhenConvertComponentInstanceRequirmentsIsRight() {
- Component component = new Resource();
- List<ComponentInstance> componentInstances = new ArrayList<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
- Map<String, Component> componentCache = new HashMap<>();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
- Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
- List<ComponentInstanceInput> inputs = new ArrayList<>();
- inputs.add(new ComponentInstanceInput());
- componentInstancesInputs.put("key", inputs);
- List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
- RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
- reldef.setFromNode("id");
- reldef.setToNode("node");
- List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
- CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
- relationship.setRelation(new RelationshipInfo());
- relationships.add(relationship);
- reldef.setRelationships(relationships);
- resourceInstancesRelations.add(reldef);
- component.setComponentInstancesRelations(resourceInstancesRelations);
-
- ComponentInstance instance = new ComponentInstance();
- instance.setUniqueId("id");
- componentInstances.add(instance);
-
- component.setComponentInstancesInputs(componentInstancesInputs);
- component.setComponentInstances(componentInstances);
-
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(Mockito.any(Map.class),
- Mockito.any(ComponentInstance.class))).thenReturn(Either.left(component));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
- }
-
- @Test
- public void testAddComponentInstanceInputs() throws Exception {
-
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
- ComponentInstance componentInstance = new ComponentInstance();
- String instanceUniqueId = "id";
- Map<String, Object> props = new HashMap<>();
-
- List<ComponentInstanceInput> componentInstanceInputs = new ArrayList<>();
- componentInstanceInputs.add(new ComponentInstanceInput());
-
- componentInstancesInputs.put(instanceUniqueId, componentInstanceInputs);
-
- // default test
- Deencapsulation.invoke(testSubject, "addComponentInstanceInputs", dataTypes, componentInstancesInputs,
- instanceUniqueId, props);
- }
-
- @Test
- public void testAddPropertiesOfComponentInstance() throws Exception {
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ComponentInstance componentInstance = new ComponentInstance();
- String instanceUniqueId = "id";
- Map<String, Object> props = new HashMap<>();
-
- ComponentInstanceProperty cip = new ComponentInstanceProperty();
- cip.setInstanceUniqueId("id");
-
- List<ComponentInstanceProperty> list = new ArrayList<>();
- list.add(cip);
-
- componentInstancesProperties.put("id", list);
-
- // default test
- Deencapsulation.invoke(testSubject, "addPropertiesOfComponentInstance", componentInstancesProperties, dataTypes,
- instanceUniqueId, props);
- }
-
- @Test
- public void testAddPropertiesOfParentComponent() throws Exception {
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ComponentInstance componentInstance = new ComponentInstance();
- Component componentOfInstance = new Resource();
- Map<String, Object> props = new HashMap<>();
-
- List<PropertyDefinition> properties = new ArrayList<>();
- properties.add(new PropertyDefinition());
-
- ((Resource) componentOfInstance).setProperties(properties);
-
- // default test
- Deencapsulation.invoke(testSubject, "addPropertiesOfParentComponent", dataTypes,
- componentOfInstance, props);
- }
-
-
- @Test
- public void testCreateNodeType() throws Exception {
-
- Component component = new Resource();
- List<String> array = new ArrayList<>();
- array.add("value");
- ((Resource) component).setDerivedFrom(array);
- ToscaNodeType result;
-
- // test when component is resource
- result = Deencapsulation.invoke(testSubject, "createNodeType", component);
-
- component = new Service();
- // test when component is service
- result = Deencapsulation.invoke(testSubject, "createNodeType", component);
- }
-
- @Test
- public void testCreateProxyInterfaceTypesComponentNotFound() throws Exception {
- Component container = new Service();
- Either<Map<String, ToscaNodeType>, ToscaError> result;
- List<ComponentInstance> componentInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setOriginType(OriginTypeEnum.ServiceProxy);
- instance.setSourceModelUid("targetModelUid");
- instance.setToscaComponentName("toscaComponentName");
-
- componentInstances.add(instance);
- container.setComponentInstances(componentInstances);
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class),
- Mockito.any(ComponentParametersView.class)))
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
- Assert.assertTrue(result.isRight());
-
- }
-
- @Test
- public void testCreateProxyInterfaceTypesWhenInterfaceLifecycleFetchFailed() {
- Component container = new Service();
- Either<Map<String, ToscaNodeType>, ToscaError> result;
- List<ComponentInstance> componentInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setOriginType(OriginTypeEnum.ServiceProxy);
- instance.setSourceModelUid("targetModelUid");
- instance.setToscaComponentName("toscaComponentName");
- componentInstances.add(instance);
- container.setComponentInstances(componentInstances);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class),
- Mockito.any(ComponentParametersView.class)))
- .thenReturn(Either.left(new Resource()));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
- Assert.assertTrue(result.isRight());
- }
-
- @Test
- public void testCreateProxyInterfaceTypesPositive() {
- Component container = new Service();
- Either<Map<String, ToscaNodeType>, ToscaError> result;
- List<ComponentInstance> componentInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setOriginType(OriginTypeEnum.ServiceProxy);
- instance.setSourceModelUid("targetModelUid");
- instance.setToscaComponentName("toscaComponentName");
- componentInstances.add(instance);
- container.setComponentInstances(componentInstances);
-
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
-
- Component proxyResource = new Resource();
- Map<String, InterfaceDefinition> proxyInterfaces = new HashMap<>();
- proxyInterfaces.put("Local", new InterfaceDefinition("Local", "desc", new HashMap<>()));
- proxyResource.setInterfaces(proxyInterfaces);
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class),
- Mockito.any(ComponentParametersView.class)))
- .thenReturn(Either.left(proxyResource));
-
- result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
- Assert.assertTrue(result.isLeft());
- Assert.assertEquals(1, result.left().value().size());
- }
-
- @Test
- public void testCreateProxyNodeTypes() throws Exception {
- Map<String, Component> componentCache = new HashMap<>();
- Component container = new Resource();
- Either<Map<String, ToscaNodeType>, ToscaError> result;
- List<ComponentInstance> componentInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setOriginType(OriginTypeEnum.ServiceProxy);
- instance.setSourceModelUid("targetModelUid");
-
- componentInstances.add(instance);
- container.setComponentInstances(componentInstances);
-
- Mockito.when(toscaOperationFacade.getLatestByName("serviceProxy"))
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
-
- // test when getLatestByName return is right
- result = Deencapsulation.invoke(testSubject, "createProxyNodeTypes", componentCache, container);
-
- }
-
- @Test
- public void testCreateProxyNodeTypesWhenGetLatestByNameReturnValue() {
- Map<String, Component> componentCache = new HashMap<>();
- Component container = new Resource();
- Either<Map<String, ToscaNodeType>, ToscaError> result;
- List<ComponentInstance> componentInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setOriginType(OriginTypeEnum.ServiceProxy);
- instance.setSourceModelUid("targetModelUid");
-
- componentInstances.add(instance);
- container.setComponentInstances(componentInstances);
-
- Mockito.when(toscaOperationFacade.getLatestByName("serviceProxy")).thenReturn(Either.left(new Resource()));
-
- ComponentParametersView parameterView = new ComponentParametersView();
- parameterView.disableAll();
- parameterView.setIgnoreCategories(false);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class),
- Mockito.any(ComponentParametersView.class)))
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
-
- // test when getLatestByName is left
- result = Deencapsulation.invoke(testSubject, "createProxyNodeTypes", componentCache, container);
- }
-
- @Test
- public void testCreateProxyNodeType() throws Exception {
- Map<String, Component> componentCache = new HashMap<>();
- Component origComponent = new Resource();
- Component proxyComponent = new Resource();
- ComponentInstance instance = new ComponentInstance();
- ToscaNodeType result;
-
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "createProxyNodeType", componentCache, origComponent,
- proxyComponent, instance);
- }
-
- @Test
- public void testConvertComponentInstanceRequirements() throws Exception {
- Component component = new Resource();
- ComponentInstance componentInstance = new ComponentInstance();
- List<RequirementCapabilityRelDef> relations = new ArrayList<>();
- ToscaNodeTemplate nodeTypeTemplate = new ToscaNodeTemplate();
- Component originComponent = new Resource();
- Map<String, Component> componentCache = new HashMap<>();
- Either<ToscaNodeTemplate, ToscaError> result;
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertComponentInstanceRequirements", component,
- componentInstance, relations, nodeTypeTemplate, originComponent, componentCache);
-
- RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
- reldef.setFromNode("name");
- reldef.setToNode("name1");
- List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
- CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
- cap.setRelation(new RelationshipInfo());
- relationships.add(cap);
- reldef.setRelationships(relationships);
- relations.add(reldef);
- componentInstance.setUniqueId("name");
-
- List<ComponentInstance> instances = new ArrayList<>();
- instances.add(componentInstance);
- component.setComponentInstances(instances);
-
- // test when filteredRElations ins't empty
- result = Deencapsulation.invoke(testSubject, "convertComponentInstanceRequirements", component,
- componentInstance, relations, nodeTypeTemplate, originComponent, componentCache);
- }
-
- @Test
- public void testAddRequirement() throws Exception {
- ComponentInstance fromInstance = new ComponentInstance();
- Component fromOriginComponent = new Resource();
- List<ComponentInstance> instancesList = new ArrayList<>();
- RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Map<String, Component> componentCache = new HashMap<>();
- boolean result;
-
- List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
- CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
- cap.setRequirement(new RequirementDataDefinition());
- RelationshipInfo relation = new RelationshipInfo();
- relation.setRequirementUid("Uid");
- relation.setRequirement("requirment");
- relation.setCapability("cap");
- relation.setCapabilityOwnerId("id1");
- cap.setRelation(relation);
- relationships.add(cap);
- rel.setRelationships(relationships);
- rel.setToNode("name");
- fromInstance.setUniqueId("name");
- fromInstance.setComponentUid("string");
- instancesList.add(fromInstance);
- Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
- fromOriginComponent.setRequirements(requirements);
-
- // default test
- result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
- rel, toscaRequirements, componentCache);
-
- }
-
- @Test
- public void testAddRequirmentsWhenFindRequirmentsReturnsValue() {
-
- ComponentInstance fromInstance = new ComponentInstance();
- Component fromOriginComponent = new Resource();
- List<ComponentInstance> instancesList = new ArrayList<>();
- RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Map<String, Component> componentCache = new HashMap<>();
- boolean result;
-
- List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
- CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
- cap.setRequirement(new RequirementDataDefinition());
- RelationshipInfo relation = new RelationshipInfo();
- relation.setRequirementUid("Uid");
- relation.setRequirement("requirment");
- relation.setCapability("cap");
- relation.setCapabilityOwnerId("id1");
- cap.setRelation(relation);
- relationships.add(cap);
- rel.setRelationships(relationships);
- rel.setToNode("name");
- fromInstance.setUniqueId("name");
- fromInstance.setComponentUid("string");
- instancesList.add(fromInstance);
- Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
-
- List<RequirementDefinition> defs = new ArrayList<>();
- RequirementDefinition def = new RequirementDefinition();
- def.setName("requirment");
- def.setCapability("cap");
- defs.add(def);
- requirements.put("key", defs);
- fromOriginComponent.setRequirements(requirements);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class),
- Mockito.any(ComponentParametersView.class)))
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
- rel, toscaRequirements, componentCache);
- }
-
- @Test
- public void testAddRequirmentsWhenCapabilityBelongsToRelation() {
- ComponentInstance fromInstance = new ComponentInstance();
- Component fromOriginComponent = new Resource();
- List<ComponentInstance> instancesList = new ArrayList<>();
- RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Map<String, Component> componentCache = new HashMap<>();
- boolean result;
-
- List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
- CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
- cap.setRequirement(new RequirementDataDefinition());
- RelationshipInfo relation = new RelationshipInfo();
- relation.setRequirementUid("Uid");
- relation.setRequirement("requirment");
- relation.setCapability("cap");
- relation.setCapabilityOwnerId("id1");
- cap.setRelation(relation);
- relationships.add(cap);
- rel.setRelationships(relationships);
- rel.setToNode("name");
- fromInstance.setUniqueId("name");
- fromInstance.setComponentUid("string");
- instancesList.add(fromInstance);
- Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
-
- List<RequirementDefinition> defs = new ArrayList<>();
- RequirementDefinition def = new RequirementDefinition();
- def.setName("requirment");
- def.setCapability("cap");
- defs.add(def);
- requirements.put("key", defs);
- fromOriginComponent.setRequirements(requirements);
-
- Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
- List<CapabilityDefinition> caps = new ArrayList<>();
- CapabilityDefinition capdef = new CapabilityDefinition();
- capdef.setOwnerId("id");
- capdef.setName("name");
- capdef.setType("type");
- caps.add(capdef);
- capabilities.put("cap", caps);
-
- fromOriginComponent.setCapabilities(capabilities);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class),
- Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(fromOriginComponent));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
- rel, toscaRequirements, componentCache);
- }
- @Ignore("need to fix change in injected class.")
- @Test
- public void testAddRequirmentsWithBuildAndAddRequirements() {
- ComponentInstance fromInstance = new ComponentInstance();
- Component fromOriginComponent = new Resource();
- List<ComponentInstance> instancesList = new ArrayList<>();
- RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Map<String, Component> componentCache = new HashMap<>();
- boolean result;
-
- List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
- CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
- cap.setRequirement(new RequirementDataDefinition());
- RelationshipInfo relation = new RelationshipInfo();
- relation.setRequirementUid("Uid");
- relation.setRequirement("requirment");
- relation.setCapability("cap");
- relation.setCapabilityOwnerId("id");
- cap.setRelation(relation);
- relationships.add(cap);
- rel.setRelationships(relationships);
- rel.setToNode("name");
- fromInstance.setUniqueId("name");
- fromInstance.setComponentUid("string");
- instancesList.add(fromInstance);
- Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
-
- List<RequirementDefinition> defs = new ArrayList<>();
- RequirementDefinition def = new RequirementDefinition();
- def.setName("requirment");
- def.setCapability("cap");
- defs.add(def);
- requirements.put("key", defs);
- fromOriginComponent.setRequirements(requirements);
-
- Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
- List<CapabilityDefinition> caps = new ArrayList<>();
- CapabilityDefinition capdef = new CapabilityDefinition();
- capdef.setOwnerId("id");
- capdef.setName("cap");
- capdef.setType("type");
- caps.add(capdef);
- capabilities.put("cap", caps);
- fromOriginComponent.setCapabilities(capabilities);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class),
- Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(fromOriginComponent));
-
- Mockito.when(capabiltyRequirementConvertor.buildSubstitutedName(Mockito.any(Map.class),
- Mockito.any(Component.class), Mockito.any(List.class), Mockito.anyString(),Mockito.anyString()))
- .thenReturn(Either.right(false));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
- rel, toscaRequirements, componentCache);
- }
- @Ignore("need to fix change in injected class.")
- @Test
- public void testBuildAndAddRequirement() throws Exception {
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Component fromOriginComponent = new Resource();
- Component toOriginComponent = new Resource();
- CapabilityDefinition capability = new CapabilityDefinition();
- RequirementDefinition requirement = new RequirementDefinition();
- RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
- ComponentInstance toInstance = new ComponentInstance();
- Map<String, Component> componentCache = new HashMap<>();
- boolean result;
- capability.setPath(new ArrayList<>());
- reqAndRelationshipPair.setCapability("cap");
- requirement.setPath(new ArrayList<>());
- reqAndRelationshipPair.setRequirement("req");
-
- Mockito.when(capabiltyRequirementConvertor.buildSubstitutedName(new HashMap<>(), toOriginComponent,
- new ArrayList<>(),Mockito.anyString(), "cap")).thenReturn(Either.left("buildCapNameRes"));
-
- Mockito.when(capabiltyRequirementConvertor.buildSubstitutedName(new HashMap<>(), fromOriginComponent,
- new ArrayList<>(),Mockito.anyString(), "req")).thenReturn(Either.right(false));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "buildAndAddRequirement", toscaRequirements, fromOriginComponent,
- toOriginComponent, capability, requirement, reqAndRelationshipPair, toInstance, componentCache);
- }
-
- @Ignore("need to fix change in injected class.")
- @Test
- public void testBuildAndAddRequirementBuildSubtitutedNameReturnsValueTwice() {
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Component fromOriginComponent = new Resource();
- Component toOriginComponent = new Resource();
- CapabilityDefinition capability = new CapabilityDefinition();
- RequirementDefinition requirement = new RequirementDefinition();
- RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
- ComponentInstance toInstance = new ComponentInstance();
- Map<String, Component> componentCache = new HashMap<>();
- boolean result;
- capability.setPath(new ArrayList<>());
- reqAndRelationshipPair.setCapability("cap");
- requirement.setPath(new ArrayList<>());
- reqAndRelationshipPair.setRequirement("req");
-
- Mockito.when(capabiltyRequirementConvertor.buildSubstitutedName(Mockito.anyMap(), Mockito.any(Resource.class),
- Mockito.anyList(), Mockito.anyString(),Mockito.anyString())).thenReturn(Either.left("buildCapNameRes"));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "buildAndAddRequirement", toscaRequirements, fromOriginComponent,
- toOriginComponent, capability, requirement, reqAndRelationshipPair, toInstance, componentCache);
- }
-
- @Test
- public void testIsRequirementBelongToRelation() throws Exception {
-
- Component originComponent = new Resource();
- RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
- RequirementDefinition requirement = new RequirementDefinition();
- String fromInstanceId = "";
- boolean result;
-
- requirement.setName("name");
- reqAndRelationshipPair.setRequirement("name1");
-
- // test return false
- result = Deencapsulation.invoke(testSubject, "isRequirementBelongToRelation", originComponent,
- reqAndRelationshipPair, requirement, fromInstanceId);
- }
-
- @Test
- public void testIsRequirementBelongToRelationWithNonAtomicComponent() {
-
- Component originComponent = new Service();
- RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
- RequirementDefinition requirement = new RequirementDefinition();
- String fromInstanceId = "";
- boolean result;
-
- // default test return true
- result = Deencapsulation.invoke(testSubject, "isRequirementBelongToRelation", originComponent,
- reqAndRelationshipPair, requirement, fromInstanceId);
- }
-
- @Test
- public void testIsRequirementBelongToOwner() throws Exception {
-
- RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
- RequirementDefinition requirement = new RequirementDefinition();
- String fromInstanceId = "";
- Component originComponent = new Resource();
- boolean result;
-
- requirement.setOwnerId("owner1");
- reqAndRelationshipPair.setRequirementOwnerId("owner");
-
- // default test
- result = Deencapsulation.invoke(testSubject, "isRequirementBelongToOwner", reqAndRelationshipPair, requirement,
- fromInstanceId, originComponent);
- }
-
- @Test
- public void testIsCvfc() throws Exception {
-
- Component component = new Resource();
- boolean result;
-
- component = new Service();
-
- result = Deencapsulation.invoke(testSubject, "isCvfc", component);
- }
-
- @Test
- public void testConvertCapabilities() throws Exception {
- Component component = new Resource();
- SubstitutionMapping substitutionMappings = new SubstitutionMapping();
- Map<String, Component> componentCache = new HashMap<>();
- Either<SubstitutionMapping, ToscaError> result;
-
- Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(componentCache, component))
- .thenReturn(Either.right(ToscaError.NODE_TYPE_CAPABILITY_ERROR));
-
- // default test return isRight
- result = Deencapsulation.invoke(testSubject, "convertCapabilities", component, substitutionMappings,
- componentCache);
- }
- @Ignore("need to fix change in injected class.")
- @Test
- public void testConvertCapabilities_1() throws Exception {
- Component component = new Resource();
- ToscaNodeType nodeType = new ToscaNodeType();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- Either<ToscaNodeType, ToscaError> result;
-
- Map<String, ToscaCapability> capabilities = new HashMap<>();
- capabilities.put("key", new ToscaCapability());
-
- Mockito.when(capabiltyRequirementConvertor.convertCapabilities(Mockito.any(Map.class), component, dataTypes)).thenReturn(capabilities);
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertCapabilities", component, nodeType, dataTypes);
- }
-
- @Test
- public void testConvertToNodeTemplateArtifacts() throws Exception {
- Map<String, ToscaArtifactDataDefinition> container = new HashMap<>();
- ToscaArtifactDataDefinition art = new ToscaArtifactDataDefinition();
- art.setFile("test_file");
- art.setType("test_type");
- Map<String, ToscaTemplateArtifact> result;
- container.put("test_art", art);
- result = Deencapsulation.invoke(testSubject, "convertToNodeTemplateArtifacts", container);
- Assert.assertTrue(MapUtils.isNotEmpty(result));
- Assert.assertTrue(result.get("test_art").getFile().equals("test_file"));
- Assert.assertTrue(result.get("test_art").getType().equals("test_type"));
- }
+
+ private static final String COMPONENT_PROPERTY_NAME = "prop1";
+ private static final String COMPONENT_PROPERTY_TYPE = "string";
+ private static final String COMPONENT_INPUT_NAME = "input1";
+ private static final String COMPONENT_INPUT_TYPE = "integer";
+ private static final String RESOURCE_NAME = "resource";
+ private static final String TOSCA_VERSION = "tosca_simple_yaml_1_1";
+
+ @InjectMocks
+ private ToscaExportHandler testSubject;
+
+ @Mock
+ private ApplicationDataTypeCache dataTypeCache;
+
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+
+ @Mock
+ private CapabilityRequirementConverter capabiltyRequirementConvertor;
+
+ @Mock
+ private InputConverter inputConverter;
+
+ @Mock
+ private GroupExportParser groupExportParser;
+
+ @Mock
+ private GroupExportParserImpl groupExportParserImpl;
+
+ @Mock
+ private InterfaceLifecycleOperation interfaceLifecycleOperation;
+
+ @Mock
+ private PolicyExportParser policyExportParser;
+
+ @Before
+ public void setUpMock() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ private Resource getNewResource() {
+ Resource resource = new Resource();
+ List<CategoryDefinition> categories = new ArrayList<>();
+ CategoryDefinition category = new CategoryDefinition();
+ List<SubCategoryDefinition> subcategories = new ArrayList<>();
+ SubCategoryDefinition subcategory = new SubCategoryDefinition();
+ List<DataTypeDefinition> dataTypes = new ArrayList<>();
+ DataTypeDefinition dataType = new DataTypeDefinition();
+ dataType.setName("dataTypeName");
+ dataType.setDerivedFromName("tosca.datatypes.Root");
+ PropertyDataDefinition propData = new PropertyDataDefinitionBuilder()
+ .setName("property")
+ .setType("type")
+ .build();
+ List<PropertyDataDefinition> propDataList = Arrays.asList(propData);
+ dataType.setPropertiesData(propDataList);
+ List<PropertyDefinition> propList = propDataList.stream().map(PropertyDefinition::new)
+ .collect(Collectors.toList());
+ dataType.setProperties(propList);
+ dataTypes.add(dataType);
+
+ subcategory.setName("name");
+ subcategories.add(subcategory);
+ category.setName("name");
+ category.setSubcategories(subcategories);
+ categories.add(category);
+
+ resource.setCategories(categories);
+ resource.setVersion("version");
+ resource.setVendorName("vendorName");
+ resource.setVendorRelease("vendorRelease");
+ resource.setResourceVendorModelNumber("resourceVendorModelNumber");
+ resource.setDataTypes(dataTypes);
+
+ return resource;
+ }
+
+ private Service getNewService() {
+ Service service = new Service();
+ List<CategoryDefinition> categories = new ArrayList<>();
+ CategoryDefinition category = new CategoryDefinition();
+ List<SubCategoryDefinition> subcategories = new ArrayList<>();
+ SubCategoryDefinition subcategory = new SubCategoryDefinition();
+
+ subcategory.setName("name");
+ subcategories.add(subcategory);
+ category.setName("name");
+ category.setSubcategories(subcategories);
+ categories.add(category);
+
+ service.setCategories(categories);
+ service.setComponentType(ComponentTypeEnum.SERVICE);
+ service.setServiceType("serviceType");
+ service.setServiceRole("serviceRole");
+ service.setEnvironmentContext("environmentContext");
+
+ return service;
+ }
+
+ @Test
+ public void testExportComponent() throws Exception {
+ Component component = getNewResource();
+ Either<ToscaRepresentation, ToscaError> result;
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ Mockito
+ .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ .thenReturn(Either.left(Collections.emptyMap()));
+
+ // default test when component is Resource
+ result = testSubject.exportComponent(component);
+ Assert.assertNotNull(result);
+
+ component = getNewService();
+ Mockito
+ .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Service.class),
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+
+ // default test when component is Service
+ result = testSubject.exportComponent(component);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testExportComponentInterface() throws Exception {
+ Component component = getNewResource();
+ Either<ToscaRepresentation, ToscaError> result;
+
+ ((Resource) component).setInterfaces(new HashMap<>());
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ .thenReturn(Either.left(Collections.emptyMap()));
+ // default test when convertInterfaceNodeType is right
+ result = testSubject.exportComponentInterface(component, false);
+ Assert.assertNotNull(result);
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ Mockito
+ .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+
+ // default test when convertInterfaceNodeType is left
+ result = testSubject.exportComponentInterface(component, false);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertInterfaceNodeTypeProperties() throws Exception {
+
+ Resource component = getNewResource();
+
+ component.setInterfaces(new HashMap<>());
+ InputDefinition input = new InputDefinition();
+ input.setName(COMPONENT_INPUT_NAME);
+ input.setType(COMPONENT_INPUT_TYPE);
+ component.setInputs(Collections.singletonList(input));
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName(COMPONENT_PROPERTY_NAME);
+ property.setType(COMPONENT_PROPERTY_TYPE);
+ component.setProperties(Collections.singletonList(property));
+ component.setName(RESOURCE_NAME);
+ component.setToscaResourceName(RESOURCE_NAME);
+
+ Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ .thenReturn(Either.left(Collections.emptyMap()));
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ // when convertRequirements is called, make it return the same value as 3rd (index=2) argument.
+ Mockito
+ .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2)));
+
+ Either<ToscaTemplate, ToscaError> result = (Either<ToscaTemplate, ToscaError>) Deencapsulation
+ .invoke(testSubject, "convertInterfaceNodeType", new HashMap<String, Component>(), component,
+ new ToscaTemplate(TOSCA_VERSION), new HashMap<String, ToscaNodeType>(), false);
+ Assert.assertNotNull(result);
+ assertThat(result.isLeft(), is(true));
+ Map<String, ToscaNodeType> nodeTypeMap = result.left().value().getNode_types();
+ assertThat(nodeTypeMap.size(), is(1));
+ ToscaNodeType toscaNodeType = nodeTypeMap.values().iterator().next();
+ Map<String, ToscaProperty> propertyMap = toscaNodeType.getProperties();
+ // Check if inputs and properties in component are merged properly
+ assertThat(propertyMap.size(), is(2));
+ assertThat(propertyMap.containsKey(COMPONENT_INPUT_NAME), is(true));
+ assertThat(propertyMap.containsKey(COMPONENT_PROPERTY_NAME), is(true));
+ }
+
+ @Test
+ public void testCreateToscaRepresentation() throws Exception {
+ ToscaTemplate toscaTemplate = new ToscaTemplate("");
+ ToscaRepresentation result;
+
+ // default test
+ result = testSubject.createToscaRepresentation(toscaTemplate);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testGetDependencies() throws Exception {
+
+ Component component = new Resource();
+ Either<ToscaTemplate, ToscaError> result;
+
+ // default test
+ result = testSubject.getDependencies(component);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertToscaTemplate() throws Exception {
+
+ Component component = getNewResource();
+ ToscaTemplate toscaNode = new ToscaTemplate("");
+ Either<ToscaTemplate, ToscaError> result;
+ List<ComponentInstance> resourceInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+
+ instance.setOriginType(OriginTypeEnum.SERVICE);
+ instance.setSourceModelUid("targetModelUid");
+ resourceInstances.add(instance);
+
+ component.setComponentInstances(resourceInstances);
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ any(ComponentInstance.class))).thenReturn(Either.right(false));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertToscaTemplateWhenComponentContainsGroup() {
+ Component component = getNewResource();
+ ToscaTemplate toscaNode = new ToscaTemplate("");
+ Either<ToscaTemplate, ToscaError> result;
+ component.setComponentInstances(new ArrayList<>());
+
+ List<GroupDefinition> groups = new ArrayList<>();
+ GroupDefinition group = new GroupDefinition();
+ List<String> artifacts = new ArrayList<>();
+ artifacts.add("artifact");
+ group.setType("org.openecomp.groups.VfModule");
+ group.setArtifacts(artifacts);
+ groups.add(group);
+ component.setGroups(groups);
+
+ Map<String, String[]> substitutionMappingMap = new HashMap<>();
+ String[] array = {"value1", "value2"};
+ substitutionMappingMap.put("key", array);
+
+ Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(any(Map.class),
+ any(Component.class))).thenReturn(Either.left(substitutionMappingMap));
+
+ Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingRequirements(any(Map.class),
+ any(Component.class), any(SubstitutionMapping.class)))
+ .thenReturn(Either.left(new SubstitutionMapping()));
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+
+ Mockito.when(inputConverter.convertInputs(any(List.class), any(Map.class)))
+ .thenReturn(new HashMap<>());
+
+ Mockito.when(groupExportParser.getGroups(component))
+ .thenReturn(null);
+
+ // test component contains group
+ result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertToscaTemplateWhenComponentIsService() throws Exception {
+ Component component = getNewService();
+ ToscaTemplate toscaNode = new ToscaTemplate("");
+ Either<ToscaTemplate, ToscaError> result;
+ component.setComponentInstances(new ArrayList<>());
+
+ List<GroupDefinition> groups = new ArrayList<>();
+ GroupDefinition group = new GroupDefinition();
+ List<String> artifacts = new ArrayList<>();
+ artifacts.add("artifact");
+ group.setType("org.openecomp.groups.VfModule");
+ group.setArtifacts(artifacts);
+ groups.add(group);
+ component.setGroups(groups);
+
+ Map<String, String[]> substitutionMappingMap = new HashMap<>();
+ String[] array = {"value1", "value2"};
+ substitutionMappingMap.put("key", array);
+
+ Mockito
+ .when(capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(anyMap(), any(Component.class)))
+ .thenReturn(Either.left(substitutionMappingMap));
+
+ Mockito.when(capabiltyRequirementConvertor
+ .convertSubstitutionMappingRequirements(anyMap(), any(Component.class), any(SubstitutionMapping.class)))
+ .thenReturn(Either.left(new SubstitutionMapping()));
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+
+ Mockito.when(inputConverter.convertInputs(anyList(), anyMap())).thenReturn(new HashMap<>());
+ // test component contains group
+ result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertMetadata_1() throws Exception {
+
+ Component component = getNewResource();
+ boolean isInstance = true;
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setOriginType(OriginTypeEnum.ServiceProxy);
+ componentInstance.setSourceModelInvariant("targetModelInvariant");
+
+ ToscaMetadata result;
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "convertMetadata", component, isInstance, componentInstance);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testFillImports() throws Exception {
+
+ Component component = getNewService();
+ ToscaTemplate toscaTemplate = new ToscaTemplate("");
+ Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> result;
+
+ ComponentInstance instance = new ComponentInstance();
+ List<ComponentInstance> resourceInstances = new ArrayList<>();
+ instance.setComponentUid("name");
+ resourceInstances.add(instance);
+ component.setComponentInstances(resourceInstances);
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("name.name2");
+ toscaArtifacts.put("assettoscatemplate", artifact);
+ component.setToscaArtifacts(toscaArtifacts);
+
+ Mockito.when(toscaOperationFacade.getToscaFullElement(any(String.class)))
+ .thenReturn(Either.left(component));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testCreateDependency() throws Exception {
+
+ Map<String, Component> componentCache = new HashMap<>();
+ List<Map<String, Map<String, String>>> imports = new ArrayList<>();
+ List<Triple<String, String, Component>> dependecies = new ArrayList<>();
+ ComponentInstance ci = new ComponentInstance();
+ Component component = getNewResource();
+
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("name.name2");
+ toscaArtifacts.put("assettoscatemplate", artifact);
+ component.setToscaArtifacts(toscaArtifacts);
+ ci.setComponentUid("name");
+ ci.setOriginType(OriginTypeEnum.ServiceProxy);
+ ci.setSourceModelUid("modelName");
+
+ Mockito.when(toscaOperationFacade.getToscaFullElement(eq("name"))).thenReturn(Either.left(component));
+
+ Mockito.when(toscaOperationFacade.getToscaFullElement(eq("modelName")))
+ .thenReturn(Either.left(new Service()));
+
+ // default test
+ Deencapsulation.invoke(testSubject, "createDependency", componentCache, imports, dependecies, ci);
+ }
+
+ @Test
+ public void testGetInterfaceFilename() throws Exception {
+ String artifactName = "artifact.name";
+ String result;
+
+ // default test
+ result = ToscaExportHandler.getInterfaceFilename(artifactName);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertNodeType() throws Exception {
+ Component component = new Resource();
+ ToscaTemplate toscaNode = new ToscaTemplate("");
+ Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
+ Either<ToscaTemplate, ToscaError> result;
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
+ Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ .thenReturn(Either.left(Collections.emptyMap()));
+ // default test
+ result = Deencapsulation
+ .invoke(testSubject, "convertNodeType", new HashMap<>(), component, toscaNode, nodeTypes);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertInterfaceNodeType() throws Exception {
+ Component component = getNewResource();
+ ToscaTemplate toscaNode = new ToscaTemplate("");
+ Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
+ Either<ToscaTemplate, ToscaError> result;
+ List<InputDefinition> inputs = new ArrayList<>();
+ inputs.add(new InputDefinition());
+ component.setInputs(inputs);
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ .thenReturn(Either.left(Collections.emptyMap()));
+
+ Mockito
+ .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "convertInterfaceNodeType", new HashMap<>(), component, toscaNode
+ , nodeTypes, false);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertReqCapAndTypeName() throws Exception {
+ Component component = new Resource();
+ ToscaTemplate toscaNode = new ToscaTemplate("");
+ Map<String, ToscaNodeType> nodeTypes = new HashMap();
+ ToscaNodeType toscaNodeType = new ToscaNodeType();
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ Either<ToscaTemplate, ToscaError> result;
+
+ Mockito.when(
+ capabiltyRequirementConvertor
+ .convertCapabilities(any(Map.class), any(Resource.class), any(Map.class)))
+ .thenReturn(new HashMap<>());
+
+ Mockito
+ .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+
+ // default test
+ result = Deencapsulation
+ .invoke(testSubject, "convertReqCapAndTypeName", new HashMap<>(), component, toscaNode, nodeTypes,
+ toscaNodeType, dataTypes);
+ Assert.assertNotNull(result);
+
+ component = new Service();
+
+ Mockito
+ .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Service.class),
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+
+ // test when component is service
+ result = Deencapsulation
+ .invoke(testSubject, "convertReqCapAndTypeName", new HashMap<>(), component, toscaNode, nodeTypes,
+ toscaNodeType, dataTypes);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertNodeTemplates() throws Exception {
+ Component component = getNewResource();
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
+ Map<String, Component> componentCache = new HashMap<>();
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
+ Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
+ List<ComponentInstanceInput> inputs = new ArrayList<>();
+ inputs.add(new ComponentInstanceInput());
+ componentInstancesInputs.put("key", inputs);
+ List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
+ RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
+ reldef.setFromNode("node");
+ resourceInstancesRelations.add(reldef);
+ component.setComponentInstancesRelations(resourceInstancesRelations);
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId("id");
+ instance.setComponentUid("uid");
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ List<GroupInstance> groupInstances = new ArrayList<>();
+ GroupInstance groupInst = new GroupInstance();
+ List<String> artifacts = new ArrayList<>();
+ artifacts.add("artifact");
+ groupInst.setArtifacts(artifacts);
+ groupInst.setType("type");
+ groupInstances.add(groupInst);
+ instance.setGroupInstances(groupInstances);
+ componentInstances.add(instance);
+
+ component.setComponentInstancesInputs(componentInstancesInputs);
+ component.setInvariantUUID("uuid");
+ component.setUUID("uuid");
+ component.setDescription("desc");
+
+ componentCache.put("uid", component);
+
+ componentInstancesProperties.put("id", new ArrayList<>());
+ componentInstancesInputs.put("id", new ArrayList<>());
+
+ Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ any(ComponentInstance.class))).thenReturn(Either.left(component));
+
+ Mockito.when(capabiltyRequirementConvertor.convertComponentInstanceCapabilities(
+ any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
+ .thenReturn(Either.left(new ToscaNodeTemplate()));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
+ componentInstancesProperties, new HashMap<>(), componentCache, dataTypes, topologyTemplate);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertNodeTemplatesWhenComponentIsService() throws Exception {
+ Component component = getNewService();
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
+ Map<String, Component> componentCache = new HashMap<>();
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
+ Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
+ List<ComponentInstanceInput> inputs = new ArrayList<>();
+ inputs.add(new ComponentInstanceInput());
+ componentInstancesInputs.put("key", inputs);
+ List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
+ RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
+ reldef.setFromNode("node");
+ resourceInstancesRelations.add(reldef);
+ component.setComponentInstancesRelations(resourceInstancesRelations);
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId("id");
+ instance.setComponentUid("uid");
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ List<GroupInstance> groupInstances = new ArrayList<>();
+ GroupInstance groupInst = new GroupInstance();
+ List<String> artifacts = new ArrayList<>();
+ artifacts.add("artifact");
+ groupInst.setArtifacts(artifacts);
+ groupInst.setType("type");
+ groupInstances.add(groupInst);
+ instance.setGroupInstances(groupInstances);
+ componentInstances.add(instance);
+
+ component.setComponentInstancesInputs(componentInstancesInputs);
+ component.setInvariantUUID("uuid");
+ component.setUUID("uuid");
+ component.setDescription("desc");
+
+ Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
+ ForwardingPathDataDefinition path = new ForwardingPathDataDefinition();
+ ListDataDefinition<ForwardingPathElementDataDefinition> list = new ListDataDefinition<>();
+ path.setPathElements(list);
+ forwardingPaths.put("key", path);
+
+ ((Service) component).setForwardingPaths(forwardingPaths);
+
+ componentCache.put("uid", component);
+
+ componentInstancesProperties.put("id", new ArrayList<>());
+ componentInstancesInterfaces.put("id", new ArrayList<>());
+ componentInstancesInputs.put("id", new ArrayList<>());
+
+ Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ any(ComponentInstance.class))).thenReturn(Either.left(component));
+
+ Mockito.when(capabiltyRequirementConvertor.convertComponentInstanceCapabilities(
+ any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
+ .thenReturn(Either.left(new ToscaNodeTemplate()));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
+ componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertNodeTemplatesWhenConvertComponentInstanceCapabilitiesIsRight() throws Exception {
+ Component component = getNewResource();
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
+ Map<String, Component> componentCache = new HashMap<>();
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
+ Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
+ List<ComponentInstanceInput> inputs = new ArrayList<>();
+ inputs.add(new ComponentInstanceInput());
+ componentInstancesInputs.put("key", inputs);
+ List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
+ RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
+ reldef.setFromNode("node");
+ resourceInstancesRelations.add(reldef);
+ component.setComponentInstancesRelations(resourceInstancesRelations);
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId("id");
+ instance.setComponentUid("uid");
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ componentInstances.add(instance);
+
+ component.setComponentInstancesInputs(componentInstancesInputs);
+ component.setInvariantUUID("uuid");
+ component.setUUID("uuid");
+ component.setDescription("desc");
+
+ componentCache.put("uid", component);
+
+ Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ any(ComponentInstance.class))).thenReturn(Either.left(component));
+
+ Mockito.when(capabiltyRequirementConvertor.convertComponentInstanceCapabilities(
+ any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
+ .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
+ componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvetNodeTemplateWhenGetOriginComponentIsRight() throws Exception {
+ Component component = getNewResource();
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
+ Map<String, Component> componentCache = new HashMap<>();
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
+ Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
+ List<ComponentInstanceInput> inputs = new ArrayList<>();
+ inputs.add(new ComponentInstanceInput());
+ componentInstancesInputs.put("key", inputs);
+ List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
+ RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
+ reldef.setFromNode("id");
+ resourceInstancesRelations.add(reldef);
+ component.setComponentInstancesRelations(resourceInstancesRelations);
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId("id");
+ instance.setComponentUid("uid");
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ componentInstances.add(instance);
+
+ component.setComponentInstancesInputs(componentInstancesInputs);
+ component.setInvariantUUID("uuid");
+ component.setUUID("uuid");
+ component.setDescription("desc");
+
+ componentCache.put("uid", component);
+
+ Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ any(ComponentInstance.class))).thenReturn(Either.right(false));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
+ componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertNodeTemplatesWhenConvertComponentInstanceRequirmentsIsRight() {
+ Component component = new Resource();
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
+ Map<String, Component> componentCache = new HashMap<>();
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
+ Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
+ List<ComponentInstanceInput> inputs = new ArrayList<>();
+ inputs.add(new ComponentInstanceInput());
+ componentInstancesInputs.put("key", inputs);
+ List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
+ RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
+ reldef.setFromNode("id");
+ reldef.setToNode("node");
+ List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
+ CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
+ relationship.setRelation(new RelationshipInfo());
+ relationships.add(relationship);
+ reldef.setRelationships(relationships);
+ resourceInstancesRelations.add(reldef);
+ component.setComponentInstancesRelations(resourceInstancesRelations);
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId("id");
+ componentInstances.add(instance);
+
+ component.setComponentInstancesInputs(componentInstancesInputs);
+ component.setComponentInstances(componentInstances);
+
+ Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ any(ComponentInstance.class))).thenReturn(Either.left(component));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
+ componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testAddComponentInstanceInputs() throws Exception {
+
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ String instanceUniqueId = "id";
+ Map<String, Object> props = new HashMap<>();
+
+ List<ComponentInstanceInput> componentInstanceInputs = new ArrayList<>();
+ componentInstanceInputs.add(new ComponentInstanceInput());
+
+ componentInstancesInputs.put(instanceUniqueId, componentInstanceInputs);
+
+ // default test
+ Deencapsulation.invoke(testSubject, "addComponentInstanceInputs", dataTypes, componentInstancesInputs,
+ instanceUniqueId, props);
+ }
+
+ @Test
+ public void testAddPropertiesOfComponentInstance() throws Exception {
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ String instanceUniqueId = "id";
+ Map<String, Object> props = new HashMap<>();
+
+ ComponentInstanceProperty cip = new ComponentInstanceProperty();
+ cip.setInstanceUniqueId("id");
+
+ List<ComponentInstanceProperty> list = new ArrayList<>();
+ list.add(cip);
+
+ componentInstancesProperties.put("id", list);
+
+ // default test
+ Deencapsulation.invoke(testSubject, "addPropertiesOfComponentInstance", componentInstancesProperties, dataTypes,
+ instanceUniqueId, props);
+ }
+
+ @Test
+ public void testAddPropertiesOfParentComponent() throws Exception {
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ Component componentOfInstance = new Resource();
+ Map<String, Object> props = new HashMap<>();
+
+ List<PropertyDefinition> properties = new ArrayList<>();
+ properties.add(new PropertyDefinition());
+
+ ((Resource) componentOfInstance).setProperties(properties);
+
+ // default test
+ Deencapsulation.invoke(testSubject, "addPropertiesOfParentComponent", dataTypes,
+ componentOfInstance, props);
+ }
+
+ @Test
+ public void testCreateNodeType() throws Exception {
+
+ Component component = new Resource();
+ List<String> array = new ArrayList<>();
+ array.add("value");
+ ((Resource) component).setDerivedFrom(array);
+ ToscaNodeType result;
+
+ // test when component is resource
+ result = Deencapsulation.invoke(testSubject, "createNodeType", component);
+ Assert.assertNotNull(result);
+
+ component = new Service();
+ // test when component is service
+ result = Deencapsulation.invoke(testSubject, "createNodeType", component);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testCreateProxyInterfaceTypesComponentNotFound() throws Exception {
+ Component container = new Service();
+ Either<Map<String, ToscaNodeType>, ToscaError> result;
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ instance.setSourceModelUid("targetModelUid");
+ instance.setToscaComponentName("toscaComponentName");
+
+ componentInstances.add(instance);
+ container.setComponentInstances(componentInstances);
+ Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ any(ComponentParametersView.class)))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
+ Assert.assertTrue(result.isRight());
+ }
+
+ @Test
+ public void testCreateProxyInterfaceTypesWhenInterfaceLifecycleFetchFailed() {
+ Component container = new Service();
+ Either<Map<String, ToscaNodeType>, ToscaError> result;
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ instance.setSourceModelUid("targetModelUid");
+ instance.setToscaComponentName("toscaComponentName");
+ componentInstances.add(instance);
+ container.setComponentInstances(componentInstances);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ any(ComponentParametersView.class)))
+ .thenReturn(Either.left(new Resource()));
+ Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
+ Assert.assertTrue(result.isRight());
+ }
+
+ @Test
+ public void testCreateProxyInterfaceTypesPositive() {
+ Component container = new Service();
+ Either<Map<String, ToscaNodeType>, ToscaError> result;
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ instance.setSourceModelUid("targetModelUid");
+ instance.setToscaComponentName("toscaComponentName");
+ componentInstances.add(instance);
+ container.setComponentInstances(componentInstances);
+
+ Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ .thenReturn(Either.left(Collections.emptyMap()));
+
+ Component proxyResource = new Resource();
+ Map<String, InterfaceDefinition> proxyInterfaces = new HashMap<>();
+ proxyInterfaces.put("Local", new InterfaceDefinition("Local", "desc", new HashMap<>()));
+ proxyResource.setInterfaces(proxyInterfaces);
+ Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ any(ComponentParametersView.class)))
+ .thenReturn(Either.left(proxyResource));
+
+ result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
+ Assert.assertNotNull(result);
+ Assert.assertTrue(result.isLeft());
+ Assert.assertEquals(1, result.left().value().size());
+ }
+
+ @Test
+ public void testCreateProxyNodeTypes() throws Exception {
+ Map<String, Component> componentCache = new HashMap<>();
+ Component container = new Resource();
+ Either<Map<String, ToscaNodeType>, ToscaError> result;
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ instance.setSourceModelUid("targetModelUid");
+
+ componentInstances.add(instance);
+ container.setComponentInstances(componentInstances);
+
+ Mockito.when(toscaOperationFacade.getLatestByName("serviceProxy"))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ // test when getLatestByName return is right
+ result = Deencapsulation.invoke(testSubject, "createProxyNodeTypes", componentCache, container);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testCreateProxyNodeTypesWhenGetLatestByNameReturnValue() {
+ Map<String, Component> componentCache = new HashMap<>();
+ Component container = new Resource();
+ Either<Map<String, ToscaNodeType>, ToscaError> result;
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ instance.setSourceModelUid("targetModelUid");
+
+ componentInstances.add(instance);
+ container.setComponentInstances(componentInstances);
+
+ Mockito.when(toscaOperationFacade.getLatestByName("serviceProxy")).thenReturn(Either.left(new Resource()));
+
+ ComponentParametersView parameterView = new ComponentParametersView();
+ parameterView.disableAll();
+ parameterView.setIgnoreCategories(false);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ any(ComponentParametersView.class)))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+
+ // test when getLatestByName is left
+ result = Deencapsulation.invoke(testSubject, "createProxyNodeTypes", componentCache, container);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testCreateProxyNodeType() throws Exception {
+ Map<String, Component> componentCache = new HashMap<>();
+ Component origComponent = new Resource();
+ Component proxyComponent = new Resource();
+ ComponentInstance instance = new ComponentInstance();
+ ToscaNodeType result;
+
+ Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "createProxyNodeType", componentCache, origComponent,
+ proxyComponent, instance);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertComponentInstanceRequirements() throws Exception {
+ Component component = new Resource();
+ ComponentInstance componentInstance = new ComponentInstance();
+ List<RequirementCapabilityRelDef> relations = new ArrayList<>();
+ ToscaNodeTemplate nodeTypeTemplate = new ToscaNodeTemplate();
+ Component originComponent = new Resource();
+ Map<String, Component> componentCache = new HashMap<>();
+ Either<ToscaNodeTemplate, ToscaError> result;
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "convertComponentInstanceRequirements", component,
+ componentInstance, relations, nodeTypeTemplate, originComponent, componentCache);
+ Assert.assertNotNull(result);
+
+ RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
+ reldef.setFromNode("name");
+ reldef.setToNode("name1");
+ List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
+ CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
+ cap.setRelation(new RelationshipInfo());
+ relationships.add(cap);
+ reldef.setRelationships(relationships);
+ relations.add(reldef);
+ componentInstance.setUniqueId("name");
+
+ List<ComponentInstance> instances = new ArrayList<>();
+ instances.add(componentInstance);
+ component.setComponentInstances(instances);
+
+ // test when filteredRElations ins't empty
+ result = Deencapsulation.invoke(testSubject, "convertComponentInstanceRequirements", component,
+ componentInstance, relations, nodeTypeTemplate, originComponent, componentCache);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testAddRequirement() throws Exception {
+ ComponentInstance fromInstance = new ComponentInstance();
+ Component fromOriginComponent = new Resource();
+ List<ComponentInstance> instancesList = new ArrayList<>();
+ RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ Map<String, Component> componentCache = new HashMap<>();
+ boolean result;
+
+ List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
+ CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
+ cap.setRequirement(new RequirementDataDefinition());
+ RelationshipInfo relation = new RelationshipInfo();
+ relation.setRequirementUid("Uid");
+ relation.setRequirement("requirment");
+ relation.setCapability("cap");
+ relation.setCapabilityOwnerId("id1");
+ cap.setRelation(relation);
+ relationships.add(cap);
+ rel.setRelationships(relationships);
+ rel.setToNode("name");
+ fromInstance.setUniqueId("name");
+ fromInstance.setComponentUid("string");
+ instancesList.add(fromInstance);
+ Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
+ fromOriginComponent.setRequirements(requirements);
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
+ rel, toscaRequirements, componentCache);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testAddRequirmentsWhenFindRequirmentsReturnsValue() {
+
+ ComponentInstance fromInstance = new ComponentInstance();
+ Component fromOriginComponent = new Resource();
+ List<ComponentInstance> instancesList = new ArrayList<>();
+ RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ Map<String, Component> componentCache = new HashMap<>();
+ boolean result;
+
+ List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
+ CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
+ cap.setRequirement(new RequirementDataDefinition());
+ RelationshipInfo relation = new RelationshipInfo();
+ relation.setRequirementUid("Uid");
+ relation.setRequirement("requirment");
+ relation.setCapability("cap");
+ relation.setCapabilityOwnerId("id1");
+ cap.setRelation(relation);
+ relationships.add(cap);
+ rel.setRelationships(relationships);
+ rel.setToNode("name");
+ fromInstance.setUniqueId("name");
+ fromInstance.setComponentUid("string");
+ instancesList.add(fromInstance);
+ Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
+
+ List<RequirementDefinition> defs = new ArrayList<>();
+ RequirementDefinition def = new RequirementDefinition();
+ def.setName("requirment");
+ def.setCapability("cap");
+ defs.add(def);
+ requirements.put("key", defs);
+ fromOriginComponent.setRequirements(requirements);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ any(ComponentParametersView.class)))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
+ rel, toscaRequirements, componentCache);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testAddRequirmentsWhenCapabilityBelongsToRelation() {
+ ComponentInstance fromInstance = new ComponentInstance();
+ Component fromOriginComponent = new Resource();
+ List<ComponentInstance> instancesList = new ArrayList<>();
+ RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ Map<String, Component> componentCache = new HashMap<>();
+ boolean result;
+
+ List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
+ CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
+ cap.setRequirement(new RequirementDataDefinition());
+ RelationshipInfo relation = new RelationshipInfo();
+ relation.setRequirementUid("Uid");
+ relation.setRequirement("requirment");
+ relation.setCapability("cap");
+ relation.setCapabilityOwnerId("id1");
+ cap.setRelation(relation);
+ relationships.add(cap);
+ rel.setRelationships(relationships);
+ rel.setToNode("name");
+ fromInstance.setUniqueId("name");
+ fromInstance.setComponentUid("string");
+ instancesList.add(fromInstance);
+ Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
+
+ List<RequirementDefinition> defs = new ArrayList<>();
+ RequirementDefinition def = new RequirementDefinition();
+ def.setName("requirment");
+ def.setCapability("cap");
+ defs.add(def);
+ requirements.put("key", defs);
+ fromOriginComponent.setRequirements(requirements);
+
+ Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
+ List<CapabilityDefinition> caps = new ArrayList<>();
+ CapabilityDefinition capdef = new CapabilityDefinition();
+ capdef.setOwnerId("id");
+ capdef.setName("name");
+ capdef.setType("type");
+ caps.add(capdef);
+ capabilities.put("cap", caps);
+
+ fromOriginComponent.setCapabilities(capabilities);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ any(ComponentParametersView.class))).thenReturn(Either.left(fromOriginComponent));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
+ rel, toscaRequirements, componentCache);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testAddRequirmentsWithBuildAndAddRequirements() {
+ ComponentInstance fromInstance = new ComponentInstance();
+ Component fromOriginComponent = new Resource();
+ List<ComponentInstance> instancesList = new ArrayList<>();
+ RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ Map<String, Component> componentCache = new HashMap<>();
+ boolean result;
+
+ List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
+ CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
+ cap.setRequirement(new RequirementDataDefinition());
+ RelationshipInfo relation = new RelationshipInfo();
+ relation.setRequirementUid("Uid");
+ relation.setRequirement("requirment");
+ relation.setCapability("cap");
+ relation.setCapabilityOwnerId("id");
+ cap.setRelation(relation);
+ relationships.add(cap);
+ rel.setRelationships(relationships);
+ rel.setToNode("name");
+ fromInstance.setUniqueId("name");
+ fromInstance.setComponentUid("string");
+ instancesList.add(fromInstance);
+ Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
+
+ List<RequirementDefinition> defs = new ArrayList<>();
+ RequirementDefinition def = new RequirementDefinition();
+ def.setName("requirment");
+ def.setCapability("cap");
+ defs.add(def);
+ requirements.put("key", defs);
+ fromOriginComponent.setRequirements(requirements);
+
+ Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
+ List<CapabilityDefinition> caps = new ArrayList<>();
+ CapabilityDefinition capdef = new CapabilityDefinition();
+ capdef.setOwnerId("id");
+ capdef.setName("cap");
+ capdef.setPreviousName("before cap");
+ capdef.setType("type");
+ caps.add(capdef);
+ capabilities.put("cap", caps);
+ fromOriginComponent.setCapabilities(capabilities);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ any(ComponentParametersView.class))).thenReturn(Either.left(fromOriginComponent));
+
+ Mockito.when(
+ capabiltyRequirementConvertor
+ .buildSubstitutedName(anyMap(), any(Component.class), anyList(), anyString(), anyString()))
+ .thenReturn(Either.right(false));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
+ rel, toscaRequirements, componentCache);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testBuildAndAddRequirement() throws Exception {
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ Component fromOriginComponent = new Resource();
+ Component toOriginComponent = new Resource();
+ CapabilityDefinition capability = new CapabilityDefinition();
+ RequirementDefinition requirement = new RequirementDefinition();
+ RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
+ ComponentInstance toInstance = new ComponentInstance();
+ Map<String, Component> componentCache = new HashMap<>();
+ boolean result;
+ capability.setPath(new ArrayList<>());
+ capability.setPreviousName("before cap");
+ reqAndRelationshipPair.setCapability("cap");
+ requirement.setPath(new ArrayList<>());
+ requirement.setPreviousName("before req");
+ reqAndRelationshipPair.setRequirement("req");
+
+ Mockito.when(
+ capabiltyRequirementConvertor
+ .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq("cap"), anyString()))
+ .thenReturn(Either.left("buildCapNameRes"));
+
+ Mockito.when(
+ capabiltyRequirementConvertor
+ .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("req"), anyString()))
+ .thenReturn(Either.right(false));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "buildAndAddRequirement", toscaRequirements, fromOriginComponent,
+ toOriginComponent, capability, requirement, reqAndRelationshipPair, toInstance, componentCache);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testBuildAndAddRequirementBuildSubtitutedNameReturnsValueTwice() {
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ Component fromOriginComponent = new Resource();
+ Component toOriginComponent = new Resource();
+ CapabilityDefinition capability = new CapabilityDefinition();
+ RequirementDefinition requirement = new RequirementDefinition();
+ RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
+ ComponentInstance toInstance = new ComponentInstance();
+ Map<String, Component> componentCache = new HashMap<>();
+ boolean result;
+ capability.setPath(new ArrayList<>());
+ reqAndRelationshipPair.setCapability("cap");
+ requirement.setPath(new ArrayList<>());
+ reqAndRelationshipPair.setRequirement("req");
+
+ Mockito.when(capabiltyRequirementConvertor.buildSubstitutedName(any(), any(), any(), any(), any()))
+ .thenReturn(Either.left("buildCapNameRes"));
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "buildAndAddRequirement", toscaRequirements, fromOriginComponent,
+ toOriginComponent, capability, requirement, reqAndRelationshipPair, toInstance, componentCache);
+ Assert.assertNotNull(result);
+ Assert.assertTrue(result);
+ }
+
+ @Test
+ public void testIsRequirementBelongToRelation() throws Exception {
+
+ Component originComponent = new Resource();
+ RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
+ RequirementDefinition requirement = new RequirementDefinition();
+ String fromInstanceId = "";
+ boolean result;
+
+ requirement.setName("name");
+ reqAndRelationshipPair.setRequirement("name1");
+
+ // test return false
+ result = Deencapsulation.invoke(testSubject, "isRequirementBelongToRelation", originComponent,
+ reqAndRelationshipPair, requirement, fromInstanceId);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testIsRequirementBelongToRelationWithNonAtomicComponent() {
+
+ Component originComponent = new Service();
+ RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
+ RequirementDefinition requirement = new RequirementDefinition();
+ String fromInstanceId = "";
+ boolean result;
+
+ // default test return true
+ result = Deencapsulation.invoke(testSubject, "isRequirementBelongToRelation", originComponent,
+ reqAndRelationshipPair, requirement, fromInstanceId);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testIsRequirementBelongToOwner() throws Exception {
+
+ RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
+ RequirementDefinition requirement = new RequirementDefinition();
+ String fromInstanceId = "";
+ Component originComponent = new Resource();
+ boolean result;
+
+ requirement.setOwnerId("owner1");
+ reqAndRelationshipPair.setRequirementOwnerId("owner");
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "isRequirementBelongToOwner", reqAndRelationshipPair, requirement,
+ fromInstanceId, originComponent);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testIsCvfc() throws Exception {
+
+ Component component = new Resource();
+ boolean result;
+
+ component = new Service();
+
+ result = Deencapsulation.invoke(testSubject, "isCvfc", component);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertCapabilities() throws Exception {
+ Component component = new Resource();
+ SubstitutionMapping substitutionMappings = new SubstitutionMapping();
+ Map<String, Component> componentCache = new HashMap<>();
+ Either<SubstitutionMapping, ToscaError> result;
+
+ Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(componentCache, component))
+ .thenReturn(Either.right(ToscaError.NODE_TYPE_CAPABILITY_ERROR));
+
+ // default test return isRight
+ result = Deencapsulation.invoke(testSubject, "convertCapabilities", component, substitutionMappings,
+ componentCache);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertCapabilities_1() throws Exception {
+ Component component = new Resource();
+ ToscaNodeType nodeType = new ToscaNodeType();
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ Either<ToscaNodeType, ToscaError> result;
+
+ Map<String, ToscaCapability> capabilities = new HashMap<>();
+ capabilities.put("key", new ToscaCapability());
+
+ // default test
+ result = Deencapsulation
+ .invoke(testSubject, "convertCapabilities", new HashMap<>(), component, nodeType, dataTypes);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertToNodeTemplateArtifacts() throws Exception {
+ Map<String, ToscaArtifactDataDefinition> container = new HashMap<>();
+ ToscaArtifactDataDefinition art = new ToscaArtifactDataDefinition();
+ art.setFile("test_file");
+ art.setType("test_type");
+ Map<String, ToscaTemplateArtifact> result;
+ container.put("test_art", art);
+ result = Deencapsulation.invoke(testSubject, "convertToNodeTemplateArtifacts", container);
+ Assert.assertNotNull(result);
+ Assert.assertTrue(MapUtils.isNotEmpty(result));
+ Assert.assertTrue(result.get("test_art").getFile().equals("test_file"));
+ Assert.assertTrue(result.get("test_art").getType().equals("test_type"));
+ }
}