70f93649abbdf083480c971e1daae03669147c29
[sdc.git] /
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  * Modifications copyright (c) 2019 Nokia
17  */
18
19 package org.onap.sdc.tosca.datatypes.model;
20
21
22 import java.io.IOException;
23
24 import java.io.InputStream;
25 import java.util.Map;
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
29
30 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
31 import static org.hamcrest.MatcherAssert.assertThat;
32
33 public class ServiceTemplateTest {
34
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";
41
42     @Test
43     public void getNormalizeInterfaceTypesTest() throws IOException {
44         ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
45         try (InputStream yamlFile = toscaExtensionYamlUtil
46                                             .loadYamlFileIs(NORMALIZE_INTERFACE_TYPE)) {
47
48             ServiceTemplate serviceTemplateFromYaml =
49                     toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
50             Map<String, InterfaceType> normalizeInterfaceTypes = serviceTemplateFromYaml.getNormalizeInterfaceTypes();
51             Assert.assertNotNull(normalizeInterfaceTypes);
52
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());
57
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());
66         }
67
68     }
69
70     @Test
71     public void shouldHaveValidGettersAndSetters() {
72         assertThat(ServiceTemplate.class,
73                 hasValidGettersAndSettersExcluding("imports", "normalizeInterfaceTypes"));
74     }
75 }