aboutsummaryrefslogtreecommitdiffstats
path: root/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java
blob: 37be2e4cfd3db77513050cbdd75a7c2435a5db32 (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
/*
 * Copyright © 2016-2018 European Support Limited
 *
 * 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.
 */

package org.onap.sdc.tosca.datatypes.model;


import java.io.IOException;

import java.io.InputStream;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;

public class ServiceTemplateTest {

    private static final String INTERFACE_NO_OPER = "amdocs.interfaces.interfaceNoOper";
    private static final String LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard";
    private static final String INTERFACE_WITH_OPER = "amdocs.interfaces.interfaceWithOper";
    public static final String NORMALIZE_INTERFACE_TYPE = "/mock/serviceTemplate/normalizeInterfaceType.yaml";
    public static final String NEW_OPER_1 = "newOper1";
    public static final String NEW_OPER_2 = "newOper2";

    @Test
    public void getNormalizeInterfaceTypesTest() throws IOException {
        ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
        try (InputStream yamlFile = toscaExtensionYamlUtil
                                            .loadYamlFileIs(NORMALIZE_INTERFACE_TYPE)) {

            ServiceTemplate serviceTemplateFromYaml =
                    toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
            Map<String, InterfaceType> normalizeInterfaceTypes = serviceTemplateFromYaml.getNormalizeInterfaceTypes();
            Assert.assertNotNull(normalizeInterfaceTypes);

            InterfaceType interfaceNoOper = normalizeInterfaceTypes.get(INTERFACE_NO_OPER);
            Assert.assertNotNull(interfaceNoOper);
            Assert.assertEquals(LIFECYCLE_STANDARD, interfaceNoOper.getDerived_from());
            Assert.assertNull(interfaceNoOper.getOperations());

            InterfaceType interfaceWithOper = normalizeInterfaceTypes.get(INTERFACE_WITH_OPER);
            Assert.assertNotNull(interfaceWithOper);
            Assert.assertEquals(LIFECYCLE_STANDARD, interfaceWithOper.getDerived_from());
            Assert.assertNotNull(interfaceWithOper.getOperations());
            Assert.assertEquals(2, interfaceWithOper.getOperations().size());
            Assert.assertNull(interfaceWithOper.getOperations().get(NEW_OPER_1));
            Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2));
            Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2).getDescription());
        }

    }
}