[SDC-29] rebase continue work to align source
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / ArtifactResolverTest.java
1 package org.openecomp.sdc.be.components.impl;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
6 import org.openecomp.sdc.be.model.ArtifactDefinition;
7 import org.openecomp.sdc.be.model.ComponentInstance;
8 import org.openecomp.sdc.be.model.Resource;
9 import org.openecomp.sdc.be.model.Service;
10
11
12 import java.util.Collections;
13 import java.util.Map;
14
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertNull;
17
18
19 public class ArtifactResolverTest {
20
21     private ArtifactResolverImpl testInstance = new ArtifactResolverImpl();
22     private Service service, noArtifactsService;
23     private Resource resource, noArtifactsResource;
24     private ComponentInstance componentInstance, noArtifactsInstance;
25
26     @Before
27     public void setUp() throws Exception {
28         noArtifactsService = new Service();
29         noArtifactsResource = new Resource();
30         resource = new Resource();
31         service = new Service();
32         componentInstance = new ComponentInstance();
33         noArtifactsInstance = new ComponentInstance();
34
35         ArtifactDefinition artifact1 = new ArtifactDefinition();
36         artifact1.setUniqueId("a1");
37
38         ArtifactDefinition artifact2 = new ArtifactDefinition();
39         artifact2.setUniqueId("a2");
40
41         ArtifactDefinition artifact3 = new ArtifactDefinition();
42         artifact3.setUniqueId("a3");
43
44         Map<String, ArtifactDefinition> artifact1Map = Collections.singletonMap("key1", artifact1);
45         Map<String, ArtifactDefinition> artifact2Map = Collections.singletonMap("key1", artifact2);
46         Map<String, ArtifactDefinition> artifact3Map = Collections.singletonMap("key1", artifact3);
47
48         resource.setDeploymentArtifacts(artifact1Map);
49         resource.setArtifacts(artifact2Map);
50
51         service.setDeploymentArtifacts(artifact1Map);
52         service.setArtifacts(artifact2Map);
53         service.setServiceApiArtifacts(artifact3Map);
54
55         componentInstance.setDeploymentArtifacts(artifact1Map);
56         componentInstance.setArtifacts(artifact2Map);
57     }
58
59     @Test
60     public void findArtifactOnComponent_noArtifactsOnComponent() throws Exception {
61         assertNull(testInstance.findArtifactOnComponent(noArtifactsResource, ComponentTypeEnum.RESOURCE, "someId"));
62         assertNull(testInstance.findArtifactOnComponent(noArtifactsService, ComponentTypeEnum.SERVICE, "someId"));
63     }
64
65     @Test
66     public void findArtifactOnComponent_resource() throws Exception {
67         assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId"));
68         assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a1"));
69         assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a2"));
70     }
71
72     @Test
73     public void findArtifactOnComponent_service() throws Exception {
74         assertNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "someId"));
75         assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a1"));
76         assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a2"));
77         assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a3"));
78     }
79
80     @Test
81     public void findArtifactOnInstance_instanceHasNoArtifacts() throws Exception {
82         assertNull(testInstance.findArtifactOnComponentInstance(noArtifactsInstance, "someId"));
83     }
84
85     @Test
86     public void findArtifactOnInstance() throws Exception {
87         assertNull(testInstance.findArtifactOnComponentInstance(componentInstance, "someId"));
88         assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a1"));
89         assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a2"));
90     }
91 }