2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.sdc.tosca.datatypes.model;
20 import java.io.IOException;
22 import java.io.InputStream;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
28 public class ServiceTemplateTest {
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";
38 public void getNormalizeInterfaceTypesTest() throws IOException {
39 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
40 try (InputStream yamlFile = toscaExtensionYamlUtil
41 .loadYamlFileIs(NORMALIZE_INTERFACE_TYPE)) {
43 ServiceTemplate serviceTemplateFromYaml =
44 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
45 Map<String, InterfaceType> normalizeInterfaceTypes = serviceTemplateFromYaml.getNormalizeInterfaceTypes();
46 Assert.assertNotNull(normalizeInterfaceTypes);
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());
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());