[sdc] rebase update
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / ArtifactResolverTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.impl;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
26 import org.openecomp.sdc.be.model.ArtifactDefinition;
27 import org.openecomp.sdc.be.model.ComponentInstance;
28 import org.openecomp.sdc.be.model.Resource;
29 import org.openecomp.sdc.be.model.Service;
30
31 import java.util.Collections;
32 import java.util.Map;
33
34 import static org.junit.Assert.assertNotNull;
35 import static org.junit.Assert.assertNull;
36
37 public class ArtifactResolverTest {
38
39     private ArtifactResolverImpl testInstance = new ArtifactResolverImpl();
40     private Service service, noArtifactsService;
41     private Resource resource, noArtifactsResource;
42     private ComponentInstance componentInstance, noArtifactsInstance;
43
44     @Before
45     public void setUp() throws Exception {
46         noArtifactsService = new Service();
47         noArtifactsResource = new Resource();
48         resource = new Resource();
49         service = new Service();
50         componentInstance = new ComponentInstance();
51         noArtifactsInstance = new ComponentInstance();
52
53         ArtifactDefinition artifact1 = new ArtifactDefinition();
54         artifact1.setUniqueId("a1");
55
56         ArtifactDefinition artifact2 = new ArtifactDefinition();
57         artifact2.setUniqueId("a2");
58
59         ArtifactDefinition artifact3 = new ArtifactDefinition();
60         artifact3.setUniqueId("a3");
61
62         Map<String, ArtifactDefinition> artifact1Map = Collections.singletonMap("key1", artifact1);
63         Map<String, ArtifactDefinition> artifact2Map = Collections.singletonMap("key1", artifact2);
64         Map<String, ArtifactDefinition> artifact3Map = Collections.singletonMap("key1", artifact3);
65
66         resource.setDeploymentArtifacts(artifact1Map);
67         resource.setArtifacts(artifact2Map);
68
69         service.setDeploymentArtifacts(artifact1Map);
70         service.setArtifacts(artifact2Map);
71         service.setServiceApiArtifacts(artifact3Map);
72
73         componentInstance.setDeploymentArtifacts(artifact1Map);
74         componentInstance.setArtifacts(artifact2Map);
75     }
76
77     @Test
78     public void findArtifactOnComponent_noArtifactsOnComponent() throws Exception {
79         assertNull(testInstance.findArtifactOnComponent(noArtifactsResource, ComponentTypeEnum.RESOURCE, "someId"));
80         assertNull(testInstance.findArtifactOnComponent(noArtifactsService, ComponentTypeEnum.SERVICE, "someId"));
81     }
82
83     @Test
84     public void findArtifactOnComponent_resource() throws Exception {
85         assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId"));
86         assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a1"));
87         assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a2"));
88     }
89
90     @Test
91     public void findArtifactOnComponent_service() throws Exception {
92         assertNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "someId"));
93         assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a1"));
94         assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a2"));
95         assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a3"));
96     }
97
98     @Test
99     public void findArtifactOnInstance_instanceHasNoArtifacts() throws Exception {
100         assertNull(testInstance.findArtifactOnComponentInstance(noArtifactsInstance, "someId"));
101     }
102
103     @Test
104     public void findArtifactOnInstance() throws Exception {
105         assertNull(testInstance.findArtifactOnComponentInstance(componentInstance, "someId"));
106         assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a1"));
107         assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a2"));
108     }
109 }