/*- * ============LICENSE_START======================================================= * SDC * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ package org.openecomp.sdc.be.components.impl; import org.junit.Before; import org.junit.Test; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.Service; import java.util.Collections; import java.util.HashMap; import java.util.Map; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; public class ArtifactResolverTest { private ArtifactResolverImpl testInstance = new ArtifactResolverImpl(); private Service service; private Service noArtifactsService; private Resource resource; private Resource noArtifactsResource; private ComponentInstance componentInstance; private ComponentInstance noArtifactsInstance; @Before public void setUp() throws Exception { noArtifactsService = new Service(); noArtifactsResource = new Resource(); resource = new Resource(); service = new Service(); componentInstance = new ComponentInstance(); noArtifactsInstance = new ComponentInstance(); ArtifactDefinition artifact1 = new ArtifactDefinition(); artifact1.setUniqueId("a1"); ArtifactDefinition artifact2 = new ArtifactDefinition(); artifact2.setUniqueId("a2"); ArtifactDefinition artifact3 = new ArtifactDefinition(); artifact3.setUniqueId("a3"); Map artifact1Map = Collections.singletonMap("key1", artifact1); Map artifact2Map = Collections.singletonMap("key1", artifact2); Map artifact3Map = Collections.singletonMap("key1", artifact3); resource.setDeploymentArtifacts(artifact1Map); resource.setArtifacts(artifact2Map); resource.setInterfaces(createInterfaceArtifact()); service.setDeploymentArtifacts(artifact1Map); service.setArtifacts(artifact2Map); service.setServiceApiArtifacts(artifact3Map); componentInstance.setDeploymentArtifacts(artifact1Map); componentInstance.setArtifacts(artifact2Map); } private Map createInterfaceArtifact() { Operation operation = new Operation(); ArtifactDefinition artifact4 = new ArtifactDefinition(); artifact4.setUniqueId("a4"); operation.setImplementation(artifact4); HashMap operationsMap = new HashMap<>(); operationsMap.put("operation", operation); InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); interfaceDefinition.setOperationsMap(operationsMap); Map interfaces = new HashMap<>(1); interfaces.put("someKey", interfaceDefinition); return interfaces; } @Test public void findArtifactOnComponent_resourceInterfaceOperation() throws Exception { assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId")); assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a4")); } @Test public void findArtifactOnComponent_noArtifactsOnComponent() throws Exception { assertNull(testInstance.findArtifactOnComponent(noArtifactsResource, ComponentTypeEnum.RESOURCE, "someId")); assertNull(testInstance.findArtifactOnComponent(noArtifactsService, ComponentTypeEnum.SERVICE, "someId")); } @Test public void findArtifactOnComponent_resource() throws Exception { assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId")); assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a1")); assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a2")); } @Test public void findArtifactOnComponent_service() throws Exception { assertNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "someId")); assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a1")); assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a2")); assertNotNull(testInstance.findArtifactOnComponent(service, ComponentTypeEnum.SERVICE, "a3")); } @Test public void findArtifactOnInstance_instanceHasNoArtifacts() throws Exception { assertNull(testInstance.findArtifactOnComponentInstance(noArtifactsInstance, "someId")); } @Test public void findArtifactOnInstance() throws Exception { assertNull(testInstance.findArtifactOnComponentInstance(componentInstance, "someId")); assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a1")); assertNotNull(testInstance.findArtifactOnComponentInstance(componentInstance, "a2")); } }