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.*;
28 import java.util.Collections;
29 import java.util.HashMap;
32 import static org.junit.Assert.assertNotNull;
33 import static org.junit.Assert.assertNull;
35 public class ArtifactResolverTest {
37 private ArtifactResolverImpl testInstance = new ArtifactResolverImpl();
38 private Service service;
39 private Service noArtifactsService;
40 private Resource resource;
41 private Resource noArtifactsResource;
42 private ComponentInstance componentInstance;
43 private ComponentInstance noArtifactsInstance;
46 public void setUp() throws Exception {
47 noArtifactsService = new Service();
48 noArtifactsResource = new Resource();
49 resource = new Resource();
50 service = new Service();
51 componentInstance = new ComponentInstance();
52 noArtifactsInstance = new ComponentInstance();
54 ArtifactDefinition artifact1 = new ArtifactDefinition();
55 artifact1.setUniqueId("a1");
57 ArtifactDefinition artifact2 = new ArtifactDefinition();
58 artifact2.setUniqueId("a2");
60 ArtifactDefinition artifact3 = new ArtifactDefinition();
61 artifact3.setUniqueId("a3");
63 Map<String, ArtifactDefinition> artifact1Map = Collections.singletonMap("key1", artifact1);
64 Map<String, ArtifactDefinition> artifact2Map = Collections.singletonMap("key1", artifact2);
65 Map<String, ArtifactDefinition> artifact3Map = Collections.singletonMap("key1", artifact3);
67 resource.setDeploymentArtifacts(artifact1Map);
68 resource.setArtifacts(artifact2Map);
69 resource.setInterfaces(createInterfaceArtifact());
71 service.setDeploymentArtifacts(artifact1Map);
72 service.setArtifacts(artifact2Map);
73 service.setServiceApiArtifacts(artifact3Map);
75 componentInstance.setDeploymentArtifacts(artifact1Map);
76 componentInstance.setArtifacts(artifact2Map);
79 private Map<String, InterfaceDefinition> createInterfaceArtifact() {
80 Operation operation = new Operation();
81 ArtifactDefinition artifact4 = new ArtifactDefinition();
82 artifact4.setUniqueId("a4");
83 operation.setImplementation(artifact4);
84 HashMap<String, Operation> operationsMap = new HashMap<>();
85 operationsMap.put("operation", operation);
86 InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
87 interfaceDefinition.setOperationsMap(operationsMap);
88 Map<String, InterfaceDefinition> interfaces = new HashMap<>(1);
89 interfaces.put("someKey", interfaceDefinition);
94 public void findArtifactOnComponent_resourceInterfaceOperation() throws Exception {
95 assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId"));
96 assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a4"));
100 public void findArtifactOnComponent_noArtifactsOnComponent() throws Exception {
101 assertNull(testInstance.findArtifactOnComponent(noArtifactsResource, ComponentTypeEnum.RESOURCE, "someId"));
102 assertNull(testInstance.findArtifactOnComponent(noArtifactsService, ComponentTypeEnum.SERVICE, "someId"));
106 public void findArtifactOnComponent_resource() throws Exception {
107 assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId"));
108 assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a1"));
109 assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a2"));
113 public void findArtifactOnComponent_service() throws Exception {
114 assertNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "someId"));
115 assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a1"));
116 assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a2"));
117 assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a3"));
121 public void findArtifactOnInstance_instanceHasNoArtifacts() throws Exception {
122 assertNull(testInstance.findArtifactOnComponentInstance(noArtifactsInstance, "someId"));
126 public void findArtifactOnInstance() throws Exception {
127 assertNull(testInstance.findArtifactOnComponentInstance(componentInstance, "someId"));
128 assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a1"));
129 assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a2"));