Sync Integ to Master
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / merge / instance / ComponentInstanceArtifactsMergeTest.java
1 package org.openecomp.sdc.be.components.merge.instance;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.mockito.InjectMocks;
6 import org.mockito.MockitoAnnotations;
7 import org.openecomp.sdc.be.model.ArtifactDefinition;
8 import org.openecomp.sdc.be.model.Component;
9 import org.openecomp.sdc.be.model.ComponentInstance;
10 import org.openecomp.sdc.be.model.Resource;
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15 import static groovy.util.GroovyTestCase.assertEquals;
16
17
18 public class ComponentInstanceArtifactsMergeTest {
19
20     @InjectMocks
21     private ComponentInstanceArtifactsMerge testInstance;
22
23     @Before
24     public void setUp() throws Exception {
25         MockitoAnnotations.initMocks(this);
26     }
27
28     @Test
29     public void testDeploymentArtifactSaveData() throws Exception {
30
31         Component containerComponent = new Resource();
32         Component originComponent = buildOriginalComponentWithOneArtifact();
33         ComponentInstance componentInstance = buildComponentInstanceWithTwoArtifacts();
34
35         DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
36         testInstance.saveDataBeforeMerge(dataForMergeHolder, containerComponent, componentInstance, originComponent);
37         Map<String, ArtifactDefinition> originalComponentDeploymentArtifactsCreatedOnTheInstance = dataForMergeHolder.getOrigComponentDeploymentArtifactsCreatedOnTheInstance();
38
39         assertEquals(originalComponentDeploymentArtifactsCreatedOnTheInstance.size() , 1);
40         assert(originalComponentDeploymentArtifactsCreatedOnTheInstance.containsKey("artifactTwo"));
41     }
42
43     @Test
44     public void testInformationalArtifactSaveData() throws Exception {
45
46         Component containerComponent = new Resource();
47         Component originComponent = buildOriginalComponentWithOneArtifact();
48         ComponentInstance componentInstance = buildComponentInstanceWithTwoArtifacts();
49
50         DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
51         testInstance.saveDataBeforeMerge(dataForMergeHolder, containerComponent, componentInstance, originComponent);
52         Map<String, ArtifactDefinition> originalComponentInformationalArtifactsCreatedOnTheInstance = dataForMergeHolder.getOrigComponentInformationalArtifactsCreatedOnTheInstance();
53
54         assertEquals(originalComponentInformationalArtifactsCreatedOnTheInstance.size() , 1);
55         assert(originalComponentInformationalArtifactsCreatedOnTheInstance.containsKey("artifactTwo"));
56     }
57
58     private ComponentInstance buildComponentInstanceWithTwoArtifacts(){
59         ArtifactDefinition artifactFromTheOriginalResource = new ArtifactDefinition();
60         artifactFromTheOriginalResource.setArtifactLabel("artifactOne");
61         ArtifactDefinition artifactCreatedOnTheInstance = new ArtifactDefinition();
62         artifactCreatedOnTheInstance.setArtifactLabel("artifactTwo");
63
64         Map<String, ArtifactDefinition> componentInstanceArtifacts = new HashMap<>();
65         componentInstanceArtifacts.put(artifactFromTheOriginalResource.getArtifactLabel(), artifactFromTheOriginalResource);
66         componentInstanceArtifacts.put(artifactCreatedOnTheInstance.getArtifactLabel(), artifactCreatedOnTheInstance);
67
68         ComponentInstance componentInstance = new ComponentInstance();
69         componentInstance.setDeploymentArtifacts(componentInstanceArtifacts);
70         componentInstance.setArtifacts(componentInstanceArtifacts);
71         return componentInstance;
72     }
73
74     private Component buildOriginalComponentWithOneArtifact() {
75         ArtifactDefinition artifactFromTheOriginalResource = new ArtifactDefinition();
76         artifactFromTheOriginalResource.setArtifactLabel("artifactOne");
77
78         Map<String, ArtifactDefinition> originComponentArtifacts = new HashMap<>();
79         originComponentArtifacts.put(artifactFromTheOriginalResource.getArtifactLabel(), artifactFromTheOriginalResource);
80         Component originComponent = new Resource();
81         originComponent.setDeploymentArtifacts(originComponentArtifacts);
82         originComponent.setArtifacts(originComponentArtifacts);
83         return originComponent;
84     }
85
86
87
88 }