2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.components.impl;
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;
31 import java.util.Collections;
34 import static org.junit.Assert.assertNotNull;
35 import static org.junit.Assert.assertNull;
37 public class ArtifactResolverTest {
39 private ArtifactResolverImpl testInstance = new ArtifactResolverImpl();
40 private Service service, noArtifactsService;
41 private Resource resource, noArtifactsResource;
42 private ComponentInstance componentInstance, noArtifactsInstance;
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();
53 ArtifactDefinition artifact1 = new ArtifactDefinition();
54 artifact1.setUniqueId("a1");
56 ArtifactDefinition artifact2 = new ArtifactDefinition();
57 artifact2.setUniqueId("a2");
59 ArtifactDefinition artifact3 = new ArtifactDefinition();
60 artifact3.setUniqueId("a3");
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);
66 resource.setDeploymentArtifacts(artifact1Map);
67 resource.setArtifacts(artifact2Map);
69 service.setDeploymentArtifacts(artifact1Map);
70 service.setArtifacts(artifact2Map);
71 service.setServiceApiArtifacts(artifact3Map);
73 componentInstance.setDeploymentArtifacts(artifact1Map);
74 componentInstance.setArtifacts(artifact2Map);
78 public void findArtifactOnComponent_noArtifactsOnComponent() throws Exception {
79 assertNull(testInstance.findArtifactOnComponent(noArtifactsResource, ComponentTypeEnum.RESOURCE, "someId"));
80 assertNull(testInstance.findArtifactOnComponent(noArtifactsService, ComponentTypeEnum.SERVICE, "someId"));
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"));
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"));
99 public void findArtifactOnInstance_instanceHasNoArtifacts() throws Exception {
100 assertNull(testInstance.findArtifactOnComponentInstance(noArtifactsInstance, "someId"));
104 public void findArtifactOnInstance() throws Exception {
105 assertNull(testInstance.findArtifactOnComponentInstance(componentInstance, "someId"));
106 assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a1"));
107 assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a2"));