summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMergeTest.java
blob: df3e0ddb68aceb34a2928f21ae3854688edb4018 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package org.openecomp.sdc.be.components.merge.instance;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.Resource;

import java.util.HashMap;
import java.util.Map;

import static groovy.util.GroovyTestCase.assertEquals;


public class ComponentInstanceArtifactsMergeTest {

    @InjectMocks
    private ComponentInstanceArtifactsMerge testInstance;

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

    @Test
    public void testDeploymentArtifactSaveData() throws Exception {

        Component containerComponent = new Resource();
        Component originComponent = buildOriginalComponentWithOneArtifact();
        ComponentInstance componentInstance = buildComponentInstanceWithTwoArtifacts();

        DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
        testInstance.saveDataBeforeMerge(dataForMergeHolder, containerComponent, componentInstance, originComponent);
        Map<String, ArtifactDefinition> originalComponentDeploymentArtifactsCreatedOnTheInstance = dataForMergeHolder.getOrigComponentDeploymentArtifactsCreatedOnTheInstance();

        assertEquals(originalComponentDeploymentArtifactsCreatedOnTheInstance.size() , 1);
        assert(originalComponentDeploymentArtifactsCreatedOnTheInstance.containsKey("artifactTwo"));
    }

    @Test
    public void testInformationalArtifactSaveData() throws Exception {

        Component containerComponent = new Resource();
        Component originComponent = buildOriginalComponentWithOneArtifact();
        ComponentInstance componentInstance = buildComponentInstanceWithTwoArtifacts();

        DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
        testInstance.saveDataBeforeMerge(dataForMergeHolder, containerComponent, componentInstance, originComponent);
        Map<String, ArtifactDefinition> originalComponentInformationalArtifactsCreatedOnTheInstance = dataForMergeHolder.getOrigComponentInformationalArtifactsCreatedOnTheInstance();

        assertEquals(originalComponentInformationalArtifactsCreatedOnTheInstance.size() , 1);
        assert(originalComponentInformationalArtifactsCreatedOnTheInstance.containsKey("artifactTwo"));
    }

    private ComponentInstance buildComponentInstanceWithTwoArtifacts(){
        ArtifactDefinition artifactFromTheOriginalResource = new ArtifactDefinition();
        artifactFromTheOriginalResource.setArtifactLabel("artifactOne");
        ArtifactDefinition artifactCreatedOnTheInstance = new ArtifactDefinition();
        artifactCreatedOnTheInstance.setArtifactLabel("artifactTwo");

        Map<String, ArtifactDefinition> componentInstanceArtifacts = new HashMap<>();
        componentInstanceArtifacts.put(artifactFromTheOriginalResource.getArtifactLabel(), artifactFromTheOriginalResource);
        componentInstanceArtifacts.put(artifactCreatedOnTheInstance.getArtifactLabel(), artifactCreatedOnTheInstance);

        ComponentInstance componentInstance = new ComponentInstance();
        componentInstance.setDeploymentArtifacts(componentInstanceArtifacts);
        componentInstance.setArtifacts(componentInstanceArtifacts);
        return componentInstance;
    }

    private Component buildOriginalComponentWithOneArtifact() {
        ArtifactDefinition artifactFromTheOriginalResource = new ArtifactDefinition();
        artifactFromTheOriginalResource.setArtifactLabel("artifactOne");

        Map<String, ArtifactDefinition> originComponentArtifacts = new HashMap<>();
        originComponentArtifacts.put(artifactFromTheOriginalResource.getArtifactLabel(), artifactFromTheOriginalResource);
        Component originComponent = new Resource();
        originComponent.setDeploymentArtifacts(originComponentArtifacts);
        originComponent.setArtifacts(originComponentArtifacts);
        return originComponent;
    }



}