Sync Integ to Master
[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;
41     private Service noArtifactsService;
42     private Resource resource;
43     private Resource noArtifactsResource;
44     private ComponentInstance componentInstance;
45     private ComponentInstance noArtifactsInstance;
46
47     @Before
48     public void setUp() throws Exception {
49         noArtifactsService = new Service();
50         noArtifactsResource = new Resource();
51         resource = new Resource();
52         service = new Service();
53         componentInstance = new ComponentInstance();
54         noArtifactsInstance = new ComponentInstance();
55
56         ArtifactDefinition artifact1 = new ArtifactDefinition();
57         artifact1.setUniqueId("a1");
58
59         ArtifactDefinition artifact2 = new ArtifactDefinition();
60         artifact2.setUniqueId("a2");
61
62         ArtifactDefinition artifact3 = new ArtifactDefinition();
63         artifact3.setUniqueId("a3");
64
65         Map<String, ArtifactDefinition> artifact1Map = Collections.singletonMap("key1", artifact1);
66         Map<String, ArtifactDefinition> artifact2Map = Collections.singletonMap("key1", artifact2);
67         Map<String, ArtifactDefinition> artifact3Map = Collections.singletonMap("key1", artifact3);
68
69         resource.setDeploymentArtifacts(artifact1Map);
70         resource.setArtifacts(artifact2Map);
71
72         service.setDeploymentArtifacts(artifact1Map);
73         service.setArtifacts(artifact2Map);
74         service.setServiceApiArtifacts(artifact3Map);
75
76         componentInstance.setDeploymentArtifacts(artifact1Map);
77         componentInstance.setArtifacts(artifact2Map);
78     }
79
80     @Test
81     public void findArtifactOnComponent_noArtifactsOnComponent() throws Exception {
82         assertNull(testInstance.findArtifactOnComponent(noArtifactsResource, ComponentTypeEnum.RESOURCE, "someId"));
83         assertNull(testInstance.findArtifactOnComponent(noArtifactsService, ComponentTypeEnum.SERVICE, "someId"));
84     }
85
86     @Test
87     public void findArtifactOnComponent_resource() throws Exception {
88         assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId"));
89         assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a1"));
90         assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a2"));
91     }
92
93     @Test
94     public void findArtifactOnComponent_service() throws Exception {
95         assertNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "someId"));
96         assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a1"));
97         assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a2"));
98         assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a3"));
99     }
100
101     @Test
102     public void findArtifactOnInstance_instanceHasNoArtifacts() throws Exception {
103         assertNull(testInstance.findArtifactOnComponentInstance(noArtifactsInstance, "someId"));
104     }
105
106     @Test
107     public void findArtifactOnInstance() throws Exception {
108         assertNull(testInstance.findArtifactOnComponentInstance(componentInstance, "someId"));
109         assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a1"));
110         assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a2"));
111     }
112 }