Added oparent to sdc main
[sdc.git] / common / onap-tosca-datatype / src / test / java / org / onap / sdc / tosca / datatypes / model / ServiceTemplateTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.sdc.tosca.datatypes.model;
18
19
20 import java.io.IOException;
21
22 import java.io.InputStream;
23 import java.util.Map;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
27
28 public class ServiceTemplateTest {
29
30     private static final String INTERFACE_NO_OPER = "amdocs.interfaces.interfaceNoOper";
31     private static final String LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard";
32     private static final String INTERFACE_WITH_OPER = "amdocs.interfaces.interfaceWithOper";
33     public static final String NORMALIZE_INTERFACE_TYPE = "/mock/serviceTemplate/normalizeInterfaceType.yaml";
34     public static final String NEW_OPER_1 = "newOper1";
35     public static final String NEW_OPER_2 = "newOper2";
36
37     @Test
38     public void getNormalizeInterfaceTypesTest() throws IOException {
39         ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
40         try (InputStream yamlFile = toscaExtensionYamlUtil
41                                             .loadYamlFileIs(NORMALIZE_INTERFACE_TYPE)) {
42
43             ServiceTemplate serviceTemplateFromYaml =
44                     toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
45             Map<String, InterfaceType> normalizeInterfaceTypes = serviceTemplateFromYaml.getNormalizeInterfaceTypes();
46             Assert.assertNotNull(normalizeInterfaceTypes);
47
48             InterfaceType interfaceNoOper = normalizeInterfaceTypes.get(INTERFACE_NO_OPER);
49             Assert.assertNotNull(interfaceNoOper);
50             Assert.assertEquals(LIFECYCLE_STANDARD, interfaceNoOper.getDerived_from());
51             Assert.assertNull(interfaceNoOper.getOperations());
52
53             InterfaceType interfaceWithOper = normalizeInterfaceTypes.get(INTERFACE_WITH_OPER);
54             Assert.assertNotNull(interfaceWithOper);
55             Assert.assertEquals(LIFECYCLE_STANDARD, interfaceWithOper.getDerived_from());
56             Assert.assertNotNull(interfaceWithOper.getOperations());
57             Assert.assertEquals(2, interfaceWithOper.getOperations().size());
58             Assert.assertNull(interfaceWithOper.getOperations().get(NEW_OPER_1));
59             Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2));
60             Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2).getDescription());
61         }
62
63     }
64 }