1 package org.openecomp.sdc.be.components.merge.instance;
3 import org.junit.Before;
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;
12 import java.util.HashMap;
15 import static groovy.util.GroovyTestCase.assertEquals;
18 public class ComponentInstanceArtifactsMergeTest {
21 private ComponentInstanceArtifactsMerge testInstance;
24 public void setUp() throws Exception {
25 MockitoAnnotations.initMocks(this);
29 public void testDeploymentArtifactSaveData() throws Exception {
31 Component containerComponent = new Resource();
32 Component originComponent = buildOriginalComponentWithOneArtifact();
33 ComponentInstance componentInstance = buildComponentInstanceWithTwoArtifacts();
35 DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
36 testInstance.saveDataBeforeMerge(dataForMergeHolder, containerComponent, componentInstance, originComponent);
37 Map<String, ArtifactDefinition> originalComponentDeploymentArtifactsCreatedOnTheInstance = dataForMergeHolder.getOrigComponentDeploymentArtifactsCreatedOnTheInstance();
39 assertEquals(originalComponentDeploymentArtifactsCreatedOnTheInstance.size() , 1);
40 assert(originalComponentDeploymentArtifactsCreatedOnTheInstance.containsKey("artifactTwo"));
44 public void testInformationalArtifactSaveData() throws Exception {
46 Component containerComponent = new Resource();
47 Component originComponent = buildOriginalComponentWithOneArtifact();
48 ComponentInstance componentInstance = buildComponentInstanceWithTwoArtifacts();
50 DataForMergeHolder dataForMergeHolder = new DataForMergeHolder();
51 testInstance.saveDataBeforeMerge(dataForMergeHolder, containerComponent, componentInstance, originComponent);
52 Map<String, ArtifactDefinition> originalComponentInformationalArtifactsCreatedOnTheInstance = dataForMergeHolder.getOrigComponentInformationalArtifactsCreatedOnTheInstance();
54 assertEquals(originalComponentInformationalArtifactsCreatedOnTheInstance.size() , 1);
55 assert(originalComponentInformationalArtifactsCreatedOnTheInstance.containsKey("artifactTwo"));
58 private ComponentInstance buildComponentInstanceWithTwoArtifacts(){
59 ArtifactDefinition artifactFromTheOriginalResource = new ArtifactDefinition();
60 artifactFromTheOriginalResource.setArtifactLabel("artifactOne");
61 ArtifactDefinition artifactCreatedOnTheInstance = new ArtifactDefinition();
62 artifactCreatedOnTheInstance.setArtifactLabel("artifactTwo");
64 Map<String, ArtifactDefinition> componentInstanceArtifacts = new HashMap<>();
65 componentInstanceArtifacts.put(artifactFromTheOriginalResource.getArtifactLabel(), artifactFromTheOriginalResource);
66 componentInstanceArtifacts.put(artifactCreatedOnTheInstance.getArtifactLabel(), artifactCreatedOnTheInstance);
68 ComponentInstance componentInstance = new ComponentInstance();
69 componentInstance.setDeploymentArtifacts(componentInstanceArtifacts);
70 componentInstance.setArtifacts(componentInstanceArtifacts);
71 return componentInstance;
74 private Component buildOriginalComponentWithOneArtifact() {
75 ArtifactDefinition artifactFromTheOriginalResource = new ArtifactDefinition();
76 artifactFromTheOriginalResource.setArtifactLabel("artifactOne");
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;