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;
41 private Service noArtifactsService;
42 private Resource resource;
43 private Resource noArtifactsResource;
44 private ComponentInstance componentInstance;
45 private ComponentInstance noArtifactsInstance;
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();
56 ArtifactDefinition artifact1 = new ArtifactDefinition();
57 artifact1.setUniqueId("a1");
59 ArtifactDefinition artifact2 = new ArtifactDefinition();
60 artifact2.setUniqueId("a2");
62 ArtifactDefinition artifact3 = new ArtifactDefinition();
63 artifact3.setUniqueId("a3");
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);
69 resource.setDeploymentArtifacts(artifact1Map);
70 resource.setArtifacts(artifact2Map);
72 service.setDeploymentArtifacts(artifact1Map);
73 service.setArtifacts(artifact2Map);
74 service.setServiceApiArtifacts(artifact3Map);
76 componentInstance.setDeploymentArtifacts(artifact1Map);
77 componentInstance.setArtifacts(artifact2Map);
81 public void findArtifactOnComponent_noArtifactsOnComponent() throws Exception {
82 assertNull(testInstance.findArtifactOnComponent(noArtifactsResource, ComponentTypeEnum.RESOURCE, "someId"));
83 assertNull(testInstance.findArtifactOnComponent(noArtifactsService, ComponentTypeEnum.SERVICE, "someId"));
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"));
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"));
102 public void findArtifactOnInstance_instanceHasNoArtifacts() throws Exception {
103 assertNull(testInstance.findArtifactOnComponentInstance(noArtifactsInstance, "someId"));
107 public void findArtifactOnInstance() throws Exception {
108 assertNull(testInstance.findArtifactOnComponentInstance(componentInstance, "someId"));
109 assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a1"));
110 assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a2"));