aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java
blob: 18af7a035a11874eda60f5d06dcaa9ced9314a83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*-
 * ============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.Resource;
import org.openecomp.sdc.be.model.Service;

import java.util.Collections;
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<String, ArtifactDefinition> artifact1Map = Collections.singletonMap("key1", artifact1);
        Map<String, ArtifactDefinition> artifact2Map = Collections.singletonMap("key1", artifact2);
        Map<String, ArtifactDefinition> artifact3Map = Collections.singletonMap("key1", artifact3);

        resource.setDeploymentArtifacts(artifact1Map);
        resource.setArtifacts(artifact2Map);

        service.setDeploymentArtifacts(artifact1Map);
        service.setArtifacts(artifact2Map);
        service.setServiceApiArtifacts(artifact3Map);

        componentInstance.setDeploymentArtifacts(artifact1Map);
        componentInstance.setArtifacts(artifact2Map);
    }

    @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"));
    }
}