UT-catalog model ModelConverter 2
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / jsontitan / utils / ModelConverterTest.java
1 /*
2
3  * Copyright (c) 2018 Huawei Intellectual Property.
4
5  *
6
7  * Licensed under the Apache License, Version 2.0 (the "License");
8
9  * you may not use this file except in compliance with the License.
10
11  * You may obtain a copy of the License at
12
13  *
14
15  *     http://www.apache.org/licenses/LICENSE-2.0
16
17  *
18
19  * Unless required by applicable law or agreed to in writing, software
20
21  * distributed under the License is distributed on an "AS IS" BASIS,
22
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
25  * See the License for the specific language governing permissions and
26
27  * limitations under the License.
28
29  */
30 package org.openecomp.sdc.be.model.jsontitan.utils;
31
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
37 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
38 import org.openecomp.sdc.be.model.Resource;
39 import org.openecomp.sdc.be.model.Service;
40 import org.openecomp.sdc.be.model.Component;
41 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
42 import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
43 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
44 import static org.assertj.core.api.Assertions.assertThat;
45 import static org.junit.Assert.assertTrue;
46
47 @RunWith(MockitoJUnitRunner.class)
48 public class ModelConverterTest {
49     @InjectMocks
50     private ModelConverter test;
51
52     @Test
53     public void testConvertToToscaElementService()
54     {
55         Service service = new Service();
56         service.setComponentType(ComponentTypeEnum.SERVICE);
57         TopologyTemplate template = test.convertToToscaElement(service);
58         assertThat(template.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE);
59     }
60
61     @Test
62     public void testConvertToToscaElementResource()
63     {
64         Resource resource = new Resource();
65         resource.setComponentType(ComponentTypeEnum.RESOURCE);
66         NodeType nodeType = test.convertToToscaElement(resource);
67         assertThat(nodeType.getToscaType()).isEqualTo(ToscaElementTypeEnum.NODE_TYPE);
68     }
69
70     @Test
71     public void testConvertFromToscaElementService()
72     {
73         TopologyTemplate topologyTemplate = new TopologyTemplate();
74         topologyTemplate.setComponentType(ComponentTypeEnum.SERVICE);
75         Component component = test.convertFromToscaElement(topologyTemplate);
76         assertThat(component.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
77     }
78
79     @Test
80     public void testConvertFromToscaElementResource()
81     {
82         TopologyTemplate topologyTemplate = new TopologyTemplate();
83         topologyTemplate.setComponentType(ComponentTypeEnum.RESOURCE);
84         Component component = test.convertFromToscaElement(topologyTemplate);
85         assertThat(component.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
86     }
87
88     @Test
89     public void testIsAtomicComponent()
90     {
91         Resource component = new Resource();
92         component.setComponentType(ComponentTypeEnum.RESOURCE);
93         boolean result = test.isAtomicComponent(component);
94         assertTrue(result);
95     }
96
97     @Test
98     public void testGetVertexType()
99     {
100         VertexTypeEnum result;
101         Resource component = new Resource();
102         component.setComponentType(ComponentTypeEnum.RESOURCE);
103         result = test.getVertexType(component);
104         assertThat(result.getName()).isEqualTo("node_type");
105     }
106 }