1 package org.openecomp.sdc.be.components.merge.property;
4 import org.junit.Before;
6 import org.mockito.InjectMocks;
7 import org.mockito.Mock;
8 import org.mockito.MockitoAnnotations;
9 import org.openecomp.sdc.be.components.merge.instance.ComponentInstancePropertiesMergeBL;
10 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
11 import org.openecomp.sdc.be.dao.api.ActionStatus;
12 import org.openecomp.sdc.be.impl.ComponentsUtils;
13 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
14 import org.openecomp.sdc.be.model.Resource;
15 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
16 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
18 import java.util.Collections;
19 import java.util.List;
21 import static org.junit.Assert.assertEquals;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.verifyNoMoreInteractions;
24 import static org.mockito.Mockito.when;
26 public class ComponentInstancePropertiesMergeBLTest {
28 private static final String INSTANCE1 = "instance1";
29 private static final String INSTANCE2 = "instance2";
32 private ComponentInstancePropertiesMergeBL testInstance;
35 private DataDefinitionsValuesMergingBusinessLogic propertyValuesMergingBusinessLogic;
38 private ToscaOperationFacade toscaOperationFacade;
41 private ComponentsUtils componentsUtils;
43 private Resource oldResource;
44 private Resource newResource;
47 public void setUp() throws Exception {
48 MockitoAnnotations.initMocks(this);
49 oldResource = new ResourceBuilder()
50 .addInstanceProperty(INSTANCE1, "property1")
51 .addInstanceProperty(INSTANCE1, "property2")
52 .addInstanceProperty(INSTANCE2, "property3")
54 .addInput("input2").build();
56 newResource = new ResourceBuilder()
57 .addInstanceProperty(INSTANCE1, "property11")
58 .addInstanceProperty(INSTANCE1, "property12")
59 .addInstanceProperty(INSTANCE2, "property13")
61 .addInput("input12").build();
65 public void mergeInstancesPropsAndInputs_mergeInstanceProps() throws Exception {
66 when(toscaOperationFacade.updateComponentInstancePropsToComponent(newResource.getComponentInstancesProperties(), newResource.getUniqueId()))
67 .thenReturn(Either.left(Collections.emptyMap()));
68 ActionStatus actionStatus = testInstance.mergeComponents(oldResource, newResource);
69 assertEquals(actionStatus, ActionStatus.OK);
70 verifyMergeBLCalled(oldResource, newResource);
74 public void mergeInstancesProps_failure() throws Exception {
75 when(toscaOperationFacade.updateComponentInstancePropsToComponent(newResource.getComponentInstancesProperties(), newResource.getUniqueId()))
76 .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
77 when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR)).thenReturn(ActionStatus.GENERAL_ERROR);
78 verifyNoMoreInteractions(toscaOperationFacade, propertyValuesMergingBusinessLogic);
79 ActionStatus actionStatus = testInstance.mergeComponents(oldResource, newResource);
80 assertEquals(ActionStatus.GENERAL_ERROR, actionStatus);
84 public void mergeInstanceProps() throws Exception {
85 List<ComponentInstanceProperty> newInstanceProps = newResource.safeGetComponentInstanceProperties(INSTANCE1);
86 List<ComponentInstanceProperty> oldInstProps = oldResource.safeGetComponentInstanceProperties(INSTANCE1);
87 when(toscaOperationFacade.updateComponentInstanceProperties(newResource, INSTANCE1, newInstanceProps))
88 .thenReturn(StorageOperationStatus.OK);
89 ActionStatus actionStatus = testInstance.mergeComponentInstanceProperties(oldInstProps, oldResource.getInputs(), newResource, INSTANCE1);
90 assertEquals(actionStatus, ActionStatus.OK);
91 verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(oldInstProps, oldResource.getInputs(), newInstanceProps, newResource.getInputs());
95 public void mergeInstanceProps_failure() throws Exception {
96 List<ComponentInstanceProperty> newInstanceProps = newResource.safeGetComponentInstanceProperties(INSTANCE1);
97 List<ComponentInstanceProperty> oldInstProps = oldResource.safeGetComponentInstanceProperties(INSTANCE1);
98 when(toscaOperationFacade.updateComponentInstanceProperties(newResource, INSTANCE1, newInstanceProps))
99 .thenReturn(StorageOperationStatus.GENERAL_ERROR);
100 when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR)).thenReturn(ActionStatus.GENERAL_ERROR);
101 ActionStatus actionStatus = testInstance.mergeComponentInstanceProperties(oldInstProps, oldResource.getInputs(), newResource, INSTANCE1);
102 assertEquals(actionStatus, ActionStatus.GENERAL_ERROR);
103 verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(oldInstProps, oldResource.getInputs(), newInstanceProps, newResource.getInputs());
106 private void verifyMergeBLCalled(Resource oldResource, Resource newResource) {
107 List<ComponentInstanceProperty> instance1oldProps = oldResource.getComponentInstancesProperties().get(INSTANCE1);
108 List<ComponentInstanceProperty> instance1newProps = newResource.getComponentInstancesProperties().get(INSTANCE1);
109 List<ComponentInstanceProperty> instance2oldProps = oldResource.getComponentInstancesProperties().get(INSTANCE2);
110 List<ComponentInstanceProperty> instance2newProps = newResource.getComponentInstancesProperties().get(INSTANCE2);
111 verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(instance1oldProps, oldResource.getInputs(), instance1newProps, newResource.getInputs());
112 verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(instance2oldProps, oldResource.getInputs(), instance2newProps, newResource.getInputs());