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.InterfaceDefinition;
29 import org.openecomp.sdc.be.model.Operation;
30 import org.openecomp.sdc.be.model.Resource;
31 import org.openecomp.sdc.be.model.Service;
33 import java.util.Collections;
34 import java.util.HashMap;
37 import static org.junit.Assert.assertNotNull;
38 import static org.junit.Assert.assertNull;
40 public class ArtifactResolverTest {
42 private ArtifactResolverImpl testInstance = new ArtifactResolverImpl();
43 private Service service;
44 private Service noArtifactsService;
45 private Resource resource;
46 private Resource noArtifactsResource;
47 private ComponentInstance componentInstance;
48 private ComponentInstance noArtifactsInstance;
51 public void setUp() throws Exception {
52 noArtifactsService = new Service();
53 noArtifactsResource = new Resource();
54 resource = new Resource();
55 service = new Service();
56 componentInstance = new ComponentInstance();
57 noArtifactsInstance = new ComponentInstance();
59 ArtifactDefinition artifact1 = new ArtifactDefinition();
60 artifact1.setUniqueId("a1");
62 ArtifactDefinition artifact2 = new ArtifactDefinition();
63 artifact2.setUniqueId("a2");
65 ArtifactDefinition artifact3 = new ArtifactDefinition();
66 artifact3.setUniqueId("a3");
68 Map<String, ArtifactDefinition> artifact1Map = Collections.singletonMap("key1", artifact1);
69 Map<String, ArtifactDefinition> artifact2Map = Collections.singletonMap("key1", artifact2);
70 Map<String, ArtifactDefinition> artifact3Map = Collections.singletonMap("key1", artifact3);
72 resource.setDeploymentArtifacts(artifact1Map);
73 resource.setArtifacts(artifact2Map);
74 resource.setInterfaces(createInterfaceArtifact());
76 service.setDeploymentArtifacts(artifact1Map);
77 service.setArtifacts(artifact2Map);
78 service.setServiceApiArtifacts(artifact3Map);
80 componentInstance.setDeploymentArtifacts(artifact1Map);
81 componentInstance.setArtifacts(artifact2Map);
84 private Map<String, InterfaceDefinition> createInterfaceArtifact() {
85 Operation operation = new Operation();
86 ArtifactDefinition artifact4 = new ArtifactDefinition();
87 artifact4.setUniqueId("a4");
88 operation.setImplementation(artifact4);
89 HashMap<String, Operation> operationsMap = new HashMap<>();
90 operationsMap.put("operation", operation);
91 InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
92 interfaceDefinition.setOperationsMap(operationsMap);
93 Map<String, InterfaceDefinition> interfaces = new HashMap<>(1);
94 interfaces.put("someKey", interfaceDefinition);
99 public void findArtifactOnComponent_resourceInterfaceOperation() throws Exception {
100 assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId"));
101 assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a4"));
105 public void findArtifactOnComponent_noArtifactsOnComponent() throws Exception {
106 assertNull(testInstance.findArtifactOnComponent(noArtifactsResource, ComponentTypeEnum.RESOURCE, "someId"));
107 assertNull(testInstance.findArtifactOnComponent(noArtifactsService, ComponentTypeEnum.SERVICE, "someId"));
111 public void findArtifactOnComponent_resource() throws Exception {
112 assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId"));
113 assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a1"));
114 assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a2"));
118 public void findArtifactOnComponent_service() throws Exception {
119 assertNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "someId"));
120 assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a1"));
121 assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a2"));
122 assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a3"));
126 public void findArtifactOnInstance_instanceHasNoArtifacts() throws Exception {
127 assertNull(testInstance.findArtifactOnComponentInstance(noArtifactsInstance, "someId"));
131 public void findArtifactOnInstance() throws Exception {
132 assertNull(testInstance.findArtifactOnComponentInstance(componentInstance, "someId"));
133 assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a1"));
134 assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a2"));