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.
16 * Modifications copyright (c) 2019 Nokia
19 package org.onap.sdc.tosca.datatypes.model;
22 import java.io.IOException;
24 import java.io.InputStream;
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
30 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
31 import static org.hamcrest.MatcherAssert.assertThat;
33 public class ServiceTemplateTest {
35 private static final String INTERFACE_NO_OPER = "amdocs.interfaces.interfaceNoOper";
36 private static final String LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard";
37 private static final String INTERFACE_WITH_OPER = "amdocs.interfaces.interfaceWithOper";
38 public static final String NORMALIZE_INTERFACE_TYPE = "/mock/serviceTemplate/normalizeInterfaceType.yaml";
39 public static final String NEW_OPER_1 = "newOper1";
40 public static final String NEW_OPER_2 = "newOper2";
43 public void getNormalizeInterfaceTypesTest() throws IOException {
44 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
45 try (InputStream yamlFile = toscaExtensionYamlUtil
46 .loadYamlFileIs(NORMALIZE_INTERFACE_TYPE)) {
48 ServiceTemplate serviceTemplateFromYaml =
49 toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
50 Map<String, InterfaceType> normalizeInterfaceTypes = serviceTemplateFromYaml.getNormalizeInterfaceTypes();
51 Assert.assertNotNull(normalizeInterfaceTypes);
53 InterfaceType interfaceNoOper = normalizeInterfaceTypes.get(INTERFACE_NO_OPER);
54 Assert.assertNotNull(interfaceNoOper);
55 Assert.assertEquals(LIFECYCLE_STANDARD, interfaceNoOper.getDerived_from());
56 Assert.assertNull(interfaceNoOper.getOperations());
58 InterfaceType interfaceWithOper = normalizeInterfaceTypes.get(INTERFACE_WITH_OPER);
59 Assert.assertNotNull(interfaceWithOper);
60 Assert.assertEquals(LIFECYCLE_STANDARD, interfaceWithOper.getDerived_from());
61 Assert.assertNotNull(interfaceWithOper.getOperations());
62 Assert.assertEquals(2, interfaceWithOper.getOperations().size());
63 Assert.assertNull(interfaceWithOper.getOperations().get(NEW_OPER_1));
64 Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2));
65 Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2).getDescription());
71 public void shouldHaveValidGettersAndSetters() {
72 assertThat(ServiceTemplate.class,
73 hasValidGettersAndSettersExcluding("imports", "normalizeInterfaceTypes"));