aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/GlobalTypesMergeBusinessLogicTest.java
blob: ec741b4953206e070cb2ce372298947eb06e9563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.openecomp.sdc.be.components.merge;

import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.merge.input.ComponentInputsMergeBL;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.Resource;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.openecomp.sdc.be.components.utils.ObjectGenerator.buildResourceWithInputs;

public class GlobalTypesMergeBusinessLogicTest {

    @InjectMocks
    private GlobalTypesMergeBusinessLogic testInstance;

    @Mock
    private ComponentInputsMergeBL resourceInputsMergeBLMock;

    @Mock
    private GlobalInputsFilteringBusinessLogic globalInputsFilteringBusinessLogic;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void mergeInstancePropsAndInputs_mergeOnlyNewResourceGenericGlobalTypes() {
        Resource oldResource = buildResourceWithInputs("input1", "input2");
        Resource newResource = buildResourceWithInputs("input1", "input2", "global1", "global2");
        List<InputDefinition> globalInputs = Arrays.asList(newResource.getInputs().get(2), newResource.getInputs().get(3));
        when(globalInputsFilteringBusinessLogic.filterGlobalInputs(newResource)).thenReturn(Either.left(globalInputs));
        when(resourceInputsMergeBLMock.mergeComponentInputs(oldResource, newResource, globalInputs)).thenReturn(ActionStatus.OK);
        ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
        assertEquals(ActionStatus.OK, actionStatus);

    }

    @Test
    public void mergeInstancePropsAndInputs_failedToFilterGlobalInputs() throws Exception {
        Resource oldResource = buildResourceWithInputs("input1", "input2");
        Resource newResource = buildResourceWithInputs("input1", "input2", "global1", "global2");
        when(globalInputsFilteringBusinessLogic.filterGlobalInputs(newResource)).thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
        ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
        assertEquals(actionStatus, ActionStatus.GENERAL_ERROR);
        verifyZeroInteractions(resourceInputsMergeBLMock);
    }


}